/* Paleta ARX Digital (arxdigital.cl) */
:root {
  --azul: #0F2A43;
  --azul-2: #163A5C;
  --azul-3: #24507A;
  --azul-noche: #0B2236;
  --rojo: #C8102E;
  --rojo-osc: #A50D26;
  --verde: #2F7D5A;
  --brand: var(--azul);
  --brand-hover: var(--azul-2);
  --accent: var(--rojo);
  --accent-hover: var(--rojo-osc);
  --focus: var(--azul-3);
  --bg: #EEF1F4;
  --surface: #FFFFFF;
  --surface-2: #F5F7F9;
  --col-bg: #E3E8ED;
  --ink: #16222E;
  --ink-2: #2E3B48;
  --muted: #5B6770;
  --line: #D5DBE1;
  --shadow: 0 1px 2px rgba(15, 42, 67, .08), 0 2px 6px rgba(15, 42, 67, .05);
  --c-idea: #5B6770;
  --c-inicio: #24507A;
  --c-detenido: #C8102E;
  --c-finalizado: #2F7D5A;
  --p-alta: #C8102E;
  --p-media: #D99A1E;
  --p-baja: #8FA3B6;
  --danger: #C8102E;
  --chart: #24507A;
  --tab-active-bg: rgba(15, 42, 67, .08);
  --tab-active-ink: #0F2A43;
  --radius: 6px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand: #24507A;
    --brand-hover: #2D5F8F;
    --accent: #D8213F;
    --accent-hover: #C8102E;
    --focus: #6E9CC7;
    --bg: #0B2236;
    --surface: #0F2A43;
    --surface-2: #163A5C;
    --col-bg: #0D2539;
    --ink: #EEF1F4;
    --ink-2: #C9D3DD;
    --muted: #8FA3B6;
    --line: #1F4566;
    --shadow: 0 1px 2px rgba(0, 0, 0, .35);
    --c-idea: #8FA3B6;
    --c-inicio: #6E9CC7;
    --c-detenido: #FF6A7E;
    --c-finalizado: #5CB88F;
    --p-alta: #FF6A7E;
    --p-baja: #5B6770;
    --danger: #FF6A7E;
    --chart: #6E9CC7;
    --tab-active-bg: rgba(255, 255, 255, .08);
    --tab-active-ink: #FFFFFF;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --brand: #24507A;
  --brand-hover: #2D5F8F;
  --accent: #D8213F;
  --accent-hover: #C8102E;
  --focus: #6E9CC7;
  --bg: #0B2236;
  --surface: #0F2A43;
  --surface-2: #163A5C;
  --col-bg: #0D2539;
  --ink: #EEF1F4;
  --ink-2: #C9D3DD;
  --muted: #8FA3B6;
  --line: #1F4566;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35);
  --c-idea: #8FA3B6;
  --c-inicio: #6E9CC7;
  --c-detenido: #FF6A7E;
  --c-finalizado: #5CB88F;
  --p-alta: #FF6A7E;
  --p-baja: #5B6770;
  --danger: #FF6A7E;
  --chart: #6E9CC7;
  --tab-active-bg: rgba(255, 255, 255, .08);
  --tab-active-ink: #FFFFFF;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 "Hanken Grotesk", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; font-weight: 700; color: var(--ink); }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
code { font-size: 12px; background: rgba(0,0,0,.06); padding: 1px 4px; border-radius: 4px; }

/* ---------- Botones e inputs ---------- */
.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 7px 12px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.accent:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.icon { padding: 6px 10px; line-height: 1; }
.btn.block { width: 100%; }
.btn.sm { padding: 4px 9px; font-size: 12px; }

input, select, textarea {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); outline-offset: -1px; }
label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 10px; }
label > input, label > select, label > textarea { margin-top: 4px; font-weight: 400; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }

