/* Cordi · design system (blueprint §13): Emerald, Inter, Lucide, Soft Modern, 44 px */
:root {
  --emerald: #10B981;
  --emerald-600: #059669;
  --emerald-700: #047857;
  --emerald-50: #ECFDF5;
  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --ink: #0F172A;
  --ink-2: #334155;
  --muted: #64748B;
  --line: #E2E8F0;
  --danger: #B91C1C;
  --danger-50: #FEF2F2;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 16px rgba(15, 23, 42, .05);
  --sidebar: 248px;
  --topbar: 64px;
  --target: 44px;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif; font-size: 15px; line-height: 1.5; color: var(--ink); background: var(--bg); }
a { color: var(--emerald-700); }
h1, h2 { line-height: 1.25; margin: 0; }
svg { flex: none; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--emerald) 55%, transparent); outline-offset: 2px; border-radius: 6px; }
.muted { color: var(--muted); margin: 0; }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 12px; top: 12px; z-index: 100; background: var(--surface); padding: 10px 14px; border-radius: var(--radius-sm); }

/* Marca */
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-weight: 700; font-size: 18px; letter-spacing: -.01em; }
.brand--center { justify-content: center; margin-bottom: 20px; }
.brand-mark { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; background: var(--emerald); color: #fff; font-size: 16px; }

/* Botones y formularios */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--target); padding: 0 18px; border-radius: var(--radius-sm); border: 1px solid transparent; font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; transition: background-color .15s, box-shadow .15s; }
.btn--primary { background: var(--emerald-600); color: #fff; }
.btn--primary:hover { background: var(--emerald-700); }
.btn--block { width: 100%; }
.btn.is-disabled { opacity: .55; cursor: not-allowed; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: var(--emerald-700); text-decoration: underline; cursor: pointer; min-height: var(--target); }
.form { display: grid; gap: 16px; margin-top: 20px; }
.form--top { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--line); }
.field { display: grid; gap: 6px; font-weight: 500; font-size: 14px; color: var(--ink-2); }
.field { min-width: 0; }
.field input, .field select { width: 100%; min-width: 0; }
.field input { min-height: var(--target); padding: 0 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); font: inherit; font-size: 16px; color: var(--ink); background: var(--surface); }
.field input:focus { border-color: var(--emerald); outline: 3px solid color-mix(in srgb, var(--emerald) 25%, transparent); outline-offset: 0; }
.hint { color: var(--muted); font-weight: 400; font-size: 13px; }

/* Avisos */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 14px; }
.alert svg { margin-top: 2px; }
.alert--error { background: var(--danger-50); color: var(--danger); }
.alert--ok { background: var(--emerald-50); color: var(--emerald-700); }
.banner { display: flex; gap: 10px; align-items: center; padding: 12px 16px; border-radius: var(--radius); background: var(--emerald-50); color: #065F46; margin-bottom: 20px; font-size: 14px; }

/* Tarjetas */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; }

/* Acceso */
.auth-body { min-height: 100vh; display: grid; place-items: center; padding: 32px 16px; }
.auth-shell { width: 100%; max-width: 420px; }
.auth-title { font-size: 22px; letter-spacing: -.01em; margin-bottom: 6px; }
.auth-alt { margin: 20px 0 0; text-align: center; font-size: 14px; color: var(--muted); }
.error-code { margin: 0 0 4px; font-size: 40px; font-weight: 700; color: var(--emerald-600); }
.org-list { display: grid; gap: 8px; margin-top: 16px; }
.org-list form { margin: 0; }
.org-list__item { width: 100%; display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 8px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); font: inherit; text-align: left; cursor: pointer; color: var(--ink); }
.org-list__item span { display: grid; }
.org-list__item small { color: var(--muted); }
.org-list__item:hover, .org-list__item.is-active { border-color: var(--emerald); background: var(--emerald-50); }

