/* ANM movement pages — matching the existing rounded-card UI */
.movement-page {
    width: min(96%, 1200px);
    margin: 22px auto 35px;
    box-sizing: border-box;
}
.movement-card {
    width: 100%;
    padding: 26px;
    box-sizing: border-box;
    background: #fff;
    color: #111827;
    border-radius: 26px;
    box-shadow: 0 10px 30px rgba(0,0,0,.10);
}
.movement-heading, .history-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}
.movement-heading { margin-bottom: 22px; }
.movement-heading h2, .history-heading h2 {
    margin: 0;
    font-size: 26px;
    font-weight: 700;
}
.movement-heading p {
    margin: 6px 0 0;
    color: #6b7280;
    font-size: 14px;
}
.movement-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px 18px;
}
.movement-grid label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    font-weight: 600;
}
.movement-grid input:not([type="radio"]), .movement-grid select, .movement-grid textarea,
.history-filters input, .history-filters select {
    width: 100%;
    min-width: 0;
    margin: 7px 0;
    padding: 13px 14px;
    box-sizing: border-box;
    border: 1px solid #d1d5db;
    border-radius: 13px;
    background: #fff;
    color: #111827;
    font: inherit;
}
.movement-grid input:focus, .movement-grid select:focus, .movement-grid textarea:focus,
.history-filters input:focus, .history-filters select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.movement-grid textarea { resize: vertical; min-height: 82px; }
.field-full { grid-column: 1 / -1; }
.model-suggest-wrap { position: relative; }
.model-suggestions {
    position: absolute;
    z-index: 20;
    top: calc(100% - 3px);
    left: 0;
    right: 0;
    max-height: 220px;
    overflow-y: auto;
    border: 1px solid #d1d5db;
    border-radius: 0 0 12px 12px;
    background: #fff;
    box-shadow: 0 8px 18px rgba(0,0,0,.14);
}
.model-suggestions[hidden] { display: none !important; }
.model-suggestion {
    display: block;
    width: 100%;
    margin: 0;
    padding: 10px 13px;
    border: 0;
    border-bottom: 1px solid #e5e7eb;
    border-radius: 0;
    background: transparent;
    color: #111827;
    text-align: left;
    font: inherit;
    cursor: pointer;
}
.model-suggestion:last-child { border-bottom: 0; }
.model-suggestion:hover, .model-suggestion:focus { background: #eff6ff; outline: none; }
.model-suggestion-empty { padding: 10px 13px; color: #6b7280; font-size: 13px; }
html.dark .model-suggestions { background: var(--card); border-color: var(--border); }
html.dark .model-suggestion { color: var(--text); border-color: var(--border); }
html.dark .model-suggestion:hover, html.dark .model-suggestion:focus { background: #30343b; }
html.dark .model-suggestion-empty { color: #9ca3af; }
.movement-toggle {
    display: flex;
    gap: 10px;
    margin: 7px 0;
}
.radio-option { flex: 1; cursor: pointer; margin: 0 !important; }
.radio-option input { position: absolute; opacity: 0; pointer-events: none; }
.radio-option span {
    min-height: 46px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #d1d5db;
    border-radius: 13px;
    background: #f9fafb;
    font-weight: 700;
}
.radio-option input:checked + span {
    color: #fff;
    background: var(--primary);
    border-color: var(--primary);
}

.movement-toggle .radio-option:has(input[value="Inward"]:checked) span {
    background: #cfe3d3;
    border-color: #a9c9b0;
    color: #284d34;
}

.movement-toggle .radio-option:has(input[value="Outward"]:checked) span {
    background: #edcfcc;
    border-color: #dcaeaa;
    color: #733a35;
}
.movement-actions {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 22px;
}
.movement-actions button, .small-btn {
    width: auto;
    min-width: 150px;
    margin: 0;
    padding: 12px 18px;
    border: 0;
    border-radius: 13px;
    background: var(--primary);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
}
.movement-actions .secondary, .small-btn.secondary, .page-btn {
    background: #6b7280;
    color: #fff;
}
.small-btn { min-width: 0; padding: 10px 14px; white-space: nowrap; }
#formStatus, #historyStatus { min-height: 18px; margin: 10px 0 0; font-size: 13px; color: #6b7280; }
.history-section { margin-top: 24px; }
.history-heading { margin-bottom: 12px; }
.history-heading h2 { font-size: 23px; }
#rowCount { color: #6b7280; font-size: 13px; font-weight: 600; }
.history-filters {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) 170px 155px 155px;
    gap: 8px;
    margin-bottom: 10px;
}
.history-filters input, .history-filters select { margin: 0; }
.history-filters .date-filter-group { display: contents; }
.table-wrapper {
    width: 100%;
    overflow: auto;
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 7px 22px rgba(0,0,0,.06);
}
#movementTable { width: 100%; min-width: 1000px; border-collapse: collapse; font-size: 13px; }
#movementTable th {
    padding: 12px;
    background: #f3f4f6;
    color: #374151;
    text-align: left;
    white-space: nowrap;
    border-bottom: 1px solid #e5e7eb;
}
#movementTable td {
    padding: 11px 12px;
    border-bottom: 1px solid #e5e7eb;
    vertical-align: top;
}
#movementTable tbody tr:hover { background: #f8fafc; }
.movement-badge { display: inline-block; padding: 4px 8px; border-radius: 8px; font-weight: 700; }
.movement-badge.inward { background: #dcfce7; color: #166534; }
.movement-badge.outward { background: #fee2e2; color: #991b1b; }
.row-action {
    width: auto;
    margin: 2px;
    padding: 6px 9px;
    border: 0;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    cursor: pointer;
}
.row-action.delete { background: #dc2626; }
.movement-cards { display: none; }
.pagination { display: flex; justify-content: center; align-items: center; gap: 10px; margin: 14px 0; }
.page-btn { width: auto !important; margin: 0 !important; padding: 8px 12px !important; border: 0; border-radius: 9px; cursor: pointer; }
#pageNo { min-width: 25px; text-align: center; font-weight: 700; }
html.dark .movement-card { background: var(--card); color: var(--text); box-shadow: 0 10px 30px rgba(0,0,0,.3); }
html.dark .movement-heading p, html.dark #rowCount, html.dark #formStatus, html.dark #historyStatus { color: #9ca3af; }
html.dark .movement-grid input:not([type="radio"]), html.dark .movement-grid select, html.dark .movement-grid textarea,
html.dark .history-filters input, html.dark .history-filters select {
    background: var(--card); color: var(--text); border-color: var(--border);
}
html.dark .radio-option span { background: #30343b; border-color: var(--border); color: var(--text); }
html.dark .radio-option input:checked + span { background: var(--primary); color: #fff; }
html.dark .movement-toggle .radio-option:has(input[value="Inward"]:checked) span {
    background: #294334; border-color: #3f604b; color: #c9e3d0;
}
html.dark .movement-toggle .radio-option:has(input[value="Outward"]:checked) span {
    background: #4a302e; border-color: #69413e; color: #f0cfca;
}
html.dark .table-wrapper { background: var(--card); border-color: var(--border); }
html.dark #movementTable th { background: #30343b; color: var(--text); border-color: var(--border); }
html.dark #movementTable td { color: var(--text); border-color: var(--border); }
html.dark #movementTable tbody tr:hover { background: #252a31; }
@media (max-width: 768px) {
    .movement-page { width: 96%; margin: 16px auto 25px; }
    .movement-card { padding: 20px; border-radius: 23px; }
    .movement-heading h2 { font-size: 23px; }
    .movement-grid { grid-template-columns: 1fr; gap: 10px; }
    .field-full { grid-column: 1; }
    .movement-actions { flex-direction: column; }
    .movement-actions button { width: 100%; }
    .history-heading { flex-direction: column; align-items: flex-start; }
    .history-filters { grid-template-columns: 1fr 1fr; }
    .history-filters input[type="search"] { grid-column: 1 / -1; }
    .table-wrapper { display: none; }
    .movement-cards { display: block; }
    .movement-cards .card {
        margin-bottom: 10px; padding: 14px; border-radius: 16px;
        background: #fff; box-shadow: 0 5px 18px rgba(0,0,0,.08);
        overflow-wrap: anywhere;
    }
    .movement-cards .card h3 { margin: 0 0 8px; font-size: 16px; }
    .movement-cards .card p { margin: 5px 0; font-size: 13px; }
    html.dark .movement-cards .card { background: var(--card); color: var(--text); }
}
@media (max-width: 360px) {
    .movement-card { padding: 16px; }
    .movement-heading { align-items: flex-start; }
    .movement-heading h2 { font-size: 20px; }
    .history-filters { gap: 6px; }
}

/* Hide the entry form until New Entry is clicked */
#movementForm[hidden] {
    display: none !important;
}

/* New Entry and Refresh buttons */
.heading-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}

.heading-actions button {
    width: auto;
    min-width: 110px;
    margin: 0;
    padding: 11px 16px;
    border: none;
    border-radius: 12px;
    background: var(--primary);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
}

/* Close Form button */
#closeFormBtn {
    background: #6b7280;
    color: #fff;
}

/* Disabled pagination buttons */
.page-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Mobile layout */
@media (max-width: 600px) {
    .movement-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .heading-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .heading-actions button {
        flex: 1;
        min-width: 0;
    }
}


/* Fill more of the available screen */
.movement-page {
    width: calc(100% - 40px);
    max-width: 1600px;
    margin: 20px auto 30px;
}

/* Make the heading card more compact */
.movement-card {
    padding: 16px 20px;
}

.movement-card:first-child .movement-heading {
    margin-bottom: 8px;
}

.movement-card:first-child .movement-heading p {
    margin-top: 3px;
}

/* Use full available width for movement history */
.history-section {
    width: 100%;
    margin-top: 24px;
}

/* Keep filters spread across the page */
.history-filters {
    display: grid;
    grid-template-columns: minmax(250px, 1fr) 180px 170px 170px;
    gap: 10px;
    width: 100%;
    margin-bottom: 16px;
}

/* Table scrolls horizontally when columns need more space */
.table-wrapper {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: auto;
    max-height: 65vh;
    border-radius: 16px;
    scrollbar-width: thin;
}

/* Wider table with readable columns */
#movementTable {
    width: 100%;
    min-width: 1150px;
    border-collapse: separate;
    border-spacing: 0;
    table-layout: auto;
    font-size: 13px;
}

/* Keep table headings visible while scrolling vertically */
#movementTable thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #f3f4f6;
}

/* Avoid unnecessarily narrow cells */
#movementTable th,
#movementTable td {
    padding: 12px;
    vertical-align: top;
}

