:root {
    --bg: #0f1117;
    --surface: #171a23;
    --surface-2: #1e222e;
    --border: #2a2f3d;
    --text: #e6e8ee;
    --muted: #9aa0ae;
    --primary: #5b8cff;
    --primary-hover: #4a7bee;
    --danger: #ff5b6a;
    --radius: 12px;
}

* { box-sizing: border-box; }

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

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

.brand {
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: .3px;
}
.brand span { color: var(--primary); }
.brand.center { text-align: center; margin-bottom: 1.5rem; }

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

/* ---------- Auth ---------- */
.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}
.auth-card {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.auth-card h1 { font-size: 1.4rem; margin: 0 0 1.25rem; }
.auth-links { margin-top: 1.25rem; text-align: center; font-size: .9rem; }

.field { margin-bottom: 1rem; }
.field label {
    display: block;
    font-size: .85rem;
    color: var(--muted);
    margin-bottom: .35rem;
}
.form-input,
.field input {
    width: 100%;
    padding: .7rem .85rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: .95rem;
}
.form-input:focus,
.field input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(91,140,255,.15);
}
.field-error { color: var(--danger); font-size: .8rem; margin-top: .35rem; }

.btn {
    display: inline-block;
    border: none;
    border-radius: 8px;
    padding: .7rem 1rem;
    font-size: .95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s ease;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); text-decoration: none; }
.btn-block { width: 100%; }
.btn-ghost {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
    width: 100%;
}
.btn-ghost:hover { color: var(--text); border-color: var(--muted); }

.alert {
    padding: .7rem .85rem;
    border-radius: 8px;
    font-size: .9rem;
    margin-bottom: 1rem;
}
.alert-error {
    background: rgba(255,91,106,.12);
    border: 1px solid rgba(255,91,106,.35);
    color: #ffb3ba;
}

/* ---------- App layout ---------- */
.app-shell { min-height: 100vh; }
.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: 240px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
}
.nav { margin-top: 1.5rem; display: flex; flex-direction: column; gap: .25rem; flex: 1; }
.nav-item {
    padding: .6rem .75rem;
    border-radius: 8px;
    color: var(--muted);
    font-size: .95rem;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--surface-2); color: var(--text); }
.nav-item.disabled { opacity: .45; cursor: not-allowed; }
.nav-item.disabled:hover { background: transparent; color: var(--muted); }
.logout { margin-top: 1rem; }

.content { flex: 1; padding: 1.75rem 2rem; }
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}
.topbar h1 { font-size: 1.35rem; margin: 0; }
.user { color: var(--muted); font-size: .9rem; }

.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}
.card-title { color: var(--muted); font-size: .85rem; }
.card-value { font-size: 1.8rem; font-weight: 700; margin: .35rem 0; }
.card-hint { color: var(--muted); font-size: .8rem; }

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
}
.panel h2 { margin-top: 0; }

@media (max-width: 720px) {
    .layout { flex-direction: column; }
    .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
}

/* ---------- Câmeras ---------- */
.grid-toolbar {
    display: flex;
    align-items: center;
    gap: .75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

/* Grid de até 8 câmeras: 4 colunas x 2 linhas em telas grandes */
.camera-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
}
.camera-cell {
    margin: 0;
    background: #000;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.camera-cell iframe {
    width: 100%;
    aspect-ratio: 16 / 9;
    border: 0;
    background: #0a0c11;
    display: block;
}
.camera-cell figcaption {
    padding: .5rem .7rem;
    font-size: .85rem;
    background: var(--surface);
    border-top: 1px solid var(--border);
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-top: 1.25rem;
}
.page-status { color: var(--muted); font-size: .9rem; }

@media (max-width: 1100px) {
    .camera-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
    .camera-grid { grid-template-columns: 1fr; }
}

/* ---------- Tabela ---------- */
.panel.no-pad { padding: 0; overflow: hidden; }
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: .9rem;
}
.table th, .table td {
    text-align: left;
    padding: .7rem .9rem;
    border-bottom: 1px solid var(--border);
}
.table th { color: var(--muted); font-weight: 600; }
.table tr:last-child td { border-bottom: none; }
.url-cell {
    max-width: 320px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--muted);
}
.actions a { margin-right: .75rem; font-size: .85rem; }
.actions a.danger { color: var(--danger); }

.badge {
    display: inline-block;
    padding: .15rem .5rem;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 600;
}
.badge.on { background: rgba(80,220,140,.15); color: #74e0a3; }
.badge.off { background: rgba(255,91,106,.15); color: #ffb3ba; }

/* ---------- Formulário de câmera ---------- */
.form-panel { max-width: 620px; }
.form-actions { display: flex; gap: .75rem; margin-top: 1.25rem; }
.field small.muted { display: block; margin-top: .3rem; font-size: .78rem; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #e64a58; text-decoration: none; }

/* Checkbox "ativa" alinhado */
.field input[type="checkbox"] { width: auto; margin-right: .4rem; }

/* Campos de checkbox no formulário de usuário: label ao lado */
.field-check { display: flex; align-items: center; gap: .5rem; flex-direction: row-reverse; justify-content: flex-end; }
.field-check label { margin: 0; }
.field-check input[type="checkbox"] { margin: 0; }

.messages { margin-bottom: 1rem; }
.alert-success {
    background: rgba(80,220,140,.12);
    border: 1px solid rgba(80,220,140,.35);
    color: #9be9bf;
}
