/* static/css/app.css */
:root {
  --bg:        #0f172a;
  --surface:   #1e293b;
  --surface2:  #263244;
  --border:    #334155;
  --text:      #e2e8f0;
  --muted:     #64748b;
  --green:     #4ade80;
  --red:       #f87171;
  --yellow:    #facc15;
  --blue:      #60a5fa;
  --purple:    #c084fc;
  --sidebar-w: 220px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; display: flex; }

/* ── SIDEBAR ── */
.sidebar {
  width: var(--sidebar-w); min-height: 100vh; background: var(--surface);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; z-index: 100;
}
.sidebar-logo {
  padding: 20px 16px 16px; border-bottom: 1px solid var(--border);
  font-size: 18px; font-weight: 800; letter-spacing: -0.5px; color: var(--text);
}
.sidebar-logo span { color: var(--blue); }
.sidebar-client {
  padding: 10px 16px; font-size: 11px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 1px; border-bottom: 1px solid var(--border);
}
.sidebar-nav { flex: 1; padding: 8px 0; overflow-y: auto; }
.nav-section { padding: 16px 16px 4px; font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 16px;
  color: var(--muted); text-decoration: none; font-size: 13px; font-weight: 500;
  border-radius: 0; transition: all 0.15s; cursor: pointer; border: none; background: none; width: 100%;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--surface2); color: var(--blue); border-left: 3px solid var(--blue); }
.nav-item .icon { font-size: 15px; width: 18px; text-align: center; }
.sidebar-footer { padding: 12px 16px; border-top: 1px solid var(--border); }

/* ── MAIN ── */
.main { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-height: 100vh; min-width: 0; }

/* ── NAVBAR ── */
.navbar {
  height: 56px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; position: sticky; top: 0; z-index: 50;
}
.navbar-title { font-size: 15px; font-weight: 600; }
.navbar-actions { display: flex; gap: 8px; align-items: center; }

/* ── CONTENT ── */
.content { padding: 24px; flex: 1; }

/* ── CARDS / KPIs ── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 24px; }
.kpi-card {
  background: var(--surface); border-radius: 12px; padding: 18px 20px;
  border-left: 3px solid var(--border); transition: transform 0.15s;
}
.kpi-card:hover { transform: translateY(-2px); }
.kpi-card.green  { border-color: var(--green); }
.kpi-card.red    { border-color: var(--red); }
.kpi-card.yellow { border-color: var(--yellow); }
.kpi-card.blue   { border-color: var(--blue); }
.kpi-card.purple { border-color: var(--purple); }
.kpi-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.kpi-value { font-size: 28px; font-weight: 700; margin-top: 6px; }
.kpi-sub   { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* ── SECTION CARD ── */
.card { background: var(--surface); border-radius: 12px; padding: 20px; margin-bottom: 16px; }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.card-title { font-size: 15px; font-weight: 600; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }
/* Las celdas de los grids deben poder encogerse: las tablas hacen scroll interno */
.grid-2 > *, .grid-main > *, .kpi-grid > * { min-width: 0; }

