/* =====================================================================
   E-Warranty & Delivery CRM — modern theme
   ===================================================================== */

:root {
    /* Brand */
    --brand: #2563eb;
    --brand-rgb: 37, 99, 235;
    --brand-dark: #1d4ed8;
    --brand-glow: rgba(37, 99, 235, .35);

    /* Sidebar (dark navy gradient) */
    --sb-bg-1: #141d33;
    --sb-bg-2: #1f2b4d;
    --sb-text: #aeb9d4;
    --sb-text-active: #ffffff;
    --sb-w: 260px;
    --sb-w-collapsed: 76px;

    /* Surfaces (light theme) */
    --bg: #eef1f8;
    --surface: #ffffff;
    --surface-2: #f6f8fc;
    --border: #e6e9f2;
    --text: #1f2733;
    --text-muted: #74809a;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
    --shadow-md: 0 4px 12px rgba(16, 24, 40, .08);
    --shadow-lg: 0 12px 32px rgba(16, 24, 40, .12);
    --radius: 16px;
    --radius-sm: 12px;
}

[data-theme="dark"] {
    --bg: #0c1322;
    --surface: #131c30;
    --surface-2: #1a2741;
    --border: #243150;
    --text: #e6ebf5;
    --text-muted: #8a97b5;
    --sb-bg-1: #0a0f1c;
    --sb-bg-2: #131d34;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 6px 18px rgba(0, 0, 0, .45);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, .55);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: .9rem;
    -webkit-font-smoothing: antialiased;
    transition: background .25s, color .25s;
}

a { color: var(--brand); }

/* ---------- Layout ---------- */
.app-wrapper { display: flex; min-height: 100vh; }
.main-content {
    flex: 1; min-width: 0;
    margin-left: var(--sb-w);
    transition: margin .22s ease;
}
.page-body { padding: 1.5rem; max-width: 1600px; }

body.sb-collapsed .main-content { margin-left: var(--sb-w-collapsed); }

/* ---------- Sidebar ---------- */
.sidebar {
    position: fixed; inset: 0 auto 0 0;
    width: var(--sb-w);
    background: linear-gradient(180deg, var(--sb-bg-1) 0%, var(--sb-bg-2) 100%);
    color: var(--sb-text);
    display: flex; flex-direction: column;
    z-index: 1040;
    transition: width .22s ease, transform .22s ease;
    overflow: hidden;
}
body.sb-collapsed .sidebar { width: var(--sb-w-collapsed); }

