/* ============================================================================
   Steaua de Mare · Dashboard design system
   Lenguaje visual heredado de dashboard-costa-sur, extendido con tema claro.
   ========================================================================== */

:root {
  --bg: #0a0f1e;
  --bg2: #0d1426;
  --card: #121b30;
  --card2: #16203a;
  --line: #1e2a44;
  --text: #e9eefb;
  --muted: #90a0c0;
  --muted2: #6b7a9a;
  --blue: #3b82f6;
  --blue2: #2563eb;
  --cyan: #22d3ee;
  --green: #22c55e;
  --red: #f05252;
  --gold: #fbbf24;
  --violet: #a78bfa;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --radius: 16px;
  --pill-bg: #16234080;
  --track: #1a2540;
}

:root[data-theme="light"] {
  --bg: #eef2fa;
  --bg2: #e4eaf6;
  --card: #ffffff;
  --card2: #f7f9ff;
  --line: #d3dcef;
  --text: #10192e;
  --muted: #55648a;
  --muted2: #7d8aa8;
  --blue: #2563eb;
  --blue2: #1d4ed8;
  --cyan: #0891b2;
  --green: #15803d;
  --red: #dc2626;
  --gold: #b45309;
  --violet: #7c3aed;
  --shadow: 0 8px 24px rgba(16, 25, 46, .10);
  --pill-bg: #eef2fb;
  --track: #e2e8f5;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #eef2fa; --bg2: #e4eaf6; --card: #ffffff; --card2: #f7f9ff;
    --line: #d3dcef; --text: #10192e; --muted: #55648a; --muted2: #7d8aa8;
    --blue: #2563eb; --blue2: #1d4ed8; --cyan: #0891b2; --green: #15803d;
    --red: #dc2626; --gold: #b45309; --violet: #7c3aed;
    --shadow: 0 8px 24px rgba(16, 25, 46, .10); --pill-bg: #eef2fb; --track: #e2e8f5;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: radial-gradient(1200px 600px at 15% -10%, var(--bg2), var(--bg)) fixed;
  color: var(--text);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 1320px; margin: 0 auto; padding: 22px 26px 60px; }

/* ── Header ────────────────────────────────────────────────────────────── */
header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 20px; flex-wrap: wrap; margin-bottom: 8px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 42px; height: 42px; border-radius: 12px;
  background: linear-gradient(135deg, var(--cyan), var(--blue2));
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 20px; color: #04122e; box-shadow: var(--shadow); flex-shrink: 0;
}
.brand h1 { margin: 0; font-size: 19px; letter-spacing: -.2px; line-height: 1.25; }
.brand p { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }
.topright { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.updated { color: var(--muted); font-size: 12px; text-align: right; line-height: 1.5; }
.updated b { color: var(--text); }

.icon-btn {
  background: var(--card2); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 12px; font-size: 13px; font-weight: 700;
  cursor: pointer; transition: .15s; white-space: nowrap; font-family: inherit;
}
.icon-btn:hover { border-color: var(--blue); }
.refresh-btn {
  background: linear-gradient(135deg, var(--blue), var(--blue2)); color: #fff; border: 0;
  border-radius: 10px; padding: 10px 15px; font-size: 13px; font-weight: 700;
  cursor: pointer; box-shadow: 0 6px 16px rgba(37, 99, 235, .35);
  transition: .15s; white-space: nowrap; font-family: inherit;
}
.refresh-btn:hover { filter: brightness(1.08); }
.refresh-btn:disabled { opacity: .6; cursor: wait; }

/* ── Live status ───────────────────────────────────────────────────────── */
.livebar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin: 14px 0 4px; font-size: 12px; color: var(--muted);
}
.led {
  width: 9px; height: 9px; border-radius: 50%; background: var(--green);
  box-shadow: 0 0 0 4px rgba(34, 197, 94, .15); animation: pulse 2.4s infinite; flex-shrink: 0;
}
.led.err { background: var(--red); box-shadow: 0 0 0 4px rgba(240, 82, 82, .15); }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .45 } }
.live-badge { color: var(--green); font-weight: 800; letter-spacing: .4px; }
.pill {
  background: var(--pill-bg); border: 1px solid var(--line); border-radius: 999px;
  padding: 3px 10px; font-size: 10.5px; color: var(--muted); white-space: nowrap;
}

