/* Montsaint CRM */
:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #f0ebe3;
  --ink: #16140f;
  --ink-2: #5d5749;
  --ink-3: #8f8778;
  --line: #e4ddd1;
  --gold: #a8874f;
  --gold-2: #8a6d3b;
  --gold-soft: #f3ead9;
  --ok: #2f7d4f;
  --ok-soft: #e3f1e8;
  --warn: #b26b00;
  --warn-soft: #fbefd9;
  --bad: #b3261e;
  --bad-soft: #f9e3e1;
  --info: #2c5d8a;
  --info-soft: #e2edf7;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(22,20,15,.06), 0 4px 16px rgba(22,20,15,.05);
  --serif: "Cormorant Garamond", "Didot", "Bodoni 72", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12110e;
    --surface: #1b1a16;
    --surface-2: #24221d;
    --ink: #f1ece2;
    --ink-2: #bdb5a5;
    --ink-3: #8a8272;
    --line: #2f2c25;
    --gold: #c9a86a;
    --gold-2: #d8bb82;
    --gold-soft: #2c2619;
    --ok: #6cc28f; --ok-soft: #173024;
    --warn: #e0a54a; --warn-soft: #33260f;
    --bad: #ef8a80; --bad-soft: #3a1a17;
    --info: #86b5e0; --info-soft: #172a3b;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--gold-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-family: var(--serif); font-size: 30px; font-weight: 500; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: 13px; word-break: break-all; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.hide { display: none !important; }