#movementTable th:last-child,
#movementTable td:last-child {
    min-width: 125px;
    white-space: nowrap;
}

/* Avoid empty-looking rows and allow long text to wrap */
#movementTable td {
    overflow-wrap: anywhere;
}

/* Keep pagination below the scrollable table */
.pagination {
    margin: 16px 0 25px;
}

/* Larger screens */
@media (min-width: 1500px) {
    .movement-page {
        max-width: 1700px;
    }

    #movementTable {
        min-width: 100%;
    }
}

/* Tablet and mobile */
@media (max-width: 768px) {
    .movement-page {
        width: calc(100% - 20px);
        margin: 12px auto 20px;
    }

    .movement-card {
        padding: 18px;
    }

    .history-filters {
        grid-template-columns: max-content repeat(2, minmax(0, 1fr));
    }

    .history-filters input[type="search"] {
        grid-column: 1 / -1;
    }

    /* Keep the table scrollable on mobile too */
    .table-wrapper {
        display: block;
        max-height: 60vh;
    }

    #movementTable {
        min-width: 1050px;
    }

    /* Hide cards when using the scrollable table */
    .movement-cards {
        display: none;
    }
}

@media (max-width: 420px) {
    .history-filters {
        grid-template-columns: 1fr;
    }

    .history-filters input[type="search"] {
        grid-column: auto;
    }
}

