/* =================================================================
   Cargo Trace — Person & Item Tracking System
   Design system + components (vanilla CSS, no build step)
   ================================================================= */

:root {
    /* Brand palette */
    --primary:        #4f46e5;
    --primary-dark:   #4338ca;
    --primary-light:  #eef2ff;
    --accent:         #0ea5e9;
    --success:        #16a34a;
    --success-bg:     #dcfce7;
    --warning:        #d97706;
    --warning-bg:     #fef3c7;
    --danger:         #dc2626;
    --danger-bg:      #fee2e2;
    --info:           #0891b2;

    /* Neutrals */
    --bg:        #f4f6fb;
    --surface:   #ffffff;
    --border:    #e5e8f0;
    --text:      #1e2335;
    --muted:     #6b7280;
    --muted-2:   #9ca3af;

    /* Effects */
    --radius:     14px;
    --radius-sm:  9px;
    --shadow-sm:  0 1px 2px rgba(16,24,40,.06);
    --shadow:     0 4px 16px rgba(16,24,40,.08);
    --shadow-lg:  0 18px 50px rgba(16,24,40,.18);
    --sidebar-w:  256px;
    --header-h:   66px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 14.5px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }

/* ---------------- Layout ---------------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    background: linear-gradient(180deg, #1e1b4b 0%, #312e81 100%);
    color: #c7d2fe;
    position: fixed;
    inset: 0 auto 0 0;
    display: flex;
    flex-direction: column;
    z-index: 40;
}
.brand {
    display: flex; align-items: center; gap: 12px;
    padding: 20px 22px;
    color: #fff;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand .logo {
    width: 38px; height: 38px; border-radius: 10px;
    background: linear-gradient(135deg, var(--accent), var(--primary));
    display: grid; place-items: center;
    font-size: 20px; box-shadow: var(--shadow);
}
.brand b { font-size: 17px; letter-spacing: .2px; }
.brand span { display: block; font-size: 11px; color: #a5b4fc; font-weight: 500; }

.nav { padding: 14px 12px; flex: 1; }
.nav-label {
    font-size: 10.5px; text-transform: uppercase; letter-spacing: 1px;
    color: #818cf8; margin: 14px 12px 6px;
}
.nav a {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 14px; border-radius: 10px;
    color: #c7d2fe; font-weight: 500; margin-bottom: 3px;
    transition: background .15s, color .15s;
}
.nav a .ic { width: 20px; text-align: center; font-size: 16px; }
.nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav a.active { background: rgba(255,255,255,.14); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }

.sidebar-foot { padding: 16px 20px; font-size: 11.5px; color: #818cf8; border-top: 1px solid rgba(255,255,255,.08); }

.main {
    flex: 1;
    margin-left: var(--sidebar-w);
    display: flex; flex-direction: column;
    min-width: 0;
}

.header {
    height: var(--header-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 28px;
    position: sticky; top: 0; z-index: 30;
}
.header h1 { font-size: 19px; font-weight: 700; }
.header .sub { font-size: 12.5px; color: var(--muted); font-weight: 400; }
.header-actions { display: flex; align-items: center; gap: 12px; }

.content { padding: 26px 28px 60px; }

/* ---------------- Buttons ---------------- */
.btn {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 9px 16px; border: 1px solid transparent; border-radius: 10px;
    font: inherit; font-weight: 600; font-size: 13.5px;
    cursor: pointer; transition: all .15s; white-space: nowrap;
    background: var(--surface); color: var(--text);
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: #f8f9fc; border-color: #d3d8e6; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; border-radius: 8px; }
.btn-icon { padding: 7px; width: 34px; height: 34px; justify-content: center; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------------- Cards / stats ---------------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.card-head h2 { font-size: 15.5px; font-weight: 700; }
.card-body { padding: 18px 20px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 18px; margin-bottom: 24px; }
.stat {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 20px; position: relative; overflow: hidden;
    box-shadow: var(--shadow-sm);
}
.stat .ic {
    width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center;
    font-size: 22px; margin-bottom: 14px;
}
.stat .ic.indigo { background: var(--primary-light); color: var(--primary); }
.stat .ic.sky    { background: #e0f2fe; color: var(--accent); }
.stat .ic.green  { background: var(--success-bg); color: var(--success); }
.stat .ic.amber  { background: var(--warning-bg); color: var(--warning); }
.stat .num { font-size: 28px; font-weight: 800; letter-spacing: -.5px; }
.stat .label { font-size: 12.5px; color: var(--muted); font-weight: 500; }

/* ---------------- Toolbar ---------------- */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.search {
    position: relative; flex: 1; max-width: 360px;
}
.search input {
    width: 100%; padding: 10px 14px 10px 38px;
    border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
    font: inherit; font-size: 13.5px;
}
.search .ic { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted-2); }
.search input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }

/* ---------------- Tables ---------------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow-sm); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
    text-align: left; padding: 13px 16px; background: #f8f9fc;
    font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted);
    border-bottom: 1px solid var(--border); white-space: nowrap; font-weight: 700;
}
tbody td { padding: 12px 16px; border-bottom: 1px solid #f0f2f7; vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbff; }
.cell-actions { display: flex; gap: 6px; justify-content: flex-end; }

.avatar {
    width: 40px; height: 40px; border-radius: 10px; object-fit: cover;
    background: var(--primary-light); display: grid; place-items: center;
    color: var(--primary); font-weight: 700; font-size: 15px; flex-shrink: 0;
}
.avatar.sq { border-radius: 8px; }
.cell-person { display: flex; align-items: center; gap: 12px; }
.cell-person .meta b { display: block; font-weight: 600; }
.cell-person .meta small { color: var(--muted); }

.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
}
.badge.green { background: var(--success-bg); color: var(--success); }
.badge.amber { background: var(--warning-bg); color: var(--warning); }
.badge.red   { background: var(--danger-bg); color: var(--danger); }
.badge.blue  { background: #e0f2fe; color: var(--info); }
.badge.gray  { background: #eef0f5; color: var(--muted); }

.mono { font-variant-numeric: tabular-nums; font-family: 'SF Mono', ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; }

/* ---------------- Empty state ---------------- */
.empty { text-align: center; padding: 56px 20px; color: var(--muted); }
.empty .ic { font-size: 44px; margin-bottom: 12px; opacity: .5; }
.empty h3 { font-size: 16px; color: var(--text); margin-bottom: 4px; }

/* ---------------- Forms ---------------- */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 6px; color: #374151; }
.field label .req { color: var(--danger); }
.field input, .field select, .field textarea {
    width: 100%; padding: 10px 12px; border: 1px solid var(--border);
    border-radius: 10px; font: inherit; font-size: 14px; background: var(--surface);
    transition: border .15s, box-shadow .15s;
}
.field textarea { resize: vertical; min-height: 76px; }
.field input:focus, .field select:focus, .field textarea:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light);
}
.field .hint { font-size: 11.5px; color: var(--muted); margin-top: 5px; }
.field .err { display: none; font-size: 11.5px; color: var(--danger); margin-top: 5px; }
.field.invalid input, .field.invalid select, .field.invalid textarea { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-bg); }
.field.invalid .err { display: block; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 16px; }