.sidebar-brand {
    display: flex; align-items: center; gap: .7rem;
    padding: 1.1rem 1.25rem;
    color: #fff; font-weight: 700; font-size: 1.05rem;
    white-space: nowrap;
}
.sidebar-brand .brand-logo {
    width: 38px; height: 38px; flex-shrink: 0;
    border-radius: 11px;
    background: linear-gradient(135deg, var(--brand), #4f8bff);
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 1.1rem;
    box-shadow: 0 6px 16px var(--brand-glow);
}
body.sb-collapsed .sidebar-brand .brand-text { display: none; }

.sidebar-user {
    display: flex; align-items: center; gap: .7rem;
    margin: .25rem .85rem 1rem;
    padding: .75rem;
    background: rgba(255, 255, 255, .05);
    border: 1px solid rgba(255, 255, 255, .07);
    border-radius: 12px;
    white-space: nowrap;
}
.su-avatar {
    width: 38px; height: 38px; flex-shrink: 0;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--brand), #6aa0ff);
    color: #fff; display: flex; align-items: center; justify-content: center;
    font-weight: 600;
}
.su-name { color: #fff; font-weight: 600; font-size: .85rem; line-height: 1.2; }
.su-role { font-size: .72rem; color: #8595bb; }
body.sb-collapsed .sidebar-user { justify-content: center; padding: .55rem; }
body.sb-collapsed .su-meta { display: none; }

.sidebar-section {
    font-size: .68rem; text-transform: uppercase; letter-spacing: .08em;
    color: #5e6c8f; padding: .4rem 1.45rem; margin-top: .35rem;
}
body.sb-collapsed .sidebar-section { text-align: center; padding: .4rem 0; font-size: 0; }
body.sb-collapsed .sidebar-section::after { content: "•••"; font-size: .7rem; }

.sidebar-nav { flex: 1; overflow-y: auto; padding-bottom: 1rem; }
.sidebar-nav a {
    position: relative;
    display: flex; align-items: center; gap: .85rem;
    margin: .15rem .7rem;
    padding: .65rem .8rem;
    border-radius: 11px;
    color: var(--sb-text); text-decoration: none;
    font-size: .88rem; font-weight: 500;
    white-space: nowrap;
    transition: background .15s, color .15s;
}
.sidebar-nav a i { width: 20px; text-align: center; font-size: 1rem; flex-shrink: 0; }
.sidebar-nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.sidebar-nav a.active {
    background: linear-gradient(135deg, var(--brand), #4f8bff);
    color: #fff;
    box-shadow: 0 8px 18px var(--brand-glow);
}
.sidebar-nav a.logout-link { color: #f49a9a; }
.sidebar-nav a.logout-link:hover { background: rgba(220, 38, 38, .16); color: #fff; }
body.sb-collapsed .sidebar-nav a { justify-content: center; padding: .7rem; }
body.sb-collapsed .sidebar-nav a .nav-text { display: none; }

.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(7, 11, 22, .55); z-index: 1039; }

/* ---------- Topbar ---------- */
.topbar {
    display: flex; align-items: center; gap: 1rem;
    background: var(--surface);
    padding: .7rem 1.4rem;
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 1020;
    box-shadow: var(--shadow-sm);
}
.topbar-title { font-weight: 700; font-size: 1.05rem; }
.topbar-spacer { flex: 1; }
.icon-btn {
    width: 40px; height: 40px; border-radius: 11px;
    border: 1px solid var(--border); background: var(--surface-2);
    color: var(--text); display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer; transition: .15s;
}
.icon-btn:hover { background: var(--brand); color: #fff; border-color: var(--brand); }

.topbar-search { position: relative; min-width: 240px; }
.topbar-search i { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }
.topbar-search input {
    width: 100%; padding: .5rem .8rem .5rem 2.2rem;
    border: 1px solid var(--border); border-radius: 11px;
    background: var(--surface-2); color: var(--text);
}
.topbar-search input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-glow); }

.topbar-user { display: flex; align-items: center; gap: .6rem; font-weight: 600; }
.topbar-user .su-avatar { width: 34px; height: 34px; font-size: .85rem; }

/* ---------- Cards ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    color: var(--text);
}
.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    padding: .9rem 1.15rem;
}
.card-body { padding: 1.15rem; }
.card-footer { background: transparent; border-top: 1px solid var(--border); }

/* ---------- Stat cards ---------- */
.stat-card {
    position: relative; overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.15rem 1.2rem;
    box-shadow: var(--shadow-sm);
    transition: transform .18s, box-shadow .18s;
    height: 100%;
}
.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.stat-card::after {
    content: ""; position: absolute; right: -28px; top: -28px;
    width: 96px; height: 96px; border-radius: 50%;
    background: var(--sc-color, var(--brand)); opacity: .1;
}
.stat-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: .65rem; }
.stat-icon {
    width: 46px; height: 46px; border-radius: 13px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem; color: #fff;
    background: var(--sc-color, var(--brand));
    box-shadow: 0 8px 18px color-mix(in srgb, var(--sc-color, var(--brand)) 40%, transparent);
}
.stat-value { font-size: 1.85rem; font-weight: 800; line-height: 1; letter-spacing: -.02em; }
.stat-label { font-size: .8rem; color: var(--text-muted); margin-top: .3rem; font-weight: 500; }

.c-blue   { --sc-color: #2563eb; }
.c-amber  { --sc-color: #f59e0b; }
.c-green  { --sc-color: #16a34a; }
.c-teal   { --sc-color: #0d9488; }
.c-red    { --sc-color: #dc2626; }
.c-purple { --sc-color: #7c3aed; }
.c-indigo { --sc-color: #4f46e5; }
.c-pink   { --sc-color: #db2777; }
.c-cyan   { --sc-color: #0891b2; }

/* ---------- Tables ---------- */
.table { color: var(--text); margin-bottom: 0; }
.table > :not(caption) > * > * { padding: .8rem .9rem; border-color: var(--border); }
.table thead th {
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: .72rem; text-transform: uppercase; letter-spacing: .04em;
    font-weight: 700; border-bottom: 1px solid var(--border);
}
.table-hover > tbody > tr:hover > * { background: color-mix(in srgb, var(--brand) 6%, transparent); }
.table tbody tr { border-bottom: 1px solid var(--border); }

/* ---------- Badges ---------- */
.badge { font-weight: 600; padding: .4em .7em; border-radius: 8px; font-size: .72rem; }
/* Soft badges: tinted background + readable coloured text for every variant */
.badge-soft.text-bg-success   { color: #15803d !important; background: rgba(22, 163, 74, .15) !important; }
.badge-soft.text-bg-warning   { color: #b45309 !important; background: rgba(245, 158, 11, .18) !important; }
.badge-soft.text-bg-danger    { color: #dc2626 !important; background: rgba(220, 38, 38, .15) !important; }
.badge-soft.text-bg-primary   { color: #2563eb !important; background: rgba(37, 99, 235, .15) !important; }
.badge-soft.text-bg-info      { color: #0e7490 !important; background: rgba(8, 145, 178, .15) !important; }
.badge-soft.text-bg-secondary { color: #475569 !important; background: rgba(100, 116, 139, .18) !important; }
/* Fallback for any other colour */
.badge-soft { background: color-mix(in srgb, currentColor 16%, transparent) !important; }

[data-theme="dark"] .badge-soft.text-bg-success   { color: #4ade80 !important; }
[data-theme="dark"] .badge-soft.text-bg-warning   { color: #fbbf24 !important; }
[data-theme="dark"] .badge-soft.text-bg-danger    { color: #f87171 !important; }
[data-theme="dark"] .badge-soft.text-bg-primary   { color: #60a5fa !important; }
[data-theme="dark"] .badge-soft.text-bg-info      { color: #22d3ee !important; }
[data-theme="dark"] .badge-soft.text-bg-secondary { color: #cbd5e1 !important; }
.status-badge { cursor: pointer; }

/* ---------- Buttons ---------- */
.btn { border-radius: 10px; font-weight: 600; }
.btn-primary { background: var(--brand); border-color: var(--brand); }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-sm { border-radius: 9px; }
.btn-icon { width: 34px; height: 34px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }

/* ---------- Forms ---------- */
.form-control, .form-select {
    border-radius: 10px; border-color: var(--border);
    background: var(--surface); color: var(--text);
}
.form-control:focus, .form-select:focus {
    border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-glow);
    background: var(--surface); color: var(--text);
}
.form-label { font-weight: 600; font-size: .82rem; color: var(--text-muted); }
.form-text { color: var(--text-muted); }

/* ---------- View page fields ---------- */
.field-label { font-size: .7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 700; }
.field-value { font-weight: 600; }
.thumb-img { max-height: 170px; object-fit: cover; cursor: pointer; transition: transform .15s; border-radius: 10px; }
.thumb-img:hover { transform: scale(1.03); }

/* ---------- Delivery stepper ---------- */
.delivery-stepper { display: flex; flex-wrap: wrap; gap: .5rem; }
.delivery-stepper .step {
    flex: 1 1 0; min-width: 90px; text-align: center;
    padding: .65rem .4rem; border-radius: 12px;
    background: var(--surface-2); border: 1px solid var(--border);
    color: var(--text-muted); font-size: .74rem; font-weight: 600;
}
.delivery-stepper .step i { display: block; font-size: 1.1rem; margin-bottom: .25rem; }
.delivery-stepper .step.done { background: color-mix(in srgb, var(--brand) 12%, transparent); color: var(--brand); border-color: transparent; }
.delivery-stepper .step.current {
    background: linear-gradient(135deg, var(--brand), #4f8bff); color: #fff; border-color: transparent;
    box-shadow: 0 8px 18px var(--brand-glow);
}

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head h4 { font-weight: 800; margin: 0; letter-spacing: -.01em; }
.page-head .sub { color: var(--text-muted); font-size: .85rem; }

/* ---------- Login ---------- */
.login-page {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: radial-gradient(1200px 600px at 10% -10%, #2d3a64 0%, transparent 60%),
                linear-gradient(135deg, #0c1322 0%, #1f2b4d 100%);
    padding: 1rem;
}
.login-card { width: 100%; max-width: 420px; border-radius: 22px; box-shadow: var(--shadow-lg); border: none; }
.login-logo {
    width: 70px; height: 70px; margin: 0 auto; border-radius: 20px;
    background: linear-gradient(135deg, var(--brand), #4f8bff); color: #fff;
    display: flex; align-items: center; justify-content: center; font-size: 1.7rem;
    box-shadow: 0 12px 28px var(--brand-glow);
}

/* ---------- DataTables tweaks ---------- */
.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select { border: 1px solid var(--border); border-radius: 8px; }

/* ---------- Responsive ---------- */
@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); width: var(--sb-w) !important; }
    .sidebar.show { transform: translateX(0); }
    .main-content { margin-left: 0 !important; }
    .sidebar-backdrop.show { display: block; }
    .topbar-search { display: none; }
}

/* fade-in */
.page-body > * { animation: fadeUp .35s ease both; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
