/* ── Variables: Dark (default) ─────────────────────────── */
:root, [data-theme="dark"] {
    --bg-body: #0f1117;
    --bg-sidebar: #161820;
    --bg-card: #1a1d27;
    --bg-card-hover: #1e2130;
    --bg-input: #1e2130;
    --bg-table-row: #1a1d27;
    --bg-table-hover: #22253a;
    --border: #2a2d3a;
    --border-light: #333649;

    --text-primary: #e4e6f0;
    --text-secondary: #8b8fa3;
    --text-muted: #5c6078;
    --text-heading: #f0f1f7;

    --accent: #6366f1;
    --accent-hover: #818cf8;
    --accent-muted: rgba(99, 102, 241, 0.15);

    --green: #22c55e;
    --green-muted: rgba(34, 197, 94, 0.15);
    --yellow: #eab308;
    --yellow-muted: rgba(234, 179, 8, 0.15);
    --red: #ef4444;
    --red-muted: rgba(239, 68, 68, 0.15);
    --blue: #3b82f6;
    --blue-muted: rgba(59, 130, 246, 0.15);
    --orange: #f97316;
    --orange-muted: rgba(249, 115, 22, 0.15);
    --cyan: #06b6d4;
    --cyan-muted: rgba(6, 182, 212, 0.15);

    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
    --shadow-lg: 0 10px 40px rgba(0,0,0,0.4);
    --transition: 150ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Variables: Light ─────────────────────────────────── */
[data-theme="light"] {
    --bg-body: #f5f6fa;
    --bg-sidebar: #ffffff;
    --bg-card: #ffffff;
    --bg-card-hover: #f8f9fc;
    --bg-input: #f1f3f9;
    --bg-table-row: #ffffff;
    --bg-table-hover: #f5f6fa;
    --border: #e2e5ef;
    --border-light: #d0d4e2;

    --text-primary: #1a1d2e;
    --text-secondary: #5c6078;
    --text-muted: #8b8fa3;
    --text-heading: #0f1117;

    --accent: #4f46e5;
    --accent-hover: #6366f1;
    --accent-muted: rgba(79, 70, 229, 0.1);

    --green: #16a34a;
    --green-muted: rgba(22, 163, 74, 0.1);
    --yellow: #ca8a04;
    --yellow-muted: rgba(202, 138, 4, 0.1);
    --red: #dc2626;
    --red-muted: rgba(220, 38, 38, 0.08);
    --blue: #2563eb;
    --blue-muted: rgba(37, 99, 235, 0.1);
    --orange: #ea580c;
    --orange-muted: rgba(234, 88, 12, 0.1);
    --cyan: #0891b2;
    --cyan-muted: rgba(8, 145, 178, 0.1);

    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-lg: 0 10px 40px rgba(0,0,0,0.08);
}

/* ── Reset & Base ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg-body);
    color: var(--text-primary);
    margin: 0;
    -webkit-font-smoothing: antialiased;
    font-size: 14px;
    line-height: 1.6;
}

a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--accent-hover); }

/* ── Top Header Bar ───────────────────────────────────── */
.topbar {
    position: fixed;
    top: 0;
    left: 240px;
    right: 0;
    height: 56px;
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0 24px;
    z-index: 90;
    gap: 8px;
}

.topbar-left { flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 6px; }

.theme-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.theme-btn:hover {
    background: var(--accent-muted);
    color: var(--accent);
}

.theme-btn svg { width: 18px; height: 18px; }
.theme-btn .icon-sun { display: none; }
.theme-btn .icon-moon { display: block; }
[data-theme="light"] .theme-btn .icon-sun { display: block; }
[data-theme="light"] .theme-btn .icon-moon { display: none; }

/* ── Profile Dropdown ─────────────────────────────────── */
.profile-dropdown { position: relative; }

.profile-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 10px 4px 4px;
    border-radius: var(--radius-sm);
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}

.profile-btn:hover {
    background: var(--bg-card-hover);
}

.profile-btn .avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent-muted);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 12px;
}

.profile-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    line-height: 1.3;
}

.profile-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.profile-role {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: capitalize;
}

.dropdown-menu {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    width: 200px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 4px;
    z-index: 200;
}

