/* ContactValue — v0.1
   Idea visual: la importancia de cada contacto se muestra como un medidor
   de nivel de mesa de mezclas (5 LEDs: verde, verde, ámbar, naranja, rojo).
   Todo lo demás es sobrio y nativo para que se sienta como una app de Apple. */

:root {
  --bg: #F2F4F7;
  --surface: #FFFFFF;
  --ink: #1B2533;
  --ink-2: #5A6677;
  --line: #DCE1E8;
  --off: #D9DEE5;
  --signal: #2F5BEA;
  --signal-ink: #FFFFFF;
  --danger: #C8323A;

  --lvl-1: #2E9E6A;
  --lvl-2: #2E9E6A;
  --lvl-3: #D9A21B;
  --lvl-4: #E2741E;
  --lvl-5: #D63B3B;

  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 22px;

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-round: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  --tabbar-h: 58px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131820;
    --surface: #1C232E;
    --ink: #E8ECF2;
    --ink-2: #98A3B3;
    --line: #2B3442;
    --off: #2F3846;
    --signal: #6C8CFF;
    --signal-ink: #0F1420;
    --danger: #FF6B70;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--signal); }
:focus-visible { outline: 3px solid var(--signal); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }

/* ---------- Estructura ---------- */
.shell { min-height: 100vh; min-height: 100dvh; }
main {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 18px) 18px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 28px);
  outline: none;
}

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  -webkit-backdrop-filter: saturate(1.6) blur(18px);
  backdrop-filter: saturate(1.6) blur(18px);
  border-top: 1px solid var(--line);
}
.tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--ink-2); text-decoration: none; font-size: 11px; font-weight: 600;
}
.tabs a svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }
.tabs a[aria-current="page"] { color: var(--signal); }
.brand { display: none; }

@media (min-width: 900px) {
  .shell { display: grid; grid-template-columns: 232px 1fr; }
  .tabs {
    position: sticky; top: 0; height: 100vh; flex-direction: column; justify-content: flex-start;
    gap: 2px; padding: 22px 12px; border-top: 0; border-right: 1px solid var(--line);
    background: var(--surface);
  }
  .tabs a { flex: none; flex-direction: row; justify-content: flex-start; gap: 10px; padding: 9px 12px; border-radius: 10px; font-size: 15px; }
  .tabs a svg { width: 22px; height: 22px; }
  .tabs a[aria-current="page"] { background: color-mix(in srgb, var(--signal) 12%, transparent); }
  .brand { display: flex; align-items: center; gap: 10px; padding: 4px 12px 20px; font: 700 18px/1 var(--font-round); }
  main { padding-top: 40px; padding-bottom: 48px; }
}

/* ---------- Cabeceras ---------- */
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 6px 0 18px; }
.head h1 { margin: 0; font: 700 34px/1.1 var(--font-round); letter-spacing: -0.01em; }
.head p { margin: 4px 0 0; color: var(--ink-2); }
h2.group {
  margin: 26px 4px 8px; font-size: 15px; font-weight: 650; color: var(--ink-2);
  display: flex; align-items: center; gap: 8px;
}
h2.group .count { font-weight: 500; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px; border-radius: 999px; border: 0; cursor: pointer;
  background: var(--signal); color: var(--signal-ink); font-weight: 650; text-decoration: none;
}
.btn--quiet { background: color-mix(in srgb, var(--signal) 12%, transparent); color: var(--signal); }
.btn--danger { background: transparent; color: var(--danger); padding: 0 6px; }
.btn--round { width: 44px; padding: 0; font-size: 26px; font-weight: 400; line-height: 1; }
.btn:active { transform: scale(.97); }

/* ---------- Medidor de importancia ---------- */
.meter {
  display: inline-flex; flex-direction: column-reverse; gap: 2px;
  width: 10px; flex: none;
}
.meter i { display: block; height: 5px; border-radius: 1.5px; background: var(--off); }
.meter[data-level="1"] i:nth-child(-n+1),
.meter[data-level="2"] i:nth-child(-n+2),
.meter[data-level="3"] i:nth-child(-n+3),
.meter[data-level="4"] i:nth-child(-n+4),
.meter[data-level="5"] i:nth-child(-n+5) { background: var(--c); }
.meter i:nth-child(1) { --c: var(--lvl-1); }
.meter i:nth-child(2) { --c: var(--lvl-2); }
.meter i:nth-child(3) { --c: var(--lvl-3); }
.meter i:nth-child(4) { --c: var(--lvl-4); }
.meter i:nth-child(5) { --c: var(--lvl-5); }
.meter--brand { width: 12px; }
.meter--brand i { height: 4px; }