/* ── Nav ───────────────────────────────────────────────────────────────── */
nav.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin: 16px 0 4px; }
nav.tabs a {
  text-decoration: none; color: var(--muted); background: var(--card);
  border: 1px solid var(--line); border-radius: 999px; padding: 8px 15px;
  font-size: 12.5px; font-weight: 700; transition: .15s; white-space: nowrap;
}
nav.tabs a:hover { color: var(--text); border-color: var(--blue); }
nav.tabs a[aria-current="page"] {
  color: #fff; background: linear-gradient(135deg, var(--blue), var(--blue2));
  border-color: transparent; box-shadow: 0 6px 16px rgba(37, 99, 235, .3);
}

/* ── Sections & panels ─────────────────────────────────────────────────── */
.section-title {
  display: flex; align-items: center; gap: 10px; margin: 30px 0 14px;
  font-size: 13px; text-transform: uppercase; letter-spacing: 1.4px; color: var(--muted);
}
.section-title::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.panel {
  background: linear-gradient(180deg, var(--card2), var(--card));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 22px; box-shadow: var(--shadow);
}
.panel > h3 {
  margin: 0 0 14px; font-size: 13.5px; font-weight: 800;
  letter-spacing: .3px; display: flex; align-items: center; gap: 8px;
}
.panel .sub { color: var(--muted); font-size: 11.5px; font-weight: 500; }

.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, 1fr); }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g4 { grid-template-columns: repeat(4, 1fr); }

/* ── KPI cards ─────────────────────────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.kpi {
  background: linear-gradient(180deg, var(--card2), var(--card));
  border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px;
  box-shadow: var(--shadow); position: relative; overflow: hidden;
  transition: transform .18s, border-color .18s;
}
.kpi:hover { transform: translateY(-2px); border-color: var(--blue); }
.kpi::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 3px;
  background: linear-gradient(90deg, var(--cyan), var(--blue));
}
.kpi.accent-green::before { background: linear-gradient(90deg, var(--green), var(--cyan)); }
.kpi.accent-gold::before { background: linear-gradient(90deg, var(--gold), #f97316); }
.kpi.accent-violet::before { background: linear-gradient(90deg, var(--violet), var(--blue)); }
.kpi.accent-red::before { background: linear-gradient(90deg, var(--red), var(--gold)); }
.kpi h3 {
  margin: 0 0 8px; font-size: 11px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .9px;
}
.kpi b { display: block; font-size: 27px; font-weight: 800; letter-spacing: -.6px; line-height: 1.1; }
.kpi .unit { font-size: 14px; font-weight: 700; color: var(--muted); margin-left: 3px; }
.kpi .sub { display: block; margin-top: 6px; font-size: 11.5px; color: var(--muted); }

/* Big operational tiles (front office) */
.tile { text-align: center; padding: 22px 16px; }
.tile b { font-size: 40px; }
.tile h3 { justify-content: center; }

/* ── Charts ────────────────────────────────────────────────────────────── */
.chart-box { position: relative; height: 280px; margin-top: 6px; }
.chart-box.sm { height: 220px; }

/* ── Tables ────────────────────────────────────────────────────────────── */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 520px; }
th, td { padding: 11px 12px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead th {
  color: var(--muted); font-size: 10.5px; text-transform: uppercase;
  letter-spacing: .9px; font-weight: 700; border-bottom: 1px solid var(--line);
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--pill-bg); }
tr.total td { font-weight: 800; border-top: 2px solid var(--line); background: var(--pill-bg); }
tr.sub-row td:first-child { padding-left: 26px; color: var(--muted); font-weight: 500; }
td.pos { color: var(--green); }
td.neg { color: var(--red); }

