@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ============================================================
   TOKENS
   ============================================================ */
:root {
    --bg-base:        #0f1117;
    --bg-surface:     #1a1d27;
    --bg-elevated:    #212535;
    --bg-hover:       #272b3d;

    --brand:          #4f7ef7;
    --brand-hover:    #3b6ef3;
    --brand-light:    rgba(79,126,247,.15);

    --success:        #22c55e;
    --success-light:  rgba(34,197,94,.15);
    --danger:         #ef4444;
    --danger-light:   rgba(239,68,68,.15);
    --warning:        #f59e0b;
    --warning-light:  rgba(245,158,11,.15);

    --text-primary:   #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted:     #64748b;

    --border:         rgba(255,255,255,.07);
    --border-focus:   rgba(79,126,247,.5);

    --radius-sm:  6px;
    --radius-md:  10px;
    --radius-lg:  14px;

    --shadow-sm:  0 1px 3px rgba(0,0,0,.4);
    --shadow-md:  0 4px 16px rgba(0,0,0,.5);
    --shadow-lg:  0 8px 32px rgba(0,0,0,.6);

    --sidebar-w: 240px;
    --topbar-h:  60px;
    --transition: .2s ease;
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 14px;
    line-height: 1.6;
    background: var(--bg-base);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
}

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

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

/* Sidebar */
.sidebar {
    width: var(--sidebar-w);
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transition: transform var(--transition);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--border);
}

.sidebar-brand .logo {
    width: 34px; height: 34px;
    background: var(--brand);
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 15px; color: #fff;
    flex-shrink: 0;
}

.sidebar-brand .brand-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
    line-height: 1.2;
}

.sidebar-brand .brand-sub {
    font-size: 11px;
    color: var(--text-muted);
}

.sidebar-nav {
    flex: 1;
    padding: 12px 10px;
    overflow-y: auto;
}

.nav-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 8px 10px 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-weight: 500;
    transition: background var(--transition), color var(--transition);
    cursor: pointer;
    margin-bottom: 2px;
}

.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active { background: var(--brand-light); color: var(--brand); }
.nav-item .icon { width: 18px; height: 18px; flex-shrink: 0; opacity: .8; }

.sidebar-footer {
    padding: 12px 10px;
    border-top: 1px solid var(--border);
}

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

/* Topbar */
.topbar {
    height: var(--topbar-h);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-title { font-weight: 600; font-size: 15px; color: var(--text-primary); }
.topbar-sub   { font-size: 12px; color: var(--text-muted); }

.topbar-user {
    display: flex; align-items: center; gap: 8px;
    font-size: 13px; color: var(--text-secondary);
}

.avatar {
    width: 32px; height: 32px;
    background: var(--brand);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 12px; color: #fff;
}

/* Page body */
.page-body { padding: 24px; flex: 1; }

/* ============================================================
   CARDS
   ============================================================ */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow-sm);
}

.card-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 16px;
}

.card-title { font-weight: 600; font-size: 15px; }
.card-sub   { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* Stat cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    display: flex; align-items: flex-start; gap: 14px;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.stat-card:hover { border-color: var(--brand); box-shadow: var(--shadow-md); }

.stat-icon {
    width: 42px; height: 42px;
    border-radius: var(--radius-md);
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; flex-shrink: 0;
}

.stat-icon.verde   { background: var(--success-light); }
.stat-icon.vermelho{ background: var(--danger-light);  }
.stat-icon.amarelo { background: var(--warning-light); }
.stat-icon.azul    { background: var(--brand-light);   }

.stat-label { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.stat-value { font-size: 28px; font-weight: 700; line-height: 1; margin: 4px 0 0; }

/* ============================================================
   TABELAS
   ============================================================ */
.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead th {
    background: var(--bg-elevated);
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background var(--transition);
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg-hover); }

tbody td {
    padding: 12px 16px;
    color: var(--text-primary);
    font-size: 13px;
    vertical-align: middle;
}

td.muted { color: var(--text-muted); }

/* ============================================================
   BADGES
   ============================================================ */
.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 9px;
    border-radius: 99px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .03em;
}

.badge::before {
    content: '';
    width: 6px; height: 6px;
    border-radius: 50%;
    background: currentColor;
    opacity: .8;
}

.badge-ativo     { background: var(--success-light); color: var(--success); }
.badge-bloqueado { background: var(--danger-light);  color: var(--danger);  }
.badge-vencendo  { background: var(--warning-light); color: var(--warning); }

