/* Auto Insurance CRM */
:root {
    --ink: #0f172a;
    --text: #334155;
    --muted: #64748b;
    --line: #e2e8f0;
    --field: #f8fafc;
    --page: #f5f7fb;
    --brand: #4f46e5;
    --brand-dark: #4338ca;
    --brand-soft: #eef2ff;
    --green: #065f46;
    --green-soft: #ecfdf5;
    --amber: #92400e;
    --amber-soft: #fffbeb;
    --red: #b91c1c;
    --red-soft: #fef2f2;
    --sidebar: 264px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.45;
    color: var(--text);
    background: var(--page);
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2 { margin: 0; color: var(--ink); letter-spacing: -0.2px; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }

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

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    width: var(--sidebar);
    display: flex;
    flex-direction: column;
    padding: 18px 14px;
    color: #cbd5e1;
    background: linear-gradient(180deg, #1e1b4b 0%, #111027 100%);
    overflow-y: auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 6px 18px;
    color: #ffffff;
}
.brand:hover { text-decoration: none; }
.brand strong { display: block; font-size: 15px; line-height: 1.2; }
.brand small { color: #a5b4fc; letter-spacing: 2px; font-weight: 700; }

.brand-badge {
    flex: 0 0 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    color: #ffffff;
    background: linear-gradient(135deg, #6366f1, #4338ca);
    box-shadow: 0 8px 18px -8px rgba(79, 70, 229, 0.8);
}

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.nav-link {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 10px 12px;
    border-radius: 10px;
    color: #cbd5e1;
    font-weight: 500;
}
.nav-link:hover { background: rgba(255, 255, 255, 0.07); color: #ffffff; text-decoration: none; }
.nav-link.active { background: var(--brand); color: #ffffff; }
.nav-link .icon { flex: 0 0 18px; }

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 16px;
    padding: 12px 8px 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}
.avatar {
    flex: 0 0 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-weight: 700;
    color: #ffffff;
    background: rgba(255, 255, 255, 0.14);
}
.who { min-width: 0; }
.who strong { display: block; color: #ffffff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who small { color: #a5b4fc; }

.sidebar-links {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 8px;
    font-size: 13px;
}
.sidebar-links a { color: #c7d2fe; }
.link-button {
    padding: 0;
    border: none;
    background: none;
    font: inherit;
    color: #c7d2fe;
    cursor: pointer;
}
.link-button:hover { text-decoration: underline; }

.backdrop { display: none; }

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

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 14px;
    min-height: 62px;
    padding: 12px 26px;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(6px);
    border-bottom: 1px solid var(--line);
}
.topbar h1 { flex: 1; min-width: 0; }
.topbar-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.menu-toggle {
    display: none;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: #ffffff;
    color: var(--ink);
    cursor: pointer;
}

.content { padding: 22px 26px 40px; max-width: 1400px; }

/* ---------- Cards ---------- */
.card {
    margin-bottom: 18px;
    padding: 20px;
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.card.narrow { max-width: 720px; }
.card.narrow-wide { max-width: 900px; }

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.grid-2 > .card { margin-bottom: 0; }
.grid-2 { margin-bottom: 18px; }
.grid-wide-left { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
.grid-wide-left .card { margin-bottom: 18px; }
.grid-wide-left { margin-bottom: 0; }

/* ---------- Stats ---------- */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}
.stat {
    padding: 16px 18px;
    background: #ffffff;
    border: 1px solid var(--line);
    border-left: 4px solid var(--brand);
    border-radius: 14px;
}
.stat-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    color: var(--muted);
}
.stat strong { display: block; margin-top: 4px; font-size: 28px; line-height: 1.1; color: var(--ink); }
.stat-pending { border-left-color: #f59e0b; }
.stat-sold { border-left-color: #10b981; }
.stat-rate { border-left-color: #8b5cf6; }
.stats-small { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.stats-small .stat { padding: 12px 14px; border-left-color: #cbd5e1; }
.stats-small .stat strong { font-size: 22px; }
.stats-small .stat-sold { border-left-color: #10b981; }
.stats-small .stat-pending { border-left-color: #f59e0b; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 38px;
    padding: 0 16px;
    font: inherit;
    font-weight: 600;
    border: 1px solid transparent;
    border-radius: 10px;
    cursor: pointer;
    white-space: nowrap;
    transition: filter .15s, background .15s;
}
.btn:hover { text-decoration: none; }
.btn-primary { color: #ffffff; background: linear-gradient(135deg, #6366f1, #4338ca); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-light { color: var(--text); background: #ffffff; border-color: var(--line); }
.btn-light:hover { background: var(--field); }
.btn-danger { color: var(--red); background: var(--red-soft); border-color: #fecaca; }
.btn-danger:hover { background: #fee2e2; }
.btn-small { height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: 8px; }
.btn-icon { width: 30px; height: 30px; padding: 0; border-radius: 8px; }
.btn-block { width: 100%; height: 46px; font-size: 15px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
    outline: 3px solid rgba(79, 70, 229, 0.3);
    outline-offset: 1px;
}

/* ---------- Forms ---------- */
label { display: block; margin-bottom: 5px; font-size: 13px; font-weight: 600; color: #334155; }
.required { color: var(--red); }

input[type="text"], input[type="password"], input[type="email"], input[type="number"],
input[type="date"], input[type="time"], input[type="file"], select, textarea {
    width: 100%;
    min-height: 40px;
    padding: 8px 12px;
    font: inherit;
    color: var(--ink);
    background: var(--field);
    border: 1.5px solid var(--line);
    border-radius: 10px;
    transition: border-color .15s, background .15s;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { background: #ffffff; border-color: var(--brand); outline: none; }
input[disabled], select[disabled] { color: var(--muted); background: #eef2f6; cursor: not-allowed; }
input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--brand); vertical-align: middle; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form-row { min-width: 0; margin-bottom: 4px; }
.form-row.wide { grid-column: 1 / -1; }
.form-row.has-error input, .form-row.has-error select, .form-row.has-error textarea { border-color: #f87171; background: #fff7f7; }
.help { display: block; margin-top: 4px; color: var(--muted); font-size: 12.5px; }
.help ul { margin: 4px 0 0; padding-left: 18px; }
.error { display: block; margin-top: 4px; color: var(--red); font-size: 12.5px; font-weight: 600; }

.check { display: flex; align-items: center; gap: 8px; margin: 8px 0 0; font-weight: 500; cursor: pointer; }

/* Checkbox lists (centers, branch heads) */
.form-row > div > div > label, .form-row ul li label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    padding: 5px 0;
    font-weight: 500;
}

.form-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }

.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form input, .inline-form select { flex: 1; min-width: 0; }

/* ---------- Filters ---------- */
.filters {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
    align-items: end;
    padding: 16px;
}
.filter.wide { grid-column: span 2; }
.filter.buttons { display: flex; gap: 8px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
.table-wrap.spaced { margin-top: 16px; }
.table { width: 100%; border-collapse: collapse; }
.table th {
    padding: 9px 10px;
    text-align: left;
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: var(--muted);
    background: var(--field);
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}
.table td { padding: 10px; border-bottom: 1px solid #eef2f6; vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: #fafbff; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .center { text-align: center; }
.row-off td { color: var(--muted); }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions form { display: inline-block; }
td.row-actions:first-child { text-align: left; }

.empty { margin: 6px 0; padding: 22px; text-align: center; color: var(--muted); background: var(--field); border-radius: 12px; }

/* ---------- Badges ---------- */
.badge {
    display: inline-block;
    padding: 3px 10px;
    font-size: 12px;
    font-weight: 700;
    border-radius: 999px;
    white-space: nowrap;
}
.badge-pending { color: var(--amber); background: #fef3c7; }
.badge-sold { color: var(--green); background: #d1fae5; }
.badge-off { color: #475569; background: #e2e8f0; }
.badge-result-updated { color: var(--green); background: #d1fae5; }
.badge-result-unmatched, .badge-result-duplicate, .badge-result-already_sold { color: #475569; background: #e2e8f0; }
.badge-result-invalid, .badge-result-failed { color: var(--red); background: #fee2e2; }

.tag {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 7px;
    font-size: 11px;
    font-weight: 600;
    color: var(--brand-dark);
    background: var(--brand-soft);
    border-radius: 6px;
}
.tag-warn { color: var(--amber); background: #fef3c7; }

/* ---------- Alerts ---------- */
.alert {
    margin-bottom: 16px;
    padding: 12px 16px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #ffffff;
}
.alert-success { color: var(--green); background: var(--green-soft); border-color: #a7f3d0; }
.alert-error { color: #991b1b; background: var(--red-soft); border-color: #fecaca; }
.alert-info { color: #1e3a8a; background: #eff6ff; border-color: #bfdbfe; }
.alert-warning { color: var(--amber); background: var(--amber-soft); border-color: #fde68a; }

/* ---------- Details ---------- */
.details { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; margin: 0; }
.details.single { grid-template-columns: 1fr; gap: 10px; }
.details dt { font-size: 11.5px; font-weight: 700; letter-spacing: 0.4px; text-transform: uppercase; color: var(--muted); }
.details dd { margin: 2px 0 0; color: var(--ink); font-size: 15px; word-break: break-word; }

.notes { margin: 0; padding-left: 18px; }
.notes li { margin-bottom: 6px; }
.id-list a { display: inline-block; margin: 0 8px 6px 0; }

pre {
    margin: 6px 0 0;
    padding: 10px;
    max-width: 460px;
    overflow-x: auto;
    font-size: 12px;
    background: var(--field);
    border: 1px solid var(--line);
    border-radius: 8px;
    white-space: pre-wrap;
    word-break: break-word;
}
summary { cursor: pointer; color: var(--brand); font-size: 12.5px; }

/* ---------- Trend chart ---------- */
.chart {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    height: 180px;
    padding-top: 8px;
}
.chart-col { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; align-items: center; }
.chart-bars { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 2px; }
.bar { display: block; width: 42%; max-width: 16px; min-height: 2px; border-radius: 4px 4px 0 0; }
.bar-total { background: #a5b4fc; }
.bar-sold { background: #10b981; }
.chart-col small { margin-top: 5px; font-size: 11px; color: var(--muted); }
.legend { display: flex; gap: 18px; margin-top: 10px; font-size: 12.5px; color: var(--muted); }
.dot { display: inline-block; width: 10px; height: 10px; margin-right: 5px; border-radius: 3px; }
.dot-total { background: #a5b4fc; }
.dot-sold { background: #10b981; }

/* ---------- Pagination ---------- */
.pagination { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin-top: 14px; color: var(--muted); }

/* ---------- Sign in ---------- */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    background:
        radial-gradient(900px 500px at 10% -10%, #dbeafe 0%, transparent 60%),
        radial-gradient(800px 500px at 100% 110%, #e0e7ff 0%, transparent 60%),
        #f5f7fb;
}
.auth-card {
    width: 100%;
    max-width: 420px;
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 20px;
    box-shadow: 0 24px 60px -24px rgba(30, 41, 99, 0.3);
    overflow: hidden;
}
.accent { height: 5px; background: linear-gradient(90deg, #818cf8, #4f46e5 55%, #7c3aed); }
.auth-head { display: flex; align-items: center; gap: 14px; padding: 24px 28px 18px; border-bottom: 1px solid var(--line); }
.auth-head .brand-badge { flex-basis: 48px; height: 48px; border-radius: 14px; }
.auth-head p { margin: 2px 0 0; color: var(--muted); }
.auth-body { padding: 22px 28px 28px; }
.auth-body .form-row { margin-bottom: 14px; }
.auth-body input { min-height: 44px; }

/* ---------- Responsive ---------- */
@media (max-width: 1000px) {
    .grid-2, .grid-wide-left { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 860px) {
    .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
    .sidebar.open { transform: none; }
    .backdrop.open { display: block; position: fixed; inset: 0; z-index: 20; background: rgba(15, 23, 42, 0.45); }
    .main { margin-left: 0; }
    .menu-toggle { display: inline-flex; }
    .topbar { padding: 10px 16px; }
    .content { padding: 16px 14px 32px; }
}

@media (max-width: 560px) {
    .form-grid, .details { grid-template-columns: 1fr; }
    .filter.wide { grid-column: 1 / -1; }
    .topbar { flex-wrap: wrap; }
    .card { padding: 16px; }
    .stat strong { font-size: 24px; }
}
