/* =========================================================
   ProgGate — Unified SaaS / Admin Dashboard Design System
   Shared stylesheet for all authenticated pages
   ========================================================= */

/* ---------- Design Tokens ---------- */
:root {
    --navy: #0F172A;
    --blue: #2563EB;
    --blue-light: #3B82F6;
    --bg: #F4F7FB;
    --surface: #FFFFFF;
    --surface-2: #F8FAFC;
    --slate: #64748B;
    --green: #16A34A;
    --orange: #F59E0B;
    --red: #DC2626;
    --border: #E5E9F0;
    --border-soft: #EDF1F7;
    --text: #0F172A;
    --text-muted: #64748B;

    --sidebar-w: 262px;
    --radius: 14px;
    --radius-sm: 10px;
    --shadow-sm: 0 1px 2px rgba(15,23,42,.05);
    --shadow: 0 10px 30px rgba(15,23,42,.08);
    --shadow-lg: 0 18px 45px rgba(15,23,42,.12);
    --transition: .22s ease;
}

/* Dark theme (driven by body.dark) */
body.dark,
[data-theme="dark"] {
    --bg: #0B1220;
    --surface: #111A2E;
    --surface-2: #16213A;
    --border: #243049;
    --border-soft: #1D2A45;
    --text: #E6EBF5;
    --text-muted: #94A3B8;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.35);
    --shadow: 0 10px 30px rgba(0,0,0,.45);
    --shadow-lg: 0 18px 45px rgba(0,0,0,.55);
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: "Segoe UI", Tahoma, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.6;
    transition: background var(--transition), color var(--transition);
    min-height: 100vh;
}
a { color: var(--blue); text-decoration: none; }
img { max-width: 100%; }
h1, h2, h3, h4 { color: var(--text); margin: 0 0 8px; font-weight: 700; line-height: 1.3; }

/* ---------- App Shell Layout ---------- */
.app-shell { min-height: 100vh; }

