/* ============================================================
   Klin · Plataforma de reporting — E.S. 3 Carreteres (3K)
   Design system: clean corporate SaaS, light mode
   Brand: navy structure · aqua data accent · orange→red spark
   Fuente de verdad portada desde el prototipo (prototype/css/app.css).
   ============================================================ */

:root {
  /* Neutrals — cool, subtly toned */
  --bg:           oklch(0.984 0.004 240);
  --surface:      #ffffff;
  --surface-2:    oklch(0.978 0.005 240);
  --surface-3:    oklch(0.965 0.006 240);
  --border:       oklch(0.916 0.006 250);
  --border-2:     oklch(0.872 0.009 250);
  --ink:          oklch(0.255 0.028 262);   /* near-black navy */
  --ink-2:        oklch(0.47 0.02 258);     /* muted */
  --ink-3:        oklch(0.60 0.016 256);    /* faint */

  /* Brand navy (from logo) */
  --navy:         oklch(0.30 0.055 262);
  --navy-700:     oklch(0.255 0.05 262);
  --navy-900:     oklch(0.20 0.045 262);

  /* Aqua / cyan accent — Klin / water / data */
  --aqua:         oklch(0.66 0.115 218);
  --aqua-600:     oklch(0.58 0.12 222);
  --aqua-700:     oklch(0.50 0.115 226);
  --aqua-50:      oklch(0.962 0.025 216);
  --aqua-100:     oklch(0.93 0.04 214);

  /* Orange→red brand spark (from logo) */
  --orange:       oklch(0.72 0.165 52);
  --red:          oklch(0.60 0.205 30);
  --spark-grad:   linear-gradient(118deg, var(--orange), var(--red));

  /* Status */
  --ok:    oklch(0.64 0.13 158);
  --ok-50: oklch(0.95 0.035 158);
  --warn:  oklch(0.74 0.135 72);
  --warn-50: oklch(0.955 0.04 78);
  --bad:   var(--red);
  --bad-50: oklch(0.95 0.04 30);
  --off:   oklch(0.66 0.012 256);
  --off-50: oklch(0.955 0.004 256);

  /* Charts */
  --c-aqua:   var(--aqua);
  --c-navy:   var(--navy);
  --c-orange: var(--orange);
  --c-violet: oklch(0.60 0.13 285);
  --c-teal:   oklch(0.66 0.10 185);
  --c-grey:   oklch(0.78 0.008 256);

  /* Radii & shadow */
  --r-sm: 7px;
  --r:    11px;
  --r-lg: 16px;
  --r-xl: 22px;
  --sh-1: 0 1px 2px oklch(0.4 0.03 262 / 0.05), 0 1px 3px oklch(0.4 0.03 262 / 0.04);
  --sh-2: 0 2px 6px oklch(0.35 0.04 262 / 0.06), 0 6px 18px oklch(0.35 0.04 262 / 0.05);
  --sh-3: 0 8px 28px oklch(0.3 0.04 262 / 0.10), 0 2px 8px oklch(0.3 0.04 262 / 0.06);

  --sans: "IBM Plex Sans", system-ui, -apple-system, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", monospace;

  --sidebar-w: 248px;
  --topbar-h: 64px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-size: 14px;
  line-height: 1.5;
}
::selection { background: var(--aqua-100); }

h1,h2,h3,h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; color: var(--ink); }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
.mono { font-family: var(--mono); font-feature-settings: "tnum" 1; }
.tnum { font-variant-numeric: tabular-nums; }

