:root {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #eef1f7;
    --border: #dce1ea;
    --text: #1c2430;
    --muted: #6b7280;
    --primary: #2f6bff;
    --primary-hover: #1f57e6;
    --danger: #e5484d;
    --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; }
/* Logo da marca (imagem). Na sidebar ocupa a largura disponível; nas telas
   de auth fica centralizado com um limite de largura. */
.brand-logo {
    display: block;
    width: 100%;
    max-width: 180px;
    height: auto;
}
.brand.center .brand-logo {
    margin: 0 auto;
    max-width: 200px;
}

.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 10px 30px rgba(28,36,48,.10);
}
.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(229,72,77,.10);
    border: 1px solid rgba(229,72,77,.35);
    color: #b42318;
}

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

.sidebar {
    width: 240px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
    /* Fica fixa do lado esquerdo mesmo com scroll na página */
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}
.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%;
        height: auto;
        position: static;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
}

/* ---------- Dashboard: grid de gráficos ---------- */
.dash-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.dash-grid .panel { margin: 0; }
.dash-grid .span-2 { grid-column: 1 / -1; }
.dash-grid .panel h2 { font-size: 1.05rem; }
.dash-grid .panel h2 small { font-weight: 400; }
.chart-hint { display: block; margin: .2rem 0 .6rem; font-size: .8rem; }

@media (max-width: 900px) {
    .dash-grid { grid-template-columns: 1fr; }
    .dash-grid .span-2 { grid-column: auto; }
}

/* ---------- 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); }
.actions .link-btn {
    background: none; border: none; padding: 0; margin-right: .75rem;
    color: var(--accent, #5b8cff); font-size: .85rem; cursor: pointer;
    font-family: inherit;
}
.actions .link-btn:hover { text-decoration: underline; }

.badge {
    display: inline-block;
    padding: .15rem .5rem;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 600;
}
.badge.on { background: rgba(34,160,90,.14); color: #1a7f43; }
.badge.off { background: rgba(229,72,77,.14); color: #b42318; }

/* ---------- 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(34,160,90,.10);
    border: 1px solid rgba(34,160,90,.35);
    color: #1a7f43;
}
.alert-warning {
    background: rgba(245,176,32,.12);
    border: 1px solid rgba(245,176,32,.4);
    color: #8a5a00;
}
.alert-info {
    background: rgba(47,107,255,.10);
    border: 1px solid rgba(47,107,255,.3);
    color: #1f57e6;
}