/* ============================================================
   BOTÕES
   ============================================================ */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px; font-weight: 500;
    border: none; cursor: pointer;
    transition: background var(--transition), transform .1s, box-shadow var(--transition);
    text-decoration: none;
    line-height: 1;
}

.btn:active { transform: scale(.97); }

.btn-primary {
    background: var(--brand); color: #fff;
    box-shadow: 0 2px 8px rgba(79,126,247,.3);
}
.btn-primary:hover { background: var(--brand-hover); color: #fff; box-shadow: 0 4px 14px rgba(79,126,247,.4); }

.btn-secondary { background: var(--bg-elevated); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg-hover); color: var(--text-primary); }

.btn-danger { background: var(--danger-light); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }

.btn-sm { padding: 5px 10px; font-size: 12px; }

.btn-icon {
    width: 32px; height: 32px; padding: 0;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: var(--radius-sm);
}

/* ============================================================
   FORMULÁRIOS
   ============================================================ */
.form-group { margin-bottom: 18px; }

label {
    display: block;
    font-size: 12px; font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    letter-spacing: .03em;
}

input[type="text"],
input[type="date"],
input[type="password"],
select {
    width: 100%;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 9px 12px;
    font-size: 13px;
    font-family: inherit;
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
    appearance: none;
}

input:focus, select:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(79,126,247,.15);
}

input.error { border-color: var(--danger) !important; }

.field-error {
    font-size: 11px; color: var(--danger);
    margin-top: 4px; display: block;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-actions {
    display: flex; align-items: center; gap: 10px;
    padding-top: 8px;
}

/* Search bar */
.search-bar {
    display: flex; gap: 8px; align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.search-bar input  { flex: 1; min-width: 200px; }
.search-bar select { width: 140px; }

/* ============================================================
   ALERTAS
   ============================================================ */
.alert {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    font-size: 13px;
    animation: slideIn .25s ease;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0);    }
}

.alert-sucesso { background: var(--success-light); color: var(--success); border: 1px solid rgba(34,197,94,.2); }
.alert-erro    { background: var(--danger-light);  color: var(--danger);  border: 1px solid rgba(239,68,68,.2); }

/* ============================================================
   PAGINAÇÃO
   ============================================================ */
.pagination {
    display: flex; align-items: center; gap: 4px;
    justify-content: flex-end;
    margin-top: 16px;
}

.page-btn {
    width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    border-radius: var(--radius-sm);
    font-size: 13px; font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    cursor: pointer; text-decoration: none;
    transition: background var(--transition);
}

.page-btn:hover    { background: var(--bg-hover); color: var(--text-primary); }
.page-btn.active   { background: var(--brand); color: #fff; border-color: var(--brand); }
.page-btn.disabled { opacity: .35; pointer-events: none; }

/* ============================================================
   MODAL DE CONFIRMAÇÃO
   ============================================================ */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.65);
    display: flex; align-items: center; justify-content: center;
    z-index: 999;
    opacity: 0; visibility: hidden;
    transition: opacity var(--transition), visibility var(--transition);
}

.modal-overlay.open { opacity: 1; visibility: visible; }

.modal {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px;
    max-width: 420px; width: 90%;
    box-shadow: var(--shadow-lg);
    transform: scale(.95);
    transition: transform var(--transition);
}

.modal-overlay.open .modal { transform: scale(1); }

.modal-title { font-weight: 600; font-size: 16px; margin-bottom: 8px; }
.modal-body  { color: var(--text-secondary); font-size: 13px; margin-bottom: 22px; line-height: 1.7; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-page {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg-base);
    padding: 24px;
}

.login-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 40px;
    width: 100%; max-width: 380px;
    box-shadow: var(--shadow-lg);
}

.login-logo {
    width: 76px;
    height: 54px;
    background: #fff;
    border-radius: var(--radius-md);
    display: flex; align-items: center; justify-content: center;
    padding: 7px;
    margin: 0 auto 20px;
}

.login-logo img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    display: block;
}

.login-title {
    display: flex;
    justify-content: center;
    text-align: center;
    margin-bottom: 8px;
}

.login-title img {
    width: min(240px, 100%);
    height: auto;
    display: block;
}

.login-sub {
    text-align: center;
    font-size: 13px; color: var(--text-muted);
    margin-bottom: 28px;
}

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-muted);
}

.empty-state .icon { font-size: 40px; margin-bottom: 12px; }
.empty-state p { font-size: 13px; }

/* ============================================================
   CNPJ DISPLAY
   ============================================================ */
.cnpj { font-family: 'Courier New', monospace; letter-spacing: .04em; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main { margin-left: 0; }
    .form-row { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
}