/* ---------- Layout ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex: 0 0 232px; background: #16140f; color: #eae4d8;
  display: flex; flex-direction: column; padding: 22px 14px; position: sticky; top: 0; height: 100vh;
}
.sidebar .logo { display: flex; align-items: center; gap: 10px; padding: 0 8px 22px; }
.sidebar .logo b { font-family: var(--serif); font-size: 22px; font-weight: 500; letter-spacing: .12em; text-transform: uppercase; }
.sidebar .logo span { font-size: 10px; letter-spacing: .2em; color: #a8874f; display: block; text-transform: uppercase; }
.sidebar nav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 9px;
  color: #cfc7b7; font-weight: 500; margin-bottom: 2px;
}
.sidebar nav a svg { width: 19px; height: 19px; opacity: .85; }
.sidebar nav a:hover { background: #24211a; text-decoration: none; color: #fff; }
.sidebar nav a.active { background: #2b261c; color: #fff; }
.sidebar nav a.active svg { color: #c9a86a; opacity: 1; }
.sidebar .foot { margin-top: auto; font-size: 12px; color: #8a8272; padding: 0 10px; }
.sidebar .foot button { color: #cfc7b7; }

.main { flex: 1; min-width: 0; padding: 28px 32px 48px; }
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.topbar h1 { flex: 1; min-width: 0; }
.topbar .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.bottomnav { display: none; }

@media (max-width: 860px) {
  .sidebar { display: none; }
  .main { padding: 16px 16px calc(var(--nav-h) + var(--safe-b) + 24px); }
  h1 { font-size: 26px; }
  .bottomnav {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
    background: var(--surface); border-top: 1px solid var(--line);
  }
  .bottomnav a {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    color: var(--ink-3); font-size: 11px; font-weight: 500;
  }
  .bottomnav a svg { width: 22px; height: 22px; }
  .bottomnav a.active { color: var(--gold-2); }
  .bottomnav a:hover { text-decoration: none; }
  .topbar { margin-bottom: 14px; padding-top: env(safe-area-inset-top, 0px); }
}

/* ---------- Components ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card-head h2 { font-size: 15px; }
.section { margin-bottom: 18px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 1100px) { .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 860px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: 600 14px var(--sans); cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--ink-3); text-decoration: none; }
.btn svg { width: 17px; height: 17px; }
.btn-primary { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.btn-primary:hover { background: #2b271e; border-color: #2b271e; }
@media (prefers-color-scheme: dark) { .btn-primary { background: var(--gold); border-color: var(--gold); color: #16140f; } .btn-primary:hover { background: var(--gold-2); } }
.btn-gold { background: var(--gold); border-color: var(--gold); color: #fff; }
.btn-danger { color: var(--bad); }
.btn-danger:hover { border-color: var(--bad); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { height: 32px; padding: 0 11px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }
.btn-icon { width: 40px; padding: 0; }
button.link { background: none; border: 0; padding: 0; font: inherit; color: var(--gold-2); cursor: pointer; }
.fab {
  display: none; position: fixed; right: 18px; bottom: calc(var(--nav-h) + var(--safe-b) + 16px); z-index: 41;
  width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--ink); color: var(--bg);
  box-shadow: 0 6px 20px rgba(0,0,0,.25); cursor: pointer; align-items: center; justify-content: center;
}
.fab svg { width: 26px; height: 26px; }
@media (prefers-color-scheme: dark) { .fab { background: var(--gold); color: #16140f; } }
@media (max-width: 860px) { .fab { display: flex; } .hide-m { display: none !important; } }
@media (min-width: 861px) { .hide-d { display: none !important; } }

.badge {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--ink-2); white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.gold { background: var(--gold-soft); color: var(--gold-2); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--ink-3); flex: 0 0 9px; }

/* ---------- Forms ---------- */
.form { display: grid; gap: 14px; }
.form h2 { margin-top: 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .form-row { grid-template-columns: 1fr; } }
label { display: grid; gap: 5px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
input, select, textarea {
  width: 100%; min-height: 42px; padding: 9px 12px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: 16px var(--sans); /* 16px evita zoom en iOS */
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold); outline-offset: -1px; border-color: transparent; }
input[type=checkbox] { width: 18px; height: 18px; min-height: 0; accent-color: var(--gold-2); }
input[type=color] { padding: 3px; height: 42px; }
.check { display: flex; align-items: center; gap: 9px; font-weight: 500; color: var(--ink); cursor: pointer; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters > * { flex: 1 1 160px; max-width: 240px; }
.filters .search { flex: 3 1 240px; max-width: none; }
.filters select, .filters input { min-height: 40px; font-size: 14px; }
@media (max-width: 860px) {
  .filters { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
  .filters > * { flex: 0 0 auto; width: auto; max-width: none; }
  .filters .search { flex: 0 0 100%; }
  .filters.wrap-m { flex-wrap: wrap; }
  .filters.wrap-m > select { flex: 1 1 45%; }
}

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
@media (max-width: 1200px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 560px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi { padding: 14px 16px; }
.kpi .label { font-size: 12px; color: var(--ink-3); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.kpi .value { font-family: var(--serif); font-size: 30px; font-weight: 500; line-height: 1.15; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.kpi.alert .value { color: var(--bad); }

/* ---------- Tables / lists ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); font-weight: 600; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--surface-2); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 12px; align-items: center; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list li.click { cursor: pointer; }
.list li.click:hover { background: var(--surface-2); }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .meta { font-size: 13px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 28px 18px; text-align: center; color: var(--ink-3); }

.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--gold); border-radius: 99px; }
.fase-row { display: grid; grid-template-columns: 160px 1fr 110px; gap: 12px; align-items: center; padding: 8px 18px; }
@media (max-width: 560px) { .fase-row { grid-template-columns: 110px 1fr 84px; font-size: 13px; } }

/* ---------- Kanban ---------- */
.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(250px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: start; scroll-snap-type: x mandatory; }
@media (max-width: 860px) { .kanban { grid-auto-columns: 82%; margin: 0 -16px; padding: 0 16px 12px; } }
.col { background: var(--surface-2); border-radius: var(--radius); padding: 10px; min-height: 140px; scroll-snap-align: start; }
.col.drop { outline: 2px dashed var(--gold); outline-offset: -2px; }
.col-head { display: flex; justify-content: space-between; align-items: baseline; padding: 4px 4px 10px; gap: 8px; }
.col-head b { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
.col-head span { font-size: 12px; color: var(--ink-3); white-space: nowrap; }
.col.ganada .col-head b { color: var(--ok); }
.col.perdida .col-head b { color: var(--bad); }
.opcard {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; margin-bottom: 8px;
  cursor: grab; box-shadow: 0 1px 2px rgba(0,0,0,.04); border-left: 3px solid var(--c, var(--line));
}
.opcard:active { cursor: grabbing; }
.opcard.dragging { opacity: .5; }
.opcard .t { font-weight: 600; font-size: 14px; }
.opcard .c { font-size: 13px; color: var(--ink-2); margin-top: 2px; }
.opcard .f { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; font-size: 12px; color: var(--ink-3); gap: 6px; }
.opcard .f b { color: var(--ink); font-size: 14px; font-variant-numeric: tabular-nums; }

/* ---------- Ficha ---------- */
.hero { padding: 20px; display: grid; gap: 14px; }
.hero .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.quick a, .quick button {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 4px; border-radius: 10px;
  background: var(--surface-2); color: var(--ink); font: 600 12px var(--sans); border: 0; cursor: pointer;
}
.quick a:hover { text-decoration: none; }
.quick svg { width: 20px; height: 20px; color: var(--gold-2); }
.quick .disabled { opacity: .35; pointer-events: none; }
dl.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; margin: 0; font-size: 14px; }
dl.kv dt { color: var(--ink-3); }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }
.timeline { list-style: none; margin: 0; padding: 4px 18px 10px; }
.timeline li { position: relative; padding: 12px 0 12px 26px; border-bottom: 1px solid var(--line); }
.timeline li:last-child { border-bottom: 0; }
.timeline li::before { content: ""; position: absolute; left: 4px; top: 18px; width: 9px; height: 9px; border-radius: 50%; background: var(--gold); }
.timeline .head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px; color: var(--ink-3); }
.timeline .body { margin-top: 4px; white-space: pre-wrap; overflow-wrap: anywhere; }
.timeline .next { margin-top: 6px; font-size: 13px; }

/* ---------- Zonas ---------- */
.zone-picker { display: grid; gap: 6px; max-height: 46vh; overflow: auto; border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
.zone-ccaa { border-radius: 8px; }
.zone-ccaa > .check { padding: 6px 4px; font-weight: 600; }
.zone-provs { display: flex; flex-wrap: wrap; gap: 4px 14px; padding: 2px 4px 8px 32px; }
.zone-provs .check { font-size: 14px; }
.zone-provs .taken { font-size: 11px; color: var(--warn); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }

/* ---------- Modal ---------- */
.modal-back {
  position: fixed; inset: 0; z-index: 100; background: rgba(15,13,9,.45);
  display: flex; align-items: center; justify-content: center; padding: 20px; animation: fade .15s ease;
}
.modal {
  background: var(--surface); border-radius: 16px; width: 100%; max-width: 620px; max-height: 92vh; display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,.3); animation: pop .18s ease;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-family: var(--serif); font-size: 22px; font-weight: 500; }
.modal-body { padding: 18px 20px; overflow: auto; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 20px calc(14px + var(--safe-b)); border-top: 1px solid var(--line); }
.modal-foot .spacer { flex: 1; }
@media (max-width: 640px) {
  .modal-back { align-items: flex-end; padding: 0; }
  .modal { max-width: none; border-radius: 16px 16px 0 0; max-height: 94vh; animation: up .2s ease; }
  .modal-foot .btn { flex: 1; }
  .modal-foot .spacer { display: none; }
}
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(.97); opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }

.fase-pick { display: grid; gap: 6px; }
.fase-pick button { text-align: left; justify-content: flex-start; height: 46px; }
.fase-pick button.current { border-color: var(--gold); background: var(--gold-soft); }

/* ---------- Toast ---------- */
#toast-root { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + var(--safe-b) + 20px); z-index: 200; display: grid; gap: 8px; }
@media (min-width: 861px) { #toast-root { bottom: 24px; } }
.toast { background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: 10px; font-weight: 600; font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.25); animation: up .2s ease; max-width: 90vw; }
.toast.err { background: var(--bad); color: #fff; }

/* ---------- Auth ---------- */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: #16140f; }
.auth-card { background: var(--surface); border-radius: 18px; padding: 32px 28px; width: 100%; max-width: 400px; box-shadow: 0 30px 80px rgba(0,0,0,.4); }
.auth-card h1 { text-align: center; margin: 10px 0 4px; }
.auth-card .sub { text-align: center; color: var(--ink-3); margin-bottom: 22px; font-size: 13px; letter-spacing: .18em; text-transform: uppercase; }
.brand-mark {
  width: 52px; height: 52px; margin: 0 auto; border-radius: 50%; border: 1.5px solid var(--gold);
  display: flex; align-items: center; justify-content: center; font-family: var(--serif); font-size: 28px; color: var(--gold);
}
.sidebar .brand-mark { width: 38px; height: 38px; font-size: 21px; margin: 0; }
.boot { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.err-box { background: var(--bad-soft); color: var(--bad); padding: 10px 12px; border-radius: 9px; font-size: 14px; }
.ok-box { background: var(--ok-soft); color: var(--ok); padding: 10px 12px; border-radius: 9px; font-size: 14px; }
.note { background: var(--gold-soft); color: var(--ink-2); padding: 10px 12px; border-radius: 9px; font-size: 13px; }

.loading { padding: 40px; text-align: center; color: var(--ink-3); }
.spin { width: 22px; height: 22px; border: 2px solid var(--line); border-top-color: var(--gold); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

.menu-link { display: flex; align-items: center; gap: 12px; color: var(--ink); }
.menu-link:hover { text-decoration: none; }
.menu-link svg { width: 22px; height: 22px; color: var(--gold-2); flex: 0 0 22px; }
@media (max-width: 560px) { .kpis .kpi:last-child:nth-child(odd) { grid-column: span 2; } }
