/* ===== Lusail font family (Qatari) ===== */
@font-face { font-family:'Lusail'; src:url('/fonts/Lusail-Light.otf') format('opentype'); font-weight:300; font-display:swap; }
@font-face { font-family:'Lusail'; src:url('/fonts/Lusail-Regular.otf') format('opentype'); font-weight:400; font-display:swap; }
@font-face { font-family:'Lusail'; src:url('/fonts/Lusail-Medium.otf') format('opentype'); font-weight:500; font-display:swap; }
@font-face { font-family:'Lusail'; src:url('/fonts/Lusail-Semibold.otf') format('opentype'); font-weight:600; font-display:swap; }
@font-face { font-family:'Lusail'; src:url('/fonts/Lusail-Bold.otf') format('opentype'); font-weight:700; font-display:swap; }
@font-face { font-family:'Lusail'; src:url('/fonts/Lusail-Extrabold.otf') format('opentype'); font-weight:800; font-display:swap; }

:root {
    --maroon: #8A1538;
    --maroon-dk: #5E0E26;
    --maroon-soft: #f7e8ee;
    --ink: #232730;
    --muted: #6b7280;
    --bg: #f4f5f8;
    --radius: 16px;
}

.bg-maroon { background: var(--maroon) !important; }
.border-maroon { border-color: var(--maroon) !important; }

* { -webkit-font-smoothing: antialiased; }

body {
    font-family: 'Lusail', 'Tajawal', 'Segoe UI', Tahoma, 'Geeza Pro', Arial, sans-serif;
    background:
        radial-gradient(1200px 400px at 100% -10%, rgba(138,21,56,.06), transparent 60%),
        var(--bg);
    color: var(--ink);
    min-height: 100vh;
}

