:root {
    --bg-body: #121212;
    --bg-container: #1e1e1e;
    --text-main: #e0e0e0;
    --text-muted: #aaaaaa;
    --border-color: #333333;
    --primary: #1a73e8;
    --primary-light: #66b2ff;
    --header-bg: #1f1f1f;
    --select-bg: #2c2c2c;
    --select-border: #444444;
    --table-header-bg: #2c2c2c;
    --row-border: #333333;
    --btn-qty-bg: #333333;
    --btn-qty-text: #e0e0e0;
    --alert-color: #ef5350;
    --note-bg: #2d2610;
    --note-border: #fbbc04;
    --note-text: #ffd54f;
    --input-bg: #2c2c2c;
    --btn-success: #2e7d32;
    --btn-warning: #f57f17;
    --btn-warning-text: #ffffff;
}

body {
    font-family: 'Segoe UI', Tahoma, sans-serif;
    padding: 0;
    margin: 0;
    background-color: var(--bg-body);
    color: var(--text-main);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.container {
    width: calc(100% - 40px);
    max-width: 600px;
    box-sizing: border-box;
    margin: 20px auto;
    background: var(--bg-container);
    padding: 20px;
    border-radius: 15px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    flex: 1;
}

header {
    background: var(--header-bg);
    color: var(--text-main);
    padding: 20px;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
}

header h1 {
    margin: 0;
    font-size: 1.5rem;
    text-transform: uppercase;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
}

header p {
    margin: 5px 0 0;
    opacity: 0.9;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.main-select-group {
    margin-bottom: 15px;
    text-align: center;
    background: var(--select-bg);
    padding: 15px;
    border-radius: 10px;
    border: 1px solid var(--select-border);
}

select#mainLocation {
    padding: 12px;
    font-size: 16px;
    border-radius: 8px;
    width: 100%;
    max-width: 300px;
    border: 1px solid var(--primary);
    outline: none;
    cursor: pointer;
    background: var(--bg-container);
    color: var(--text-main);
}

/* Style cho mấy dòng gạch ngang trong menu */
select#mainLocation option[disabled] {
    color: var(--text-muted);
    font-weight: bold;
    background-color: var(--border-color);
}

#statusUpdate:not(:empty) {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-container);
    padding: 20px 30px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5), 0 0 0 9999px rgba(0, 0, 0, 0.7);
    z-index: 10000;
    font-size: 16px;
    font-weight: bold;
    text-align: center;
    min-width: 250px;
    max-width: 80%;
    animation: scaleIn 0.3s ease-out forwards;
    border: 2px solid currentColor;
    color: var(--primary-light);
}

#statusUpdate:empty {
    display: none;
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: translate(-50%, -60%) scale(0.9);
    }

    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

table {
    width: 100%;
    border-collapse: collapse;
    color: var(--text-main);
}

td {
    border-bottom: 1px solid var(--row-border);
    padding: 12px 10px;
}

.table-header-row td {
    background-color: var(--table-header-bg);
    font-weight: bold;
    color: var(--text-muted);
    font-size: 0.85rem;
    text-transform: uppercase;
    border-bottom: 2px solid var(--primary);
    text-align: center;
}

.desc-cell {
    word-wrap: break-word;
    overflow-wrap: break-word;
    color: var(--text-main);
    line-height: 1.4;
}

.item-name {
    display: block;
    font-weight: 600;
    font-size: 1rem;
    color: #ffffff;
}

.item-note {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: normal;
    margin-top: 2px;
    font-style: italic;
}

.item-last-updated {
    display: block;
    font-size: 0.75rem;
    color: #757575;
    font-weight: normal;
    margin-top: 4px;
    font-style: italic;
}

.desc-input {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    box-sizing: border-box;
    background: var(--input-bg);
    color: var(--text-main);
}

.counter-group {
    display: flex;
    align-items: center;
    gap: 15px;
    justify-content: flex-end;
}

.btn-qty {
    background: var(--btn-qty-bg);
    color: var(--btn-qty-text);
    border: none;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.qty-val {
    font-weight: bold;
    min-width: 30px;
    text-align: center;
    color: var(--primary-light);
    font-size: 1.1rem;
}

.btn-add-row {
    display: none;
    margin: 15px auto;
    padding: 8px 20px;
    background: var(--bg-container);
    color: var(--primary-light);
    border: 2px dashed var(--primary-light);
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
}

.btn-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 20px;
}

.sticky-save-btn {
    position: sticky;
    bottom: 20px;
    z-index: 100;
}

