/* ============================================================================
   Themis — earthy brand tokens (source of truth: templates/login.html splash)
   Palette: clay / coffee base, terracotta, ochre, olive, warm sand/cream.
   Type: Fraunces (display/headings) · Sora (body/UI) · IBM Plex Mono (labels).
   ============================================================================ */
:root {
    /* clay / coffee base */
    --thm-clay-950: #20140c;
    --thm-clay-900: #2b1d14;
    --thm-clay-800: #3a2719;
    --thm-clay-700: #4d3320;
    /* accents */
    --thm-terra:    #c2693a;
    --thm-terra-2:  #d98a4f;
    --thm-ochre:    #d9a441;
    --thm-ochre-2:  #e8be6a;
    --thm-olive:    #7c7a3f;
    --thm-olive-2:  #9a9656;
    /* warm surfaces */
    --thm-sand:     #efe6d5;
    --thm-sand-2:   #f7f1e6;
    --thm-paper:    #f4ece0;
    --thm-card:     #fffdf9;
    --thm-line:     #e3d6c2;
    /* text */
    --thm-text:     #2e2317;
    --thm-muted:    #8a7763;
    --thm-muted-2:  #b3a48f;
    --thm-danger:   #b23a2f;
    --thm-warn:     #a76a16;
    /* fonts */
    --thm-font-body:    "Sora", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    --thm-font-display: "Fraunces", Georgia, "Times New Roman", serif;
    --thm-font-mono:    "IBM Plex Mono", ui-monospace, "SFMono-Regular", monospace;
    /* radii */
    --thm-radius:   12px;
    --thm-radius-lg: 16px;
}

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

body {
    font-family: var(--thm-font-body);
    background: var(--thm-paper);
    color: var(--thm-text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-family: var(--thm-font-display); }

/* Navbar */
.navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background:
        radial-gradient(120% 180% at 88% -40%, rgba(217,164,65,.16), transparent 60%),
        linear-gradient(115deg, var(--thm-clay-950) 0%, var(--thm-clay-900) 55%, var(--thm-clay-700) 130%);
    color: #f3e8d8;
    padding: 0 1.5rem;
    height: 56px;
    box-shadow: 0 2px 10px rgba(43,29,20,0.28);
    border-bottom: 1px solid rgba(217,164,65,.18);
}
.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.nav-logo { height: 32px; }
/* Brand shield mark */
.nav-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 9px;
    background: linear-gradient(150deg, var(--thm-ochre), var(--thm-terra));
    box-shadow: 0 6px 16px rgba(0,0,0,.32), inset 0 1px 0 rgba(255,255,255,.28);
    flex: 0 0 auto;
}
.nav-mark svg { width: 17px; height: 17px; display: block; }
.nav-title {
    font-family: var(--thm-font-display);
    font-weight: 600;
    font-size: 1.15rem;
    letter-spacing: -.01em;
    color: #fbf0dd;
}
.nav-env {
    font-size: 0.7rem;
    background: rgba(217,164,65,.18);
    color: var(--thm-ochre-2);
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 600;
    font-family: var(--thm-font-mono);
    letter-spacing: .08em;
}
.nav-env-select {
    font-size: 0.72rem;
    font-weight: 600;
    font-family: var(--thm-font-mono);
    letter-spacing: .06em;
    padding: 3px 8px;
    border-radius: 6px;
    border: 1px solid rgba(217,164,65,.32);
    background: rgba(217,164,65,.10);
    color: var(--thm-ochre-2);
    cursor: pointer;
    outline: none;
}
.nav-env-select:hover { background: rgba(217,164,65,.18); }
.nav-env-select option { background: var(--thm-clay-800); color: #f3e8d8; }
/* Hamburger button */
.hamburger {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 36px;
    height: 36px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    transition: background 0.15s;
}
.hamburger:hover { background: rgba(232,190,106,0.16); }
.hamburger span {
    display: block;
    width: 20px;
    height: 2px;
    background: #f3e8d8;
    border-radius: 1px;
}

/* Sidebar */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(32,20,12,0.5);
    z-index: 998;
}
.sidebar-overlay.open { display: block; }

.sidebar {
    position: fixed;
    top: 0;
    left: -260px;
    width: 260px;
    height: 100vh;
    background:
        radial-gradient(90% 50% at 0% 100%, rgba(124,122,63,.20), transparent 60%),
        linear-gradient(167deg, var(--thm-clay-900) 0%, var(--thm-clay-950) 100%);
    z-index: 999;
    transition: left 0.25s ease;
    display: flex;
    flex-direction: column;
    box-shadow: 4px 0 24px rgba(32,20,12,0.4);
    border-right: 1px solid rgba(217,164,65,.14);
}
.sidebar.open { left: 0; }

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid rgba(217,164,65,.16);
}
.sidebar-title {
    color: #fbf0dd;
    font-family: var(--thm-font-display);
    font-weight: 600;
    font-size: 1.05rem;
}
.sidebar-close {
    background: none;
    border: none;
    color: var(--thm-muted-2);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}