/* ---------- Marca ---------- */
.wordmark { font-weight: 800; font-size: 22px; letter-spacing: -.02em; color: var(--azul); line-height: 1; display: inline-flex; align-items: baseline; }
.wordmark span { color: var(--rojo); }
.wordmark small { font-size: 13px; font-weight: 600; color: var(--muted); margin-left: 8px; letter-spacing: 0; }
.wordmark.lg { font-size: 34px; }
:root[data-theme="dark"] .wordmark { color: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .wordmark { color: #fff; } }

/* ---------- Login ---------- */
.login {
  min-height: 100%; display: flex; align-items: center; justify-content: center; gap: 56px;
  padding: 24px 16px; background: var(--azul-noche);
  background-image: radial-gradient(circle at 15% 20%, rgba(36, 80, 122, .55), transparent 55%);
}
.login-hero { max-width: 340px; color: #fff; }
.login-tag { margin: 0 0 10px; font-size: 13px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: #FF6A7E; }
.login-claim { margin: 0; font-size: 28px; line-height: 1.2; font-weight: 700; color: #fff; }
.login-card {
  width: 100%; max-width: 380px;
  background: #fff; color: #16222E;
  border-radius: 8px; padding: 30px 26px; box-shadow: 0 20px 50px rgba(0, 0, 0, .35);
}
.login-card .wordmark { color: #0F2A43; }
.login-card h1 { font-size: 20px; margin: 18px 0 4px; color: #16222E; }
.login-card p { margin: 0 0 18px; color: #5B6770; }
.login-card label { color: #2E3B48; }
.login-card input[type=email], .login-card input[type=password] { background: #fff; color: #16222E; border-color: #D5DBE1; }
.login-card .btn.primary { background: #0F2A43; border-color: #0F2A43; margin-top: 4px; padding: 10px 12px; }
.login-card .btn.primary:hover { background: #163A5C; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: 13px; cursor: pointer; margin: 2px 0 14px; }
label.check input { width: 16px; height: 16px; margin: 0; accent-color: #C8102E; flex: none; }
@media (max-width: 760px) {
  .login { flex-direction: column; gap: 22px; justify-content: flex-start; padding-top: max(40px, env(safe-area-inset-top)); }
  .login-hero { text-align: left; width: 100%; max-width: 380px; }
  .login-claim { font-size: 20px; }
}
.error { color: var(--danger); margin: 10px 0 0 !important; font-size: 13px; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand small { font-size: 13px; font-weight: 600; color: var(--muted); }
.tabs { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.tab {
  border: 0; background: none; font: inherit; color: var(--muted); font-weight: 500;
  padding: 7px 12px; border-radius: var(--radius); cursor: pointer; white-space: nowrap; position: relative;
}
.tab:hover { color: var(--ink); background: var(--surface-2); }
.tab.active { color: var(--tab-active-ink); background: var(--tab-active-bg); font-weight: 700; }
.tab.active::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: 2px; height: 2px; border-radius: 2px; background: var(--accent); }
.badge {
  display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 6px;
  border-radius: 9px; background: var(--c-detenido); color: #fff; font-size: 11px; line-height: 18px; text-align: center;
}
.top-actions { display: flex; align-items: center; gap: 8px; position: relative; }
.sync { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.sync.ok { background: var(--c-finalizado); }
.sync.busy { background: var(--p-media); }
.sync.err { background: var(--danger); }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 230px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.15); padding: 6px; z-index: 30;
}
.menu button {
  display: block; width: 100%; text-align: left; border: 0; background: none;
  font: inherit; color: var(--ink); padding: 8px 10px; border-radius: 6px; cursor: pointer;
}
.menu button:hover { background: var(--surface-2); }
.menu-user { padding: 6px 10px 8px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line); margin-bottom: 4px; word-break: break-all; }

.banner { padding: 8px 16px; font-size: 13px; background: rgba(36, 80, 122, .12); color: var(--ink-2); }
.banner.warn { background: rgba(232, 163, 23, .18); }

/* ---------- Vistas ---------- */
.view { padding: 14px 16px 32px; }
.filters { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.filters input { max-width: 280px; }
.filters select { width: auto; min-width: 150px; }

/* ---------- Tablero ---------- */
.board {
  display: grid;
  grid-template-columns: repeat(4, minmax(250px, 1fr));
  gap: 12px;
  align-items: start;
}
.column {
  background: var(--col-bg);
  border-radius: 8px;
  display: flex; flex-direction: column;
  max-height: calc(100vh - 150px);
  border-top: 3px solid var(--accent);
}
.col-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px 4px; min-height: 40px; }
.col-head h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--accent); }
.col-count { font-size: 12px; color: var(--muted); font-weight: 600; }
.col-head .spacer { flex: 1; }
.col-head .btn { font-size: 12px; padding: 2px 8px; line-height: 1.4; }
.cards { padding: 4px 8px 8px; overflow-y: auto; flex: 1; min-height: 60px; }
.add-inline { padding: 0 8px 10px; }
.add-inline input { background: transparent; border-style: dashed; font-size: 13px; }
.add-inline input:focus { background: var(--surface); border-style: solid; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 10px 8px 12px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
  cursor: grab;
  position: relative;
  user-select: none;
}
.card::before {
  content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0;
  background: var(--prio, transparent);
}
.card:hover { border-color: var(--muted); }
.card-title { font-weight: 500; word-wrap: break-word; }
.card-desc { color: var(--muted); font-size: 12px; margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-motivo { font-size: 12px; color: var(--c-detenido); margin-top: 4px; font-style: italic; }
.card-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; font-size: 11px; color: var(--muted); }
.chip { background: var(--surface-2); border: 1px solid var(--line); border-radius: 20px; padding: 0 7px; line-height: 18px; color: var(--ink-2); }
.due.over { color: var(--danger); font-weight: 600; }
.due.soon { color: #B57A00; font-weight: 600; }
.card.ghost { opacity: .35; }
.card.chosen { box-shadow: 0 8px 20px rgba(0,0,0,.18); }
.card.drag { transform: rotate(1.5deg); }
.empty-col { text-align: center; color: var(--muted); font-size: 12px; padding: 14px 0 6px; }
.empty-board { text-align: center; margin: 28px auto 0; max-width: 420px; color: var(--muted); }
.empty-board h3 { font-size: 16px; margin-bottom: 6px; }
.empty-board p { margin: 0; }
kbd { font: 600 12px/1 inherit; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 2px 6px; background: var(--surface); color: var(--ink); }

/* ---------- Historial ---------- */
.hist-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; }
.hist-grid h2 { margin-bottom: 10px; }
.hist-item {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; margin-bottom: 8px; display: flex; gap: 10px; align-items: flex-start;
}
.hist-item .grow { flex: 1; min-width: 0; }
.hist-item .t { font-weight: 500; }
.hist-item .m { font-size: 12px; color: var(--muted); margin-top: 2px; }
.hist-day { font-size: 12px; font-weight: 600; color: var(--muted); margin: 14px 0 6px; }
.event { font-size: 13px; padding: 7px 0; border-bottom: 1px solid var(--line); display: flex; gap: 10px; }
.event time { color: var(--muted); font-size: 12px; white-space: nowrap; min-width: 92px; }
.pill { display: inline-block; font-size: 11px; font-weight: 600; padding: 0 6px; border-radius: 4px; color: #fff; line-height: 17px; }
.pill.idea { background: var(--c-idea); }
.pill.inicio { background: var(--c-inicio); }
.pill.detenido { background: var(--c-detenido); }
.pill.finalizado { background: var(--c-finalizado); }

/* ---------- Recurrentes ---------- */
.rec-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 10px; }
.rec-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.rec-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 14px;
  border-left: 4px solid var(--state, var(--line));
}
.rec-card h3 { font-size: 15px; display: flex; justify-content: space-between; gap: 8px; }
.rec-next { font-size: 22px; font-weight: 600; margin: 8px 0 2px; }
.rec-when { font-size: 13px; font-weight: 600; color: var(--state, var(--muted)); }
.rec-card .m { font-size: 12px; color: var(--muted); margin-top: 6px; }
.rec-actions { display: flex; gap: 6px; margin-top: 12px; }

/* ---------- Métricas ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 14px; }
.kpi .v { font-size: 26px; font-weight: 600; line-height: 1.1; }
.kpi .l { font-size: 12px; color: var(--muted); margin-top: 4px; }
.charts { display: grid; grid-template-columns: 1.5fr 1fr; gap: 12px; }
.chart-card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 14px; }
.chart-card:last-child { grid-column: 1 / -1; }
.chart-card h3 { margin-bottom: 2px; }
.bars { display: flex; align-items: flex-end; gap: 8px; height: 180px; margin-top: 14px; padding-bottom: 22px; border-bottom: 1px solid var(--line); position: relative; }
.bar-wrap { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; position: relative; cursor: default; }
.bar { width: 100%; max-width: 36px; background: var(--chart); border-radius: 4px 4px 0 0; min-height: 2px; transition: opacity .15s; }
.bar-wrap:hover .bar { opacity: .75; }
.bar-val { font-size: 11px; color: var(--ink-2); margin-bottom: 3px; font-weight: 600; }
.bar-lbl { position: absolute; bottom: -20px; font-size: 11px; color: var(--muted); white-space: nowrap; }
.hbars { margin-top: 12px; }
.hbar { display: grid; grid-template-columns: 100px 1fr 28px; gap: 8px; align-items: center; margin-bottom: 8px; font-size: 13px; }
.hbar .track { background: var(--surface-2); border-radius: 4px; height: 14px; }
.hbar .fill { background: var(--chart); height: 100%; border-radius: 0 4px 4px 0; min-width: 2px; }
.hbar .n { text-align: right; font-weight: 600; color: var(--ink-2); }
.hbar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stale { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; cursor: pointer; }
.stale .d { color: var(--c-detenido); font-weight: 600; white-space: nowrap; }

/* ---------- Diálogos ---------- */
.dialog {
  border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(520px, calc(100vw - 24px));
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.dialog.small { width: min(400px, calc(100vw - 24px)); }
.dialog::backdrop { background: rgba(11, 34, 54, .55); }
.dialog form { padding: 18px 20px; }
.dlg-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.dialog h2 { font-size: 17px; }
#blockForm h2 { margin-bottom: 4px; }
#blockForm input { margin: 10px 0 4px; }
.dlg-foot { display: flex; gap: 8px; align-items: center; margin-top: 14px; flex-wrap: wrap; }
.spacer { flex: 1; }
.meta { margin-top: 2px; line-height: 1.6; }

.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #0B2236; color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 13px;
  z-index: 100; box-shadow: 0 6px 20px rgba(0,0,0,.25); display: flex; gap: 12px; align-items: center;
  max-width: calc(100vw - 32px);
}
.toast button { background: none; border: 0; color: #FF9AA8; font: inherit; font-weight: 600; cursor: pointer; padding: 0; }

/* ---------- Móvil ---------- */
@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; gap: 8px; padding: 8px 12px; }
  .brand span { display: none; }
  .tabs { order: 3; flex-basis: 100%; }
  .top-actions { margin-left: auto; }
  .view { padding: 12px 12px 28px; }
  .board {
    display: flex; overflow-x: auto; scroll-snap-type: x mandatory; gap: 10px;
    margin: 0 -12px; padding: 0 12px 8px; scroll-padding: 0 12px;
  }
  .column { flex: 0 0 86%; scroll-snap-align: start; max-height: calc(100vh - 190px); }
  .hist-grid, .charts { grid-template-columns: 1fr; }
  .filters input, .filters select { max-width: none; flex: 1 1 140px; min-width: 0; }
  .row { flex-direction: column; gap: 0; }
}