/* Panel */
.app { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 16px; padding: 16px 12px; background: var(--surface); border-right: 1px solid var(--line); overflow-y: auto; }
.sidebar > .brand { padding: 4px 8px; min-height: 40px; }
.nav { display: grid; gap: 2px; }
.nav__link { display: flex; align-items: center; gap: 12px; min-height: var(--target); padding: 0 12px; border-radius: var(--radius-sm); color: var(--ink-2); text-decoration: none; font-weight: 500; }
.nav__link:hover { background: var(--bg); color: var(--ink); }
.nav__link.is-active { background: var(--emerald-50); color: var(--emerald-700); }
.nav__link.is-soon { color: #94A3B8; cursor: default; }
.nav__link.is-soon:hover { background: none; }
.nav__link em { margin-left: auto; font-style: normal; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: #94A3B8; }
.nav__btn { width: 100%; background: none; border: 0; font: inherit; cursor: pointer; }
.sidebar__foot { margin-top: auto; }

.org-switch { position: relative; }
.org-switch summary { list-style: none; display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 6px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); cursor: pointer; }
.org-switch summary::-webkit-details-marker { display: none; }
.org-switch__icon { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 8px; background: var(--bg); color: var(--ink-2); }
.org-switch__text { display: grid; min-width: 0; flex: 1; }
.org-switch__name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.org-switch__role { font-size: 12px; color: var(--muted); }
.org-switch__menu { position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 20; display: grid; gap: 2px; padding: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: var(--shadow); }
.org-switch__menu form { margin: 0; }
.org-switch__item { width: 100%; display: flex; align-items: center; min-height: var(--target); padding: 0 10px; border: 0; border-radius: 8px; background: none; font: inherit; font-size: 14px; color: var(--ink); text-align: left; text-decoration: none; cursor: pointer; }
.org-switch__item:hover { background: var(--bg); }
.org-switch__item.is-active { color: var(--emerald-700); font-weight: 600; }
.org-switch__new { color: var(--emerald-700); border-top: 1px solid var(--line); border-radius: 0 0 8px 8px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 10; height: var(--topbar); display: flex; align-items: center; gap: 12px; padding: 0 24px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.topbar__title { font-size: 18px; font-weight: 600; }
.topbar__right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.icon-btn { width: var(--target); height: var(--target); display: grid; place-items: center; border: 0; border-radius: var(--radius-sm); background: none; color: var(--ink); cursor: pointer; }
.chip { display: inline-flex; align-items: center; min-height: 28px; padding: 0 10px; border-radius: 999px; background: var(--emerald-50); color: var(--emerald-700); font-size: 13px; font-weight: 600; }
.topbar .topbar__menu { display: none; }
.avatar { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; background: var(--ink); color: #fff; font-weight: 600; font-size: 14px; }
.content { padding: 24px; max-width: 1200px; width: 100%; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; margin-bottom: 16px; }
.stat__label { font-size: 14px; font-weight: 500; color: var(--muted); }
.stat__value { margin: 8px 0 12px; font-size: 28px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat__value span { font-size: 15px; font-weight: 500; color: var(--muted); }
.meter { height: 8px; border-radius: 999px; background: var(--bg); overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--emerald); border-radius: inherit; }
.empty { text-align: center; padding: 40px 24px; display: grid; justify-items: center; gap: 8px; }
.empty__icon { width: 56px; height: 56px; display: grid; place-items: center; border-radius: 16px; background: var(--emerald-50); color: var(--emerald-600); margin-bottom: 4px; }
.empty h2 { font-size: 18px; }
.empty .btn { margin-top: 12px; }

/* Formularios del panel */
.stack { display: grid; gap: 16px; }
.small { font-size: 13px; }
.section-title { font-size: 16px; font-weight: 600; margin: 0 0 4px; padding: 0; }
.field select { min-height: var(--target); padding: 0 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); font: inherit; font-size: 16px; background: var(--surface); color: var(--ink); }
.field input[type=number] { font-variant-numeric: tabular-nums; }
.form--grid { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.form__full { grid-column: 1 / -1; margin: 0; }
.fieldset { border: 1px solid var(--line); margin: 0; display: grid; gap: 14px; min-width: 0; }
.fieldset legend { float: left; width: 100%; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row--4 { grid-template-columns: repeat(4, 1fr); margin-top: 12px; }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); margin: 0; }
.quote-foot { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 12px; margin-top: 20px; }
.field--inline { min-width: 220px; }
.btn--ghost { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn--ghost:hover { background: var(--bg); }
.btn--danger { color: var(--danger); }
.btn[disabled] { opacity: .7; cursor: progress; }

/* Conexiones */
.list { display: grid; gap: 12px; }
.conn { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 20px; }
.conn__main { display: flex; gap: 14px; align-items: flex-start; min-width: 0; }
.conn__icon { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 10px; background: var(--emerald-50); color: var(--emerald-600); }
.conn__title { font-size: 16px; }
.conn__state { margin: 4px 0 0; }
.conn__state.is-ok { color: var(--emerald-700); }
.conn__state.is-bad { color: var(--danger); }
.conn__actions { display: flex; gap: 8px; }
.conn__actions form { margin: 0; }

/* Tarifas */
.rates-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; justify-content: space-between; }
.rates { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 8px; }
.rate { display: grid; grid-template-columns: 1fr auto auto; gap: 16px; align-items: center; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.rate--pick { border-color: color-mix(in srgb, var(--emerald) 45%, var(--line)); background: color-mix(in srgb, var(--emerald-50) 55%, var(--surface)); }
.rate__who { display: grid; gap: 2px; min-width: 0; }
.rate__tags { display: flex; gap: 6px; margin-top: 4px; }
.rate__why { color: var(--ink-2); }
.rate__days { color: var(--ink-2); font-size: 14px; white-space: nowrap; }
.rate__price { font-weight: 700; font-size: 17px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.chip--blue { background: #EFF6FF; color: #1D4ED8; }
.chip--warn { background: #FFFBEB; color: #B45309; }

/* Móvil: drawer */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(var(--sidebar), 86vw); z-index: 40; transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.is-open { transform: none; box-shadow: 0 0 40px rgba(15, 23, 42, .2); }
  .scrim { position: fixed; inset: 0; z-index: 30; background: rgba(15, 23, 42, .35); }
  .topbar { padding: 0 12px; }
  .topbar .topbar__menu { display: grid; }
  .content { padding: 16px; }
  .row--4 { grid-template-columns: 1fr 1fr; }
  .rate { grid-template-columns: 1fr auto; }
  .rate__days { grid-row: 2; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
