/* ============================================================
   SINAPI Admin — Estilos principais
   CSS puro, sem frameworks externos
   ============================================================ */

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

:root {
    --color-primary:    #1a56db;
    --color-primary-h:  #1648c0;
    --color-success:    #057a55;
    --color-warning:    #b45309;
    --color-danger:     #c81e1e;
    --color-info:       #0891b2;
    --color-bg:         #f3f4f6;
    --color-surface:    #ffffff;
    --color-border:     #e5e7eb;
    --color-text:       #111827;
    --color-text-muted: #6b7280;
    --color-sidebar:    #1e2a3a;
    --color-sidebar-h:  #263348;
    --sidebar-w:        240px;
    --radius:           8px;
    --shadow:           0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md:        0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
    --transition:       150ms ease;
}

html { font-size: 15px; }
body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.5;
    min-height: 100vh;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }

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

/* ---- Sidebar ---------------------------------------------- */
.sidebar {
    width: var(--sidebar-w);
    background: var(--color-sidebar);
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    z-index: 100;
    overflow-y: auto;
}

.sidebar-logo {
    padding: 1.25rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-logo .logo-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: #f1f5f9;
    letter-spacing: .3px;
}
.sidebar-logo .logo-sub {
    font-size: .72rem;
    color: #94a3b8;
    margin-top: 2px;
}

.sidebar-nav { padding: .75rem 0; flex: 1; }
.sidebar-nav ul { list-style: none; }
.sidebar-nav li a {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .6rem 1rem;
    color: #94a3b8;
    font-size: .875rem;
    border-left: 3px solid transparent;
    transition: background var(--transition), color var(--transition);
}
.sidebar-nav li a:hover,
.sidebar-nav li a.active {
    background: var(--color-sidebar-h);
    color: #f1f5f9;
    text-decoration: none;
    border-left-color: var(--color-primary);
}
.sidebar-nav li a .nav-icon { font-size: 1.05rem; opacity: .9; }

.sidebar-footer {
    padding: .75rem 1rem;
    font-size: .72rem;
    color: #475569;
    border-top: 1px solid rgba(255,255,255,.06);
}

/* ---- Conteúdo principal ----------------------------------- */
.main-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.topbar {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: .85rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow);
}
.topbar-title { font-size: 1rem; font-weight: 600; }
.topbar-actions { display: flex; gap: .5rem; align-items: center; }

.page-body { padding: 1.5rem; flex: 1; }

/* ---- Cards ------------------------------------------------ */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
    font-weight: 600;
    font-size: .9rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.card-body { padding: 1.25rem; }

