:root {
    --bg: #f5f7fb;
    --card: #ffffff;
    --line: #e6ebf2;
    --text: #152033;
    --muted: #667085;
    --primary: #0b72b5;
    --primary-soft: #e8f4fb;
    --danger: #cf3f4f;
    --success: #198754;
    --warning: #f59e0b;
    --dark: #0d1829;
    --shadow: 0 12px 28px rgba(16, 24, 40, 0.08);
    --radius: 20px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: 'Figtree', sans-serif;
    background: var(--bg);
    color: var(--text);
}
a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; }

.login-body {
    min-height: 100vh;
    background:
        radial-gradient(circle at top left, rgba(11,114,181,0.12), transparent 35%),
        radial-gradient(circle at bottom right, rgba(25,135,84,0.12), transparent 35%),
        var(--bg);
}
.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}
.login-card {
    width: 100%;
    max-width: 480px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 30px;
    box-shadow: var(--shadow);
    padding: 30px;
}
.login-card h1 { margin: 12px 0 8px; }
.login-card p { margin: 0 0 16px; color: var(--muted); }

.app-shell {
    min-height: 100vh;
    display: flex;
}
.sidebar {
    width: 290px;
    background: linear-gradient(180deg, #0d1829 0%, #13233c 100%);
    color: #fff;
    padding: 22px;
    position: sticky;
    top: 0;
    height: 100vh;
    transition: transform 0.25s ease;
    z-index: 50;
}
.sidebar-top {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 26px;
}
.brand-mark {
    width: 52px;
    height: 52px;
    border-radius: 18px;
    display: grid;
    place-items: center;
    font-weight: 800;
    background: rgba(255,255,255,0.14);
}
.brand-title { font-size: 19px; font-weight: 800; }
.brand-subtitle { font-size: 13px; color: rgba(255,255,255,0.72); }

.sidebar-nav { display: grid; gap: 10px; }
.nav-heading {
    color: rgba(255,255,255,0.6);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-top: 10px;
}
.nav-link,
.nav-sublink,
.nav-toggle {
    width: 100%;
    border: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: 16px;
    padding: 14px 16px;
    background: transparent;
    color: rgba(255,255,255,0.84);
    cursor: pointer;
    text-align: left;
}
.nav-link:hover,
.nav-sublink:hover,
.nav-toggle:hover,
.nav-link.active,
.nav-sublink.active,
.nav-toggle.active {
    background: rgba(255,255,255,0.11);
    color: #fff;
}
.nav-group .nav-submenu {
    display: none;
    padding-left: 12px;
    gap: 8px;
}
.nav-group.open .nav-submenu { display: grid; }
.caret { transition: transform 0.2s ease; }
.nav-group.open .caret { transform: rotate(180deg); }

.content-shell {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    padding: 24px 28px 0;
}
.topbar-left {
    display: flex;
    gap: 14px;
    align-items: center;
}
.topbar h1 {
    margin: 0 0 4px;
    font-size: 30px;
    line-height: 1.15;
}
.topbar p { margin: 0; color: var(--muted); }
.menu-btn {
    display: none;
    border: 0;
    background: var(--card);
    border-radius: 14px;
    width: 46px;
    height: 46px;
    box-shadow: var(--shadow);
    cursor: pointer;
}
.user-pill {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    box-shadow: var(--shadow);
}
.user-pill span { color: var(--muted); font-size: 13px; }
.page-content { padding: 28px; }

.card,
.table-card,
.form-card,
.stat-card,
.empty-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.card,
.table-card,
.form-card,
.empty-card { padding: 20px; }
.empty-card.compact { padding: 16px 18px; }
.stats-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 18px;
}
.quick-grid {
    display: grid;
    grid-template-columns: 1.3fr 1fr;
    gap: 18px;
    margin-top: 18px;
}
.stat-card { padding: 22px; }
.stat-card .label { color: var(--muted); font-size: 14px; margin-bottom: 8px; }
.stat-card .value { font-size: 34px; font-weight: 800; }
.section-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}
.section-head h2,
.section-head h3,
.section-head p { margin: 0; }
.data-table-wrap,
.table-scroller { overflow-x: auto; }
.data-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 840px;
}
.data-table th,
.data-table td {
    padding: 14px 12px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
}
.data-table th {
    font-size: 13px;
    letter-spacing: 0.04em;
    color: var(--muted);
    text-transform: uppercase;
}
.form-grid-2,
.form-grid-3 {
    display: grid;
    gap: 16px;
}
.form-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field { display: grid; gap: 8px; }
.field label { font-size: 14px; font-weight: 600; }
.input,
.textarea,
.select {
    width: 100%;
    border: 1px solid #d5deea;
    background: #fff;
    color: var(--text);
    border-radius: 14px;
    padding: 13px 14px;
    outline: none;
}
.textarea {
    min-height: 110px;
    resize: vertical;
}
.input:focus,
.textarea:focus,
.select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(11, 114, 181, 0.12);
}
.compact-input { min-width: 100px; padding: 10px 12px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }
.btn {
    border: 0;
    border-radius: 14px;
    padding: 12px 16px;
    cursor: pointer;
    font-weight: 700;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-light { background: #eef3f8; color: var(--text); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border-radius: 999px;
    padding: 8px 12px;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 13px;
    font-weight: 700;
}
.badge.badge-danger { background: #fff1f2; color: #cf3f4f; }
.badge.badge-success { background: #edf8f2; color: #157347; }
.alert {
    padding: 14px 16px;
    border-radius: 16px;
    margin-bottom: 18px;
    border: 1px solid transparent;
}
.alert-success { background: #edf8f2; border-color: #cbe8d7; color: #157347; }
.alert-error { background: #fff2f3; border-color: #f3c6cb; color: #a82a39; }
.footer-note,
.muted { color: var(--muted); }
.inline-form { display: inline-flex; }

.mobile-cards { display: none; }
.mobile-card {
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 16px;
    margin-bottom: 12px;
    background: #fff;
}
.mobile-item-title { font-size: 17px; font-weight: 800; margin-bottom: 10px; }
.mobile-meta { display: grid; gap: 7px; color: var(--muted); margin-bottom: 12px; }

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}
.kpi-box {
    background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 18px;
}
.kpi-box .label { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.kpi-box .value { font-size: 28px; font-weight: 800; }
.summary-chip-wrap { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; }
.stock-negative { color: var(--danger); font-weight: 800; }
.stock-positive { color: var(--success); font-weight: 800; }
.stock-low { color: var(--warning); font-weight: 800; }

.member-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    align-items: center;
    margin-bottom: 10px;
}
.member-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.member-tag {
    background: #eef6ff;
    border: 1px solid #d6e8ff;
    color: #0b72b5;
    border-radius: 999px;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 700;
}

.modal {
    position: fixed;
    inset: 0;
    background: rgba(13, 24, 41, 0.58);
    display: grid;
    place-items: center;
    padding: 24px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.22s ease, visibility 0.22s ease;
    z-index: 120;
}
.modal.show { opacity: 1; visibility: visible; }
.modal-card {
    width: min(100%, 760px);
    max-height: calc(100vh - 48px);
    overflow: auto;
    background: #fff;
    border-radius: 26px;
    border: 1px solid var(--line);
    box-shadow: 0 22px 48px rgba(13, 24, 41, 0.18);
    padding: 22px;
    transform: translateY(28px) scale(0.98);
    opacity: 0;
    transition: transform 0.24s ease, opacity 0.24s ease;
}
.modal.show .modal-card { transform: translateY(0) scale(1); opacity: 1; }
.modal-card.small { width: min(100%, 620px); }
.modal-card.large { width: min(100%, 1080px); }
.modal-card.xl { width: min(100%, 1280px); }
.modal-card.xxl { width: min(100%, 1440px); }
.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
}
.icon-btn {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    border: 0;
    background: #f2f5f9;
    cursor: pointer;
    font-size: 18px;
    font-weight: 700;
}
.modal-sticky-actions {
    position: sticky;
    bottom: 0;
    background: linear-gradient(180deg, rgba(255,255,255,0) 0%, #fff 18%);
    padding-top: 16px;
    margin-top: 16px;
}

.tracking-summary {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}
.tracking-mini {
    background: #f8fbff;
    border: 1px solid #e1edf7;
    border-radius: 16px;
    padding: 14px;
}
.tracking-mini .title { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.tracking-mini .value { font-weight: 800; font-size: 22px; }
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter,
.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_paginate { margin-bottom: 12px; }
.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
    border: 1px solid #d5deea;
    border-radius: 10px;
    padding: 6px 10px;
    background: #fff;
}
.dataTables_wrapper .dataTables_paginate .paginate_button {
    border-radius: 10px !important;
    margin: 0 2px;
}

table.dataTable thead th,
table.dataTable thead td { border-bottom: 1px solid var(--line) !important; }
table.dataTable.no-footer { border-bottom: 0 !important; }

@media (max-width: 1180px) {
    .stats-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .quick-grid,
    .kpi-grid,
    .tracking-summary,
    .form-grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        left: 0;
        transform: translateX(-100%);
    }
    .sidebar.show { transform: translateX(0); }
    .menu-btn { display: inline-grid; place-items: center; }
    .page-content,
    .topbar { padding-left: 18px; padding-right: 18px; }
    .topbar { align-items: flex-start; }
    .stats-grid,
    .quick-grid,
    .kpi-grid,
    .tracking-summary,
    .form-grid-2,
    .form-grid-3 { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
    .page-content { padding: 16px; }
    .topbar { padding: 16px 16px 0; }
    .topbar h1 { font-size: 24px; }
    .desktop-only { display: none !important; }
    .mobile-cards { display: block; }
    .section-head { align-items: flex-start; flex-direction: column; }
    .modal { padding: 12px; }
    .modal-card,
    .modal-card.small,
    .modal-card.large,
    .modal-card.xl,
    .modal-card.xxl { width: 100%; border-radius: 20px; padding: 16px; }
    .member-row { grid-template-columns: 1fr; }
}