/* ---- scrollbars ---- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: oklch(0.86 0.01 256); border-radius: 8px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: oklch(0.79 0.012 256); }
::-webkit-scrollbar-track { background: transparent; }

/* ============================================================
   App shell
   ============================================================ */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  z-index: 20;
}
.sb-brand {
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 10px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
}
.sb-brand img { height: 42px; width: auto; display: block; }
.sb-brand .klin-tag {
  font-family: var(--mono);
  font-size: 10px; font-weight: 600; letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--aqua-700);
  background: var(--aqua-50);
  padding: 3px 7px; border-radius: 999px;
  border: 1px solid var(--aqua-100);
}
.sb-nav { padding: 14px 12px; display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.sb-section { font-size: 10.5px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-3); padding: 14px 12px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; border-radius: var(--r-sm);
  color: var(--ink-2); font-weight: 500; font-size: 13.5px;
  border: none; background: none; width: 100%; text-align: left;
  transition: background .13s, color .13s;
  position: relative;
}
.nav-item svg { width: 18px; height: 18px; flex: 0 0 18px; stroke-width: 1.8; }
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.active { background: var(--aqua-50); color: var(--aqua-700); font-weight: 600; }
.nav-item.active::before {
  content: ""; position: absolute; left: -12px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 20px; border-radius: 0 3px 3px 0; background: var(--aqua-600);
}
.nav-item .badge-dot { margin-left: auto; }

.sb-foot { border-top: 1px solid var(--border); padding: 10px 12px; }
.user-chip {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--r-sm);
  cursor: pointer; transition: background .13s; width: 100%; border: none; background: none; text-align: left;
}
.user-chip:hover { background: var(--surface-2); }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: 0 0 34px;
  display: grid; place-items: center; color: #fff; font-weight: 600; font-size: 13px;
  background: var(--spark-grad);
}
.user-chip .nm { font-size: 13px; font-weight: 600; line-height: 1.2; }
.user-chip .rl { font-size: 11px; color: var(--ink-3); }

/* main column */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--topbar-h); flex: 0 0 var(--topbar-h);
  background: oklch(0.99 0.004 240 / 0.82); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px; padding: 0 26px;
  position: sticky; top: 0; z-index: 15;
}
.tb-title h1 { font-size: 19px; }
.tb-title .crumb { font-size: 12px; color: var(--ink-3); font-weight: 500; }
.tb-spacer { flex: 1; }

.content { padding: 26px; max-width: 1500px; width: 100%; margin: 0 auto; }
.page-pad { padding: 26px; }

/* ============================================================
   Buttons / controls
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  height: 38px; padding: 0 16px; border-radius: var(--r-sm);
  font-size: 13.5px; font-weight: 600; border: 1px solid var(--border-2);
  background: var(--surface); color: var(--ink); transition: all .14s;
  white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; stroke-width: 1.9; }
.btn:hover { background: var(--surface-2); border-color: var(--ink-3); }
.btn.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn.primary:hover { background: var(--navy-700); }
.btn.aqua { background: var(--aqua-600); color: #fff; border-color: var(--aqua-600); }
.btn.aqua:hover { background: var(--aqua-700); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn.sm { height: 32px; padding: 0 12px; font-size: 12.5px; }
.btn.icon { width: 38px; padding: 0; }
.btn.icon.sm { width: 32px; }
.btn[disabled] { opacity: .65; cursor: default; }

.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 3px; gap: 2px; }
.seg button, .seg a {
  border: none; background: none; padding: 6px 13px; border-radius: 6px;
  font-size: 12.5px; font-weight: 600; color: var(--ink-2); transition: all .13s;
  display: inline-flex; align-items: center; cursor: pointer;
}
.seg button.on, .seg a.on { background: var(--surface); color: var(--ink); box-shadow: var(--sh-1); }
.seg button:hover:not(.on), .seg a:hover:not(.on) { color: var(--ink); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.input, .select {
  height: 40px; padding: 0 13px; border-radius: var(--r-sm); border: 1px solid var(--border-2);
  background: var(--surface); font-family: inherit; font-size: 14px; color: var(--ink);
  transition: border-color .14s, box-shadow .14s; width: 100%;
}
.input:focus, .select:focus { outline: none; border-color: var(--aqua-600); box-shadow: 0 0 0 3px var(--aqua-50); }
.input::placeholder { color: var(--ink-3); }

.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 11px;
  border-radius: 999px; font-size: 12px; font-weight: 600; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink-2);
}

/* ============================================================
   Cards
   ============================================================ */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
}
.card.pad { padding: 20px; }
.card-h { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-h h3 { font-size: 14.5px; }
.card-h .sub { font-size: 12px; color: var(--ink-3); }
.card-h .sp { flex: 1; }
.card-b { padding: 20px; }

.grid { display: grid; gap: 18px; }
.cols-4 { grid-template-columns: repeat(4, 1fr); }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1180px) { .cols-4 { grid-template-columns: repeat(2,1fr);} .cols-3{grid-template-columns:repeat(2,1fr);} }
@media (max-width: 760px) { .cols-4,.cols-3,.cols-2 { grid-template-columns: 1fr; } }

