/* ============================================================
   3K Carreteres · Plataforma de preus Solred Repsol
   Design tokens + components — tema clar corporatiu
   ============================================================ */

:root {
  /* Brand */
  --brand-orange: #F7941E;
  --brand-red:    #EE3320;
  --brand:        #F0571E;
  --grad:         linear-gradient(135deg, #F7941E 0%, #EE3320 100%);
  --grad-soft:    linear-gradient(135deg, rgba(247,148,30,.12), rgba(238,51,32,.12));

  /* Ink / navy */
  --ink:    #16233F;
  --ink-2:  #2C3A56;
  --muted:  #66718A;
  --faint:  #97A1B4;
  --navy-grad: linear-gradient(165deg, #1B2A4A 0%, #111C33 55%, #0C1527 100%);

  /* Surfaces */
  --bg:        #F4F6F9;
  --surface:   #FFFFFF;
  --surface-2: #FAFBFD;
  --line:      #E6E9F0;
  --line-2:    #EEF1F6;

  /* States */
  --up:      #E5484D;   /* preu puja = car = vermell */
  --up-bg:   #FCEDED;
  --down:    #18935A;   /* preu baixa = bo = verd */
  --down-bg: #E8F4EE;
  --info:    #2F6FED;

  /* Geometry */
  --r-xs: 7px;  --r-sm: 10px; --r: 14px; --r-lg: 18px; --r-xl: 24px;
  --sh-xs: 0 1px 2px rgba(20,30,55,.06);
  --sh-sm: 0 2px 6px rgba(20,30,55,.06), 0 1px 2px rgba(20,30,55,.05);
  --sh:    0 6px 20px rgba(20,30,55,.08), 0 2px 6px rgba(20,30,55,.05);
  --sh-lg: 0 24px 60px rgba(16,25,50,.16), 0 8px 24px rgba(16,25,50,.10);

  --font-sans: 'Hanken Grotesk', system-ui, -apple-system, sans-serif;
  --font-disp: 'Space Grotesk', var(--font-sans);
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;

  --sidebar-w: 256px;
  --topbar-h: 68px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-size: 15px;
  line-height: 1.5;
}
#root { min-height: 100vh; }
::selection { background: rgba(247,148,30,.22); }
button { font-family: inherit; cursor: pointer; }
a { color: inherit; text-decoration: none; }
input, button { font-family: inherit; }

.mono { font-family: var(--font-mono); font-feature-settings: "tnum" 1; }
.tnum { font-variant-numeric: tabular-nums; }

/* ============================== App shell ============================== */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  z-index: 30;
}
.sidebar__brand {
  height: var(--topbar-h); display: flex; align-items: center;
  padding: 0 20px; border-bottom: 1px solid var(--line-2);
}
.sidebar__brand img { height: 30px; width: auto; }
.sidebar__nav { padding: 16px 14px; display: flex; flex-direction: column; gap: 3px; flex: 1; }
.nav-label {
  font-size: 11px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
  color: var(--faint); padding: 14px 12px 7px;
}
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: var(--r-sm);
  color: var(--ink-2); font-weight: 600; font-size: 14.5px;
  border: 1px solid transparent; background: none; width: 100%; text-align: left;
  position: relative; transition: background .15s, color .15s;
}
.nav-item svg { width: 19px; height: 19px; flex: none; color: var(--faint); transition: color .15s; }
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item:hover svg { color: var(--ink-2); }
.nav-item.is-active { background: var(--ink); color: #fff; box-shadow: var(--sh-sm); }
.nav-item.is-active svg { color: var(--brand-orange); }
.sidebar__foot { padding: 14px; border-top: 1px solid var(--line-2); }

.tenant-card {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 11px; border-radius: var(--r-sm);
  background: var(--surface-2); border: 1px solid var(--line);
}
.tenant-card .dot {
  width: 36px; height: 36px; border-radius: 9px; flex: none;
  background: var(--grad); color: #fff; display: grid; place-items: center;
  font-family: var(--font-disp); font-weight: 700; font-size: 15px;
}
.tenant-card .t-name { font-weight: 700; font-size: 13.5px; line-height: 1.2; }
.tenant-card .t-sub { font-size: 11.5px; color: var(--muted); }

/* ============================== Topbar ============================== */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: var(--topbar-h); position: sticky; top: 0; z-index: 20;
  background: rgba(255,255,255,.82); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 26px; gap: 16px;
}
.topbar__crumb { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 13.5px; font-weight: 600; }
.topbar__crumb b { color: var(--ink); }
.topbar__right { display: flex; align-items: center; gap: 10px; }