/* ── TABLES ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th { text-align: left; padding: 10px 12px; color: var(--muted); border-bottom: 1px solid var(--border); font-size: 11px; text-transform: uppercase; letter-spacing: .3px; white-space: nowrap; }
tbody td { padding: 10px 12px; border-bottom: 1px solid var(--surface2); white-space: nowrap; }
tbody tr:hover td { background: var(--surface2); }
tbody tr:last-child td { border-bottom: none; }

/* ── BADGES ── */
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge-green  { background: #14532d; color: var(--green); }
.badge-red    { background: #7c2d12; color: var(--red); }
.badge-yellow { background: #713f12; color: var(--yellow); }
.badge-blue   { background: #1e3a5f; color: var(--blue); }
.badge-purple { background: #4c1d95; color: var(--purple); }

/* ── ALERT ── */
.alert { background: #7c2d12; border: 1px solid #dc2626; border-radius: 10px; padding: 14px 18px; margin-bottom: 16px; }
.alert-title { font-weight: 700; color: #fca5a5; margin-bottom: 8px; font-size: 14px; }
.alert-item  { color: #fde8d8; padding: 3px 0; font-size: 13px; }

/* ── BUTTONS ── */
.btn { display: inline-flex; align-items: center; gap: 6px; border: none; padding: 8px 16px; border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 500; transition: opacity 0.15s; text-decoration: none; }
.btn:hover { opacity: 0.85; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: #2563eb; color: white; }
.btn-danger  { background: #dc2626; color: white; }
.btn-success { background: #16a34a; color: white; }
.btn-ghost   { background: var(--surface2); color: var(--text); }
.upload-btn  { background: #2563eb; color: white; cursor: pointer; }

/* ── TOAST ── */
.toast {
  position: fixed; bottom: 20px; right: 20px; background: var(--surface);
  border: 1px solid var(--green); color: var(--text); padding: 12px 18px;
  border-radius: 10px; font-size: 13px; display: none; z-index: 999; max-width: 320px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}

/* ── CHARTS ── */
canvas { max-height: 240px; }

/* ── SEARCH ── */
.search-input {
  background: var(--surface2); border: 1px solid var(--border); color: var(--text);
  padding: 7px 12px; border-radius: 8px; font-size: 13px; width: 220px; outline: none;
}
.search-input:focus { border-color: var(--blue); }

/* ── EMPTY STATE ── */
.empty { text-align: center; padding: 40px; color: var(--muted); font-size: 14px; }

/* ═══════════════════ CENTRO DE CONTROL (Sprint 001) ═══════════════════ */

/* ── AUTH (login + selección de empresa) ── */
.auth-body {
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 70% -10%, #1e3a5f 0%, var(--bg) 55%);
  padding: 20px;
}
.auth-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 40px; width: 100%; max-width: 400px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, .45);
}
.auth-card-wide { max-width: 460px; }
.auth-logo { font-size: 28px; font-weight: 800; letter-spacing: -0.5px; color: var(--text); }
.auth-logo span { color: var(--blue); }
.auth-subtitle { color: var(--muted); font-size: 13px; margin: 4px 0 28px; }
.auth-form { display: flex; flex-direction: column; }
.auth-label {
  font-size: 11px; color: var(--muted); text-transform: uppercase;
  letter-spacing: .5px; margin: 0 0 6px;
}
.auth-input {
  background: var(--surface2); border: 1px solid var(--border); color: var(--text);
  padding: 11px 14px; border-radius: 8px; font-size: 14px; outline: none;
  margin-bottom: 18px; transition: border-color .15s;
}
.auth-input:focus { border-color: var(--blue); }
.auth-submit { justify-content: center; padding: 12px; font-size: 14px; margin-top: 4px; }
.auth-error {
  background: rgba(220, 38, 38, .12); border: 1px solid #7f1d1d; color: #fca5a5;
  border-radius: 8px; padding: 10px 14px; font-size: 13px; margin-bottom: 20px;
}
.auth-footer { color: var(--muted); font-size: 11px; text-align: center; margin-top: 28px; }
.auth-link {
  display: block; text-align: center; color: var(--muted); font-size: 12px;
  margin-top: 24px; text-decoration: none;
}
.auth-link:hover { color: var(--text); }

.empresa-list { display: flex; flex-direction: column; gap: 10px; }
.empresa-btn {
  display: flex; align-items: center; gap: 14px; width: 100%;
  background: var(--surface2); border: 1px solid var(--border); border-radius: 10px;
  padding: 16px; cursor: pointer; text-align: left; transition: all .15s;
}
.empresa-btn:hover { border-color: var(--blue); background: #2d3f55; transform: translateY(-1px); }
.empresa-avatar {
  width: 40px; height: 40px; border-radius: 10px; background: #1e3a5f; color: var(--blue);
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; font-weight: 700; flex-shrink: 0;
}
.empresa-info { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.empresa-nombre { color: var(--text); font-size: 14px; font-weight: 600; }
.empresa-tipo { color: var(--muted); font-size: 11px; }
.empresa-arrow { color: var(--muted); font-size: 16px; }

/* ── SIDEBAR: empresa y usuario ── */
.sidebar-empresa {
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 2px;
}
.sidebar-empresa-nombre {
  font-size: 12px; font-weight: 700; color: var(--text);
  text-transform: uppercase; letter-spacing: .5px;
}
.sidebar-empresa-cambiar { font-size: 11px; color: var(--blue); text-decoration: none; }
.sidebar-empresa-cambiar:hover { text-decoration: underline; }
.sidebar-user {
  display: flex; align-items: center; gap: 10px; padding: 4px 0 10px;
}
.sidebar-user-avatar {
  width: 28px; height: 28px; border-radius: 50%; background: #1e3a5f; color: var(--blue);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.sidebar-user-nombre { font-size: 12px; color: var(--text); font-weight: 500; }
.nav-disabled { opacity: .35; cursor: default; }
.nav-logout { color: var(--red) !important; padding-left: 0 !important; }
.nav-item .icon { font-size: 13px; color: inherit; }

/* ── LAYOUT DEL CENTRO DE CONTROL ── */
.grid-main { display: grid; grid-template-columns: 3fr 2fr; gap: 16px; margin-bottom: 16px; }
@media (max-width: 1000px) { .grid-main { grid-template-columns: 1fr; } }

/* ── ALERTAS ── */
.alerta-row {
  padding: 10px 14px; border-radius: 8px; margin-bottom: 8px;
  background: var(--surface2); border-left: 3px solid var(--border);
}
.alerta-row.critica { border-left-color: var(--red); }
.alerta-row.alta    { border-left-color: #fb923c; }
.alerta-row.media   { border-left-color: var(--yellow); }
.alerta-row:last-child { margin-bottom: 0; }
.alerta-titulo { font-size: 13px; font-weight: 600; color: var(--text); }
.alerta-detalle { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ── FILAS DE ESTADÍSTICAS (Estado Joist) ── */
.stat-rows { display: flex; flex-direction: column; }
.stat-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 9px 2px; border-bottom: 1px solid var(--surface2); font-size: 13px;
}
.stat-row:last-child { border-bottom: none; }
.stat-row span { color: var(--muted); }
.stat-row strong { font-weight: 600; }

/* ── FILAS DE PROYECTOS ── */
.proyecto-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 2px; border-bottom: 1px solid var(--surface2); font-size: 13px;
}
.proyecto-row:last-child { border-bottom: none; }
.proyecto-nombre { flex: 1; color: var(--text); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.proyecto-monto { font-weight: 600; color: var(--text); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.status-dot.ok  { background: var(--green); }
.status-dot.off { background: var(--muted); }

/* ── BOTÓN PEQUEÑO ── */
.btn-sm { padding: 5px 12px; font-size: 12px; border-radius: 6px; }

/* ── CELDA TRUNCADA ── */
.td-trunc { max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