/* Phone layout: keep the full workflow usable without horizontal scrolling. */
@media (max-width: 600px) {
    .movement-card:first-child {
        padding: 10px 12px;
    }

    .movement-heading {
        margin-bottom: 7px;
        gap: 6px;
    }

    .movement-heading p {
        margin-top: 2px;
        line-height: 1.2;
    }

    .movement-heading h2 {
        font-size: 19px;
        line-height: 1.15;
    }

    .movement-card:first-child {
        padding: 8px 12px;
    }

    .movement-heading {
        margin-bottom: 0;
        gap: 4px;
    }

    .movement-heading > div:first-child p {
        margin-bottom: 0;
    }

    .movement-heading > div:first-child {
        margin: 0;
    }

    .movement-page {
        width: 100%;
        margin: 8px auto 20px;
        padding: 0 10px;
    }

    .movement-card {
        padding: 12px 14px;
        border-radius: 18px;
    }

    .movement-heading {
        gap: 12px;
        margin-bottom: 16px;
    }

    .movement-heading h2 { font-size: 21px; line-height: 1.2; }
    .movement-heading p { font-size: 13px; }

    .heading-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .heading-actions button {
        min-height: 44px;
        padding: 10px 8px;
        font-size: 14px;
    }

    .movement-grid { gap: 8px; }
    .movement-grid label { margin-bottom: 3px; font-size: 13px; }
    .movement-grid input:not([type="radio"]),
    .movement-grid select,
    .movement-grid textarea,
    .history-filters input,
    .history-filters select {
        min-height: 46px;
        margin: 4px 0 8px;
        padding: 11px 12px;
        border-radius: 11px;
        font-size: 16px;
    }

    .movement-grid textarea { min-height: 88px; }
    .movement-toggle { gap: 8px; }
    .radio-option span { min-height: 48px; border-radius: 11px; }

    .movement-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        margin-top: 12px;
    }

    .movement-actions button {
        min-width: 0;
        min-height: 44px;
        padding: 10px;
        border-radius: 11px;
    }

    .movement-actions #saveBtn { grid-column: 1 / -1; }
    .history-section { margin-top: 16px; }
    .history-heading {
        flex-direction: row;
        align-items: center;
        margin: 0 2px 10px;
    }
    .history-heading h2 { font-size: 19px; }
    #rowCount { white-space: nowrap; font-size: 12px; }

    .history-filters {
        grid-template-columns: minmax(0, 1fr) max-content;
        grid-template-rows: auto auto;
        gap: 7px;
        margin-bottom: 10px;
    }
    .history-filters input[type="search"] {
        grid-column: 1;
        grid-row: 1;
        height: 46px;
        min-height: 46px;
        margin: 0;
        box-sizing: border-box;
    }
    .history-filters select {
        grid-column: 2;
        grid-row: 1;
        align-self: center;
        width: auto;
        min-width: max-content;
        height: 46px;
        min-height: 46px;
        margin: 0;
        padding: 8px 23px 8px 9px;
        box-sizing: border-box;
        font-size: 13px;
        white-space: nowrap;
    }
    .history-filters .date-filter-group {
        grid-column: 1 / -1;
        grid-row: 2;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 7px;
        width: 100%;
        min-width: 0;
    }
    .history-filters .date-filter-group input[type="date"] {
        width: 100%;
        min-width: 0;
        min-height: 40px;
        margin: 0;
        padding: 8px 9px;
        font-size: 13px;
    }
    .history-filters input,
    .history-filters select { min-width: 0; }

    .table-wrapper { display: none; }
    .movement-cards { display: block; }
    .movement-cards .card {
        margin: 0 0 9px;
        padding: 14px;
        border: 1px solid #e5e7eb;
        border-radius: 15px;
        background: #fff;
        box-shadow: 0 3px 12px rgba(0,0,0,.06);
        overflow-wrap: anywhere;
    }
    .movement-cards .card h3 { margin: 0 0 7px; font-size: 16px; }
    .movement-cards .card p { margin: 5px 0; font-size: 13px; line-height: 1.4; }
    .movement-cards .row-action { min-height: 38px; padding: 8px 12px; }

    .pagination { gap: 12px; margin: 12px 0 5px; }
    .pagination .page-btn { min-height: 40px; padding: 8px 12px !important; }

    html.dark .movement-cards .card {
        background: var(--card);
        color: var(--text);
        border-color: var(--border);
    }
}

@media (max-width: 360px) {
    .movement-page { padding: 0 7px; }
    .movement-card { padding: 14px 11px; }
    .movement-heading h2 { font-size: 19px; }
    .history-heading h2 { font-size: 17px; }
    .history-filters {
        grid-template-columns: minmax(0, 1fr) max-content;
        gap: 5px;
    }
    .history-filters input[type="search"] { grid-column: 1; }
    .history-filters select {
        width: auto;
        min-height: 38px;
        padding: 7px 24px 7px 9px;
        font-size: 13px;
    }
    .history-filters .date-filter-group { gap: 5px; }
    .history-filters .date-filter-group input[type="date"] { min-height: 38px; padding: 7px; }
}