.lang-toggle { display: flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.lang-toggle button {
  border: none; background: none; padding: 5px 12px; border-radius: 999px;
  font-size: 12.5px; font-weight: 700; color: var(--muted); letter-spacing: .02em;
}
.lang-toggle button.on { background: var(--ink); color: #fff; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink-2); display: grid; place-items: center;
  transition: background .15s, border-color .15s;
}
.icon-btn:hover { background: var(--surface-2); border-color: #D9DEE8; }
.icon-btn svg { width: 19px; height: 19px; }

.user-chip {
  display: flex; align-items: center; gap: 10px; padding: 5px 13px 5px 6px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
}
.user-chip .av {
  width: 30px; height: 30px; border-radius: 50%; background: var(--ink); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 12.5px;
}
.user-chip .u-name { font-size: 13px; font-weight: 700; line-height: 1; }
.user-chip .u-role { font-size: 11px; color: var(--muted); }

/* ============================== Page ============================== */
.page { padding: 30px 36px 56px; max-width: 1320px; width: 100%; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 26px; flex-wrap: wrap; }
.page-title { font-family: var(--font-disp); font-size: 28px; font-weight: 700; letter-spacing: -.02em; margin: 0; }
.page-sub { color: var(--muted); font-size: 14.5px; margin-top: 5px; }
.page-sub b { color: var(--ink-2); }

/* ============================== Buttons ============================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  padding: 11px 18px; border-radius: var(--r-sm); border: 1px solid transparent;
  font-weight: 700; font-size: 14.5px; letter-spacing: -.01em; white-space: nowrap;
  transition: transform .05s, box-shadow .15s, background .15s, border-color .15s;
}
.btn:active { transform: translateY(1px); }
.btn svg { width: 18px; height: 18px; }
.btn--brand { background: var(--grad); color: #fff; box-shadow: 0 6px 16px rgba(238,51,32,.26); }
.btn--brand:hover { box-shadow: 0 10px 22px rgba(238,51,32,.34); }
.btn--ink { background: var(--ink); color: #fff; }
.btn--ink:hover { background: #0F1B33; }
.btn--ghost { background: var(--surface); border-color: var(--line); color: var(--ink-2); }
.btn--ghost:hover { background: var(--surface-2); border-color: #D9DEE8; }
.btn--sm { padding: 8px 13px; font-size: 13px; border-radius: var(--r-xs); }
.btn--lg { padding: 14px 22px; font-size: 16px; }
.btn--block { width: 100%; }
.btn:disabled { opacity: .5; pointer-events: none; }

/* ============================== Cards ============================== */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--sh-sm); }
.card__head { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 18px 22px; border-bottom: 1px solid var(--line-2); }
.card__title { font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.card__sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.card__body { padding: 22px; }

/* ============================== Metric cards ============================== */
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 22px; }
.metric {
  position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 18px 20px; box-shadow: var(--sh-sm);
}
.metric.is-hero { background: var(--navy-grad); border-color: transparent; color: #fff; }
.metric.is-hero .metric__label { color: rgba(255,255,255,.62); }
.metric.is-hero .metric__sub { color: rgba(255,255,255,.55); }
.metric__top { display: flex; align-items: center; justify-content: space-between; }
.metric__label { font-size: 12.5px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; color: var(--muted); }
.metric__ic { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--grad-soft); color: var(--brand); }
.metric.is-hero .metric__ic { background: rgba(255,255,255,.12); color: var(--brand-orange); }
.metric__val { font-family: var(--font-disp); font-size: 33px; font-weight: 700; letter-spacing: -.025em; margin-top: 14px; line-height: 1; font-variant-numeric: tabular-nums; }
.metric__val .u { font-size: 15px; font-weight: 600; color: var(--muted); margin-left: 4px; letter-spacing: 0; }
.metric.is-hero .metric__val .u { color: rgba(255,255,255,.6); }
.metric__sub { font-size: 12.5px; color: var(--muted); margin-top: 9px; display: flex; align-items: center; gap: 7px; }
.metric__road { position: absolute; right: -10px; bottom: -10px; opacity: .5; pointer-events: none; }