/* KPI tile */
.kpi { position: relative; overflow: hidden; }
.kpi .kpi-top { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.kpi .kpi-ic { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; flex: 0 0 36px; }
.kpi .kpi-ic svg { width: 19px; height: 19px; stroke-width: 1.9; }
.kpi .kpi-label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.kpi .kpi-val { font-size: 30px; font-weight: 600; letter-spacing: -0.02em; line-height: 1; font-variant-numeric: tabular-nums; }
.kpi .kpi-val .u { font-size: 15px; color: var(--ink-3); font-weight: 600; margin-left: 3px; }
.kpi .kpi-sub { margin-top: 9px; display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-3); }
.kpi .spark { margin-top: 14px; }

.ic-aqua { background: var(--aqua-50); color: var(--aqua-700); }
.ic-navy { background: oklch(0.93 0.02 262); color: var(--navy); }
.ic-orange{ background: oklch(0.95 0.04 55); color: oklch(0.55 0.16 45); }
.ic-ok   { background: var(--ok-50); color: var(--ok); }
.ic-violet{ background: oklch(0.94 0.04 285); color: var(--c-violet); }

.delta { display: inline-flex; align-items: center; gap: 3px; font-weight: 600; font-size: 12px; }
.delta svg { width: 13px; height: 13px; }
.delta.up { color: var(--ok); }
.delta.down { color: var(--bad); }

/* ============================================================
   Status badges
   ============================================================ */
