:root {
    --mdt-red: #C00403;
    --mdt-yellow: #FECD00;
    --bg: #f5f5f5;
    --text: #222;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Poppins', -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

input, select, textarea, button {
    font-family: inherit;
}

:root {
    --sidebar-width: 250px;
    --sidebar-bg: #17181c;
    --sidebar-text: #c7c9d1;
}

/* ---------- Sidebar ---------- */

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    padding: 1.25rem 0.9rem;
    z-index: 40;
    transition: transform 0.2s ease;
}

.sidebar .brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--mdt-yellow);
    text-decoration: none;
    font-weight: 700;
    font-size: 1.15rem;
    padding: 0 0.5rem 0.85rem;
    margin-bottom: 0.35rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar .brand .mdi { font-size: 1.4rem; }

.sidebar nav {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
}

.sidebar nav::-webkit-scrollbar { width: 6px; }
.sidebar nav::-webkit-scrollbar-track { background: transparent; }
.sidebar nav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}
.sidebar nav::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.35); }

.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--sidebar-text);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.92rem;
    padding: 0.45rem 0.75rem;
    border-radius: 8px;
}

.sidebar nav a .mdi { font-size: 1.25rem; color: inherit; }

.sidebar nav a:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
}

.sidebar nav a.active {
    background: var(--mdt-red);
    color: #fff;
}

.nav-group {
    margin: 0.15rem 0;
}

.nav-group-title {
    display: flex;
    align-items: center;
    width: 100%;
    gap: 0.75rem;
    padding: 0.45rem 0.75rem;
    font-size: 0.82rem;
    font-weight: 700;
    color: #c7c9d1;
    background: none;
    border: none;
    cursor: pointer;
    border-radius: 8px;
    font-family: inherit;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-group-title span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.nav-group-title:hover { background: rgba(255, 255, 255, 0.06); }

.nav-group-title .mdi:first-child { font-size: 1.15rem; }

.nav-group-chevron {
    margin-left: auto;
    font-size: 1.1rem !important;
    transition: transform 0.15s ease;
}

.nav-group.open .nav-group-chevron { transform: rotate(180deg); }

.nav-group-body {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 0.18s ease;
}

.nav-group-body-inner {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    overflow: hidden;
    min-height: 0;
}

.nav-group.open .nav-group-body {
    grid-template-rows: 1fr;
}

.nav-sublink {
    display: flex;
    align-items: center;
    color: var(--sidebar-text);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.88rem;
    padding: 0.4rem 0.75rem 0.4rem 2.1rem;
    border-radius: 8px;
    position: relative;
}

.nav-sublink::before {
    content: '';
    position: absolute;
    left: 1rem;
    top: 50%;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.5;
    transform: translateY(-50%);
}

.nav-sublink:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
}

.nav-sublink.active {
    background: var(--mdt-red);
    color: #fff;
}

.nav-sublink.active::before { opacity: 1; }

.sidebar .logout-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--sidebar-text);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.92rem;
    padding: 0.75rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    margin-top: 0.5rem;
}

.sidebar .logout-link:hover { color: var(--mdt-yellow); }

.sidebar-toggle {
    display: none;
    position: fixed;
    top: 0.75rem;
    left: 0.75rem;
    z-index: 50;
    background: var(--sidebar-bg);
    color: #fff;
    border: none;
    border-radius: 8px;
    width: 42px;
    height: 42px;
    font-size: 1.3rem;
    cursor: pointer;
    align-items: center;
    justify-content: center;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 30;
}

.sidebar-backdrop.open { display: block; }

main {
    margin: 1.5rem auto;
    padding: 0 1.5rem;
}

body.has-sidebar main {
    margin-left: var(--sidebar-width);
    margin-right: 0;
}

@media (max-width: 880px) {
    .sidebar {
        transform: translateX(-100%);
        box-shadow: 2px 0 12px rgba(0, 0, 0, 0.3);
    }

    .sidebar.open { transform: translateX(0); }

    .sidebar-toggle { display: flex; }

    body.has-sidebar main {
        margin-left: 0;
        margin-right: 0;
        padding-top: 4rem;
    }
}

