:root {
    --bg:        #0f1117;
    --surface:  #1a1d27;
    --card:     #222638;
    --border:   #2e3347;
    --primary:  #3b82f6;
    --primary-dark: #1d4ed8;
    --success:  #10b981;
    --warning:  #f59e0b;
    --danger:   #ef4444;
    --text:     #e2e8f0;
    --muted:    #64748b;
    --radius:   8px;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* ── Navigation ─────────────────────────────────────── */
.nav {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 60px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 100;
}
.nav-logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    text-decoration: none;
    letter-spacing: -0.5px;
}
.nav-links {
    display: flex;
    gap: 4px;
    list-style: none;
}
.nav-links a {
    color: var(--muted);
    text-decoration: none;
    padding: 6px 14px;
    border-radius: var(--radius);
    font-size: 0.875rem;
    transition: all 0.15s;
}
.nav-links a:hover,
.nav-links a.active {
    background: var(--card);
    color: var(--text);
}
.nav-user {
    display: flex;
    align-items: center;
    gap: 12px;
}
.nav-user .avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
}
.nav-user .logout-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--muted);
    padding: 4px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.15s;
}
.nav-user .logout-btn:hover {
    border-color: var(--danger);
    color: var(--danger);
}

/* ── Main ────────────────────────────────────────────── */
.main { padding: 80px 24px 40px; max-width: 1200px; margin: 0 auto; }

.page-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 24px;
}

/* ── Cards ───────────────────────────────────────────── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 24px;
}
.card-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    margin-bottom: 8px;
}
.card-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text);
}
.card-sub {
    font-size: 0.8rem;
    color: var(--muted);
    margin-top: 4px;
}

/* ── Grid ────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

/* ── Progress bar ────────────────────────────────────── */
.usage-bar-wrap { margin-top: 16px; }
.usage-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--muted);
    margin-bottom: 6px;
}
.usage-bar {
    height: 6px;
    background: var(--border);
    border-radius: 99px;
    overflow: hidden;
}
.usage-bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 99px;
    transition: width 0.4s ease;
}

/* ── Buttons ─────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.15s;
    text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}
.btn-outline:hover { background: var(--card); border-color: var(--muted); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }

.actions { display: flex; gap: 12px; align-items: center; margin-bottom: 24px; }

/* ── Upload Zone ─────────────────────────────────────── */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 48px 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 20px;
}
.upload-zone:hover, .upload-zone.drag-over {
    border-color: var(--primary);
    background: rgba(59, 130, 246, 0.05);
}
.upload-zone input[type=file] { display: none; }
.upload-zone .icon { font-size: 3rem; margin-bottom: 12px; color: var(--muted); }
.upload-zone .title { font-size: 1rem; font-weight: 600; margin-bottom: 4px; }
.upload-zone .sub { font-size: 0.8rem; color: var(--muted); }