/* Variation pill */
.var { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; font-size: 12.5px; padding: 3px 8px; border-radius: 999px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.var svg { width: 13px; height: 13px; }
.var--up { color: var(--up); background: var(--up-bg); }
.var--down { color: var(--down); background: var(--down-bg); }
.var--flat { color: var(--muted); background: var(--line-2); }
.metric.is-hero .var--up { background: rgba(229,72,77,.18); }
.metric.is-hero .var--down { background: rgba(24,147,90,.22); color: #6EE7A8; }

/* ============================== Chart ============================== */
.chart-wrap { position: relative; width: 100%; }
.chart-svg { display: block; width: 100%; height: auto; overflow: visible; }
.seg-toggle { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-xs); padding: 3px; }
.seg-toggle button { border: none; background: none; padding: 6px 13px; border-radius: 7px; font-size: 13px; font-weight: 700; color: var(--muted); }
.seg-toggle button.on { background: var(--surface); color: var(--ink); box-shadow: var(--sh-xs); }

.chart-tip {
  position: absolute; transform: translate(-50%, -118%); pointer-events: none;
  background: var(--ink); color: #fff; padding: 9px 12px; border-radius: 10px;
  box-shadow: var(--sh); font-size: 12.5px; white-space: nowrap; z-index: 5;
}
.chart-tip .tt-d { color: rgba(255,255,255,.6); font-size: 11px; margin-bottom: 3px; }
.chart-tip .tt-p { font-family: var(--font-disp); font-weight: 700; font-size: 15px; }
.chart-tip::after { content:''; position: absolute; left: 50%; top: 100%; transform: translateX(-50%); border: 6px solid transparent; border-top-color: var(--ink); }

/* ============================== Tables ============================== */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th {
  text-align: left; font-size: 11.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  color: var(--faint); padding: 12px 16px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.tbl th.r, .tbl td.r { text-align: right; }
.tbl td { padding: 13px 16px; border-bottom: 1px solid var(--line-2); font-size: 14px; vertical-align: middle; }
.tbl tbody tr { transition: background .12s; }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl .price { font-family: var(--font-disp); font-weight: 700; font-variant-numeric: tabular-nums; font-size: 15px; }
.tbl .price-iva { font-family: var(--font-mono); font-size: 13px; color: var(--muted); }

.period { display: flex; align-items: center; gap: 10px; }
.period .cal-ic { width: 32px; height: 32px; border-radius: 9px; background: var(--grad-soft); color: var(--brand); display: grid; place-items: center; flex: none; }
.period .cal-ic svg { width: 16px; height: 16px; }
.period .p-main { font-weight: 700; font-size: 14px; white-space: nowrap; }
.period .p-sub { font-size: 12px; color: var(--muted); white-space: nowrap; text-transform: capitalize; }

.days-badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; background: var(--line-2); color: var(--ink-2); font-size: 12px; font-weight: 700; white-space: nowrap; }

.row-actions { display: flex; gap: 6px; justify-content: flex-end; opacity: 0; transition: opacity .12s; }
.tbl tbody tr:hover .row-actions { opacity: 1; }
.act-btn { width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); display: grid; place-items: center; color: var(--muted); }
.act-btn:hover { color: var(--ink); border-color: #D9DEE8; background: var(--surface-2); }
.act-btn.danger:hover { color: var(--up); border-color: #F3C9CB; background: var(--up-bg); }
.act-btn svg { width: 16px; height: 16px; }

/* ============================== Forms ============================== */
.field { display: flex; flex-direction: column; gap: 8px; }
.label { font-size: 13.5px; font-weight: 700; color: var(--ink-2); }
.hint { font-size: 12.5px; color: var(--muted); }
.input {
  width: 100%; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: var(--r-sm);
  font-size: 15px; color: var(--ink); background: var(--surface); transition: border-color .15s, box-shadow .15s;
}
.input:focus { outline: none; border-color: var(--brand-orange); box-shadow: 0 0 0 4px rgba(247,148,30,.14); }

.price-input { position: relative; display: flex; align-items: stretch; }
.price-input input {
  flex: 1; font-family: var(--font-disp); font-size: 30px; font-weight: 700; letter-spacing: -.02em;
  padding: 16px 18px; border: 1.5px solid var(--line); border-radius: var(--r-sm) 0 0 var(--r-sm);
  border-right: none; font-variant-numeric: tabular-nums;
}
.price-input input:focus { outline: none; border-color: var(--brand-orange); box-shadow: 0 0 0 4px rgba(247,148,30,.14); z-index: 2; }
.price-input .unit { display: grid; place-items: center; padding: 0 18px; border: 1.5px solid var(--line); border-left: none; border-radius: 0 var(--r-sm) var(--r-sm) 0; background: var(--surface-2); color: var(--muted); font-weight: 700; font-size: 16px; }
.stepper { display: flex; flex-direction: column; border: 1.5px solid var(--line); border-left: none; border-radius: 0 var(--r-sm) var(--r-sm) 0; overflow: hidden; }
.stepper button { flex: 1; width: 42px; border: none; background: var(--surface-2); color: var(--ink-2); display: grid; place-items: center; }
.stepper button:hover { background: var(--line-2); }
.stepper button:first-child { border-bottom: 1px solid var(--line); }
.stepper svg { width: 15px; height: 15px; }

.preset-row { display: flex; flex-wrap: wrap; gap: 8px; }
.preset {
  padding: 8px 14px; border-radius: 999px; border: 1.5px solid var(--line); background: var(--surface);
  font-size: 13px; font-weight: 700; color: var(--ink-2); white-space: nowrap;
}
.preset:hover { border-color: #D9DEE8; background: var(--surface-2); }
.preset.on { border-color: var(--brand-orange); background: var(--grad-soft); color: var(--brand); }

/* IVA preview */
.iva-preview { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line-2); border-radius: var(--r-sm); overflow: hidden; border: 1px solid var(--line); }
.iva-cell { background: var(--surface); padding: 15px 16px; }
.iva-cell .k { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.iva-cell .v { font-family: var(--font-disp); font-size: 24px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.iva-cell.accent { background: var(--ink); color: #fff; }
.iva-cell.accent .k { color: rgba(255,255,255,.6); }

/* ============================== Calendar ============================== */
.cal { user-select: none; }
.cal__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.cal__title { font-weight: 700; font-size: 15px; text-transform: capitalize; }
.cal__nav { display: flex; gap: 6px; }
.cal__grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal__dow { text-align: center; font-size: 11px; font-weight: 700; color: var(--faint); text-transform: uppercase; padding-bottom: 6px; }
.cal__cell {
  aspect-ratio: 1; border: none; background: none; border-radius: 9px; font-size: 13.5px; font-weight: 600;
  color: var(--ink-2); position: relative; display: grid; place-items: center; transition: background .12s;
}
.cal__cell:hover:not(:disabled):not(.sel) { background: var(--surface-2); }
.cal__cell:disabled { color: var(--line); }
.cal__cell.muted { color: var(--faint); opacity: .55; }
.cal__cell.has { box-shadow: inset 0 0 0 1.5px var(--line); }
.cal__cell.has::after { content:''; position: absolute; bottom: 5px; width: 4px; height: 4px; border-radius: 50%; background: var(--brand); }
/* seleccionado: oscuro + borde naranja, también bajo el cursor (el hover no lo tapa) */
.cal__cell.sel,
.cal__cell.sel:hover { background: var(--ink); color: #fff; font-weight: 700; box-shadow: inset 0 0 0 1.5px var(--brand-orange); }
.cal__cell.sel::after { background: var(--brand-orange); }
.cal__cell.in-range { background: var(--grad-soft); color: var(--brand); border-radius: 0; }
.cal__cell.today { box-shadow: inset 0 0 0 1.5px var(--brand-orange); }

/* ============================== Misc ============================== */
.grid-2 { display: grid; grid-template-columns: 1.15fr .85fr; gap: 22px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 22px; }
.divider { height: 1px; background: var(--line-2); margin: 4px 0; }
.empty { text-align: center; padding: 40px; color: var(--muted); }
.kbd { font-family: var(--font-mono); font-size: 11px; background: var(--line-2); border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; }

.chip-note { display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px; border-radius: 999px; background: var(--grad-soft); color: var(--brand); font-size: 12.5px; font-weight: 700; }
.chip-note svg { width: 14px; height: 14px; }

.summary-line { display: flex; align-items: center; justify-content: space-between; padding: 11px 0; border-bottom: 1px solid var(--line-2); font-size: 14px; }
.summary-line:last-child { border-bottom: none; }
.summary-line .sk { color: var(--muted); white-space: nowrap; }
.summary-line .sv { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }

/* ============================== Toast ============================== */
.toast-wrap { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.toast {
  display: flex; align-items: center; gap: 11px; padding: 13px 18px; border-radius: 12px;
  background: var(--ink); color: #fff; box-shadow: var(--sh-lg); font-size: 14px; font-weight: 600;
  animation: toastIn .3s cubic-bezier(.2,.8,.2,1);
}
.toast .tk { width: 26px; height: 26px; border-radius: 50%; background: var(--down); display: grid; place-items: center; flex: none; }
.toast .tk svg { width: 15px; height: 15px; }
@keyframes toastIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }

/* ============================== Modal ============================== */
.modal-back { position: fixed; inset: 0; background: rgba(16,25,50,.42); backdrop-filter: blur(3px); z-index: 90; display: grid; place-items: center; padding: 24px; animation: fadeIn .18s; }
.modal { width: 100%; max-width: 460px; background: var(--surface); border-radius: var(--r-xl); box-shadow: var(--sh-lg); overflow: hidden; animation: modalIn .24s cubic-bezier(.2,.8,.2,1); }
.modal__head { padding: 22px 24px 0; }
.modal__title { font-family: var(--font-disp); font-size: 20px; font-weight: 700; }
.modal__body { padding: 20px 24px; display: flex; flex-direction: column; gap: 16px; }
.modal__foot { padding: 16px 24px; background: var(--surface-2); border-top: 1px solid var(--line-2); display: flex; gap: 10px; justify-content: flex-end; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalIn { from { opacity: 0; transform: translateY(16px) scale(.98); } to { opacity: 1; transform: none; } }

/* ============================== Login ============================== */
.login { min-height: 100vh; display: grid; grid-template-columns: 1.05fr .95fr; }
.login__brand { position: relative; background: var(--navy-grad); overflow: hidden; display: flex; flex-direction: column; justify-content: space-between; padding: 48px; color: #fff; }
.login__form { display: grid; place-items: center; padding: 40px; }
.login__inner { width: 100%; max-width: 380px; }
.login__logo { height: 40px; width: auto; margin-bottom: 34px; }
.login-title { font-family: var(--font-disp); font-size: 27px; font-weight: 700; letter-spacing: -.02em; }
.login-sub { color: var(--muted); font-size: 14.5px; margin-top: 7px; margin-bottom: 30px; }
.login .field + .field { margin-top: 16px; }
.login__brand-card { position: absolute; inset: 48px; display: flex; flex-direction: column; justify-content: space-between; z-index: 2; }
.brand-badge { width: 92px; height: 92px; border-radius: 22px; background: rgba(255,255,255,.97); display: grid; place-items: center; box-shadow: 0 18px 40px rgba(0,0,0,.25); }
.brand-badge img { width: 70px; height: auto; }
.brand-claim { font-family: var(--font-disp); font-size: 38px; font-weight: 700; line-height: 1.08; letter-spacing: -.025em; max-width: 460px; }
.brand-claim .hl { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand-meta { display: flex; gap: 28px; }
.brand-meta .bm-k { font-family: var(--font-disp); font-size: 22px; font-weight: 700; white-space: nowrap; }
.brand-meta .bm-v { font-size: 12.5px; color: rgba(255,255,255,.6); }
.road-deco { position: absolute; inset: 0; opacity: .5; pointer-events: none; }

.pw-wrap { position: relative; }
.pw-wrap .input { padding-right: 46px; }
.pw-toggle { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); width: 32px; height: 32px; border: none; background: none; color: var(--faint); display: grid; place-items: center; border-radius: 7px; }
.pw-toggle:hover { color: var(--ink-2); background: var(--surface-2); }
.login-cred { margin-top: 22px; padding: 13px 15px; border: 1px dashed var(--line); border-radius: var(--r-sm); background: var(--surface-2); font-size: 12.5px; color: var(--muted); }
.login-cred b { color: var(--ink-2); }
.login-cred code { font-family: var(--font-mono); background: #fff; border: 1px solid var(--line); border-radius: 5px; padding: 1px 6px; color: var(--ink); }

.fade-in { animation: fadeUp .45s cubic-bezier(.2,.8,.2,1); }
@keyframes fadeUp { from { transform: translateY(10px); } to { transform: none; } }

/* Density tweak */
body[data-density="compact"] .tbl td { padding: 9px 16px; }
body[data-density="compact"] .card__body { padding: 16px; }
body[data-density="compact"] .metric { padding: 14px 18px; }
body[data-density="comfy"] .tbl td { padding: 18px 16px; }
body[data-density="comfy"] .card__body { padding: 28px; }
body[data-density="comfy"] .metric { padding: 24px 24px; }

/* ============================== Avalador / Central ============================== */
.central-tag {
  display: inline-flex; align-items: center; gap: 6px; margin-left: 10px;
  padding: 3px 9px; border-radius: 999px; background: var(--ink); color: #fff;
  font-size: 10.5px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase;
}
.central-tag .d { width: 6px; height: 6px; border-radius: 50%; background: var(--brand-orange); }

.station-cell { display: flex; align-items: center; gap: 11px; }
.station-cell .sc-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.station-cell .sc-name { font-weight: 700; font-size: 14px; white-space: nowrap; }
.station-cell .sc-town { font-size: 12px; color: var(--muted); white-space: nowrap; }

.diff { display: inline-flex; align-items: center; gap: 5px; font-weight: 700; font-size: 13.5px; padding: 4px 10px; border-radius: 999px; font-variant-numeric: tabular-nums; white-space: nowrap; font-family: var(--font-disp); }
.diff svg { width: 14px; height: 14px; }
.diff--up { color: var(--up); background: var(--up-bg); }
.diff--down { color: var(--down); background: var(--down-bg); }
.diff--flat { color: var(--muted); background: var(--line-2); }

.legend { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 16px; }
.legend-item { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.legend-item .lg { width: 14px; height: 3px; border-radius: 2px; }
.legend-item.ref .lg { height: 4px; background: var(--grad); }

.isolation-bar {
  display: flex; align-items: center; gap: 9px; padding: 10px 16px; margin-bottom: 22px;
  border-radius: var(--r-sm); background: var(--grad-soft); color: var(--brand);
  font-size: 13px; font-weight: 700; border: 1px solid rgba(238,51,32,.16);
}
.isolation-bar svg { width: 16px; height: 16px; flex: none; }

/* ============================== Responsive ============================== */
@media (max-width: 1080px) {
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .login { grid-template-columns: 1fr; }
  .login__brand { display: none; }
  .page { padding: 22px 18px 48px; }
}

/* ============================== Rails additions ============================== */
/* Toast de error (alert) — variante roja del toast de confirmación */
.toast.toast--alert .tk { background: var(--up); }
.toast.toast--alert { }
/* Error de login bajo el formulario */
.login-error {
  margin-top: 16px; padding: 11px 14px; border-radius: var(--r-sm);
  background: var(--up-bg); color: var(--up); border: 1px solid #F3C9CB;
  font-size: 13px; font-weight: 700; display: flex; gap: 8px; align-items: center;
}
.login-error svg { width: 16px; height: 16px; flex: none; }
/* Estado oculto util para Stimulus */
[hidden] { display: none !important; }
button[disabled] { opacity: .5; pointer-events: none; }

/* Enlaces estilizados como toggles (lang / sort) y reset de button_to forms */
.lang-toggle a {
  border: none; background: none; padding: 5px 12px; border-radius: 999px;
  font-size: 12.5px; font-weight: 700; color: var(--muted); letter-spacing: .02em;
  display: inline-flex; align-items: center; text-decoration: none;
}
.lang-toggle a.on { background: var(--ink); color: #fff; }
.seg-toggle a {
  border: none; background: none; padding: 6px 13px; border-radius: 7px;
  font-size: 13px; font-weight: 700; color: var(--muted); display: inline-flex; align-items: center;
}
.seg-toggle a.on { background: var(--surface); color: var(--ink); box-shadow: var(--sh-xs); }
.row-actions form { display: inline; margin: 0; }
.sidebar__foot form { margin: 0; }
.sidebar__foot form .nav-item { width: 100%; }

/* ============================== Filtro por cliente (central) ============================== */
.filter-bar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px; margin-bottom: 22px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--sh-sm);
}
.filter-bar__label { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.filter-bar__label svg { width: 15px; height: 15px; }
.filter-chips { display: flex; flex-wrap: wrap; gap: 7px; flex: 1; }
.fchip {
  display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px; border-radius: 999px;
  border: 1.5px solid var(--line); background: var(--surface); color: var(--ink-2);
  font-size: 13px; font-weight: 700; white-space: nowrap; transition: opacity .12s, border-color .12s, background .12s;
}
.fchip:hover { border-color: #D9DEE8; background: var(--surface-2); }
.fchip__dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.fchip.off { opacity: .4; }
.fchip.off .fchip__dot { background: var(--faint) !important; }
.fchip.off .sc-name { text-decoration: line-through; }

/* Tooltip multilínea de la gráfica */
.chart-tip .tt-row { display: flex; align-items: center; gap: 8px; margin-top: 4px; font-size: 12px; }
.chart-tip .tt-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.chart-tip .tt-name { color: rgba(255,255,255,.78); margin-right: 10px; white-space: nowrap; }
.chart-tip .tt-val { margin-left: auto; font-family: var(--font-disp); font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.chart-tip[hidden] { display: none; }

/* ============================== Alta de cliente (central) ============================== */
.mono-cell { font-family: var(--font-mono); font-size: 12.5px; color: var(--ink-2); background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 2px 7px; }
.slug-preview { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 10px; }
.slug-preview span { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); font-weight: 600; }
.slug-preview svg { width: 13px; height: 13px; }
.slug-preview code { font-family: var(--font-mono); background: var(--grad-soft); color: var(--brand); border-radius: 5px; padding: 1px 7px; }

.creds-card {
  background: var(--surface); border: 1px solid rgba(24,147,90,.30); border-left: 4px solid var(--down);
  border-radius: var(--r-lg); box-shadow: var(--sh-sm); padding: 18px 20px; margin-bottom: 22px;
}
.creds-card__head { display: flex; align-items: center; gap: 9px; font-size: 15px; }
.creds-card__head .tk { width: 24px; height: 24px; border-radius: 50%; background: var(--down); color: #fff; display: grid; place-items: center; flex: none; }
.creds-card__warn { display: flex; align-items: center; gap: 7px; margin-top: 8px; font-size: 12.5px; font-weight: 700; color: var(--up); }
.creds-card__rows { display: flex; flex-wrap: wrap; gap: 10px 22px; margin-top: 14px; }
.creds-card__rows .k { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--faint); margin-right: 7px; }
.creds-card__rows code { font-family: var(--font-mono); font-size: 14px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 7px; padding: 4px 10px; color: var(--ink); font-weight: 600; }
.creds-card__note { display: flex; align-items: center; gap: 7px; margin-top: 14px; font-size: 12.5px; color: var(--muted); }

/* ============================== Formulario "Afegir usuari" ============================== */
.add-user-form { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.add-user-form .field { flex: 1 1 280px; max-width: 420px; }
.add-user-form .btn { flex: none; padding-top: 12px; padding-bottom: 12px; }
@media (max-width: 640px) {
  .add-user-form .btn { width: 100%; }
}

/* ============================== Menú de usuario (topbar) ============================== */
.user-menu { position: relative; }
.user-menu .user-chip { cursor: pointer; transition: border-color .15s, background .15s; }
.user-menu .user-chip:hover { border-color: #D9DEE8; background: var(--surface-2); }
.user-chip__chev { color: var(--faint); display: grid; place-items: center; margin-left: 2px; }
.user-menu__panel {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 50;
  min-width: 230px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--sh-lg);
  animation: modalIn .18s cubic-bezier(.2,.8,.2,1);
}
.user-menu__item {
  display: flex; align-items: center; gap: 11px; width: 100%;
  padding: 10px 12px; border: none; background: none; border-radius: var(--r-xs);
  font-size: 14px; font-weight: 600; color: var(--ink-2); text-align: left;
  transition: background .12s, color .12s;
}
.user-menu__item svg { width: 17px; height: 17px; color: var(--faint); flex: none; }
.user-menu__item:hover { background: var(--surface-2); color: var(--ink); }
.user-menu__item:hover svg { color: var(--ink-2); }
.user-menu__item.danger:hover { background: var(--up-bg); color: var(--up); }
.user-menu__item.danger:hover svg { color: var(--up); }
.user-menu__sep { height: 1px; background: var(--line-2); margin: 5px 6px; }
.user-menu__panel form { margin: 0; }

/* ============================== Leyenda clicable (selector de estaciones) ============================== */
.legend--toggle .legend-item:not(.ref) {
  border: none; background: none; padding: 4px 8px; border-radius: 7px;
  cursor: pointer; transition: opacity .12s, background .12s;
}
.legend--toggle .legend-item:not(.ref):hover { background: var(--surface-2); }
.legend--toggle .legend-item.off { opacity: .32; text-decoration: line-through; }
.legend--toggle .legend-item.off .lg { background: var(--faint) !important; }
.legend-acts { display: inline-flex; align-items: center; gap: 7px; margin-left: auto; color: var(--faint); font-size: 12px; }
.legend-acts button {
  border: none; background: none; padding: 3px 6px; border-radius: 6px;
  font-size: 12px; font-weight: 700; color: var(--brand); cursor: pointer;
}
.legend-acts button:hover { background: var(--grad-soft); }