.card {
    background: #fff;
    border: 1px solid #ececec;
    border-radius: 12px;
    padding: 1.25rem;
    margin-bottom: 1.25rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

h1, h2 { margin-top: 0; }

h1 { font-size: 1.5rem; font-weight: 800; }
h2 { font-size: 1.1rem; font-weight: 700; }

/* ---------- Tables ---------- */

.table-wrap {
    overflow-x: auto;
    border: 1px solid #ececec;
    border-radius: 10px;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.qty-input {
    max-width: 100px;
}

@media (min-width: 701px) {
    .qty-cell { width: 110px; }
}

th, td {
    text-align: left;
    padding: 0.7rem 0.9rem;
    white-space: nowrap;
}

@media (max-width: 700px) {
    .table-wrap.responsive-cards {
        border: none;
        overflow-x: visible;
    }

    .table-wrap.responsive-cards table,
    .table-wrap.responsive-cards tbody,
    .table-wrap.responsive-cards tr,
    .table-wrap.responsive-cards td {
        display: block;
        width: 100%;
    }

    .table-wrap.responsive-cards thead { display: none; }

    .table-wrap.responsive-cards tr {
        background: #fff;
        border: 1px solid #ececec;
        border-radius: 10px;
        padding: 0.3rem 0.9rem;
        margin-bottom: 0.75rem;
    }

    .table-wrap.responsive-cards tr:nth-child(even) { background: #fff; }

    .table-wrap.responsive-cards td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 1rem;
        white-space: normal;
        text-align: right;
        padding: 0.6rem 0;
        border-bottom: 1px solid #f4f4f4;
    }

    .table-wrap.responsive-cards td:last-child { border-bottom: none; }

    .table-wrap.responsive-cards td::before {
        content: attr(data-label);
        font-weight: 700;
        color: #888;
        font-size: 0.72rem;
        text-transform: uppercase;
        letter-spacing: 0.06em;
        text-align: left;
    }

    .table-wrap.responsive-cards td[data-label=""]::before,
    .table-wrap.responsive-cards td:not([data-label])::before {
        content: none;
    }

    .table-wrap.responsive-cards td[colspan] {
        display: block;
        text-align: center;
        padding: 1rem 0;
    }

    .table-wrap.responsive-cards td[colspan]::before {
        content: none;
    }
}

thead th {
    background: #fafafa;
    color: #666;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 1px solid #ececec;
}

tbody tr { border-bottom: 1px solid #f1f1f1; }
tbody tr:last-child { border-bottom: none; }
tbody tr:nth-child(even) { background: #fbfbfb; }
tbody tr:hover { background: #fdf3f3; }

/* ---------- KPI cards ---------- */

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.kpi-card {
    background: #fff;
    border: 1px solid #ececec;
    border-radius: 12px;
    padding: 1.25rem;
    display: flex;
    align-items: flex-start;
    gap: 1rem;
}

.kpi-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1.3rem;
    background: rgba(192, 4, 3, 0.1);
    color: var(--mdt-red);
}

.kpi-icon.yellow { background: rgba(254, 205, 0, 0.18); color: #a67c00; }
.kpi-icon.green { background: rgba(26, 122, 26, 0.12); color: #1a7a1a; }
.kpi-icon.dark { background: rgba(23, 24, 28, 0.08); color: #17181c; }

.kpi-body { min-width: 0; }

.kpi-label {
    font-size: 0.68rem;
    color: #888;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin: 0 0 0.35rem;
}

.kpi-value {
    font-size: 1.65rem;
    font-weight: 800;
    color: var(--text);
    line-height: 1;
}

.kpi-sub {
    font-size: 0.75rem;
    color: #888;
    margin: 0.35rem 0 0;
}

/* ---------- Pagination ---------- */

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    margin-top: 1.1rem;
}

.pagination a, .pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 0.6rem;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text);
    border: 1px solid #ececec;
}

.pagination a:hover { background: #fafafa; }

.pagination .current {
    background: var(--mdt-red);
    border-color: var(--mdt-red);
    color: #fff;
}

.pagination .disabled {
    color: #ccc;
    border-color: #f1f1f1;
    cursor: default;
}

.btn {
    display: inline-block;
    background: var(--mdt-red);
    color: #fff;
    border: none;
    padding: 0.6rem 1.2rem;
    border-radius: 6px;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
}

.btn:hover { opacity: 0.9; }

.btn:disabled, .btn-loading {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
}

.btn-secondary {
    background: var(--mdt-yellow);
    color: #222;
}

input, select, textarea {
    padding: 0.5rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    width: 100%;
}

textarea {
    resize: vertical;
}

input[type="checkbox"] {
    width: 1.15rem;
    height: 1.15rem;
    accent-color: var(--mdt-red);
    cursor: pointer;
    flex-shrink: 0;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-weight: 600;
    cursor: pointer;
}

label { font-weight: 600; display: block; margin: 0.6rem 0 0.2rem; }

.stat {
    display: inline-block;
    min-width: 150px;
    margin-right: 1rem;
    margin-bottom: 0.5rem;
}

.stat .value { font-size: 1.6rem; font-weight: 800; color: var(--mdt-red); }
.stat .label { font-size: 0.85rem; color: #666; }

.alert {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    font-weight: 600;
}

.alert-success { background: #e6f7e6; color: #1a7a1a; }
.alert-danger { background: #fdeaea; color: var(--mdt-red); }

.diff-pos { color: #1a7a1a; font-weight: 700; }
.diff-neg { color: var(--mdt-red); font-weight: 700; }
.diff-zero { color: #666; }

form.inline { display: inline; }

/* ---------- Guide ---------- */

.guide-layout {
    display: flex;
    align-items: flex-start;
    gap: 1.5rem;
}

.guide-nav {
    width: 240px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    position: sticky;
    top: 1.5rem;
}

.guide-nav-link {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.55rem 0.7rem;
    border-radius: 8px;
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.88rem;
}

.guide-nav-link .mdi { font-size: 1.1rem; color: #999; flex-shrink: 0; }

.guide-nav-link:hover { background: #f5f5f5; }

.guide-nav-link.active {
    background: var(--mdt-red);
    color: #fff;
}

.guide-nav-link.active .mdi { color: #fff; }

.guide-content {
    flex: 1;
    min-width: 0;
}

.guide-content h2 { margin-top: 0; }
.guide-content h3 { margin: 1.25rem 0 0.5rem; font-size: 1rem; }
.guide-content p, .guide-content li { line-height: 1.6; }
.guide-content ul, .guide-content ol { padding-left: 1.3rem; }

.guide-pager {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 2rem;
    padding-top: 1.25rem;
    border-top: 1px solid #eee;
}

@media (max-width: 880px) {
    .guide-layout { flex-direction: column; }
    .guide-nav {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        position: static;
    }
    .guide-nav-link span { display: none; }
    .guide-nav-link { padding: 0.5rem; }
}

/* ---------- Confirm modal ---------- */

.confirm-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 100;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.confirm-modal.open { display: flex; }

.confirm-modal-box {
    background: #fff;
    border-radius: 12px;
    padding: 1.75rem;
    max-width: 400px;
    width: 100%;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
    animation: confirm-modal-in 0.15s ease;
}

@keyframes confirm-modal-in {
    from { transform: scale(0.95); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.confirm-modal-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(192, 4, 3, 0.1);
    color: var(--mdt-red);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin: 0 auto 1rem;
}

#confirm-modal-message {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text);
    margin: 0 0 1.5rem;
    line-height: 1.5;
}

.confirm-modal-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
}

.confirm-modal-actions .btn { flex: 1; }

/* ---------- Drawer ---------- */

.drawer {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 90;
}

.drawer.open { display: block; }

.drawer-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
}

.drawer-panel {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 420px;
    background: #fff;
    box-shadow: -8px 0 24px rgba(0, 0, 0, 0.15);
    padding: 1.5rem;
    overflow-y: auto;
    animation: drawer-in 0.2s ease;
}

@keyframes drawer-in {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

.drawer-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.4rem;
    color: #888;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.drawer-close:hover { background: #f5f5f5; color: var(--text); }

.drawer-body { margin-top: 1rem; }

.drawer-body h3 {
    font-size: 1.1rem;
    margin: 0 0 1rem;
}

.drawer-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 0;
    border-bottom: 1px solid #f1f1f1;
    font-size: 0.9rem;
}

.drawer-row:last-child { border-bottom: none; }
.drawer-row .label { color: #888; font-weight: 600; }
.drawer-row .value { font-weight: 700; }

.drawer-section-title {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #888;
    margin: 1.25rem 0 0.4rem;
}