.profile-dropdown.open .dropdown-menu { display: block; }

.dropdown-header {
    padding: 10px 12px 8px;
}

.dropdown-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-heading);
}

.dropdown-role {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: capitalize;
}

.dropdown-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text-secondary);
    transition: all var(--transition);
}

.dropdown-item svg { width: 16px; height: 16px; opacity: 0.6; flex-shrink: 0; }

.dropdown-item:hover {
    background: var(--accent-muted);
    color: var(--accent);
}

.dropdown-item:hover svg { opacity: 1; }

.dropdown-item-danger:hover {
    background: var(--red-muted);
    color: var(--red);
}

/* ── Sidebar ──────────────────────────────────────────── */
.sidebar {
    width: 240px;
    min-height: 100vh;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 0;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 100;
}

.sidebar-brand {
    height: 56px;
    padding: 0 20px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--border);
}

.sidebar-brand h5 {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: var(--text-heading);
    letter-spacing: -0.02em;
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-brand .brand-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.5);
}

.sidebar-nav {
    padding: 12px 8px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 13.5px;
    font-weight: 500;
    transition: all var(--transition);
}

.sidebar-nav a:hover {
    background: var(--accent-muted);
    color: var(--text-primary);
}

.sidebar-nav a.active {
    background: var(--accent-muted);
    color: var(--accent);
}

.sidebar-nav a svg {
    width: 18px;
    height: 18px;
    opacity: 0.7;
    flex-shrink: 0;
}

.sidebar-nav a.active svg,
.sidebar-nav a:hover svg { opacity: 1; }

.sidebar-section {
    padding: 20px 12px 6px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

/* ── Main Content ─────────────────────────────────────── */
.main-content {
    margin-left: 240px;
    padding-top: 80px; /* 56px topbar + 24px spacing */
    padding-left: 40px;
    padding-right: 40px;
    padding-bottom: 32px;
    min-height: 100vh;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 28px;
}

.page-header h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-heading);
    margin: 0;
    letter-spacing: -0.02em;
}

.page-header .subtitle {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ── Cards ────────────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 13px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: transparent;
}

.card-body { padding: 20px; }

/* Stat cards */
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    transition: all var(--transition);
}

.stat-card:hover {
    border-color: var(--border-light);
    background: var(--bg-card-hover);
}

.stat-card .stat-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 14px;
}

.stat-card .stat-icon svg { width: 20px; height: 20px; }

.stat-card .stat-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

.stat-card .stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-heading);
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.stat-card .stat-change {
    font-size: 12px;
    margin-top: 6px;
}

.stat-accent .stat-icon { background: var(--accent-muted); color: var(--accent); }
.stat-green .stat-icon { background: var(--green-muted); color: var(--green); }
.stat-yellow .stat-icon { background: var(--yellow-muted); color: var(--yellow); }
.stat-cyan .stat-icon { background: var(--cyan-muted); color: var(--cyan); }
.stat-red .stat-icon { background: var(--red-muted); color: var(--red); }

/* ── Tables ───────────────────────────────────────────── */
.table-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.table-toolbar {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    gap: 12px;
}

.table-toolbar h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-heading);
    margin: 0;
}

table {
    width: 100%;
    border-collapse: collapse;
}

table thead th {
    padding: 12px 16px;
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    background: rgba(255,255,255,0.02);
    white-space: nowrap;
}

table tbody td {
    padding: 12px 16px;
    font-size: 13px;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

table tbody tr:last-child td { border-bottom: none; }

table tbody tr {
    transition: background var(--transition);
}

table tbody tr:hover {
    background: var(--bg-table-hover);
}

table .mono {
    font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
    font-size: 12.5px;
}

table .text-muted { color: var(--text-muted); }
table .text-secondary { color: var(--text-secondary); }

.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
}

.empty-state svg { width: 48px; height: 48px; margin-bottom: 12px; opacity: 0.3; }
.empty-state p { margin: 0; font-size: 14px; }

