:root {
    --bg: #eef2f0;
    --bg-soft: #f7f9f8;
    --surface: #ffffff;
    --ink: #1c2b24;
    --muted: #5b6b63;
    --line: #d5ddd8;
    --brand: #0f4c3a;
    --brand-deep: #0a3328;
    --brand-soft: #dceae4;
    --accent: #b45309;
    --verde: #15803d;
    --verde-bg: #dcfce7;
    --amarillo: #a16207;
    --amarillo-bg: #fef3c7;
    --rojo: #b91c1c;
    --rojo-bg: #fee2e2;
    --warn: #9a3412;
    --shadow: 0 10px 30px rgba(15, 40, 30, 0.08);
    --radius: 10px;
    --font: "Source Sans 3", "Segoe UI", sans-serif;
    --display: "Libre Baskerville", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: var(--font);
    color: var(--ink);
    background:
        radial-gradient(circle at 10% -10%, #d9ebe3 0, transparent 42%),
        linear-gradient(180deg, #f4f7f5 0%, var(--bg) 40%, #e8eeea 100%);
    min-height: 100vh;
}

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

.topbar {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 0.85rem 1.5rem;
    background: linear-gradient(90deg, var(--brand-deep), var(--brand));
    color: #f4faf7;
    border-bottom: 3px solid #c4a35a;
    flex-wrap: wrap;
}
.topbar a { color: #f4faf7; text-decoration: none; }
.topbar-brand a {
    font-family: var(--display);
    font-size: 1.25rem;
    font-weight: 700;
}
.topbar-sub {
    display: block;
    font-size: 0.75rem;
    opacity: 0.75;
    margin-top: 0.1rem;
}
.topbar-nav {
    display: flex;
    gap: 0.85rem;
    flex: 1;
    flex-wrap: wrap;
}
.topbar-nav a {
    opacity: 0.9;
    font-weight: 600;
    font-size: 0.95rem;
}
.topbar-nav a:hover { opacity: 1; text-decoration: underline; }
.topbar-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.user-meta {
    display: flex;
    flex-direction: column;
    font-size: 0.8rem;
    text-align: right;
}
.user-meta span { opacity: 0.8; text-transform: capitalize; }

.container {
    width: min(1120px, calc(100% - 2rem));
    margin: 1.5rem auto 3rem;
}

.footer {
    width: min(1120px, calc(100% - 2rem));
    margin: 0 auto 2rem;
    display: flex;
    justify-content: space-between;
    color: var(--muted);
    font-size: 0.85rem;
    gap: 1rem;
    flex-wrap: wrap;
}

.page-head { margin-bottom: 1.25rem; }
.page-head h1 {
    font-family: var(--display);
    margin: 0 0 0.35rem;
    font-size: 1.85rem;
    color: var(--brand-deep);
}
.page-head p { margin: 0; color: var(--muted); }
.eyebrow {
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.75rem;
    color: var(--accent);
    font-weight: 700;
    margin: 0 0 0.25rem;
}
.row-between {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: flex-start;
    flex-wrap: wrap;
}
.head-badges { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.1rem 1.2rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow);
}
.panel h2 {
    margin: 0 0 0.85rem;
    font-size: 1.05rem;
    color: var(--brand);
}
.panel-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
}
.panel-head h2 { margin: 0; }
.panel-alerta { border-color: #fca5a5; background: linear-gradient(180deg, #fff5f5, #fff); }
.panel-warn { border-color: #fdba74; background: linear-gradient(180deg, #fff7ed, #fff); }

.stats-row {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}
.stat {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0.9rem 1rem;
    box-shadow: var(--shadow);
}
.stat-label {
    display: block;
    color: var(--muted);
    font-size: 0.8rem;
    margin-bottom: 0.35rem;
}
.stat strong { font-size: 1.6rem; color: var(--brand-deep); }
.stat-verde { border-bottom: 3px solid var(--verde); }
.stat-amarillo { border-bottom: 3px solid #ca8a04; }
.stat-rojo { border-bottom: 3px solid var(--rojo); }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}
.table th, .table td {
    padding: 0.65rem 0.55rem;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
}
.table th {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    white-space: nowrap;
}

.table-users {
    min-width: 980px;
    table-layout: fixed;
}
.table-users th:nth-child(1),
.table-users td:nth-child(1) { width: 18%; }
.table-users th:nth-child(2),
.table-users td:nth-child(2) { width: 12%; }
.table-users th:nth-child(3),
.table-users td:nth-child(3) { width: 12%; }
.table-users th:nth-child(4),
.table-users td:nth-child(4) { width: 16%; }
.table-users th:nth-child(5),
.table-users td:nth-child(5) { width: 12%; }
.table-users th:nth-child(6),
.table-users td:nth-child(6) { width: 16%; }
.table-users th:nth-child(7),
.table-users td:nth-child(7) { width: 10%; }
.table-users th:nth-child(8),
.table-users td:nth-child(8) { width: 4%; white-space: nowrap; }
.table-users input,
.table-users select {
    width: 100%;
    max-width: 100%;
    font: inherit;
    padding: 0.45rem 0.55rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    box-sizing: border-box;
}
.table-users td { white-space: nowrap; }

.form-inline-nowrap {
    flex-wrap: nowrap;
    min-width: 900px;
}

.sr-only-form {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.badge {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    background: var(--brand-soft);
    color: var(--brand-deep);
    font-size: 0.78rem;
    font-weight: 600;
}
.badge-soft { background: #eef2f0; color: var(--muted); }

.semaforo {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
}
.sem-verde { background: var(--verde-bg); color: var(--verde); }
.sem-amarillo { background: var(--amarillo-bg); color: var(--amarillo); }
.sem-rojo { background: var(--rojo-bg); color: var(--rojo); }
.sem-cerrado { background: #e5e7eb; color: #374151; }
.sem-na { background: #f3f4f6; color: #6b7280; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 0.55rem 0.95rem;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}
.btn:hover { text-decoration: none; filter: brightness(0.97); }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.85rem; }
.btn-block { width: 100%; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-secondary { background: var(--brand-soft); color: var(--brand-deep); border-color: #b9d0c6; }
.btn-ghost { background: transparent; border-color: rgba(255,255,255,0.35); color: inherit; }
.topbar .btn-ghost { color: #fff; }
.container .btn-ghost, .panel .btn-ghost {
    border-color: var(--line);
    color: var(--ink);
    background: var(--bg-soft);
}
.btn-warn { background: #fff7ed; color: var(--warn); border-color: #fdba74; }
.btn-group { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.alert {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    border: 1px solid;
}
.alert-error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert-success { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }

.filters {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}
.filters input, .filters select,
.form-grid input, .form-grid select, .form-grid textarea,
.stack-form input, .stack-form select, .stack-form textarea,
.form-inline input, .form-inline select,
.login-form input {
    font: inherit;
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
}
.filters input[type="search"] { min-width: 220px; flex: 1; }

.form-grid fieldset {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    padding: 1rem;
    margin: 0 0 1rem;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.85rem;
    box-shadow: var(--shadow);
}
.form-grid legend {
    padding: 0 0.4rem;
    font-weight: 700;
    color: var(--brand);
}
.form-grid label, .stack-form label, .login-form label {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--muted);
}
.form-grid label.full { grid-column: 1 / -1; }
.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.6rem;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}
.dl {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 0.45rem 0.75rem;
    margin: 0;
}
.dl dt { color: var(--muted); font-size: 0.85rem; }
.dl dd { margin: 0; }
.file-list { list-style: none; padding: 0; margin: 0 0 1rem; }
.file-list li {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    align-items: center;
    padding: 0.65rem 0;
    border-bottom: 1px solid var(--line);
}
.muted { color: var(--muted); font-size: 0.82rem; display: block; }
.empty { color: var(--muted); font-style: italic; }
.stack-form { display: flex; flex-direction: column; gap: 0.65rem; margin-top: 0.5rem; }
.stack-form hr, .panel hr { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
    padding: 0.75rem 0 0.75rem 0.9rem;
    border-left: 3px solid var(--brand-soft);
    margin-left: 0.25rem;
}
.timeline-meta {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 0.25rem;
    font-size: 0.85rem;
}
.form-inline {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    align-items: center;
}
.form-inline input, .form-inline select { min-width: 120px; }

/* Auth */
.auth-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
    background:
        linear-gradient(135deg, rgba(15,76,58,0.92), rgba(10,51,40,0.88)),
        url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.06'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}
.auth-wrap { width: min(420px, 100%); }
.login-card {
    background: #fff;
    border-radius: 14px;
    padding: 1.75rem;
    box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}
.login-header h1 {
    font-family: var(--display);
    margin: 0.2rem 0 0.4rem;
    color: var(--brand-deep);
    font-size: 2rem;
}
.login-eyebrow {
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-size: 0.72rem;
    color: var(--accent);
    font-weight: 700;
}
.login-lead { margin: 0 0 1.25rem; color: var(--muted); }
.login-form { display: grid; gap: 0.85rem; }
.login-hint {
    margin-top: 1.25rem;
    padding-top: 1rem;
    border-top: 1px solid var(--line);
    font-size: 0.85rem;
    color: var(--muted);
}
.login-hint ul { margin: 0.35rem 0 0; padding-left: 1.1rem; }
.link { font-weight: 600; }

@media (max-width: 900px) {
    .stats-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .detail-grid { grid-template-columns: 1fr; }
    .form-grid fieldset { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
    .stats-row { grid-template-columns: 1fr; }
    .topbar-user .user-meta { display: none; }
}
