/* Mesa de Transacciones · Key to Realty
   Colores de la marca: verde lima de Key to Realty (#8dc63f) como acento,
   un verde más oscuro para botones y links (legible sobre blanco) y los
   grises del logo. Para ajustar, cambiá solo estos tokens.
   Layout: barra superior fija + contenido de una columna que se abre en
   dos (panel lateral + checklist) en pantallas anchas. */

:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-2: #f3f5f0;
  --ink: #3a3c40;
  --muted: #6d6e71;
  --line: #e0e3dc;
  --brand: #4f7a1a;
  --brand-ink: #ffffff;
  --brand-soft: #edf5e0;
  --accent: #8dc63f;
  --ok: #3f7d22;
  --ok-soft: #e6f2da;
  --warn: #946006;
  --warn-soft: #fbf0db;
  --bad: #b23a3a;
  --bad-soft: #f8e3e3;
  --k-auto: #4f7a1a;
  --k-approve: #8a6418;
  --k-manual: #6d6e71;

  --font-display: "Poppins", "Segoe UI", system-ui, sans-serif;
  --font-body: "Nunito Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(30 35 25 / 6%), 0 4px 14px rgb(30 35 25 / 5%);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141712; --surface: #1c2019; --surface-2: #22271e; --ink: #e8ebe4; --muted: #a3a8a0; --line: #30362b;
    --brand: #a5d65e; --brand-ink: #15200a; --brand-soft: #26341a; --accent: #8dc63f;
    --ok: #8fcf63; --ok-soft: #1f3317; --warn: #e3a547; --warn-soft: #3a2b12; --bad: #ea7676; --bad-soft: #3d1b1b;
    --k-auto: #a5d65e; --k-approve: #e0b052; --k-manual: #a3a8a0;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141712; --surface: #1c2019; --surface-2: #22271e; --ink: #e8ebe4; --muted: #a3a8a0; --line: #30362b;
  --brand: #a5d65e; --brand-ink: #15200a; --brand-soft: #26341a; --accent: #8dc63f;
  --ok: #8fcf63; --ok-soft: #1f3317; --warn: #e3a547; --warn-soft: #3a2b12; --bad: #ea7676; --bad-soft: #3d1b1b;
  --k-auto: #a5d65e; --k-approve: #e0b052; --k-manual: #a3a8a0;
  --shadow: 0 1px 2px rgb(0 0 0 / 30%);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--font-body);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); }