/* Image upload */
.uploader { display: flex; align-items: center; gap: 16px; }
.uploader .preview {
    width: 84px; height: 84px; border-radius: 12px; object-fit: cover;
    border: 2px dashed var(--border); background: #f8f9fc;
    display: grid; place-items: center; color: var(--muted-2); font-size: 24px; flex-shrink: 0;
}
.uploader .preview img { width: 100%; height: 100%; object-fit: cover; border-radius: 10px; }

/* ---------------- Modal ---------------- */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(15,20,40,.55);
    backdrop-filter: blur(2px);
    display: none; align-items: flex-start; justify-content: center;
    z-index: 100; padding: 40px 16px; overflow-y: auto;
}
.modal-backdrop.open { display: flex; }
.modal {
    background: var(--surface); border-radius: 18px; width: 100%; max-width: 560px;
    box-shadow: var(--shadow-lg); animation: pop .18s ease;
    margin: auto 0;
}
.modal.wide { max-width: 920px; }
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 17px; }
.modal-head .x { background: #f1f3f8; border: none; width: 32px; height: 32px; border-radius: 8px; cursor: pointer; font-size: 17px; color: var(--muted); }
.modal-head .x:hover { background: #e6e9f2; }
.modal-body { padding: 22px 24px; }
.modal-foot { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; background: #fbfcfe; border-radius: 0 0 18px 18px; }

/* ---------------- Toast ---------------- */
.toasts { position: fixed; bottom: 18px; right: 18px; z-index: 200; display: flex; flex-direction: column-reverse; gap: 10px; }
.toast {
    background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--primary);
    border-radius: 12px; padding: 13px 16px; box-shadow: var(--shadow-lg);
    display: flex; gap: 11px; align-items: flex-start; min-width: 280px; max-width: 380px;
    animation: slidein .25s ease;
}
@keyframes slidein { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: none; } }
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast .ic { font-size: 18px; }
.toast.success .ic { color: var(--success); }
.toast.error .ic { color: var(--danger); }
.toast b { display: block; font-size: 13.5px; }
.toast small { color: var(--muted); font-size: 12.5px; }

/* ---------------- Misc ---------------- */
.spinner { width: 18px; height: 18px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .6s linear infinite; }
.spinner.dark { border-color: var(--border); border-top-color: var(--primary); }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-row td { text-align: center; padding: 40px; color: var(--muted); }
.flex { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.muted { color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.divider { height: 1px; background: var(--border); margin: 20px 0; }
.pill-count { background: var(--primary-light); color: var(--primary); font-weight: 700; font-size: 12px; padding: 2px 9px; border-radius: 999px; }

/* Assignment builder (flight detail) */
.assign-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.person-chip { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; margin-bottom: 10px; background: #fbfcff; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); font-weight: 700; margin-bottom: 12px; }

/* ---------------- flatpickr theme overrides ---------------- */
.flatpickr-calendar { border-radius: 14px; box-shadow: var(--shadow-lg); border: 1px solid var(--border); font-family: var(--font); }
.flatpickr-day.selected, .flatpickr-day.selected:hover { background: var(--primary); border-color: var(--primary); }
.flatpickr-day:hover { background: var(--primary-light); border-color: var(--primary-light); }
.flatpickr-day.today { border-color: var(--accent); }
.flatpickr-months .flatpickr-month, .flatpickr-weekdays, span.flatpickr-weekday { color: var(--text); }
.flatpickr-current-month .flatpickr-monthDropdown-months, .flatpickr-current-month input.cur-year { font-weight: 700; }
.flatpickr-monthDropdown-months:hover { background: var(--primary-light) !important; }

/* Custom dropdown-based time selector (replaces the spinner inputs) */
.flatpickr-time.ct-time { height: auto; max-height: none; }
.flatpickr-time.ct-time .numInputWrapper,
.flatpickr-time.ct-time > .flatpickr-time-separator,
.flatpickr-time.ct-time .flatpickr-am-pm { display: none !important; }
.ct-time-row { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 12px; }
.ct-time-row select {
    appearance: none; -webkit-appearance: none;
    border: 1px solid var(--border); border-radius: 9px; background: var(--surface);
    padding: 8px 12px; font: inherit; font-size: 14px; font-weight: 600; color: var(--text);
    cursor: pointer; text-align: center; min-width: 64px;
    transition: border .15s, box-shadow .15s;
}
.ct-time-row select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.ct-time-row select.ct-a { min-width: 60px; }
.ct-time-row .ct-sep { font-weight: 800; color: var(--muted); }

/* Mobile menu toggle (hidden on desktop) */
.menu-toggle { display: none; background: none; border: none; font-size: 22px; cursor: pointer; }

@media (max-width: 980px) {
    .grid-2, .grid-3, .assign-grid { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
    .sidebar { transform: translateX(-100%); transition: transform .25s; }
    .sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
    .main { margin-left: 0; }
    .menu-toggle { display: block; }
    .content { padding: 18px 16px 60px; }
    .header { padding: 0 16px; }
}
