:root {
    --color-bg: #f4f5f7;
    --color-surface: #ffffff;
    --color-border: #d9dce1;
    --color-text: #1f2430;
    --color-text-muted: #6b7280;
    --color-primary: #2563eb;
    --color-primary-dark: #1d4ed8;
    --color-danger: #dc2626;
    --color-warning: #d97706;
    --color-success: #16a34a;
    --radius: 6px;
    font-size: 14px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
}

h1 { font-size: 1.4rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 0.5rem; }

/* --- Topbar --- */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.25rem;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    flex-wrap: wrap;
    gap: 0.5rem;
}

.topbar-info { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }

.info-pill {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 999px;
    padding: 0.25rem 0.75rem;
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.info-pill.link { color: var(--color-primary); text-decoration: none; cursor: pointer; }
.info-pill.link:hover { background: #eef2ff; }

.mode-pill.mode-dryrun { border-color: var(--color-warning); color: var(--color-warning); }
.mode-pill.mode-production { border-color: var(--color-danger); color: var(--color-danger); }

/* --- Content --- */
.content { padding: 1.25rem; max-width: 100%; }

/* --- Toolbar --- */
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.toolbar-group { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

.btn {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 0.5rem 0.9rem;
    font-size: 0.85rem;
    cursor: pointer;
    color: var(--color-text);
}

.btn:hover { background: #f0f1f3; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); }

.btn-warning { background: #fff7ed; border-color: var(--color-warning); color: var(--color-warning); }
.btn-danger { background: #fef2f2; border-color: var(--color-danger); color: var(--color-danger); }
.btn-small { padding: 0.25rem 0.6rem; font-size: 0.75rem; }

details > summary { cursor: pointer; display: inline-block; margin-right: 0.5rem; color: var(--color-text-muted); }
details[open] { display: flex; gap: 0.5rem; align-items: center; }

/* --- Filters --- */
.filters {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 0.75rem;
}

.filters input[type=search],
.filters select {
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
}

.checkbox-label { display: flex; align-items: center; gap: 0.3rem; font-size: 0.85rem; color: var(--color-text-muted); }
.selection-count { margin-left: auto; font-size: 0.8rem; color: var(--color-text-muted); }

/* --- Grid --- */
.grid-wrapper {
    overflow-x: auto;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
}

table.grid { border-collapse: collapse; width: 100%; min-width: 1400px; }

table.grid th, table.grid td {
    padding: 0.5rem 0.6rem;
    border-bottom: 1px solid var(--color-border);
    text-align: left;
    white-space: nowrap;
    font-size: 0.82rem;
}

table.grid th {
    background: #f9fafb;
    cursor: pointer;
    user-select: none;
    position: sticky;
    top: 0;
    z-index: 1;
}

table.grid tbody tr:hover { background: #f9fafb; }
table.grid tbody tr.selected { background: #eef2ff; }

.col-check { width: 2rem; }
.empty-row { text-align: center; color: var(--color-text-muted); padding: 2rem !important; }

.copyable { cursor: pointer; }
.copyable:hover { text-decoration: underline dotted; }

.student-link { color: var(--color-primary); text-decoration: none; }
.student-link:hover { text-decoration: underline; }

.password-cell { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.password-hidden::after { content: "••••••••"; letter-spacing: 1px; }
.password-hidden { color: transparent; position: relative; }
.password-hidden::after { color: var(--color-text-muted); position: absolute; left: 0; }

/* --- Badges --- */
.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-ok, .badge-Sim { background: #dcfce7; color: #166534; }
.badge-pending, .badge-Não { background: #f3f4f6; color: #6b7280; }
.badge-running { background: #dbeafe; color: #1d4ed8; }
.badge-error, .badge-Erro { background: #fee2e2; color: #991b1b; }
.badge-conflict, .badge-Conflito { background: #fef3c7; color: #92400e; }
.badge-unknown, .badge-Desconhecido { background: #ede9fe; color: #5b21b6; }
.badge-aviso { background: #fef3c7; color: #92400e; }

/* --- Alerts --- */
.alert { padding: 0.65rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: 0.85rem; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }

/* --- Login --- */
.login-page { display: flex; align-items: center; justify-content: center; height: 100vh; background: var(--color-bg); }
.login-box { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 2rem; width: 320px; }
.login-box .subtitle { color: var(--color-text-muted); margin: 0.25rem 0 1.25rem; font-size: 0.85rem; }
.login-box form { display: flex; flex-direction: column; gap: 0.5rem; }
.login-box label { font-size: 0.8rem; color: var(--color-text-muted); margin-top: 0.5rem; }
.login-box input { padding: 0.5rem; border: 1px solid var(--color-border); border-radius: var(--radius); }
.login-box button { margin-top: 1rem; padding: 0.6rem; background: var(--color-primary); color: #fff; border: none; border-radius: var(--radius); cursor: pointer; }

/* --- Config form --- */
.config-form { display: flex; flex-direction: column; gap: 0.4rem; max-width: 420px; background: var(--color-surface); padding: 1.5rem; border: 1px solid var(--color-border); border-radius: var(--radius); }
.config-form label { font-size: 0.8rem; color: var(--color-text-muted); margin-top: 0.5rem; }
.config-form input { padding: 0.5rem; border: 1px solid var(--color-border); border-radius: var(--radius); }
.config-form button { margin-top: 1rem; padding: 0.6rem; cursor: pointer; }
.note { color: var(--color-text-muted); font-size: 0.8rem; max-width: 420px; }

/* --- Diagnostics --- */
.diagnostic-list { display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 1.5rem; }
.diagnostic-row { display: flex; align-items: center; gap: 0.75rem; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 0.5rem 0.75rem; }
.diagnostic-name { font-weight: 600; min-width: 220px; }
.diagnostic-message { color: var(--color-text-muted); font-size: 0.85rem; }
.diagnostic-actions { display: flex; gap: 0.5rem; align-items: center; }
.test-result { font-size: 0.85rem; color: var(--color-text-muted); }

/* --- Progress panel --- */
.progress-panel {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    width: 380px;
    max-height: 60vh;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    display: flex;
    flex-direction: column;
    z-index: 50;
}

.progress-panel.hidden { display: none; }
.progress-panel-header { display: flex; justify-content: space-between; align-items: center; padding: 0.6rem 0.8rem; border-bottom: 1px solid var(--color-border); }
.progress-body { padding: 0.6rem 0.8rem; overflow-y: auto; }
.progress-student { margin-bottom: 0.75rem; }
.progress-student-name { font-weight: 600; margin-bottom: 0.2rem; }
.progress-step { font-size: 0.8rem; display: flex; gap: 0.4rem; align-items: baseline; }
.progress-step .icon-ok { color: var(--color-success); }
.progress-step .icon-error { color: var(--color-danger); }
.progress-step .icon-pending { color: var(--color-text-muted); }

/* --- Modal --- */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.4);
    display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-overlay.hidden { display: none; }
.modal-box {
    background: var(--color-surface); border-radius: var(--radius);
    padding: 1.5rem; width: 480px; max-width: 90vw; max-height: 85vh; overflow-y: auto;
}
.modal-box h2 { margin-bottom: 0.75rem; }
.modal-box table { width: 100%; border-collapse: collapse; margin: 0.75rem 0; font-size: 0.8rem; }
.modal-box table td, .modal-box table th { border-bottom: 1px solid var(--color-border); padding: 0.3rem 0.4rem; text-align: left; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1rem; }
.modal-box input[type=text], .modal-box input[type=file] {
    width: 100%; padding: 0.5rem; border: 1px solid var(--color-border); border-radius: var(--radius); margin: 0.4rem 0;
}

@media (max-width: 768px) {
    .topbar { flex-direction: column; align-items: flex-start; }
    .filters { flex-direction: column; align-items: stretch; }
    .selection-count { margin-left: 0; }
}