/* ── Badges ───────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.badge-final { background: var(--green-muted); color: var(--green); }
.badge-provisional { background: var(--yellow-muted); color: var(--yellow); }
.badge-placeholder { background: var(--bg-input); color: var(--text-secondary); border: 1px solid var(--border); }
.badge-pushed { background: var(--blue-muted); color: var(--blue); }
.badge-human { background: var(--red-muted); color: var(--red); }
.badge-delivered { background: var(--green-muted); color: var(--green); }
.badge-pending { background: var(--bg-input); color: var(--text-muted); border: 1px solid var(--border); }
.badge-none { background: var(--bg-input); color: var(--text-muted); }

/* ── Buttons ──────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    line-height: 1.4;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    color: #fff;
}

.btn-secondary {
    background: transparent;
    color: var(--text-secondary);
    border-color: var(--border);
}

.btn-secondary:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
    border-color: var(--border-light);
}

.btn-danger {
    background: transparent;
    color: var(--red);
    border-color: var(--border);
}

.btn-danger:hover {
    background: var(--red-muted);
    border-color: rgba(239, 68, 68, 0.3);
}

.btn-sm {
    padding: 5px 10px;
    font-size: 12px;
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: none;
    padding: 6px 10px;
}

.btn-ghost:hover { background: var(--accent-muted); color: var(--accent); }

/* ── Forms ────────────────────────────────────────────── */
.form-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-control, .form-select {
    width: 100%;
    padding: 9px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 13.5px;
    transition: border-color var(--transition);
    font-family: inherit;
}

.form-control:focus, .form-select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-muted);
}

.form-control::placeholder { color: var(--text-muted); }

.form-text {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.form-check-input {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
}

/* ── Search bar ───────────────────────────────────────── */
.search-bar {
    display: flex;
    gap: 8px;
}

.search-bar .form-control {
    max-width: 280px;
}

/* ── Alerts ───────────────────────────────────────────── */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    margin-bottom: 16px;
}

.alert-danger {
    background: var(--red-muted);
    color: var(--red);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

/* ── Pagination ───────────────────────────────────────── */
.pagination {
    list-style: none;
    display: flex;
    gap: 4px;
    padding: 16px 20px;
    margin: 0;
}

.pagination a, .pagination span {
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    transition: all var(--transition);
}

.pagination a:hover {
    background: var(--accent-muted);
    color: var(--accent);
    border-color: var(--accent);
}

.pagination .active span {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* ── Login page ───────────────────────────────────────── */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-body);
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 40px;
    box-shadow: var(--shadow-lg);
}

.login-card h3 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-heading);
    text-align: center;
    margin: 0 0 8px;
}

.login-card .login-subtitle {
    text-align: center;
    color: var(--text-muted);
    font-size: 13.5px;
    margin-bottom: 28px;
}

.login-card .form-group {
    margin-bottom: 18px;
}

.login-card .btn-primary {
    width: 100%;
    padding: 11px;
    font-size: 14px;
    font-weight: 600;
    justify-content: center;
}

/* ── Utilities ────────────────────────────────────────── */
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mt-4 { margin-top: 32px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.gap-2 { gap: 16px; }
.gap-1 { gap: 8px; }
.d-flex { display: flex; }
.d-inline { display: inline-flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-1 { flex: 1; }
.text-right { text-align: right; }

@media (max-width: 1024px) {
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
    .main-content { padding-left: 20px; padding-right: 20px; }
}

@media (max-width: 768px) {
    .sidebar { display: none; }
    .topbar { left: 0; }
    .main-content { margin-left: 0; padding-top: 72px; }
    .grid-4, .grid-3 { grid-template-columns: 1fr; }
}

/* Light-mode tweak for table header */
[data-theme="light"] table thead th {
    background: rgba(0,0,0,0.02);
}

/* ── Sortable table headers ────────────────────────────── */
.sortable { cursor: pointer; user-select: none; }
.sortable:hover { color: var(--accent); }
.sortable .sort-icon::after { content: ''; margin-left: 4px; }
.sortable.sort-asc .sort-icon::after { content: ' \25B2'; font-size: 10px; }
.sortable.sort-desc .sort-icon::after { content: ' \25BC'; font-size: 10px; }

/* Responsive: topbar adjusts with sidebar */
@media (max-width: 768px) {
    .topbar { left: 0; }
    .main-content { padding-top: 72px; }
}