.btn {
    padding: 15px;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: 0.3s;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.btn-continue {
    background: var(--primary);
    color: white;
}

footer {
    text-align: center;
    padding: 15px;
    color: var(--text-muted);
    font-size: 0.85rem;
    background: var(--bg-container);
    border-top: 1px solid var(--border-color);
}

@media screen and (max-width: 480px) {
    body:not(.exporting) #myTable .table-header-row {
        display: none;
    }

    body:not(.exporting) #myTable tr {
        display: grid;
        grid-template-columns: 30px auto 1fr;
        align-items: center;
        padding: 10px 0;
        border-bottom: 2px solid var(--border-color);
    }

    body:not(.exporting) #myTable td {
        border: none;
        padding: 5px 0;
        width: auto;
        text-align: left;
    }

    body:not(.exporting) #myTable td:nth-child(1) {
        grid-column: 1;
        grid-row: 1;
        padding-right: 5px;
        text-align: center;
    }

    body:not(.exporting) #myTable td:nth-child(2) {
        grid-column: 2 / 4;
        grid-row: 1;
    }

    body:not(.exporting) #myTable td:nth-child(3) {
        grid-column: 2;
        grid-row: 2;
        padding-right: 10px;
    }

    body:not(.exporting) #myTable td:nth-child(3):last-child {
        grid-column: 2 / 4;
    }

    body:not(.exporting) #myTable td:nth-child(4) {
        grid-column: 3;
        grid-row: 2;
    }

    body:not(.exporting) #myTable .counter-group {
        justify-content: flex-end;
    }
}

.stt-cell {
    width: 40px;
    text-align: center;
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: bold;
}

.extra-note-container {
    margin-top: 20px;
    background: var(--note-bg);
    padding: 15px;
    border-radius: 10px;
    border: 1px dashed var(--note-border);
}

.extra-note-container label {
    display: block;
    font-weight: bold;
    margin-bottom: 8px;
    color: var(--note-text);
}

#extraNoteText {
    resize: vertical;
    min-height: 80px;
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--note-border);
    box-sizing: border-box;
    font-family: inherit;
    background: var(--input-bg);
    color: var(--text-main);
}

.tabs-nav {
    display: flex;
    background-color: var(--bg-dark);
    border-radius: 12px;
    padding: 6px;
    margin-bottom: 25px;
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.5);
}

.tab-btn {
    flex: 1;
    padding: 12px;
    background: transparent;
    color: var(--text-muted);
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tab-btn:hover {
    color: #fff;
}

.tab-btn.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 12px rgba(26, 115, 232, 0.4);
}

.history-day-group {
    margin-bottom: 20px;
}

.history-date {
    font-weight: bold;
    font-size: 1.1rem;
    color: var(--text-main);
    margin-bottom: 10px;
    padding-bottom: 5px;
    border-bottom: 1px solid var(--border-color);
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 10px;
    border-bottom: 1px solid var(--row-border);
    background: var(--select-bg);
    margin-bottom: 5px;
    border-radius: 8px;
}

.history-item-info {
    flex: 1;
}

.history-loc {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.history-name {
    font-weight: bold;
    color: #fff;
    margin: 3px 0;
}

.history-diff {
    font-weight: bold;
    font-size: 1.2rem;
    min-width: 50px;
    text-align: right;
    margin-right: 15px;
}

.history-diff.positive {
    color: #81c995;
}

.history-diff.negative {
    color: #f28b82;
}

.history-note-btn {
    background: transparent;
    border: 1px solid var(--primary-light);
    color: var(--primary-light);
    padding: 5px 10px;
    border-radius: 5px;
    font-size: 0.8rem;
    cursor: pointer;
    margin-top: 5px;
}

.history-note-text {
    display: block;
    font-size: 0.85rem;
    color: #ffd54f;
    font-style: italic;
    margin-top: 5px;
}

/* ---- MODAL STYLES ---- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10001;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
    padding: 15px;
    box-sizing: border-box;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-card {
    background: #1e1e1e;
    border: 1px solid #333333;
    border-radius: 16px;
    width: 100%;
    max-width: 520px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
    overflow: hidden;
    transform: scale(0.92);
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.modal-overlay.active .modal-card {
    transform: scale(1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #2a2a2a;
    background: #252525;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.15rem;
    color: #ffffff;
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-close-btn {
    background: transparent;
    border: none;
    color: #888888;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 5px;
    transition: color 0.2s;
}

.modal-close-btn:hover {
    color: #ffffff;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
}

.modal-footer {
    display: flex;
    gap: 10px;
    padding: 15px 20px;
    border-top: 1px solid #2a2a2a;
    background: #252525;
    justify-content: flex-end;
    align-items: center;
}

.modal-item-subtitle {
    font-size: 0.95rem;
    margin-bottom: 12px;
    line-height: 1.4;
}

.note-modal-label {
    color: #66b2ff;
    font-weight: 600;
}

.note-modal-val {
    color: #ffffff;
    font-weight: 500;
}

.modal-footer-balanced {
    display: flex;
    gap: 12px;
    width: 100%;
    box-sizing: border-box;
}

.modal-footer-balanced .modal-btn {
    flex: 1;
    text-align: center;
    padding: 12px 18px;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-textarea {
    width: 100%;
    min-height: 90px;
    background: #121212;
    color: #e0e0e0;
    border: 1px solid #3d3d3d;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 0.95rem;
    box-sizing: border-box;
    resize: vertical;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}

.modal-textarea:focus {
    border-color: #1a73e8;
}

.quick-tags-container {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.quick-tags-label {
    font-size: 0.8rem;
    color: #888888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.quick-tags-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.quick-tag-chip {
    background: #2a2a2a;
    border: 1px solid #404040;
    color: #e0e0e0;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
}

.quick-tag-chip:hover {
    background: #333333;
    border-color: #66b2ff;
    color: #ffffff;
}

.modal-btn {
    padding: 10px 18px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
}

.modal-btn-cancel {
    background: #333333;
    color: #cccccc;
}

.modal-btn-cancel:hover {
    background: #444444;
    color: #ffffff;
}

.modal-btn-save {
    background: #1a73e8;
    color: #ffffff;
}

.modal-btn-save:hover {
    background: #1557b0;
}

/* ---- HISTORY TOOLBAR ---- */
.history-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    justify-content: space-between;
    background: var(--select-bg);
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid var(--select-border);
    margin-bottom: 15px;
}