/* Sidebar */
.app-sidebar {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    width: var(--sidebar-w);
    background: linear-gradient(180deg, #0B1B3A 0%, #0F172A 60%, #0B1220 100%);
    color: #E6EBF5;
    display: flex;
    flex-direction: column;
    z-index: 1040;
    overflow-y: auto;
    overflow-x: hidden;
    box-shadow: 2px 0 24px rgba(15,23,42,.18);
    transition: transform var(--transition), width var(--transition);
}
body.dark .app-sidebar { box-shadow: 2px 0 24px rgba(0,0,0,.5); }

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 18px 16px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand .logo-img { height: 42px; width: 42px; object-fit: contain; border-radius: 10px; background: #fff; padding: 3px; }
.sidebar-brand .brand-name { font-size: 15px; font-weight: 800; letter-spacing: .2px; }
.sidebar-brand .brand-sub { font-size: 11px; color: #94A3B8; font-weight: 500; }

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 11px;
    margin: 14px 14px 6px;
    padding: 12px;
    background: rgba(255,255,255,.06);
    border: 1px solid rgba(255,255,255,.08);
    border-radius: var(--radius-sm);
}
.sidebar-user .avatar {
    width: 40px; height: 40px; border-radius: 50%;
    background: linear-gradient(135deg, var(--blue-light), var(--blue));
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; color: #fff; font-size: 16px; flex-shrink: 0;
}
.sidebar-user .u-name { font-weight: 700; font-size: 13.5px; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user .u-role { font-size: 11px; color: #94A3B8; }

.sidebar-nav { flex: 1; padding: 8px 12px; }
.sidebar-nav .nav-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 1px; color: #64748B; padding: 14px 10px 6px; font-weight: 700; }
.nav-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10.5px 12px;
    border-radius: 10px;
    color: #CBD5E1;
    font-weight: 600;
    font-size: 13.5px;
    margin-bottom: 3px;
    cursor: pointer;
    transition: background var(--transition), color var(--transition), transform var(--transition);
    border: 1px solid transparent;
}
.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; transform: translateX(2px); }
.nav-item.active { background: linear-gradient(135deg, var(--blue), var(--blue-light)); color: #fff; box-shadow: 0 8px 18px rgba(37,99,235,.35); }
.nav-item .nav-icon { font-size: 17px; width: 22px; text-align: center; flex-shrink: 0; }

/* Sidebar footer controls */
.sidebar-footer { padding: 12px; border-top: 1px solid rgba(255,255,255,.08); display: flex; flex-direction: column; gap: 8px; }
.sidebar-action {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; border-radius: 10px;
    background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.08);
    color: #E6EBF5; font-weight: 600; font-size: 13px; cursor: pointer;
    transition: background var(--transition); width: 100%; font-family: inherit;
}
.sidebar-action:hover { background: rgba(255,255,255,.12); }
.sidebar-action.logout { color: #FCA5A5; }
.sidebar-action.logout:hover { background: rgba(220,38,38,.18); }
.sidebar-action .nav-icon { font-size: 16px; width: 22px; text-align: center; }

/* Main area */
.app-main { margin-inline-start: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }

/* Topbar (mobile hamburger + breadcrumb) */
.app-topbar {
    position: sticky; top: 0; z-index: 1020;
    display: flex; align-items: center; gap: 14px;
    padding: 14px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border-soft);
}
.burger-btn {
    display: none; align-items: center; justify-content: center;
    width: 40px; height: 40px; border-radius: 10px;
    background: var(--surface-2); border: 1px solid var(--border);
    color: var(--text); font-size: 20px; cursor: pointer;
}

/* Page header */
.app-page-header {
    padding: 26px 28px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border-soft);
}
.app-page-header .crumb { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.app-page-header h1 { font-size: 24px; margin-bottom: 4px; display: flex; align-items: center; gap: 10px; }
.app-page-header p { margin: 0; color: var(--text-muted); font-size: 13.5px; }

.app-content { padding: 24px 28px 40px; flex: 1; }

/* ---------- Cards ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    padding: 22px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition), transform var(--transition);
}
.card:hover { box-shadow: var(--shadow); }
.card + .card { margin-top: 20px; }
.card-title { font-size: 16px; font-weight: 700; margin-bottom: 16px; display: flex; align-items: center; gap: 8px; }

/* KPI / Stat cards */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; margin-bottom: 22px; }
.kpi-card {
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    display: flex; align-items: center; gap: 16px;
    transition: transform var(--transition), box-shadow var(--transition);
}
.kpi-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.kpi-card .kpi-icon {
    width: 52px; height: 52px; border-radius: 14px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center; font-size: 24px;
    background: rgba(37,99,235,.1); color: var(--blue);
}
.kpi-card .kpi-icon.green { background: rgba(22,163,74,.12); color: var(--green); }
.kpi-card .kpi-icon.orange { background: rgba(245,158,11,.14); color: var(--orange); }
.kpi-card .kpi-icon.red { background: rgba(220,38,38,.12); color: var(--red); }
.kpi-card .kpi-icon.slate { background: rgba(100,116,139,.14); color: var(--slate); }
.kpi-card .kpi-meta .kpi-value { font-size: 24px; font-weight: 800; line-height: 1.1; }
.kpi-card .kpi-meta .kpi-label { font-size: 12.5px; color: var(--text-muted); font-weight: 600; margin-top: 3px; }



/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 18px; border-radius: var(--radius-sm);
    border: 1px solid transparent; cursor: pointer;
    font-family: inherit; font-size: 13.5px; font-weight: 700;
    transition: transform var(--transition), box-shadow var(--transition), background var(--transition), opacity var(--transition);
    white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none !important; }