/* ---- Stat cards ------------------------------------------- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.15rem 1.25rem;
    box-shadow: var(--shadow);
    display: flex;
    align-items: flex-start;
    gap: .9rem;
}
.stat-icon {
    width: 44px; height: 44px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0;
}
.stat-icon.blue   { background: #dbeafe; }
.stat-icon.green  { background: #d1fae5; }
.stat-icon.yellow { background: #fef3c7; }
.stat-icon.purple { background: #ede9fe; }
.stat-icon.red    { background: #fee2e2; }
.stat-info .stat-value { font-size: 1.55rem; font-weight: 700; line-height: 1.2; }
.stat-info .stat-label { font-size: .78rem; color: var(--color-text-muted); margin-top: 2px; }

/* ---- Buttons ---------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .5rem 1rem;
    border-radius: 6px;
    font-size: .85rem;
    font-weight: 500;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background var(--transition), opacity var(--transition);
    text-decoration: none;
    white-space: nowrap;
    line-height: 1.4;
}
.btn:hover { opacity: .88; text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary   { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-h); }
.btn-success   { background: var(--color-success); color: #fff; }
.btn-danger    { background: var(--color-danger); color: #fff; }
.btn-secondary { background: #f1f5f9; color: var(--color-text); border-color: var(--color-border); }
.btn-outline   { background: transparent; border-color: var(--color-primary); color: var(--color-primary); }
.btn-sm        { padding: .3rem .7rem; font-size: .8rem; }
.btn-lg        { padding: .7rem 1.4rem; font-size: .95rem; }

/* ---- Badges ----------------------------------------------- */
.badge {
    display: inline-flex; align-items: center; gap: .25rem;
    padding: .2rem .6rem;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .3px;
}
.badge-success  { background: #d1fae5; color: #065f46; }
.badge-danger   { background: #fee2e2; color: #991b1b; }
.badge-warning  { background: #fef3c7; color: #92400e; }
.badge-info     { background: #cffafe; color: #164e63; }
.badge-secondary{ background: #f1f5f9; color: #475569; }
.badge-dot::before {
    content: '';
    display: inline-block;
    width: 6px; height: 6px;
    border-radius: 50%;
    background: currentColor;
}

/* ---- Forms ------------------------------------------------ */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: .84rem; font-weight: 500; margin-bottom: .35rem; }
.form-control {
    width: 100%;
    padding: .5rem .75rem;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font-size: .875rem;
    background: var(--color-surface);
    color: var(--color-text);
    transition: border-color var(--transition);
}
.form-control:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(26,86,219,.12);
}
.form-control::placeholder { color: #9ca3af; }
select.form-control { cursor: pointer; }
.form-text { font-size: .78rem; color: var(--color-text-muted); margin-top: .25rem; }

.filters-bar {
    display: flex;
    flex-wrap: wrap;
    gap: .75rem;
    align-items: flex-end;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow);
}
.filters-bar .form-group { margin-bottom: 0; flex: 1; min-width: 160px; }
.filters-bar .form-group.wide { flex: 2; min-width: 240px; }

/* ---- Tables ----------------------------------------------- */
.table-wrapper {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.table-scroll { overflow-x: auto; }
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .84rem;
}
.data-table thead tr { background: #f8fafc; }
.data-table th {
    padding: .7rem 1rem;
    text-align: left;
    font-weight: 600;
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: var(--color-text-muted);
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}
.data-table td {
    padding: .65rem 1rem;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
}
.data-table tbody tr:hover { background: #fafafa; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table .text-right { text-align: right; }
.data-table .text-center { text-align: center; }
.data-table .mono { font-family: "SFMono-Regular", Consolas, monospace; }
.data-table td.desc { max-width: 340px; }
.data-table td.desc .desc-text {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.row-link { cursor: pointer; }
.row-link:hover td { background: #eff6ff; }

/* ---- Pagination ------------------------------------------- */
.pagination {
    display: flex;
    align-items: center;
    gap: .3rem;
    padding: .75rem 1rem;
    border-top: 1px solid var(--color-border);
    justify-content: space-between;
    font-size: .84rem;
}
.pagination-info { color: var(--color-text-muted); }
.pagination-pages { display: flex; gap: .25rem; }
.page-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px;
    border-radius: 5px;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: .82rem;
    cursor: pointer;
    transition: background var(--transition);
}
.page-btn:hover  { background: #f1f5f9; }
.page-btn.active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ---- Modal ------------------------------------------------ */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 1000;
    display: flex; align-items: center; justify-content: center;
    padding: 1rem;
    opacity: 0; pointer-events: none;
    transition: opacity 200ms ease;
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }
.modal {
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: 0 20px 40px rgba(0,0,0,.15);
    width: 100%;
    max-width: 700px;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    transform: translateY(12px);
    transition: transform 200ms ease;
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
    display: flex; align-items: center; justify-content: space-between;
    font-weight: 600;
}
.modal-body { padding: 1.25rem; overflow-y: auto; flex: 1; }
.modal-footer {
    padding: .75rem 1.25rem;
    border-top: 1px solid var(--color-border);
    display: flex; gap: .5rem; justify-content: flex-end;
}
.modal-close {
    background: none; border: none; cursor: pointer;
    font-size: 1.25rem; color: var(--color-text-muted);
    padding: .2rem .4rem; border-radius: 4px;
}
.modal-close:hover { background: #f1f5f9; }

/* ---- Detail grid (dentro de modal) ------------------------ */
.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .75rem 1.5rem;
}
.detail-item .detail-label {
    font-size: .75rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: .3px;
    margin-bottom: .2rem;
}
.detail-item .detail-value { font-size: .9rem; }
.detail-item.full { grid-column: 1 / -1; }

/* ---- Comparativo de UFs ----------------------------------- */
.uf-compare-table { font-size: .82rem; }
.uf-compare-table th, .uf-compare-table td { padding: .4rem .6rem; }

/* ---- Gráfico de barras HTML ------------------------------ */
.bar-chart { display: flex; flex-direction: column; gap: .45rem; padding: .5rem 0; }
.bar-row {
    display: flex;
    align-items: center;
    gap: .6rem;
    font-size: .8rem;
}
.bar-label { width: 30px; text-align: right; font-weight: 600; color: var(--color-text-muted); }
.bar-track {
    flex: 1;
    height: 18px;
    background: #f1f5f9;
    border-radius: 4px;
    overflow: hidden;
}
.bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--color-primary), #60a5fa);
    border-radius: 4px;
    transition: width .5s ease;
    min-width: 4px;
}
.bar-value { width: 70px; text-align: right; color: var(--color-text-muted); }

/* ---- Progress / loading ----------------------------------- */
.spinner {
    display: inline-block;
    width: 18px; height: 18px;
    border: 2px solid #e5e7eb;
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin .65s linear infinite;
    vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-row td { text-align: center; padding: 2rem; color: var(--color-text-muted); }

/* ---- Alerts ----------------------------------------------- */
.alert {
    padding: .75rem 1rem;
    border-radius: 6px;
    border: 1px solid transparent;
    font-size: .875rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: flex-start;
    gap: .5rem;
}
.alert-success { background: #f0fdf4; border-color: #86efac; color: #166534; }
.alert-danger   { background: #fff1f2; border-color: #fca5a5; color: #991b1b; }
.alert-warning  { background: #fffbeb; border-color: #fcd34d; color: #92400e; }
.alert-info     { background: #eff6ff; border-color: #93c5fd; color: #1e40af; }

/* ---- Log output ------------------------------------------- */
.log-output {
    background: #0f172a;
    color: #94a3b8;
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: .8rem;
    padding: 1rem;
    border-radius: 6px;
    min-height: 120px;
    max-height: 400px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
}
.log-output .log-ok    { color: #4ade80; }
.log-output .log-err   { color: #f87171; }
.log-output .log-warn  { color: #fbbf24; }
.log-output .log-info  { color: #38bdf8; }

/* ---- Empty state ------------------------------------------ */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--color-text-muted);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: .75rem; }
.empty-state h3 { font-size: 1rem; font-weight: 600; margin-bottom: .5rem; color: var(--color-text); }
.empty-state p  { font-size: .875rem; }

/* ---- Utility ---------------------------------------------- */
.mt-1 { margin-top: .25rem; } .mt-2 { margin-top: .5rem; }
.mt-3 { margin-top: .75rem; } .mt-4 { margin-top: 1rem; }
.mb-1 { margin-bottom: .25rem; } .mb-2 { margin-bottom: .5rem; }
.mb-3 { margin-bottom: .75rem; } .mb-4 { margin-bottom: 1rem; }
.gap-2 { gap: .5rem; } .gap-3 { gap: .75rem; }
.flex  { display: flex; } .flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.text-muted { color: var(--color-text-muted); }
.text-sm    { font-size: .84rem; }
.text-xs    { font-size: .75rem; }
.font-bold  { font-weight: 700; }
.w-full     { width: 100%; }
.hidden     { display: none !important; }
.divider    { border: none; border-top: 1px solid var(--color-border); margin: 1rem 0; }

/* ---- Responsividade --------------------------------------- */
@media (max-width: 900px) {
    :root { --sidebar-w: 0px; }
    .sidebar { display: none; }
    .main-content { margin-left: 0; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .detail-grid { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
    .stats-grid { grid-template-columns: 1fr; }
    .filters-bar { flex-direction: column; }
    .filters-bar .form-group, .filters-bar .form-group.wide { min-width: 100%; }
}