.history-filter-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 170px;
}

.history-month-select {
    padding: 8px 12px;
    font-size: 0.9rem;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: var(--bg-container);
    color: var(--text-main);
    cursor: pointer;
    outline: none;
    width: 100%;
    max-width: 220px;
}

.history-month-select:focus {
    border-color: var(--primary);
}

.btn-export-monthly {
    background: linear-gradient(135deg, #1e88e5, #1565c0);
    color: #ffffff;
    border: none;
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: opacity 0.2s;
    white-space: nowrap;
}

.btn-export-monthly:hover {
    opacity: 0.9;
}

/* ---- MONTHLY REPORT MODAL ---- */
.report-stat-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 12px;
}

.report-stat-card {
    background: #181818;
    border: 1px solid #333333;
    border-radius: 8px;
    padding: 8px 4px;
    text-align: center;
}

.report-stat-card .stat-val {
    font-size: 1.25rem;
    font-weight: bold;
    margin-bottom: 2px;
}

.report-stat-card .stat-label {
    font-size: 0.72rem;
    color: #aaaaaa;
    white-space: nowrap;
}

.report-table-container {
    max-height: 340px;
    overflow-y: auto;
    border: 1px solid #333333;
    border-radius: 8px;
    margin-bottom: 15px;
    background: #141414;
    padding: 6px;
}

/* Kiểu hiển thị danh sách thẻ giao dịch tháng cực kỳ tối ưu cho mobile & desktop */
.report-item-card {
    background: #1c1c1c;
    border: 1px solid #2d2d2d;
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 6px;
    transition: background 0.15s;
}

.report-item-card:hover {
    background: #242424;
}

.report-item-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 5px;
}

.report-item-name {
    font-weight: 600;
    color: #ffffff;
    font-size: 0.95rem;
    line-height: 1.35;
    word-break: break-word;
}

.report-item-diff {
    font-weight: bold;
    font-size: 1.15rem;
    white-space: nowrap;
}

.report-item-diff.positive {
    color: #81c995;
}

.report-item-diff.negative {
    color: #f28b82;
}

.report-item-diff.purchased {
    color: #4ade80;
}

.report-item-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 10px;
    font-size: 0.78rem;
    color: #888888;
}

.report-type-badge {
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 0.72rem;
    font-weight: 500;
}

.report-type-badge.purchased {
    background: #1b432a;
    color: #4ade80;
}

.report-type-badge.other {
    background: #2b2b2b;
    color: #cccccc;
}

.report-item-note {
    margin-top: 6px;
    padding-top: 5px;
    border-top: 1px dashed #2d2d2d;
    font-size: 0.82rem;
    color: #ffd54f;
    line-height: 1.35;
    word-break: break-word;
}

.report-export-buttons {
    display: flex;
    gap: 8px;
    width: 100%;
}

.btn-export-xlsx {
    flex: 1;
    background: #2e7d32;
    color: white;
    padding: 10px 8px;
    border-radius: 8px;
    font-weight: bold;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    font-size: 0.9rem;
    transition: background 0.2s;
    white-space: nowrap;
}

.btn-export-xlsx:hover {
    background: #256628;
}

.btn-export-img {
    flex: 1;
    background: #1976d2;
    color: white;
    padding: 10px 8px;
    border-radius: 8px;
    font-weight: bold;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    font-size: 0.9rem;
    transition: background 0.2s;
    white-space: nowrap;
}

.btn-export-img:hover {
    background: #1565c0;
}

@media (max-width: 500px) {
    .modal-header h3 {
        font-size: 1rem;
    }
    .modal-header {
        padding: 12px 16px;
    }
    .modal-body {
        padding: 12px;
    }
    .history-toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    .history-month-select {
        max-width: 100%;
    }
    .btn-export-monthly {
        justify-content: center;
    }
    .report-stat-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    .report-export-buttons {
        flex-direction: row;
    }
}
