/* ─── Reset & Base ─────────────────────────────────────────────────────── */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary: #1a56db;
    --primary-dark: #1648c0;
    --primary-light: #eff6ff;
    --accent: #f59e0b;
    --green: #15803d;
    --green-bg: #dcfce7;
    --red: #dc2626;
    --red-bg: #fee2e2;
    --amber: #b45309;
    --amber-bg: #fef3c7;
    --text: #0d1b2e;
    --text-2: #475569;
    --text-3: #94a3b8;
    --border: #e2e8f0;
    --bg: #f0f2f5;
    --white: #ffffff;
    --sidebar-w: 220px;
    --topbar-h: 56px;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.05);
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}

/* ─── Layout ────────────────────────────────────────────────────────────── */
.app { display: flex; min-height: 100vh; }
.main-content { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.page-body { flex: 1; overflow-y: auto; padding: 24px; }

/* ─── Screens ───────────────────────────────────────────────────────────── */
.screen { display: none; }
.screen.active { display: flex; flex-direction: column; min-height: 100vh; }
#app-screen { flex-direction: row; }

/* ─── Login ─────────────────────────────────────────────────────────────── */
.login-bg {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0d1b2e 0%, #1a3358 60%, #0d2040 100%);
    position: relative;
    overflow: hidden;
}
.login-bg::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px);
    background-size: 40px 40px;
}
.login-box {
    background: var(--white);
    border-radius: 20px;
    padding: 42px 40px;
    width: 420px;
    box-shadow: 0 25px 60px rgba(0,0,0,.35);
    position: relative;
    z-index: 1;
}
.login-logo {
    width: 60px; height: 60px;
    border-radius: 16px;
    background: linear-gradient(135deg, #1a56db, #3b82f6);
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 16px;
    box-shadow: 0 8px 24px rgba(26,86,219,.4);
    font-size: 26px;
}
.login-box h1 {
    text-align: center;
    font-size: 26px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
}
.login-box .subtitle {
    text-align: center;
    color: var(--text-3);
    font-size: 13px;
    margin-bottom: 28px;
}
.tabs { display: flex; gap: 4px; background: #f1f5f9; border-radius: 10px; padding: 4px; margin-bottom: 24px; }
.tab-btn {
    flex: 1; padding: 8px; border: none; border-radius: 8px;
    font-size: 13px; font-weight: 600; cursor: pointer;
    background: transparent; color: var(--text-3); transition: all .15s;
}
.tab-btn.active { background: var(--white); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.1); }
.tab-content { display: none; }
.tab-content.active { display: flex; flex-direction: column; gap: 14px; }

/* ─── Sidebar ───────────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    background: #0d1b2e;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    flex-shrink: 0;
    overflow-y: auto;
}
.sidebar-logo {
    padding: 18px 16px 14px;
    border-bottom: 1px solid rgba(255,255,255,.07);
    display: flex;
    align-items: center;
    gap: 10px;
}
.sidebar-logo-icon {
    width: 38px; height: 38px;
    border-radius: 10px;
    background: linear-gradient(135deg, #1a56db, #3b82f6);
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; flex-shrink: 0;
}
.sidebar-logo-text { font-size: 15px; font-weight: 700; color: #fff; }
.sidebar-logo-sub  { font-size: 10px; color: #4a6080; margin-top: 1px; }
.nav-section {
    font-size: 9px; font-weight: 700; color: #36506b;
    letter-spacing: .8px; text-transform: uppercase;
    padding: 12px 14px 5px;
}
.nav-item {
    display: flex; align-items: center; gap: 9px;
    padding: 9px 12px; margin: 1px 8px;
    border-radius: 9px; cursor: pointer;
    color: #8899af; font-size: 13px; font-weight: 500;
    transition: all .15s; user-select: none; text-decoration: none;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #c8d8ec; }
.nav-item.active { background: rgba(245,158,11,.14); color: #f59e0b; }
.nav-item .nav-icon { font-size: 15px; flex-shrink: 0; }
.nav-badge {
    margin-left: auto;
    background: #ef4444; color: #fff;
    border-radius: 99px; min-width: 17px; height: 17px;
    font-size: 9px; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    padding: 0 4px;
}
.sidebar-user {
    margin-top: auto;
    padding: 10px 12px 16px;
    border-top: 1px solid rgba(255,255,255,.07);
    display: flex; align-items: center; gap: 10px;
}
.user-avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: linear-gradient(135deg, #1a56db, #7c3aed);
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.user-name  { font-size: 12px; font-weight: 600; color: #c8d8ec; }
.user-role  { font-size: 10px; color: #4a6080; }
#btn-logout {
    margin-left: auto; background: transparent; border: none;
    color: #4a6080; cursor: pointer; font-size: 16px; padding: 4px;
}
#btn-logout:hover { color: #ef4444; }

/* ─── Topbar ─────────────────────────────────────────────────────────────── */
.topbar {
    background: var(--white);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    height: var(--topbar-h);
    display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-size: 17px; font-weight: 700; color: var(--text); }
.topbar-sub   { font-size: 11px; color: var(--text-3); margin-top: 1px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

/* ─── Cards ──────────────────────────────────────────────────────────────── */
.card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.card-body { padding: 20px; }
.card-hover { transition: transform .18s, box-shadow .18s; cursor: pointer; }
.card-hover:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,.1); }