h1, h2, h3 { font-family: var(--font-display); text-wrap: balance; margin: 0; line-height: 1.2; }
h1 { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 1.1rem; font-weight: 650; }
h3 { font-size: 0.95rem; font-weight: 650; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.strong { font-weight: 650; }
.right { text-align: right; }
.pre { white-space: pre-wrap; margin: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.row { display: flex; align-items: center; }
.gap { gap: 8px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- barra superior */
.top { position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 3px solid var(--accent); }
.top-inner { max-width: 1280px; margin: 0 auto; padding: 10px 20px; display: flex; align-items: center; gap: 20px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-family: var(--font-display); font-weight: 700; font-size: 1.05rem; white-space: nowrap; }
.brand-logo { height: 40px; width: auto; display: block; background: #fff; border-radius: 6px; padding: 2px 4px; }
.brand-name { font-size: 0.95rem; color: var(--muted); font-weight: 600; padding-left: 12px; border-left: 2px solid var(--accent); }
.nav { display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.nav a { padding: 7px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: 0.9rem; white-space: nowrap; }
.nav a:hover { color: var(--ink); background: var(--surface-2); }
.nav a.on { color: var(--brand); background: var(--brand-soft); }
.top-actions { display: flex; gap: 8px; align-items: center; margin-left: auto; }

/* ---------- avisos */
.banner { max-width: 1280px; margin: 12px auto 0; padding: 10px 14px; border-radius: 8px; font-size: 0.88rem; width: calc(100% - 40px); }
.banner.info { background: var(--brand-soft); color: var(--ink); }
.banner.warn { background: var(--warn-soft); color: var(--ink); }

.main { max-width: 1280px; margin: 0 auto; padding: 24px 20px 64px; display: grid; gap: 20px; }
.lede { margin: -8px 0 0; color: var(--muted); max-width: 70ch; }
.h-sub { font-size: 0.85rem; font-weight: 500; color: var(--muted); margin-left: 6px; font-family: var(--font-body); }
.back { font-size: 0.88rem; text-decoration: none; color: var(--muted); }
.back:hover { color: var(--brand); }
.empty { padding: 28px; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); display: grid; gap: 12px; justify-items: center; }
.empty p { margin: 0; }

/* ---------- botones e inputs */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: 600 0.88rem var(--font-body); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn svg { width: 14px; height: 14px; }
.btn:hover:not(:disabled) { border-color: var(--brand); color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); color: var(--brand-ink); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn.small { padding: 5px 10px; font-size: 0.8rem; }
.btn.danger { color: var(--bad); }
.btn.danger-fill { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn:disabled, .icon-btn:disabled, .link:disabled, .check:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.n8n { border-color: var(--k-auto); color: var(--k-auto); }
.btn.n8n:hover { background: var(--brand-soft); }
.link { background: none; border: 0; padding: 0; color: var(--brand); font: 600 0.82rem var(--font-body); cursor: pointer; }
.link:hover:not(:disabled) { text-decoration: underline; }
.link.danger { color: var(--bad); }
.icon-btn { border: 1px solid var(--line); background: var(--surface); color: var(--muted); width: 28px; height: 28px; border-radius: 6px; cursor: pointer; display: inline-grid; place-items: center; font-size: 0.85rem; }
.icon-btn:hover:not(:disabled) { color: var(--brand); border-color: var(--brand); }
.icon-btn.danger:hover:not(:disabled) { color: var(--bad); border-color: var(--bad); }
.icon-link { color: var(--muted); display: inline-grid; place-items: center; }
.icon-link svg { width: 16px; height: 16px; }
.icon-link:hover { color: var(--brand); }

.input { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); font: 0.9rem var(--font-body); }
.input:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px var(--brand-soft); }
.input[aria-invalid="true"] { border-color: var(--bad); }
.input.small { padding: 5px 8px; font-size: 0.82rem; width: auto; }
.input.tiny { width: 64px; padding: 4px 6px; }
.input.tiny-select { width: 110px; padding: 4px 6px; font-size: 0.78rem; }
textarea.input { resize: vertical; }
#tx-search { width: 260px; max-width: 100%; }
.field { display: grid; gap: 4px; }
.field label, .label { font-size: 0.8rem; font-weight: 600; color: var(--muted); }
.form-grid { display: grid; gap: 12px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
.fs { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px 14px; margin: 0; display: grid; gap: 10px; }
.fs legend { font-weight: 650; font-size: 0.88rem; padding: 0 6px; }
.client-row { display: grid; grid-template-columns: 1.3fr 1.3fr 1fr auto; gap: 10px; align-items: end; }

/* segmented */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; padding: 2px; background: var(--surface); }
.seg button { border: 0; background: none; padding: 5px 11px; border-radius: 6px; font: 600 0.8rem var(--font-body); color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--brand-soft); color: var(--brand); }

/* ---------- piezas */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; display: grid; gap: 12px; align-content: start; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px; font-size: 0.74rem; font-weight: 650; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.chip.side-buyer { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.chip.side-listing { background: var(--warn-soft); color: var(--k-approve); border-color: transparent; }
.chip.st-active { color: var(--ok); background: var(--ok-soft); border-color: transparent; }
.chip.st-closed { color: var(--ink); }
.chip.st-cancelled { color: var(--bad); background: var(--bad-soft); border-color: transparent; }
.chip.ex { border-style: dashed; }
.owner { display: inline-flex; align-items: center; gap: 5px; font-size: 0.78rem; font-weight: 650; color: var(--ink); --chip: var(--muted); }
.owner .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--chip); }
.kind { display: inline-flex; align-items: center; gap: 4px; font-size: 0.74rem; font-weight: 650; padding: 1px 7px 1px 5px; border-radius: 6px; }
.kind svg { width: 12px; height: 12px; }
.kind.k-auto { color: var(--k-auto); background: var(--brand-soft); }
.kind.k-approve { color: var(--k-approve); background: var(--warn-soft); }
.kind.k-manual { color: var(--k-manual); background: var(--surface-2); }
.due { font-size: 0.74rem; font-weight: 700; padding: 1px 7px; border-radius: 6px; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
.due.warn { color: var(--warn); background: var(--warn-soft); }
.due.bad { color: var(--bad); background: var(--bad-soft); }
.bar { height: 6px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.bar.slim { height: 4px; width: 90px; display: inline-block; vertical-align: middle; margin-right: 6px; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: 0.82rem; color: var(--muted); }

/* tiles */
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; border-top: 3px solid var(--accent); }
.tile.warn { border-top-color: var(--warn); }
.tile.bad { border-top-color: var(--bad); }
.tile-value { font-family: var(--font-display); font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.tile.bad .tile-value { color: var(--bad); }
.tile-label { color: var(--muted); font-size: 0.84rem; font-weight: 600; }
.tile-extra { margin-top: 6px; font-size: 0.8rem; }

.dash { display: grid; grid-template-columns: minmax(280px, 380px) 1fr; gap: 20px; align-items: start; }
.attn { list-style: none; margin: 0; padding: 0; display: grid; }
.attn li { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: start; padding: 10px 0; border-top: 1px solid var(--line); }
.attn li:first-child { border-top: 0; }
.attn-title { color: var(--ink); text-decoration: none; font-weight: 600; font-size: 0.88rem; }
.attn-title:hover { color: var(--brand); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 8px; color: var(--ink); text-decoration: none; align-content: start; }
a.card:hover { border-color: var(--brand); box-shadow: var(--shadow); }
.card-top { display: flex; gap: 6px; }
.card-title { font-family: var(--font-display); font-weight: 650; font-size: 1.05rem; }
.card-sub { color: var(--muted); font-size: 0.84rem; min-height: 1.2em; }
.card-row { display: flex; justify-content: space-between; font-size: 0.8rem; color: var(--muted); }
.card-facts { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; border-top: 1px solid var(--line); padding-top: 8px; }
.card-facts dt { font-size: 0.72rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.card-facts dd { margin: 0; font-size: 0.84rem; font-weight: 600; }
.kinds { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

/* tablas */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.panel .table-wrap { border: 0; }
.table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.table th { text-align: left; font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 650; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.table td { padding: 10px 12px; border-top: 1px solid var(--line); vertical-align: top; }
.table tbody tr:first-child td { border-top: 0; }
.table a { text-decoration: none; }
.table.edit td { padding: 8px 6px; }
.table.edit textarea { min-width: 240px; margin-bottom: 4px; }
.table.edit td:nth-child(2) { min-width: 110px; }
.table.edit td:nth-child(3) { min-width: 120px; }
.table.edit td:nth-child(5) { min-width: 200px; }
.due-cell { display: grid; gap: 4px; min-width: 150px; }
.row-actions { white-space: nowrap; }
.row-actions > * { margin: 0 2px 4px 0; }

/* ---------- transacción */
.tx-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.tx-head h1 { margin: 6px 0 2px; }
.tx-grid { display: grid; grid-template-columns: 320px 1fr; gap: 20px; align-items: start; }
.tx-side { display: grid; gap: 20px; }
.dates { list-style: none; margin: 0; padding: 0; display: grid; }
.dates li { display: grid; grid-template-columns: 1fr auto 52px 20px; gap: 8px; align-items: center; padding: 7px 0; border-top: 1px solid var(--line); font-size: 0.86rem; }
.dates li:first-child { border-top: 0; }
.dates li.past { color: var(--muted); }
.date-label { font-weight: 600; }
.date-rel { font-size: 0.76rem; color: var(--muted); text-align: right; }
.contact { padding: 8px 0; border-top: 1px solid var(--line); display: grid; gap: 2px; font-size: 0.86rem; }
.contact:first-child { border-top: 0; padding-top: 0; }
.contact-role { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 650; }
.copyline { display: flex; gap: 8px; align-items: baseline; color: var(--muted); word-break: break-all; }
.legend { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; align-items: center; padding: 10px 12px; background: var(--surface-2); border-radius: 8px; }
.phase { display: grid; gap: 4px; }
.phase h3 { display: flex; justify-content: space-between; padding: 12px 0 6px; border-bottom: 2px solid var(--line); text-transform: uppercase; letter-spacing: 0.05em; font-size: 0.8rem; color: var(--muted); }

.steps { list-style: none; margin: 0; padding: 0; display: grid; }
.step { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: start; padding: 12px 4px; border-top: 1px solid var(--line); }
.steps .step:first-child { border-top: 0; }
.step-main { display: grid; gap: 4px; min-width: 0; }
.step-title { font-weight: 600; font-size: 0.92rem; overflow-wrap: anywhere; }
.step.done .step-title { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--line); }
.step.is-na .step-title { color: var(--muted); }
.step-note { font-size: 0.8rem; color: var(--muted); font-style: italic; }
.step-note.user { font-style: normal; color: var(--ink); background: var(--surface-2); border-left: 3px solid var(--accent); padding: 4px 8px; border-radius: 0 6px 6px 0; }
.step-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.nolink { white-space: nowrap; }
.check { width: 24px; height: 24px; border-radius: 7px; border: 2px solid var(--line); background: var(--surface); color: transparent; cursor: pointer; display: grid; place-items: center; padding: 0; margin-top: 1px; font-weight: 700; }
.check svg { width: 14px; height: 14px; }
.check:hover:not(:disabled) { border-color: var(--ok); }
.check.on { background: var(--ok); border-color: var(--ok); color: #fff; }
.check.na { color: var(--muted); border-style: dashed; }

/* corridas de n8n */
.run { display: inline-flex; align-items: center; gap: 4px; font-size: 0.76rem; font-weight: 700; padding: 2px 8px; border-radius: 6px; white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.run svg { width: 12px; height: 12px; }
.run.queued { color: var(--brand); background: var(--brand-soft); }
.run.review { color: var(--warn); background: var(--warn-soft); }
.run.done { color: var(--ok); background: var(--ok-soft); }
.run.error { color: var(--bad); background: var(--bad-soft); white-space: normal; }
.run-msg { max-width: 260px; text-align: right; }

/* login */
.auth-card { max-width: 440px; width: 100%; margin: 48px auto 0; padding: 28px; gap: 14px; }
.auth-card p { margin: 0; }

/* plantillas */
.phase-edit .field input { font-weight: 650; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch input { position: absolute; opacity: 0; }
.swatch span { display: block; width: 26px; height: 26px; border-radius: 50%; background: var(--chip); border: 3px solid var(--surface); box-shadow: 0 0 0 1px var(--line); cursor: pointer; }
.swatch input:checked + span { box-shadow: 0 0 0 2px var(--ink); }
.swatch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* modal y toast */
.modal-back { position: fixed; inset: 0; background: rgb(10 16 22 / 45%); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--surface); border-radius: 12px; width: min(520px, 100%); max-height: calc(100dvh - 32px); display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 20px 60px rgb(0 0 0 / 25%); }
.modal.wide { width: min(760px, 100%); }
.modal-form { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.modal-body { flex: 1; min-height: 0; }
.modal-head, .modal-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 18px; }
.modal-head { border-bottom: 1px solid var(--line); }
.modal-foot { border-top: 1px solid var(--line); justify-content: flex-end; }
.modal-body { padding: 16px 18px; overflow-y: auto; display: grid; gap: 14px; }
.modal-body p { margin: 0; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); padding: 10px 16px; border-radius: 8px; background: var(--ink); color: var(--bg); font-weight: 600; font-size: 0.88rem; z-index: 60; box-shadow: var(--shadow); }
.toast.bad { background: var(--bad); color: #fff; }

/* ---------- responsive */
@media (max-width: 1000px) {
  .dash, .tx-grid { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .top-inner { flex-wrap: wrap; gap: 10px; padding: 10px 16px; }
  .brand { flex: 1; min-width: 0; }
  .brand-name { display: none; }
  .nav { order: 3; flex-basis: 100%; }
  .top-actions .btn.primary span { display: none; }
  .main { padding: 18px 16px 48px; }
  .banner { width: calc(100% - 32px); }
  h1 { font-size: 1.4rem; }
  .form-grid.two, .form-grid.three { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .client-row { grid-template-columns: 1fr; }
  .step { grid-template-columns: auto 1fr; }
  .step-actions { grid-column: 2; flex-direction: row; flex-wrap: wrap; align-items: center; }
  #tx-search { width: 100%; }
}
@media (max-width: 420px) {
  .tiles { grid-template-columns: 1fr 1fr; gap: 10px; }
  .tile-value { font-size: 1.6rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