/* ── File list ───────────────────────────────────────── */
.file-list { margin-bottom: 24px; }
.file-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--card);
    border-radius: var(--radius);
    margin-bottom: 8px;
}
.file-item .name { flex: 1; font-size: 0.875rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-item .size { font-size: 0.75rem; color: var(--muted); }
.file-item .status {
    font-size: 0.75rem;
    padding: 3px 8px;
    border-radius: 99px;
    font-weight: 500;
}
.status-uploaded   { background: #1e293b; color: #94a3b8; }
.status-queued     { background: #1c1917; color: #fbbf24; }
.status-processing { background: #1c1917; color: #f59e0b; }
.status-processed  { background: #052e16; color: var(--success); }
.status-failed     { background: #450a0a; color: var(--danger); }

/* ── Table ───────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}
thead tr {
    border-bottom: 1px solid var(--border);
}
th {
    text-align: left;
    padding: 10px 16px;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    font-weight: 600;
}
td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}
tbody tr:hover { background: var(--card); }
tbody tr:last-child td { border-bottom: none; }
td a { color: var(--primary); text-decoration: none; }
td a:hover { text-decoration: underline; }
td .chave { font-family: monospace; font-size: 0.8rem; color: var(--muted); }

/* ── Pagination ──────────────────────────────────────── */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 24px;
}
.pagination button {
    padding: 6px 12px;
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.875rem;
}
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }
.pagination button.active { background: var(--primary); border-color: var(--primary); }
.pagination .info { font-size: 0.8rem; color: var(--muted); }

/* ── Filters ─────────────────────────────────────────── */
.filters {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}
.filters input, .filters select {
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 12px;
    border-radius: var(--radius);
    font-size: 0.875rem;
}
.filters input { flex: 1; min-width: 200px; }
.filters input::placeholder { color: var(--muted); }
.filters label { font-size: 0.75rem; color: var(--muted); display: block; margin-bottom: 4px; }
.filter-group { display: flex; flex-direction: column; }

/* ── Modal ───────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}
.modal-header h2 { font-size: 1.1rem; }
.modal-close {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}
.modal-close:hover { color: var(--text); }

/* ── Toast / Alerta ─────────────────────────────────── */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 0.875rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    animation: slideIn 0.2s ease;
    max-width: 360px;
}
.toast-success { background: var(--success); color: #fff; }
.toast-error   { background: var(--danger); color: #fff; }
.toast-warning { background: var(--warning); color: #000; }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to   { transform: translateX(0);    opacity: 1; }
}

/* ── Spinner ─────────────────────────────────────────── */
.spinner {
    display: inline-block;
    width: 16px; height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── NFe Detail ──────────────────────────────────────── */
.nfe-section {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 16px;
    overflow: hidden;
}
.nfe-section-header {
    padding: 12px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    font-weight: 600;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.nfe-section-body { padding: 16px 20px; }
.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}
.info-item .label { font-size: 0.75rem; color: var(--muted); margin-bottom: 2px; }
.info-item .value { font-size: 0.875rem; font-weight: 500; }

.items-table td:nth-child(3),
.items-table td:nth-child(5),
.items-table td:nth-child(6),
.items-table td:nth-child(7) { text-align: right; font-variant-numeric: tabular-nums; }

/* ── Loading state ───────────────────────────────────── */
.loading-row td { color: var(--muted); font-style: italic; }

/* ── Auth pages ──────────────────────────────────────── */
.auth-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    padding: 24px;
}
.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 40px;
    width: 100%;
    max-width: 420px;
}
.auth-card .logo {
    text-align: center;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 8px;
}
.auth-card .subtitle {
    text-align: center;
    color: var(--muted);
    font-size: 0.875rem;
    margin-bottom: 32px;
}
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-size: 0.8rem;
    color: var(--muted);
    margin-bottom: 6px;
}
.form-group input {
    width: 100%;
    padding: 10px 14px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.9rem;
}
.form-group input:focus {
    outline: none;
    border-color: var(--primary);
}
.form-group .hint { font-size: 0.75rem; color: var(--muted); margin-top: 4px; }
.form-group .error { font-size: 0.75rem; color: var(--danger); margin-top: 4px; }
.form-actions { margin-top: 24px; }
.form-actions .btn { width: 100%; justify-content: center; }
.auth-link {
    text-align: center;
    margin-top: 20px;
    font-size: 0.875rem;
    color: var(--muted);
}
.auth-link a { color: var(--primary); text-decoration: none; }
.auth-link a:hover { text-decoration: underline; }

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 768px) {
    .nav-links { display: none; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .filters { flex-direction: column; }
    .actions { flex-direction: column; align-items: stretch; }
}

/* ── Select ───────────────────────────────────────────── */
select {
    width: 100%;
    padding: 10px 14px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.9rem;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}
select:focus { outline: none; border-color: var(--primary); }

.form-group input, .form-group select { width: 100%; }

/* ── Admin tabs ──────────────────────────────────────── */
.admin-tabs { display:flex; gap:4px; margin-bottom:24px; border-bottom:1px solid var(--border); padding-bottom:0; }
.admin-tabs .tab { padding:8px 20px; border:none; background:none; color:var(--muted); cursor:pointer; border-bottom:2px solid transparent; margin-bottom:-1px; font-size:0.875rem; }
.admin-tabs .tab.active { color:var(--text); border-bottom-color:var(--primary); }
.admin-tabs .tab:hover { color:var(--text); }

/* ── Tenant switcher ────────────────────────────────── */
.nav-tenant-btn { display:flex; align-items:center; gap:6px; }
.tenant-picker-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    min-width: 220px;
    z-index: 300;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.tenant-picker-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    color: var(--text);
    text-decoration: none;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--border);
}
.tenant-picker-item:last-child { border-bottom: none; }
.tenant-picker-item:hover { background: var(--card); }
.tenant-picker-item.active { background: var(--card); color: var(--primary); }
.tenant-status { width: 8px; height: 8px; border-radius: 50%; }
.tenant-status.active { background: var(--success); }
.tenant-status.inactive { background: var(--danger); }

/* ── Admin modal overlay ──────────────────────────────── */
.admin-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.admin-modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
}
.admin-modal-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}
.admin-modal-actions {
    display: flex;
    gap: 8px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}
.admin-modal-actions .btn { flex: 1; justify-content: center; }