/* Navbar */
.app-navbar {
    background: linear-gradient(100deg, var(--maroon-dk), var(--maroon));
    box-shadow: 0 4px 20px rgba(94,14,38,.25);
}
.app-navbar .navbar-brand { color: #fff; letter-spacing: .3px; }
.app-navbar .brand-dot { color: #f1c7d4; }
.app-navbar .brand-sub { font-weight: 400; font-size: .9rem; opacity: .85; }
.app-navbar .nav-link { color: rgba(255,255,255,.82); margin-inline: 1px; border-radius: 10px; padding-inline: 9px !important; transition: .15s; }
.app-navbar .navbar-brand span { font-size: 1.05rem; }
.app-navbar .nav-link:hover { color: #fff; background: rgba(255,255,255,.14); }
.app-navbar .dropdown-menu { border: 0; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.15); }
.app-navbar .dropdown-item:active { background: var(--maroon); }

/* Buttons */
.btn { border-radius: 10px; font-weight: 500; transition: .15s; }
.btn-maroon { background: var(--maroon); border-color: var(--maroon); color: #fff; box-shadow: 0 2px 8px rgba(138,21,56,.25); }
.btn-maroon:hover { background: var(--maroon-dk); border-color: var(--maroon-dk); color: #fff; transform: translateY(-1px); }
.btn-outline-maroon { color: var(--maroon); border-color: var(--maroon); }
.btn-outline-maroon:hover { background: var(--maroon); color: #fff; }
.text-maroon { color: var(--maroon) !important; }

/* Cards / stats */
.card { border: 0; border-radius: var(--radius); box-shadow: 0 4px 18px rgba(20,20,40,.06); transition: .18s; }
.card-header { background: #fff; border-bottom: 1px solid #eef0f3; font-weight: 700; border-radius: var(--radius) var(--radius) 0 0 !important; }
.card-stat { position: relative; overflow: hidden; }
.card-stat:hover { transform: translateY(-3px); box-shadow: 0 10px 26px rgba(20,20,40,.10); }
.card-stat .stat-value { font-size: 2.1rem; font-weight: 800; color: var(--maroon-dk); line-height: 1.1; }
.card-stat .stat-icon {
    font-size: 1.4rem; color: #fff; opacity: 1;
    background: linear-gradient(135deg, var(--maroon), var(--maroon-dk));
    width: 42px; height: 42px; border-radius: 12px;
    display: inline-flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 12px rgba(138,21,56,.3);
}

/* Tables */
.table { --bs-table-bg: transparent; }
.table > thead { background: var(--maroon); color: #fff; }
.table > thead th { font-weight: 600; border-color: var(--maroon-dk); white-space: nowrap; }
.table-hover > tbody > tr:hover > * { background: var(--maroon-soft); }
.table > tbody > tr { border-color: #eef0f3; }

/* Badges a touch rounder */
.badge { border-radius: 8px; font-weight: 600; padding: .4em .65em; }

/* Forms */
.form-control, .form-select { border-radius: 10px; border-color: #e1e4ea; }
.form-control:focus, .form-select:focus { border-color: var(--maroon); box-shadow: 0 0 0 .2rem rgba(138,21,56,.12); }
.form-label { font-weight: 600; font-size: .9rem; color: #424857; }

/* Page heading */
.page-title { color: var(--maroon-dk); font-weight: 800; }
.page-title .bi { color: var(--maroon); }

a { text-decoration: none; }
.app-footer { border-top: 1px solid #e9eaee; background: #fff; }
.required-star { color: #c0392b; }

/* Navbar tidy */
.brand-logo { height: 42px; width: 42px; object-fit: contain; background: #fff; border-radius: 50%; padding: 4px; box-shadow: 0 2px 6px rgba(0,0,0,.25); }
.app-navbar .navbar-nav { gap: 2px; align-items: center; }
.app-navbar .nav-link { white-space: nowrap; }
#themeToggle { font-size: 1.05rem; }

/* Subtle entrance animation for cards */
@keyframes riseIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
main .card { animation: riseIn .35s ease both; }
main .row > [class*="col"]:nth-child(2) .card { animation-delay: .04s; }
main .row > [class*="col"]:nth-child(3) .card { animation-delay: .08s; }
main .row > [class*="col"]:nth-child(4) .card { animation-delay: .12s; }
@media (prefers-reduced-motion: reduce) { main .card { animation: none; } }

/* ===================== Dark mode ===================== */
:root[data-theme="dark"] {
    --ink: #e6e8ec;
    --muted: #9aa3b2;
    --bg: #0f1216;
    --maroon-soft: #2a1820;
}
:root[data-theme="dark"] body { background: radial-gradient(1200px 400px at 100% -10%, rgba(138,21,56,.10), transparent 60%), #0f1216; color: var(--ink); }
:root[data-theme="dark"] .card { background: #171b21; color: var(--ink); box-shadow: 0 4px 18px rgba(0,0,0,.4); }
:root[data-theme="dark"] .card-header { background: #1b2027; border-bottom-color: #262c35; color: var(--ink); }
:root[data-theme="dark"] .text-muted { color: var(--muted) !important; }
:root[data-theme="dark"] .table { color: var(--ink); }
:root[data-theme="dark"] .table > tbody > tr { border-color: #262c35; }
:root[data-theme="dark"] .table-hover > tbody > tr:hover > * { background: #221a1f; color: var(--ink); }
:root[data-theme="dark"] .form-control, :root[data-theme="dark"] .form-select { background: #11151a; border-color: #2a313b; color: var(--ink); }
:root[data-theme="dark"] .form-control::placeholder { color: #6b7480; }
:root[data-theme="dark"] .form-label { color: #c4ccd8; }
:root[data-theme="dark"] .btn-light { background: #232a33; border-color: #2a313b; color: var(--ink); }
:root[data-theme="dark"] .btn-light:hover { background: #2c343f; color: #fff; }
:root[data-theme="dark"] .app-footer { background: #11151a; border-top-color: #20262e; }
:root[data-theme="dark"] .dropdown-menu { background: #1b2027; border: 1px solid #2a313b; }
:root[data-theme="dark"] .dropdown-item { color: var(--ink); }
:root[data-theme="dark"] .dropdown-item:hover { background: #262c35; }
:root[data-theme="dark"] .input-group-text { background: #232a33; border-color: #2a313b; color: var(--ink); }
:root[data-theme="dark"] .page-title { color: #f0d9e1; }
:root[data-theme="dark"] .border, :root[data-theme="dark"] .border-top { border-color: #262c35 !important; }
:root[data-theme="dark"] .bg-light { background: #1b2027 !important; color: var(--ink); }

/* ===================== UI v3: interactivity & polish ===================== */

/* Top navigation progress bar */
#top-progress { position: fixed; top: 0; inset-inline-start: 0; height: 3px; width: 0; z-index: 2000;
    background: linear-gradient(90deg, var(--maroon), #e0567c); box-shadow: 0 0 8px rgba(138,21,56,.6);
    opacity: 0; transition: width .2s ease, opacity .3s ease; }
#top-progress.active { opacity: 1; }

/* Toasts */
.toast-stack { position: fixed; bottom: 1rem; inset-inline-end: 1rem; z-index: 2100; display: flex; flex-direction: column; gap: .5rem; }
.app-toast { min-width: 240px; max-width: 360px; background: #fff; color: var(--ink); border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0,0,0,.18); padding: .7rem .9rem; display: flex; align-items: center; gap: .6rem;
    border-inline-start: 4px solid var(--maroon); animation: toastIn .25s ease both; }
.app-toast.hide { animation: toastOut .25s ease both; }
.app-toast.success { border-inline-start-color: #198754; }
.app-toast.error { border-inline-start-color: #dc3545; }
.app-toast.info { border-inline-start-color: #0d6efd; }
.app-toast .bi { font-size: 1.2rem; }
.app-toast.success .bi { color: #198754; } .app-toast.error .bi { color: #dc3545; } .app-toast.info .bi { color: #0d6efd; }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(12px); } }
:root[data-theme="dark"] .app-toast { background: #1b2027; color: var(--ink); }

/* Table toolbar (search) + sortable headers + clickable rows */
.table-toolbar { display: flex; justify-content: flex-end; padding: .6rem .8rem; }
.table-toolbar .search-wrap { position: relative; max-width: 280px; width: 100%; }
.table-toolbar .search-wrap .bi { position: absolute; top: 50%; inset-inline-start: 10px; transform: translateY(-50%); color: var(--muted); }
.table-toolbar input { padding-inline-start: 32px; border-radius: 999px; }
.table > thead th.sortable { cursor: pointer; user-select: none; }
.table > thead th.sortable:hover { background: var(--maroon-dk); }
.table > thead th .sort-ind { opacity: .5; font-size: .75rem; margin-inline-start: 4px; }
.table tbody tr.clickable { cursor: pointer; }
.table .no-rows td { color: var(--muted); }
.table-sticky thead th { position: sticky; top: 0; z-index: 5; }

/* Count-up keeps layout stable */
.stat-value { font-variant-numeric: tabular-nums; }

/* Skeleton shimmer */
.skeleton { background: linear-gradient(90deg, #e9ecef 25%, #f3f5f7 37%, #e9ecef 63%); background-size: 400% 100%;
    animation: shimmer 1.2s ease-in-out infinite; border-radius: 8px; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
:root[data-theme="dark"] .skeleton { background: linear-gradient(90deg, #1b2027 25%, #232a33 37%, #1b2027 63%); background-size: 400% 100%; }

/* Button busy spinner */
.btn .btn-spin { display: inline-block; width: 1em; height: 1em; border: 2px solid currentColor; border-right-color: transparent;
    border-radius: 50%; animation: spin .6s linear infinite; vertical-align: -2px; margin-inline-end: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Command palette */
.cmdk-backdrop { position: fixed; inset: 0; background: rgba(10,12,16,.45); z-index: 2200; display: none; align-items: flex-start; justify-content: center; }
.cmdk-backdrop.open { display: flex; }
.cmdk { margin-top: 12vh; width: min(620px, 92vw); background: #fff; border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.3); overflow: hidden; animation: toastIn .18s ease both; }
.cmdk input { border: 0; width: 100%; padding: 16px 18px; font-size: 1.05rem; outline: none; background: transparent; color: var(--ink); }
.cmdk .cmdk-head { display: flex; align-items: center; gap: 8px; padding-inline-start: 16px; border-bottom: 1px solid #eef0f3; }
.cmdk-results { max-height: 50vh; overflow-y: auto; padding: 6px; }
.cmdk-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; cursor: pointer; color: var(--ink); }
.cmdk-item.active, .cmdk-item:hover { background: var(--maroon-soft); }
.cmdk-item .ci-type { font-size: .72rem; color: #fff; background: var(--maroon); border-radius: 6px; padding: 1px 7px; margin-inline-start: auto; }
.cmdk-empty { padding: 18px; text-align: center; color: var(--muted); }
:root[data-theme="dark"] .cmdk { background: #171b21; }
:root[data-theme="dark"] .cmdk .cmdk-head { border-bottom-color: #262c35; }

/* Mobile bottom nav */
.bottom-nav { display: none; }
@media (max-width: 768px) {
    .bottom-nav { display: flex; position: fixed; bottom: 0; inset-inline: 0; z-index: 1500;
        background: #fff; border-top: 1px solid #e7e9ee; box-shadow: 0 -4px 18px rgba(0,0,0,.08); }
    .bottom-nav a { flex: 1; text-align: center; padding: 8px 0 6px; color: var(--muted); font-size: .68rem; }
    .bottom-nav a .bi { display: block; font-size: 1.25rem; margin-bottom: 1px; }
    .bottom-nav a.active { color: var(--maroon); }
    main.container { padding-bottom: 72px !important; }
    .toast-stack { bottom: 76px; }
    /* larger touch targets */
    .btn-sm { padding: .35rem .6rem; }
    .table td, .table th { padding-top: .65rem; padding-bottom: .65rem; }
}
:root[data-theme="dark"] .bottom-nav { background: #11151a; border-top-color: #20262e; }

/* Tom Select theming to match Bootstrap/maroon */
.ts-control { border-radius: 10px !important; border-color: #e1e4ea !important; min-height: 38px; }
.ts-control.focus { border-color: var(--maroon) !important; box-shadow: 0 0 0 .2rem rgba(138,21,56,.12) !important; }
.ts-dropdown { border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.15); border: 1px solid #e1e4ea; }
.ts-dropdown .active { background: var(--maroon-soft); color: var(--maroon-dk); }
:root[data-theme="dark"] .ts-control { background: #11151a !important; border-color: #2a313b !important; color: var(--ink); }
:root[data-theme="dark"] .ts-dropdown { background: #1b2027; color: var(--ink); border-color: #2a313b; }
:root[data-theme="dark"] .ts-dropdown .active { background: #262c35; color: #fff; }
:root[data-theme="dark"] .ts-control .item { color: var(--ink); }

/* Step wizard */
.wizard-steps { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; padding: 0; margin-bottom: 1rem; }
.wizard-steps .wstep { display: flex; align-items: center; gap: 6px; padding: 6px 14px; border-radius: 999px;
    background: #eef0f3; color: var(--muted); font-size: .85rem; font-weight: 600; cursor: pointer; transition: .15s; }
.wizard-steps .wstep .n { width: 22px; height: 22px; border-radius: 50%; background: #cfd4dc; color: #fff;
    display: inline-flex; align-items: center; justify-content: center; font-size: .8rem; }
.wizard-steps .wstep.active { background: var(--maroon); color: #fff; }
.wizard-steps .wstep.active .n { background: #fff; color: var(--maroon); }
.wizard-steps .wstep.done { background: var(--maroon-soft); color: var(--maroon-dk); }
.wizard-steps .wstep.done .n { background: #198754; }
.wizard-steps .wstep.done .n::before { content: "✓"; }
.wizard-steps .wstep.done .n { font-size: 0; }
.wizard-steps .wstep.done .n::before { font-size: .8rem; }
:root[data-theme="dark"] .wizard-steps .wstep { background: #1b2027; }
:root[data-theme="dark"] .wizard-steps .wstep .n { background: #2a313b; }

/* ===================== UI v4 — aesthetics ===================== */

/* Subtle dotted background pattern + softer gradient */
body {
    background:
        radial-gradient(1200px 500px at 100% -10%, rgba(138,21,56,.07), transparent 60%),
        radial-gradient(900px 500px at -10% 110%, rgba(138,21,56,.05), transparent 60%),
        radial-gradient(rgba(138,21,56,.045) 1px, transparent 1px) 0 0 / 22px 22px,
        var(--bg);
}
:root[data-theme="dark"] body {
    background:
        radial-gradient(1200px 500px at 100% -10%, rgba(138,21,56,.16), transparent 60%),
        radial-gradient(rgba(255,255,255,.02) 1px, transparent 1px) 0 0 / 22px 22px,
        #0f1216;
}

/* Softer, deeper card elevation + hover lift everywhere */
.card { box-shadow: 0 6px 22px rgba(20,20,40,.07); transition: transform .18s ease, box-shadow .18s ease; }
.card:hover { box-shadow: 0 14px 36px rgba(20,20,40,.12); }
main > .card, .row > [class*="col"] > .card { will-change: transform; }

/* Glassmorphism hero/banner */
.glass-hero {
    background: linear-gradient(115deg, var(--maroon-dk), var(--maroon) 55%, #b3325a);
    color: #fff; border-radius: 20px; padding: 22px 26px; position: relative; overflow: hidden;
    box-shadow: 0 16px 40px rgba(138,21,56,.28);
}
.glass-hero::after {
    content: ""; position: absolute; inset-inline-end: -40px; top: -40px; width: 220px; height: 220px;
    background: radial-gradient(circle, rgba(255,255,255,.18), transparent 70%); border-radius: 50%;
}
.glass-hero .hero-greet { font-size: 1.4rem; font-weight: 800; }
.glass-hero .hero-sub { opacity: .85; }
.glass-hero .hero-stat { background: rgba(255,255,255,.14); border-radius: 14px; padding: 8px 14px; backdrop-filter: blur(6px); }
.glass-hero .hero-stat .v { font-size: 1.5rem; font-weight: 800; line-height: 1; }
.glass-hero .hero-stat .l { font-size: .75rem; opacity: .85; }

/* Avatars with initials */
.avatar { width: 38px; height: 38px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 700; font-size: .85rem; flex: 0 0 auto; box-shadow: inset 0 0 0 2px rgba(255,255,255,.25); }
.avatar-sm { width: 30px; height: 30px; font-size: .72rem; }

/* Status chips (icon + label) */
.status-chip { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: .32em .7em; font-weight: 600; font-size: .82rem; }

/* Empty states */
.empty-state { text-align: center; padding: 34px 16px; color: var(--muted); }
.empty-state .bi { font-size: 2.4rem; color: #c9ced8; display: block; margin-bottom: 8px; }
:root[data-theme="dark"] .empty-state .bi { color: #3a424e; }
.empty-state .es-title { font-weight: 600; color: var(--ink); }

/* Work-order status timeline (horizontal stepper) */
.wo-timeline { display: flex; align-items: flex-start; overflow-x: auto; gap: 0; padding: 6px 0; }
.wo-timeline .step { flex: 1 1 0; min-width: 78px; text-align: center; position: relative; }
.wo-timeline .step .dot { width: 34px; height: 34px; border-radius: 50%; background: #e7e9ee; color: #9aa3b2;
    display: inline-flex; align-items: center; justify-content: center; position: relative; z-index: 2; transition: .2s; }
.wo-timeline .step::before { content: ""; position: absolute; top: 17px; inset-inline-start: -50%; width: 100%; height: 3px; background: #e7e9ee; z-index: 1; }
.wo-timeline .step:first-child::before { display: none; }
.wo-timeline .step .lbl { font-size: .7rem; margin-top: 6px; color: var(--muted); }
.wo-timeline .step.done .dot { background: #2e9e6b; color: #fff; }
.wo-timeline .step.done::before { background: #2e9e6b; }
.wo-timeline .step.active .dot { background: var(--maroon); color: #fff; box-shadow: 0 0 0 5px var(--maroon-soft); }
.wo-timeline .step.active .lbl { color: var(--maroon); font-weight: 700; }
:root[data-theme="dark"] .wo-timeline .step .dot, :root[data-theme="dark"] .wo-timeline .step::before { background: #2a313b; }

/* Card entrance already exists; add a gentle pop for stat values */
.card-stat:hover .stat-icon { transform: scale(1.08) rotate(-4deg); transition: .2s; }

/* Confetti canvas overlay */
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 3000; }

/* Buttons: subtle gradient on primary maroon */
.btn-maroon { background: linear-gradient(135deg, var(--maroon), var(--maroon-dk)); }

/* Rounded chart container */
.chart-card canvas { max-height: 260px; }

/* Mobile arrangement polish */
@media (max-width: 576px) {
    main .d-flex.justify-content-between { flex-wrap: wrap; gap: .5rem; }
    main .d-flex.justify-content-between > div { display: flex; flex-wrap: wrap; gap: .4rem; }
    .page-title { font-size: 1.25rem; }
    .glass-hero { padding: 16px 18px; }
    .glass-hero .hero-greet { font-size: 1.15rem; }
    .glass-hero .hero-stat .v { font-size: 1.2rem; }
    .card-body { padding: 14px; }
    .btn { white-space: nowrap; }
    .wo-timeline .step { min-width: 64px; }
    .wo-timeline .step .lbl { font-size: .62rem; }
    h3.page-title .bi { font-size: 1.1rem; }
}