.sidebar-close:hover { color: var(--thm-ochre-2); }

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 0;
}
.sidebar-nav a {
    display: block;
    color: rgba(243,224,196,0.66);
    text-decoration: none;
    padding: 0.6rem 1.25rem;
    font-size: 0.9rem;
    transition: all 0.15s;
    border-left: 3px solid transparent;
}
.sidebar-nav a:hover {
    color: #fbf0dd;
    background: rgba(217,164,65,0.08);
}
.sidebar-nav a.active {
    color: #fff;
    background: rgba(194,105,58,0.16);
    border-left-color: var(--thm-terra);
}
.sidebar-section {
    color: var(--thm-ochre);
    font-size: 0.66rem;
    font-family: var(--thm-font-mono);
    text-transform: uppercase;
    letter-spacing: 0.16em;
    padding: 1rem 1.25rem 0.3rem;
    font-weight: 600;
    opacity: .85;
}

.nav-user {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.9rem;
    color: rgba(243,224,196,0.78);
    min-width: 0; /* let the name below actually truncate instead of forcing overflow */
}
.nav-user-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 40vw;
}
.btn-logout {
    color: var(--thm-terra-2);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    flex-shrink: 0; /* logout must stay reachable, never the thing that gets squeezed off */
}
.btn-logout:hover { color: var(--thm-ochre-2); }

/* Narrow screens: the env/tenant badge is redundant chrome (this is a
   single-tenant deployment) — drop it before the user name/logout link
   get crowded into a 3-line wrap (was clipping "Cerrar sesión"). */
@media (max-width: 640px) {
    .navbar { padding: 0 0.85rem; }
    .nav-env { display: none; }
    .nav-title { font-size: 1rem; }
}

/* Content */
.content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}
.content.content-wide {
    max-width: 100%;
}
h1 { margin-bottom: 0.5rem; color: var(--thm-text); letter-spacing: -.01em; }
h2 { color: var(--thm-text); margin-bottom: 0.75rem; letter-spacing: -.01em; }
.subtitle { color: var(--thm-muted); margin-bottom: 1.5rem; }

/* Cards */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-top: 1.5rem;
}
.card {
    background: var(--thm-card);
    border-radius: var(--thm-radius);
    padding: 1.5rem;
    text-decoration: none;
    color: inherit;
    border: 1px solid var(--thm-line);
    transition: box-shadow 0.2s, border-color 0.2s, transform 0.2s;
}
.card:hover {
    box-shadow: 0 14px 30px -18px rgba(74,51,32,0.45);
    border-color: var(--thm-terra);
    transform: translateY(-2px);
}
.card h3 { margin-bottom: 0.5rem; color: var(--thm-text); }
.card p { color: var(--thm-muted); font-size: 0.9rem; }

/* Metric cards */
.metric-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.metric-card {
    background: var(--thm-card);
    border: 1px solid var(--thm-line);
    border-radius: 10px;
    padding: 1rem 1.25rem;
    text-align: center;
}
.metric-card .metric-label {
    font-size: 0.7rem;
    font-family: var(--thm-font-mono);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--thm-muted);
    margin-bottom: 0.25rem;
}
.metric-card .metric-value {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--thm-text);
    font-variant-numeric: tabular-nums;
}
.metric-card.metric-warning .metric-value { color: var(--thm-warn); }
.metric-card.metric-danger .metric-value { color: var(--thm-danger); }

/* Controls */
.controls { margin-bottom: 1.5rem; }
.form-group { margin-bottom: 1rem; }
.form-group label { font-weight: 500; margin-right: 0.5rem; color: var(--thm-text); }
.form-inline { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
select, input[type="text"], input[type="password"], input[type="month"], input[type="date"] {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--thm-line);
    border-radius: 8px;
    font-size: 0.9rem;
    font-family: inherit;
    background: #fffaf2;
    color: var(--thm-text);
}
select:focus, input:focus {
    outline: none;
    border-color: var(--thm-terra);
    box-shadow: 0 0 0 4px rgba(194,105,58,0.15);
    background: #fff;
}

/* Buttons */
.btn {
    padding: 0.5rem 1rem;
    border: 1px solid var(--thm-line);
    border-radius: 8px;
    background: var(--thm-card);
    cursor: pointer;
    font-size: 0.9rem;
    font-family: inherit;
    transition: all 0.15s;
    color: var(--thm-text);
}
.btn:hover { background: var(--thm-sand-2); border-color: var(--thm-terra); }
.btn-primary {
    background: linear-gradient(180deg, var(--thm-terra-2), var(--thm-terra));
    color: #fff;
    border-color: var(--thm-terra);
    box-shadow: 0 10px 20px -12px rgba(194,105,58,0.8);
}
.btn-primary:hover {
    filter: brightness(1.05);
    border-color: var(--thm-terra);
    background: linear-gradient(180deg, var(--thm-terra-2), var(--thm-terra));
}
.btn-full { width: 100%; }
.btn-sm { padding: 0.25rem 0.75rem; font-size: 0.8rem; }