/* ── Bars / progress ───────────────────────────────────────────────────── */
.barline { margin-bottom: 13px; }
.barline:last-child { margin-bottom: 0; }
.barline .top {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 10px; margin-bottom: 6px; font-size: 12.5px;
}
.barline .top span { color: var(--muted); }
.barline .top b { font-weight: 800; font-size: 13px; }
.track { height: 8px; border-radius: 999px; background: var(--track); overflow: hidden; }
.track > i {
  display: block; height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, var(--cyan), var(--blue)); transition: width .5s ease;
}
.track > i.green { background: linear-gradient(90deg, var(--green), var(--cyan)); }
.track > i.gold { background: linear-gradient(90deg, var(--gold), #f97316); }
.track > i.red { background: linear-gradient(90deg, var(--red), var(--gold)); }
.track > i.violet { background: linear-gradient(90deg, var(--violet), var(--blue)); }

/* ── Lists ─────────────────────────────────────────────────────────────── */
.list { display: flex; flex-direction: column; gap: 10px; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 11px 13px; border: 1px solid var(--line); border-radius: 11px; background: var(--pill-bg);
}
.row .l { display: flex; align-items: center; gap: 10px; min-width: 0; }
.row .name { font-weight: 700; font-size: 13px; }
.row .meta { font-size: 11.5px; color: var(--muted); }
.row .r { text-align: right; white-space: nowrap; }
.time-chip {
  background: linear-gradient(135deg, var(--cyan), var(--blue2)); color: #04122e;
  font-weight: 800; font-size: 11.5px; padding: 4px 9px; border-radius: 8px; flex-shrink: 0;
}
.tag {
  display: inline-block; background: var(--pill-bg); border: 1px solid var(--line);
  border-radius: 999px; padding: 3px 9px; font-size: 11px; color: var(--muted); margin: 0 5px 5px 0;
}

.stars { color: var(--gold); font-size: 15px; letter-spacing: 2px; }

/* ── Gauge ─────────────────────────────────────────────────────────────── */
.gauge { display: flex; align-items: center; justify-content: center; gap: 18px; flex-wrap: wrap; }
.gauge .val { font-size: 34px; font-weight: 800; letter-spacing: -.8px; }
.gauge .val small { font-size: 15px; color: var(--muted); font-weight: 700; }

/* ── States ────────────────────────────────────────────────────────────── */
.state {
  border: 1px dashed var(--line); border-radius: var(--radius); padding: 26px;
  text-align: center; color: var(--muted); font-size: 13px; background: var(--card);
}
.state.error { border-color: var(--red); color: var(--red); border-style: solid; }
.skeleton {
  background: linear-gradient(90deg, var(--card2) 25%, var(--line) 50%, var(--card2) 75%);
  background-size: 200% 100%; animation: sk 1.4s infinite; border-radius: 6px;
  color: transparent !important;
}
@keyframes sk { 0% { background-position: 200% 0 } 100% { background-position: -200% 0 } }

footer {
  margin-top: 42px; padding-top: 18px; border-top: 1px solid var(--line);
  display: flex; justify-content: space-between; gap: 14px; flex-wrap: wrap;
  color: var(--muted2); font-size: 11.5px;
}

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 1080px) {
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
  .g4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 860px) {
  .wrap { padding: 18px 16px 48px; }
  .kpi-grid, .g2, .g3, .g4 { grid-template-columns: repeat(2, 1fr); }
  header { align-items: flex-start; }
  .topright { width: 100%; justify-content: space-between; }
  .updated { text-align: left; }
  .brand h1 { font-size: 16.5px; }
  .kpi b { font-size: 23px; }
  .tile b { font-size: 32px; }
}
@media (max-width: 560px) {
  .kpi-grid, .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .chart-box { height: 240px; }
}
@media print {
  body { background: #fff; }
  .refresh-btn, .icon-btn, nav.tabs { display: none; }
}