/* Medidor grande y pulsable en la ficha */
.meter-big { display: flex; align-items: flex-end; gap: 6px; }
.meter-big button {
  width: 34px; border: 0; border-radius: 6px; cursor: pointer; padding: 0;
  background: var(--off); transition: background-color .15s;
}
.meter-big button:nth-child(1) { height: 14px; --c: var(--lvl-1); }
.meter-big button:nth-child(2) { height: 20px; --c: var(--lvl-2); }
.meter-big button:nth-child(3) { height: 26px; --c: var(--lvl-3); }
.meter-big button:nth-child(4) { height: 32px; --c: var(--lvl-4); }
.meter-big button:nth-child(5) { height: 38px; --c: var(--lvl-5); }
.meter-big button.on { background: var(--c); }
.meter-big + .meter-label { margin-top: 6px; color: var(--ink-2); font-size: 14px; }

/* ---------- Listas ---------- */
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--r-md); overflow: hidden; }
.list > li + li { border-top: 1px solid var(--line); }
.row {
  display: flex; align-items: center; gap: 14px; width: 100%;
  padding: 13px 16px; min-height: 60px;
  text-decoration: none; color: inherit; background: none; border: 0; text-align: left; cursor: pointer;
}
.row:active { background: color-mix(in srgb, var(--ink) 5%, transparent); }
.row .meter { height: 33px; justify-content: flex-start; }
.row-main { flex: 1; min-width: 0; }
.row-title { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { display: block; color: var(--ink-2); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-end { color: var(--ink-2); font-size: 13px; text-align: right; flex: none; }
.chev { width: 8px; height: 14px; flex: none; stroke: var(--off); stroke-width: 2; fill: none; }

/* Recordatorio */
.rem { display: flex; align-items: center; gap: 12px; padding: 12px 14px 12px 12px; }
.rem-time { width: 64px; flex: none; font: 600 16px/1.15 var(--font-round); font-variant-numeric: tabular-nums; }
.rem-time small { display: block; font-weight: 500; color: var(--ink-2); font-size: 13px; }
.rem .row { padding: 0; min-height: 0; flex: 1; min-width: 0; gap: 12px; }
.rem.now { box-shadow: inset 4px 0 0 var(--signal); }
.tag-now { display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 999px; font-size: 12px; font-weight: 650; background: var(--signal); color: var(--signal-ink); vertical-align: 1px; }
.rem.done .row-title { text-decoration: line-through; color: var(--ink-2); }

.check {
  width: 26px; height: 26px; flex: none; border-radius: 50%; cursor: pointer;
  border: 2px solid var(--off); background: transparent; display: grid; place-items: center; padding: 0;
}
.check svg { width: 14px; height: 14px; stroke: var(--signal-ink); stroke-width: 3; fill: none; opacity: 0; }
.check[aria-pressed="true"] { background: var(--signal); border-color: var(--signal); }
.check[aria-pressed="true"] svg { opacity: 1; }

/* ---------- Búsqueda ---------- */
.search {
  width: 100%; height: 40px; padding: 0 14px; border-radius: 12px; border: 0;
  background: color-mix(in srgb, var(--ink) 7%, transparent);
}

/* ---------- Ficha de contacto ---------- */
.back { display: inline-flex; align-items: center; gap: 4px; margin: 0 0 10px -4px; padding: 6px 4px; color: var(--signal); text-decoration: none; font-weight: 500; }
.profile { background: var(--surface); border-radius: var(--r-lg); padding: 22px 20px; }
.profile h1 { margin: 0; font: 700 28px/1.15 var(--font-round); }
.profile .sub { color: var(--ink-2); margin: 2px 0 18px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.facts { margin: 18px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 15px; }
.facts dt { color: var(--ink-2); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.notes { white-space: pre-wrap; background: var(--surface); border-radius: var(--r-md); padding: 14px 16px; margin: 0; }
.foot-actions { display: flex; justify-content: space-between; margin-top: 28px; }

/* ---------- Vacíos y avisos ---------- */
.empty { background: var(--surface); border-radius: var(--r-md); padding: 26px 20px; text-align: center; }
.empty p { margin: 0 0 14px; color: var(--ink-2); }
.banner {
  display: flex; gap: 12px; align-items: flex-start;
  background: color-mix(in srgb, var(--signal) 10%, var(--surface)); border-radius: var(--r-md);
  padding: 14px 16px; margin-bottom: 18px; font-size: 15px;
}
.banner p { margin: 0; flex: 1; }
.banner button { border: 0; background: none; color: var(--ink-2); font-size: 20px; line-height: 1; cursor: pointer; padding: 0 2px; }

/* ---------- Ajustes ---------- */
.setting { display: flex; align-items: center; gap: 14px; padding: 12px 16px; }
.setting label { flex: 1; font-weight: 550; }
.setting select { max-width: 55%; }
.hint { color: var(--ink-2); font-size: 14px; margin: 8px 4px 0; }

/* ---------- Hoja modal ---------- */
dialog#sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 560px;
  max-height: 92vh; max-height: 92dvh; border-radius: var(--r-lg) var(--r-lg) 0 0;
  background: var(--bg); color: var(--ink); overflow: auto;
}
dialog#sheet::backdrop { background: rgb(10 14 20 / .45); }
dialog#sheet[open] { animation: sheet-in .28s cubic-bezier(.2,.8,.2,1); }
@keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } }
@media (min-width: 700px) {
  dialog#sheet { margin: auto; border-radius: var(--r-lg); }
}
.sheet-bar {
  position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.sheet-bar h2 { margin: 0; font-size: 17px; font-weight: 650; }
.sheet-bar button { border: 0; background: none; color: var(--signal); font-size: 17px; cursor: pointer; padding: 4px 2px; }
.sheet-bar button[type="submit"] { font-weight: 650; }
.sheet-body { padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); }

.fields { background: var(--surface); border-radius: var(--r-md); overflow: hidden; margin-bottom: 18px; }
.field { display: flex; align-items: center; gap: 12px; padding: 0 16px; min-height: 48px; }
.field + .field { border-top: 1px solid var(--line); }
.field > span { width: 92px; flex: none; color: var(--ink-2); font-size: 15px; }
.field input, .field select, .field textarea {
  flex: 1; min-width: 0; border: 0; background: transparent; padding: 12px 0; outline: none;
}
.field textarea { min-height: 96px; resize: vertical; }
.field--stack { flex-direction: column; align-items: stretch; gap: 10px; padding: 14px 16px; }
.field--stack > span { width: auto; }
.field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible { outline: none; }
.field:focus-within { box-shadow: inset 3px 0 0 var(--signal); }
.preview { color: var(--ink-2); font-size: 14px; margin: -6px 4px 18px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 15px;
  transition: opacity .2s, transform .2s; max-width: calc(100% - 32px); z-index: 30;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- v0.2: acceso, sincronización y avisos ---------- */
body.sin-sesion .tabs { display: none; }
body.sin-sesion .shell { display: block; }
.login { max-width: 400px; margin: 8vh auto 0; text-align: center; }
.login-logo { width: 88px; height: 88px; border-radius: 20px; box-shadow: 0 6px 20px rgb(0 0 0 / .18); }
.login h1 { font: 700 30px/1.1 var(--font-round); margin: 16px 0 6px; }
.login > p { color: var(--ink-2); margin: 0 0 22px; }
.login .fields { text-align: left; }
.login-aviso { background: color-mix(in srgb, var(--lvl-3) 18%, var(--surface)); border-radius: var(--r-md); padding: 10px 14px; }
.login .login-error { color: var(--danger); min-height: 1.4em; margin-top: 12px !important; }
.btn--wide { width: 100%; }
.btn--small { min-height: 34px; padding: 0 14px; font-size: 14px; }
.btn:disabled { opacity: .6; }
.panel { background: var(--surface); border-radius: var(--r-md); padding: 14px 16px; }
.panel p { margin: 0; }
.panel .actions { margin-top: 12px; }
.setting-text { flex: 1; font-size: 15px; }
.sync-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--off); }
.sync-dot--ok { background: var(--lvl-1); }
.sync-dot--enviando { background: var(--signal); }
.sync-dot--offline, .sync-dot--error { background: var(--lvl-4); }