/* Tables */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--thm-card);
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--thm-line);
}
.data-table th {
    background: var(--thm-sand);
    text-align: left;
    padding: 0.75rem 1rem;
    font-size: 0.75rem;
    font-family: var(--thm-font-mono);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--thm-clay-700);
    border-bottom: 2px solid var(--thm-line);
    font-weight: 600;
}
.data-table td {
    padding: 0.6rem 1rem;
    border-bottom: 1px solid var(--thm-sand);
    font-size: 0.88rem;
    color: var(--thm-text);
}
.data-table tbody tr:hover { background: var(--thm-sand-2); }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.row-warning { background: rgba(217,164,65,0.18) !important; }
.row-well-header {
    background: var(--thm-sand) !important;
    font-weight: 600;
}
.row-well-header td { border-top: 2px solid var(--thm-line); color: var(--thm-text); }
.data-table tfoot td {
    padding: 0.75rem 1rem;
    border-top: 2px solid var(--thm-line);
    font-size: 0.9rem;
    background: var(--thm-sand-2);
}

/* Login */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(157deg, var(--thm-clay-950) 0%, var(--thm-clay-900) 45%, var(--thm-clay-700) 130%);
}
.login-card {
    background: var(--thm-card);
    border-radius: var(--thm-radius-lg);
    padding: 2.5rem;
    width: 100%;
    max-width: 400px;
    text-align: center;
    border: 1px solid var(--thm-line);
    box-shadow: 0 30px 60px -34px rgba(74,51,32,0.55);
}
.login-logo { height: 64px; margin-bottom: 1rem; }
.login-card h2 { margin-bottom: 0.25rem; color: var(--thm-text); }
.login-subtitle { color: var(--thm-muted); margin-bottom: 1.5rem; }
.login-card .form-group {
    text-align: left;
    margin-bottom: 1rem;
}
.login-card input {
    width: 100%;
    padding: 0.6rem 0.75rem;
}
.login-card .btn { margin-top: 0.5rem; }

/* Alerts */
.alert { padding: 0.75rem 1rem; border-radius: 8px; margin-bottom: 1rem; font-size: 0.9rem; }
.alert-error { background: rgba(178,58,47,0.08); color: var(--thm-danger); border: 1px solid rgba(178,58,47,0.24); }

/* Status & Loading */
.status-text { color: var(--thm-muted); font-size: 0.9rem; margin-top: 0.5rem; }
.loading { color: var(--thm-muted); font-size: 0.9rem; padding: 1rem 0; }

/* Report */
.report-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}
.report-content {
    background: var(--thm-card);
    border: 1px solid var(--thm-line);
    border-radius: 10px;
    padding: 1.5rem;
    white-space: pre-wrap;
    font-size: 0.85rem;
    line-height: 1.5;
    max-height: 70vh;
    overflow-y: auto;
}

/* DataTable sort/filter */
.dt-wrapper { overflow-x: auto; }
.dt-sortable { cursor: pointer; user-select: none; white-space: nowrap; }
.dt-sort-icon { font-size: 0.6rem; margin-left: 0.25rem; opacity: 0.25; }
.dt-sort-asc .dt-sort-icon,
.dt-sort-desc .dt-sort-icon { opacity: 1; color: var(--thm-terra); }
.dt-filter-row td { padding: 0.3rem 0.4rem; background: var(--thm-sand-2); border-bottom: 2px solid var(--thm-line); }
.dt-filter-input,
.dt-filter-select { width: 100%; padding: 0.25rem 0.4rem; font-size: 0.78rem; border: 1px solid var(--thm-line); border-radius: 4px; box-sizing: border-box; background: #fffaf2; }
.dt-filter-range { display: flex; flex-direction: column; gap: 0.2rem; }
.dt-filter-range input { width: 100%; padding: 0.2rem 0.3rem; font-size: 0.72rem; border: 1px solid var(--thm-line); border-radius: 4px; box-sizing: border-box; background: #fffaf2; }
.dt-footer { margin-top: 0.5rem; color: var(--thm-muted); }

/* Links */
a { color: var(--thm-terra); }
a:hover { color: var(--thm-clay-700); }

/* Accessibility utilities */
.sr-only {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, [tabindex]:focus-visible {
    outline: 2px solid var(--thm-terra);
    outline-offset: 2px;
}

/* Panels */
.panel {
    background: var(--thm-card);
    border-radius: var(--thm-radius);
    border: 1px solid var(--thm-line);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}
.panel h2 { margin-top: 0; }