.btn:active { transform: scale(.97); }
.btn-primary { background: linear-gradient(135deg, var(--blue), var(--blue-light)); color: #fff; box-shadow: 0 8px 18px rgba(37,99,235,.28); }
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 12px 26px rgba(37,99,235,.36); }
.btn-success { background: linear-gradient(135deg, #16A34A, #22C55E); color: #fff; box-shadow: 0 8px 18px rgba(22,163,74,.28); }
.btn-success:hover { transform: translateY(-2px); }
.btn-danger { background: linear-gradient(135deg, #DC2626, #EF4444); color: #fff; box-shadow: 0 8px 18px rgba(220,38,38,.25); }
.btn-danger:hover { transform: translateY(-2px); }
.btn-warning { background: linear-gradient(135deg, #D97706, #F59E0B); color: #fff; }
.btn-outline { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-outline:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 7px 13px; font-size: 12.5px; border-radius: 8px; }
.btn-lg { padding: 13px 24px; font-size: 15px; }

/* ---------- Forms ---------- */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 700; margin-bottom: 6px; color: var(--text); }
.input, select.input, textarea.input, .form-control {
    width: 100%; padding: 11px 14px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text);
    font-family: inherit; font-size: 14px; transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}
.input:focus, select.input:focus, textarea.input:focus, .form-control:focus {
    border-color: var(--blue-light); box-shadow: 0 0 0 3px rgba(59,130,246,.14);
}
select.input { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='2.4'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; }
html[dir="ltr"] select.input { background-position: left 14px center; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border-soft); margin-bottom: 22px; overflow-x: auto; scrollbar-width: thin; }
.tab-btn {
    padding: 11px 18px; border: none; background: transparent; cursor: pointer;
    font-family: inherit; font-size: 14px; font-weight: 700; color: var(--text-muted);
    border-bottom: 3px solid transparent; margin-bottom: -2px;
    display: inline-flex; align-items: center; gap: 8px; white-space: nowrap;
    transition: color var(--transition), border-color var(--transition);
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--blue); border-bottom-color: var(--blue); }
.tab-pane { display: none; }
.tab-pane.active { display: block; animation: fadeIn .25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Tables ---------- */
.table-responsive { overflow-x: auto; border-radius: var(--radius-sm); border: 1px solid var(--border-soft); background: var(--surface); }
table.dataTable, table.display {
    width: 100% !important; border-collapse: collapse; font-size: 13.5px;
}
table.dataTable thead th, table.display thead th {
    background: var(--surface-2); color: var(--text-muted);
    padding: 12px 14px; text-align: start; font-weight: 700; font-size: 12.5px;
    border-bottom: 2px solid var(--border-soft); white-space: nowrap;
}
table.dataTable tbody td, table.display tbody td { padding: 11px 14px; border-bottom: 1px solid var(--border-soft); }
table.dataTable tbody tr:hover { background: var(--surface-2); }

/* DataTables wrapper overrides */
.dataTables_wrapper .dataTables_filter input {
    border: 1px solid var(--border) !important; border-radius: 8px !important;
    padding: 7px 12px !important; background: var(--surface) !important; color: var(--text) !important;
}
.dataTables_wrapper .dataTables_length select {
    border: 1px solid var(--border) !important; border-radius: 8px !important;
    padding: 5px 8px !important; background: var(--surface) !important; color: var(--text) !important;
}
.dataTables_wrapper .dataTables_paginate .paginate_button {
    border-radius: 8px !important; border: 1px solid var(--border) !important; margin: 0 2px;
    background: var(--surface) !important; color: var(--text) !important;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.current {
    background: var(--blue) !important; color: #fff !important; border-color: var(--blue) !important;
}
.dataTables_wrapper .dataTables_info, .dataTables_wrapper .dataTables_length, .dataTables_wrapper .dataTables_filter { color: var(--text-muted) !important; }



/* ---------- Badges ---------- */
.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 11px; border-radius: 20px; font-size: 11.5px; font-weight: 700; line-height: 1.5;
}
.badge-green { background: rgba(22,163,74,.14); color: var(--green); }
.badge-blue { background: rgba(37,99,235,.14); color: var(--blue); }
.badge-orange { background: rgba(245,158,11,.16); color: var(--orange); }
.badge-red { background: rgba(220,38,38,.13); color: var(--red); }
.badge-slate { background: rgba(100,116,139,.15); color: var(--slate); }

/* Price difference colors */
.price-lower { color: var(--green); font-weight: 700; }
.price-higher { color: var(--red); font-weight: 700; }
.price-equal { color: var(--orange); font-weight: 700; }

/* ---------- Loading overlay ---------- */
.loading-overlay {
    position: fixed; inset: 0; display: none; align-items: center; justify-content: center;
    background: rgba(15,23,42,.6); backdrop-filter: blur(4px); z-index: 99999; cursor: wait;
}
.loading-overlay.active { display: flex; }
.loading-box {
    background: var(--surface); color: var(--text); padding: 34px 46px; border-radius: 18px;
    min-width: 300px; max-width: 90%; text-align: center; box-shadow: var(--shadow-lg);
}
.loading-box .spinner {
    width: 56px; height: 56px; border: 5px solid var(--border); border-top-color: var(--blue);
    border-radius: 50%; animation: spin 1s linear infinite; margin: 0 auto 18px;
}
.loading-box .loading-title { font-size: 19px; font-weight: 800; margin-bottom: 8px; }
.loading-box .loading-text { font-size: 13.5px; color: var(--text-muted); line-height: 1.7; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Modal ---------- */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(15,23,42,.55);
    display: none; align-items: center; justify-content: center; z-index: 1100; padding: 20px;
}
.modal-overlay.active { display: flex; }
.modal-box {
    background: var(--surface); color: var(--text); border-radius: 16px; width: 100%;
    max-width: 560px; max-height: 88vh; overflow-y: auto; box-shadow: var(--shadow-lg); padding: 24px;
}
.modal-box .modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-box .modal-close { background: none; border: none; font-size: 24px; cursor: pointer; color: var(--text-muted); line-height: 1; }

/* ---------- Toast ---------- */
#toast, .toast {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
    background: var(--navy); color: #fff; padding: 12px 24px; border-radius: 10px;
    font-size: 13.5px; display: none; z-index: 1200; box-shadow: var(--shadow-lg);
}

/* ---------- Utility ---------- */
.flex { display: flex; } .flex-wrap { flex-wrap: wrap; } .gap-12 { gap: 12px; } .gap-8 { gap: 8px; }
.items-center { align-items: center; } .justify-between { justify-content: space-between; }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; } .mb-16 { margin-bottom: 16px; } .mt-16 { margin-top: 16px; }
.text-muted { color: var(--text-muted); }
.w-full { width: 100%; }
.hidden { display: none !important; }


/* ---------- Dark mode legacy compatibility ---------- */
body.dark .dataTables_wrapper .dataTables_filter input,
body.dark .dataTables_wrapper .dataTables_length select { background: var(--surface) !important; color: var(--text) !important; border-color: var(--border) !important; }
body.dark table.dataTable tbody tr { background: transparent; }
body.dark table.dataTable tbody tr:hover { background: var(--surface-2); }

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
    :root { --sidebar-w: 262px; }
    .app-sidebar { transform: translateX(100%); }
    html[dir="ltr"] .app-sidebar { transform: translateX(-100%); }
    .app-sidebar.open { transform: translateX(0); }
    .app-main { margin-inline-start: 0; }
    .burger-btn { display: flex; }
    .app-backdrop {
        position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 1030; opacity: 0; pointer-events: none; transition: opacity var(--transition);
    }
    .app-backdrop.show { opacity: 1; pointer-events: auto; }
}

@media (max-width: 640px) {
    .app-content { padding: 16px 14px 32px; }
    .app-page-header { padding: 20px 18px 16px; }
    .app-page-header h1 { font-size: 20px; }
    .kpi-grid { grid-template-columns: 1fr; }
    .btn { width: 100%; }
    .btn.inline { width: auto; }
    .file-name { min-width: 0; width: 100%; }
}

/* File upload chip */
.file-upload { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 8px 0 16px; }
.file-btn { display: inline-flex; align-items: center; gap: 8px; padding: 10px 18px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px dashed var(--blue-light); color: var(--blue); cursor: pointer; font-weight: 700; font-size: 13.5px; transition: background var(--transition); }
.file-btn:hover { background: rgba(37,99,235,.08); }
.file-name { color: var(--text-muted); font-size: 13px; background: var(--surface-2); padding: 9px 14px; border-radius: 9px; border: 1px solid var(--border-soft); min-width: 200px; text-align: center; }

/* Section divider */
.section-divider { border: none; height: 1px; background: var(--border-soft); margin: 22px 0; }