.badge {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 9px 0 8px;
  border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.badge .dot { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 7px; }
.badge.ok  { background: var(--ok-50); color: oklch(0.42 0.1 158); }  .badge.ok .dot{background:var(--ok);}
.badge.warn{ background: var(--warn-50); color: oklch(0.48 0.11 70); } .badge.warn .dot{background:var(--warn);}
.badge.bad { background: var(--bad-50); color: oklch(0.47 0.16 30); }  .badge.bad .dot{background:var(--bad);}
.badge.off { background: var(--off-50); color: var(--ink-2); }         .badge.off .dot{background:var(--off);}
.badge.aqua{ background: var(--aqua-50); color: var(--aqua-700); }      .badge.aqua .dot{background:var(--aqua-600);}

.dot-pulse { position: relative; }
.dot-pulse::after {
  content: ""; position: absolute; inset: -3px; border-radius: 50%;
  background: currentColor; opacity: 0.3; animation: pulse 2s ease-out infinite;
}
@keyframes pulse { 0%{transform:scale(.6);opacity:.5;} 100%{transform:scale(1.9);opacity:0;} }

/* ============================================================
   Tables
   ============================================================ */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th {
  text-align: left; font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--ink-3); padding: 10px 16px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.tbl th.r, .tbl td.r { text-align: right; }
.tbl td { padding: 13px 16px; border-bottom: 1px solid var(--border); font-size: 13.5px; vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tbody tr { transition: background .12s; }
.tbl.hover tbody tr:hover { background: var(--surface-2); cursor: pointer; }
.tbl .muted { color: var(--ink-3); }

.tag { font-family: var(--mono); font-size: 11.5px; color: var(--ink-2); background: var(--surface-2); padding: 2px 7px; border-radius: 5px; border: 1px solid var(--border); }

/* progress / bars */
.bar { height: 7px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 999px; }

/* note / estimate banner */
.note {
  display: flex; gap: 10px; align-items: flex-start; padding: 11px 14px; border-radius: var(--r);
  background: var(--aqua-50); border: 1px solid var(--aqua-100); color: var(--aqua-700); font-size: 12.5px;
}
.note svg { width: 16px; height: 16px; flex: 0 0 16px; margin-top: 1px; }
.note.amber { background: var(--warn-50); border-color: oklch(0.88 0.06 78); color: oklch(0.46 0.11 65); }
.note.red { background: var(--bad-50); border-color: oklch(0.88 0.06 30); color: oklch(0.46 0.14 30); }

.est-tag {
  font-family: var(--mono); font-size: 9.5px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  color: oklch(0.55 0.16 45); background: oklch(0.96 0.035 55); padding: 2px 6px; border-radius: 5px;
  border: 1px solid oklch(0.9 0.05 55);
}

/* legend */
.legend { display: flex; flex-wrap: wrap; gap: 14px; }
.legend .li { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--ink-2); font-weight: 500; }
.legend .sw { width: 11px; height: 11px; border-radius: 3px; }

/* tooltip */
.chart-tip {
  position: absolute; pointer-events: none; background: var(--navy-900); color: #fff;
  padding: 8px 11px; border-radius: 8px; font-size: 12px; box-shadow: var(--sh-3);
  transform: translate(-50%, -120%); white-space: nowrap; z-index: 50; opacity: 0; transition: opacity .1s;
}
.chart-tip .t-row { display: flex; align-items: center; gap: 7px; }
.chart-tip .t-row + .t-row { margin-top: 3px; }
.chart-tip b { font-variant-numeric: tabular-nums; }
.chart-tip .sw { width: 8px; height: 8px; border-radius: 2px; }

/* ============================================================
   Login
   ============================================================ */
.login-wrap { display: grid; grid-template-columns: 1.05fr 0.95fr; min-height: 100vh; }
.login-aside {
  position: relative; overflow: hidden; padding: 48px;
  background: linear-gradient(160deg, var(--navy-700), var(--navy-900) 65%);
  color: #fff; display: flex; flex-direction: column; justify-content: space-between;
}
.login-aside::after {
  content: ""; position: absolute; right: -120px; top: -80px; width: 460px; height: 460px; border-radius: 50%;
  background: radial-gradient(circle, oklch(0.66 0.115 218 / 0.5), transparent 68%);
  filter: blur(8px);
}
.login-aside .spark-line { position: absolute; inset: 0; opacity: 0.5; }
.login-form-side { display: flex; align-items: center; justify-content: center; padding: 40px; background: var(--surface); }
.login-card { width: 100%; max-width: 380px; }
@media (max-width: 880px) { .login-wrap { grid-template-columns: 1fr; } .login-aside { display: none; } }

@keyframes spin { to { transform: rotate(360deg); } }
.spin { animation: spin 0.7s linear infinite; }
.water-rise { animation: rise 0.7s cubic-bezier(.2,.7,.3,1) both; }
@keyframes rise { from { transform: translateY(14px);} to { transform: none;} }

/* misc utils */
.row { display: flex; align-items: center; gap: 12px; }
.col { display: flex; flex-direction: column; }
.gap6{gap:6px;} .gap8{gap:8px;} .gap10{gap:10px;} .gap12{gap:12px;} .gap16{gap:16px; } .gap20{gap:20px;}
.wrap{flex-wrap:wrap;}
.spacer{flex:1;} .sp{flex:1;}
.muted{color:var(--ink-2);} .faint{color:var(--ink-3);}
.fz10{font-size:10px;} .fz11{font-size:11px;} .fz12{font-size:12px;} .fz13{font-size:13px;} .fz18{font-size:18px;}
.fw500{font-weight:500;} .fw600{font-weight:600;} .fw700{font-weight:700;}
.mt0{margin-top:0;} .mt2{margin-top:2px;} .mt4{margin-top:4px;} .mt8{margin-top:8px;} .mt12{margin-top:12px;} .mt16{margin-top:16px;} .mt20{margin-top:20px;} .mt24{margin-top:24px;}
.mb4{margin-bottom:4px;} .mb8{margin-bottom:8px;} .mb12{margin-bottom:12px;} .mb16{margin-bottom:16px;} .mb20{margin-bottom:20px;}
.tr{text-align:right;} .tc{text-align:center;}
.divider{height:1px;background:var(--border);margin:0;border:none;}
.hidden{display:none!important;}
.full{width:100%;}

.page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h2 { font-size: 22px; }
.page-head .ph-sub { font-size: 13px; color: var(--ink-3); margin-top: 3px; }
.page-head .sp { flex: 1; }

/* machine type icon tile */
.mtile { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; flex: 0 0 40px; background: var(--surface-2); border: 1px solid var(--border); color: var(--navy); }
.mtile svg { width: 22px; height: 22px; stroke-width: 1.6; }

/* image placeholder (striped) */
.imgph {
  background-image: repeating-linear-gradient(45deg, var(--surface-2), var(--surface-2) 10px, var(--surface-3) 10px, var(--surface-3) 20px);
  border: 1px dashed var(--border-2); border-radius: var(--r); display: grid; place-items: center;
  color: var(--ink-3); font-family: var(--mono); font-size: 11px;
}

/* skeleton fade-in for views */
.view-enter { animation: viewin .3s ease both; }
@keyframes viewin { from { transform: translateY(8px);} to { transform:none;} }

/* heat cells */
.heat { display: grid; gap: 3px; }
.heat .cell { aspect-ratio: 1; border-radius: 3px; background: var(--surface-3); }

/* timeline strip (availability) */
.tl { display: flex; height: 30px; border-radius: 6px; overflow: hidden; border: 1px solid var(--border); }
.tl > span { display: block; height: 100%; }

/* ============================================================
   Añadidos para la implementación Rails
   ============================================================ */
.check-aqua { accent-color: var(--aqua-600); width: 16px; height: 16px; }
.link-aqua { color: var(--aqua-700); font-weight: 600; }

/* flash messages */
.flash { display: flex; gap: 10px; align-items: flex-start; padding: 11px 14px; border-radius: var(--r); font-size: 13px; margin-bottom: 16px; }
.flash svg { width: 16px; height: 16px; flex: 0 0 16px; margin-top: 1px; }
.flash.alert { background: var(--bad-50); border: 1px solid oklch(0.88 0.06 30); color: oklch(0.46 0.14 30); }
.flash.notice { background: var(--ok-50); border: 1px solid oklch(0.88 0.05 158); color: oklch(0.40 0.10 158); }

/* desplegables de la topbar (buscar / notificaciones) */
.dd { position: relative; }
.dd-panel { position: absolute; right: 0; top: calc(100% + 8px); width: 330px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--sh-3); z-index: 60; overflow: hidden; }
.dd-head { padding: 12px 14px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 13px; display: flex; align-items: center; gap: 8px; }
.dd-search { padding: 10px; border-bottom: 1px solid var(--border); }
.dd-list { max-height: 340px; overflow-y: auto; }
.dd-item { display: flex; gap: 10px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--border); color: inherit; }
.dd-item:last-child { border-bottom: none; }
.dd-item:hover { background: var(--surface-2); }
.dd-empty { padding: 18px 14px; color: var(--ink-3); font-size: 13px; text-align: center; }
.dd-foot { padding: 10px 14px; border-top: 1px solid var(--border); }

/* pestañas de Ajustes (botón activo = navy) */
.tabbtn.on { background: var(--navy); color: #fff; border-color: var(--navy); }
.tabbtn.on:hover { background: var(--navy-700); }

/* machine card hover (lista de máquinas) */
.machine-card { display: block; transition: box-shadow .15s, transform .15s; color: inherit; }
.machine-card:hover { box-shadow: var(--sh-2); transform: translateY(-2px); }

/* fila de tabla clicable como enlace */
tr.link-row { cursor: pointer; }

/* placeholder de sección (provisional, Fase 3) */
.section-ph { display: grid; place-items: center; min-height: 340px; text-align: center; }
.section-ph .ph-ic { width: 54px; height: 54px; border-radius: 14px; display: grid; place-items: center; background: var(--aqua-50); color: var(--aqua-700); margin: 0 auto 14px; }
.section-ph .ph-ic svg { width: 26px; height: 26px; }