/* KPIs */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
.kpi-card { background: var(--white); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.kpi-icon { width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 18px; margin-bottom: 12px; }
.kpi-val  { font-size: 26px; font-weight: 800; color: var(--text); line-height: 1; }
.kpi-lbl  { font-size: 11px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: .4px; margin-top: 5px; }
.kpi-sub  { font-size: 11px; color: #b0bec5; margin-top: 2px; }

/* ─── Badges ────────────────────────────────────────────────────────────── */
.badge {
    display: inline-flex; align-items: center; gap: 3px;
    padding: 2px 9px; border-radius: 99px;
    font-size: 11px; font-weight: 600;
}
.badge-green  { background: var(--green-bg);  color: var(--green); }
.badge-red    { background: var(--red-bg);    color: var(--red); }
.badge-amber  { background: var(--amber-bg);  color: var(--amber); }
.badge-blue   { background: #dbeafe;          color: #1d4ed8; }
.badge-slate  { background: #f1f5f9;          color: #475569; }
.badge-orange { background: #ffedd5;          color: #c2410c; }
.badge-purple { background: #f3e8ff;          color: #7e22ce; }

/* ─── Buttons ───────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 8px 14px; border-radius: 9px;
    font-family: inherit; font-size: 13px; font-weight: 600;
    cursor: pointer; transition: all .13s; border: none; outline: none;
    white-space: nowrap; text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); box-shadow: 0 4px 14px rgba(26,86,219,.3); }
.btn-ghost   { background: transparent; color: var(--text-2); border: 1.5px solid var(--border); }
.btn-ghost:hover { background: #f8fafc; color: var(--text); }
.btn-danger  { background: var(--red-bg); color: var(--red); }
.btn-danger:hover { background: #fecaca; }
.btn-sm      { padding: 5px 10px; font-size: 12px; }
.btn-block   { width: 100%; justify-content: center; }

/* ─── Forms ─────────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label {
    font-size: 11px; font-weight: 700; color: var(--text-2);
    text-transform: uppercase; letter-spacing: .4px;
}
.form-group input,
.form-group select,
.form-group textarea {
    padding: 9px 12px;
    border: 1.5px solid var(--border);
    border-radius: 9px;
    font-family: inherit; font-size: 13px; color: var(--text);
    background: var(--white); transition: border .13s; outline: none;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26,86,219,.08);
}
.form-group input:disabled,
.form-group select:disabled {
    background: #f8fafc; color: #94a3b8; cursor: not-allowed;
}
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.form-section {
    border-left: 3px solid var(--primary);
    padding-left: 12px;
    margin-bottom: 20px;
}
.form-section-title {
    font-size: 12px; font-weight: 700; color: var(--primary);
    text-transform: uppercase; letter-spacing: .5px; margin-bottom: 14px;
}
.retorno-section {
    background: #f8fafc;
    border: 1.5px dashed var(--border);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 20px;
}
.retorno-section-title {
    font-size: 11px; font-weight: 700; color: var(--text-3);
    text-transform: uppercase; letter-spacing: .5px; margin-bottom: 14px;
    display: flex; align-items: center; gap: 6px;
}

/* ─── Table ──────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead tr { border-bottom: 2px solid #f1f5f9; }
th {
    padding: 9px 13px; text-align: left;
    font-size: 10px; font-weight: 700; color: var(--text-3);
    text-transform: uppercase; letter-spacing: .4px; white-space: nowrap;
}
td { padding: 10px 13px; font-size: 13px; color: #334155; border-bottom: 1px solid #f8fafc; }
tbody tr { transition: background .1s; }
tbody tr:hover { background: #f8fafc; }
tbody tr:last-child td { border-bottom: none; }
.mono { font-family: 'Courier New', monospace; }
.pill {
    display: inline-block; background: #f1f5f9; color: #475569;
    border-radius: 6px; padding: 2px 7px;
    font-family: 'Courier New', monospace; font-size: 11px; font-weight: 600;
}
.table-actions { display: flex; gap: 4px; }
.tbl-pagination {
    padding: 10px 14px;
    border-top: 1px solid #f1f5f9;
    display: flex; justify-content: space-between; align-items: center;
}
.tbl-info { font-size: 12px; color: var(--text-3); }

/* ─── Search bar ────────────────────────────────────────────────────────── */
.search-wrap {
    display: flex; gap: 8px; align-items: center;
    margin-bottom: 16px; flex-wrap: wrap;
}
.search-input-wrap { position: relative; flex: 1; min-width: 200px; }
.search-input-wrap input { padding-left: 34px; }
.search-icon {
    position: absolute; left: 10px; top: 50%;
    transform: translateY(-50%);
    color: var(--text-3); font-size: 14px; pointer-events: none;
}
.filter-btn {
    padding: 8px 12px; border-radius: 9px; cursor: pointer;
    border: 1.5px solid var(--border); background: var(--white);
    font-family: inherit; font-size: 13px; font-weight: 600;
    color: var(--text-2); transition: all .13s; white-space: nowrap;
}
.filter-btn.active {
    background: var(--primary); color: var(--white); border-color: var(--primary);
}
.filter-btn:hover:not(.active) { background: #f8fafc; }

/* ─── Alert cards ───────────────────────────────────────────────────────── */
.alert-card {
    display: flex; align-items: flex-start; gap: 13px;
    padding: 13px 16px; border-radius: 10px; border-left: 3px solid;
    margin-bottom: 8px;
}
.alert-high { background: #fff5f5; border-color: #ef4444; }
.alert-med  { background: #fffbeb; border-color: #f59e0b; }
.alert-low  { background: #eff6ff; border-color: #3b82f6; }
.alert-icon { font-size: 16px; flex-shrink: 0; margin-top: 1px; }
.alert-title { font-size: 13px; font-weight: 600; color: var(--text); }
.alert-desc  { font-size: 12px; color: var(--text-2); margin-top: 2px; }

/* ─── Messages ──────────────────────────────────────────────────────────── */
.msg { padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-top: 8px; }
.msg-error   { background: var(--red-bg); color: var(--red); border: 1px solid #fca5a5; }
.msg-success { background: var(--green-bg); color: var(--green); border: 1px solid #86efac; }
.msg-info    { background: #dbeafe; color: #1d4ed8; border: 1px solid #93c5fd; }

/* ─── Loading ───────────────────────────────────────────────────────────── */
.loading { display: none; text-align: center; padding: 40px; color: var(--text-3); }
.loading.active { display: block; }
.spinner {
    width: 32px; height: 32px; border-radius: 50%;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    animation: spin .7s linear infinite;
    margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Empty state ───────────────────────────────────────────────────────── */
.empty-state {
    text-align: center; padding: 60px 20px; color: var(--text-3);
}
.empty-state .empty-icon { font-size: 48px; margin-bottom: 16px; }
.empty-state p { font-size: 14px; }

/* ─── Modal (detalhe) ───────────────────────────────────────────────────── */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.info-box { background: #f8fafc; border-radius: 8px; padding: 10px 12px; }
.info-box .ib-label { font-size: 10px; font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: .4px; }
.info-box .ib-val   { font-size: 13px; font-weight: 600; color: var(--text); margin-top: 3px; }
.progress-bar { height: 6px; border-radius: 3px; background: #f1f5f9; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 3px; background: var(--primary); transition: width .6s; }

/* ─── Section headers inside pages ─────────────────────────────────────── */
.page-header {
    display: flex; align-items: center;
    justify-content: space-between; margin-bottom: 20px;
}
.page-header-left .sec-title { font-size: 15px; font-weight: 700; color: var(--text); }
.page-header-left .sec-sub   { font-size: 12px; color: var(--text-3); margin-top: 2px; }

/* ─── Dashboard charts (placeholder) ───────────────────────────────────── */
.chart-card { padding: 20px; }
.chart-title { font-size: 14px; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.chart-sub   { font-size: 12px; color: var(--text-3); margin-bottom: 16px; }
.chart-area  { height: 200px; background: linear-gradient(135deg, #eff6ff, #dbeafe); border-radius: 8px; display: flex; align-items: center; justify-content: center; color: var(--text-3); font-size: 13px; }

/* ─── SAV Number display ────────────────────────────────────────────────── */
.sav-number { font-size: 22px; font-weight: 800; color: var(--primary); font-family: 'Courier New', monospace; }

/* ─── Motorista card ────────────────────────────────────────────────────── */
.motorista-card { padding: 20px; }
.motorista-avatar {
    width: 50px; height: 50px; border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; font-weight: 700; color: #fff; flex-shrink: 0;
    font-family: 'Courier New', monospace;
}
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }

/* ─── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
    .sidebar { display: none; }
    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .form-grid-2 { grid-template-columns: 1fr; }
    .form-grid-3 { grid-template-columns: 1fr; }
    .detail-grid { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
    .kpi-grid { grid-template-columns: 1fr; }
    .login-box { width: 95vw; padding: 28px 20px; }
}
