/* Punt de Gir · CRM de presupuestos */
:root {
  --ink: #1b1a1c;
  --ink-2: #4b4a4f;
  --muted: #85848a;
  --line: #e5e4e0;
  --line-2: #efeeea;
  --bg: #f5f4f1;
  --surface: #ffffff;
  --accent: #c4262e;
  --accent-ink: #a01d24;
  --accent-soft: #fbeceb;
  --series-1: #3a6ab0;
  --series-2: #c4262e;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 20, 20, .04), 0 4px 16px rgba(20, 20, 20, .04);
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.5 var(--font); color: var(--ink); background: var(--bg); display: flex; min-height: 100vh; }
a { color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 15px; font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
code, .code { font-family: Consolas, monospace; font-size: 12px; }
.code { background: #f3f3f1; padding: 12px; border-radius: 8px; overflow: auto; }

/* ---------- Sidebar */
.sidebar { width: 232px; flex: none; background: #111; color: #d8d7d3; display: flex; flex-direction: column; padding: 22px 14px; position: sticky; top: 0; height: 100vh; }
.brand { display: block; padding: 0 8px 22px; }
.brand img { width: 128px; display: block; }
.new-quote { margin-bottom: 18px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; text-decoration: none; color: #bdbcb8; }
.sidebar nav a:hover { background: #1e1e1e; color: #fff; }
.sidebar nav a.active { background: #262626; color: #fff; }
.sidebar nav svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.nav-count { margin-left: auto; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; border-radius: 10px; padding: 0 7px; line-height: 18px; }
.sidebar-user { border-top: 1px solid #262626; padding: 14px 10px 0; display: flex; justify-content: space-between; font-size: 13px; }
.sidebar-user a { color: #8c8b87; }

/* ---------- Main */
.main { flex: 1; min-width: 0; padding: 26px 34px 60px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; min-height: 38px; }
.page-head h1 { font-size: 24px; font-weight: 700; letter-spacing: -.01em; }
.page-head h1 small { font-size: 14px; font-weight: 500; color: var(--muted); margin-left: 8px; }
.page-actions { display: flex; gap: 8px; align-items: center; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--line-2); }
.stack { display: flex; flex-direction: column; gap: 18px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-main { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; align-items: start; }

/* ---------- Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--ink); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #cfcec9; background: #fafaf8; }
.btn-primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-primary:hover { background: #333; border-color: #333; }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-danger { color: var(--accent); }
.btn-danger:hover { background: var(--accent-soft); border-color: #f0c9c7; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-icon { width: 30px; padding: 0; height: 30px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------- Forms */
label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 600; color: var(--ink-2); }
input, select, textarea { font: inherit; font-size: 14px; color: var(--ink); background: #fff; border: 1px solid #d9d8d3; border-radius: 8px; padding: 8px 10px; width: 100%; font-weight: 400; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(196, 38, 46, .18); border-color: var(--accent); }
textarea { resize: vertical; min-height: 70px; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }
label.check { flex-direction: row; align-items: center; gap: 8px; font-size: 14px; font-weight: 500; color: var(--ink); cursor: pointer; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid.three { grid-template-columns: 1fr 1fr 1fr; }
.form-grid.four { grid-template-columns: repeat(4, 1fr); }
.span2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }
.input-suffix { position: relative; }
.input-suffix input { padding-right: 28px; }
.input-suffix span { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 13px; }

.filters { display: flex; gap: 10px; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line-2); flex-wrap: wrap; }
.filters input[type=search] { max-width: 280px; }
.filters select { width: auto; }

/* ---------- Tables */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--line); background: #fbfbfa; }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr.link { cursor: pointer; }
.table tr.link:hover td { background: #fafaf8; }
.table .actions { text-align: right; white-space: nowrap; width: 1%; }
.table .code { background: none; padding: 0; font-weight: 600; font-size: 13px; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; white-space: nowrap; border: 1px solid transparent; }
.badge-borrador { background: #f0efeb; color: #5c5b60; }
.badge-enviado { background: #e8eff9; color: #2a5491; }
.badge-negociacion { background: #fdf3e1; color: #8a5a0b; }
.badge-aceptado { background: #e5f4ea; color: #1f7240; }
.badge-rechazado { background: var(--accent-soft); color: var(--accent-ink); }
.flag { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: #8a5a0b; font-weight: 600; margin-left: 6px; }
.flag::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #e09a1c; }

/* ---------- Dashboard */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; margin-bottom: 18px; }
.kpi { padding: 16px 20px; }
.kpi .label { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi .value { font-size: 28px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.chart-wrap { padding: 16px 20px 12px; position: relative; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--ink-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.chart { display: grid; grid-template-columns: 44px 1fr; }
.y-axis { position: relative; height: 200px; }
.y-axis span { position: absolute; right: 8px; transform: translateY(50%); font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.plot { position: relative; height: 200px; border-bottom: 1px solid #cfcec9; display: grid; grid-template-columns: repeat(12, 1fr); }
.gridline { position: absolute; left: 0; right: 0; border-top: 1px solid var(--line-2); pointer-events: none; }
.month { position: relative; display: flex; gap: 2px; align-items: flex-end; justify-content: center; height: 100%; }
.month:hover { background: rgba(0, 0, 0, .025); }
.bar { width: 30%; max-width: 16px; border-radius: 4px 4px 0 0; }
.x-axis { display: grid; grid-template-columns: repeat(12, 1fr); font-size: 11px; color: var(--muted); text-align: center; padding-top: 6px; }
.tip { position: absolute; pointer-events: none; background: var(--ink); color: #fff; font-size: 12px; padding: 8px 10px; border-radius: 8px; white-space: nowrap; z-index: 5; display: none; box-shadow: var(--shadow); }
.tip b { display: block; margin-bottom: 2px; }
.tip i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }

.rank { list-style: none; margin: 0; padding: 6px 0; }
.rank li { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 8px 20px; }
.rank .meter { grid-column: 1 / -1; height: 6px; background: var(--line-2); border-radius: 4px; overflow: hidden; }
.rank .meter span { display: block; height: 100%; background: var(--series-1); border-radius: 4px; }

/* ---------- Catalog */
.cat-block + .cat-block { margin-top: 18px; }
.cat-head { display: flex; align-items: center; gap: 8px; }
.cat-head h2 { font-size: 16px; }
.cat-head .muted { font-weight: 400; }
.inactive td { color: var(--muted); }

/* ---------- Referents */
.ref-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 18px; }
.ref-card { display: flex; flex-direction: column; overflow: hidden; }
.ref-card[hidden] { display: none; }
.ref-thumb { position: relative; display: block; aspect-ratio: 16 / 9; background: #111; }
.ref-thumb img, .ref-preview img, .ref-pick img, .ref-chip img { width: 100%; height: 100%; object-fit: cover; display: block; }
.play { position: absolute; left: 50%; top: 50%; width: 44px; height: 44px; margin: -22px 0 0 -22px; border-radius: 50%; background: rgba(0, 0, 0, .55); }
.play::after { content: ""; position: absolute; left: 17px; top: 13px; border-left: 14px solid #fff; border-top: 9px solid transparent; border-bottom: 9px solid transparent; }
.ref-thumb:hover .play { background: var(--accent); }
.ref-body { padding: 12px 16px 4px; flex: 1; }
.ref-body h3 { font-size: 14px; font-weight: 650; }
.ref-body p { margin: 4px 0 0; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.ref-foot { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px 12px 16px; }
.ref-preview { aspect-ratio: 16 / 9; background: #f0efeb; border-radius: 8px; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.ref-image-actions { display: flex; gap: 8px; align-items: center; margin-top: -4px; }
.ref-image-actions label.btn { flex-direction: row; font-size: 13px; color: var(--ink); }

.ref-chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; padding: 16px; }
.ref-chip { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.ref-chip .img { aspect-ratio: 16 / 9; background: #111; }
.ref-chip .meta { display: flex; align-items: center; gap: 4px; padding: 6px 6px 6px 10px; font-size: 13px; font-weight: 600; }
.ref-chip .meta span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ref-chip button { width: 22px; height: 22px; border: 0; background: none; cursor: pointer; color: var(--muted); border-radius: 4px; flex: none; }
.ref-chip button:hover { background: var(--line-2); color: var(--ink); }
.ref-chip button.del:hover { color: var(--accent); background: var(--accent-soft); }
.ref-picker-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.ref-pick { position: relative; border: 2px solid var(--line); border-radius: 10px; overflow: hidden; cursor: pointer; background: #fff; padding: 0; font: inherit; text-align: left; color: inherit; }
.ref-pick .img { aspect-ratio: 16 / 9; background: #111; }
.ref-pick .t { display: block; padding: 8px 10px; font-size: 13px; font-weight: 600; }
.ref-pick.on { border-color: var(--accent); }
.ref-pick.on::after { content: "✓"; position: absolute; top: 8px; right: 8px; width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center; font-size: 13px; }
.ref-pick[hidden] { display: none; }

/* ---------- Quote editor */
.lines { width: 100%; border-collapse: collapse; }
.lines th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 10px 8px; border-bottom: 1px solid var(--line); }
.lines td { padding: 8px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
.lines input, .lines textarea { padding: 6px 8px; font-size: 13px; }
.lines textarea { min-height: 34px; height: 34px; margin-top: 6px; color: var(--ink-2); }
.lines .c-qty { width: 90px; }
.lines .c-unit { width: 110px; }
.lines .c-price { width: 110px; }
.lines .c-amount { width: 110px; padding-top: 14px; font-weight: 600; }
.lines .c-act { width: 74px; white-space: nowrap; padding-top: 10px; }
.lines .c-act button { width: 22px; height: 22px; border: 0; background: none; cursor: pointer; color: var(--muted); border-radius: 4px; font-size: 14px; line-height: 1; }
.lines .c-act button:hover { background: var(--line-2); color: var(--ink); }
.lines .c-act button.del:hover { color: var(--accent); background: var(--accent-soft); }
.lines-foot { display: flex; gap: 8px; padding: 14px 16px; }

.totals { width: 100%; border-collapse: collapse; }
.totals td { padding: 6px 0; }
.totals tr.grand td { border-top: 1px solid var(--line); padding-top: 12px; font-size: 20px; font-weight: 700; }
.discount-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.meta-list { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13px; }
.meta-list dt { color: var(--muted); }
.meta-list dd { margin: 0; }

.client-picker { display: flex; gap: 8px; }
.client-picker select { flex: 1; }

/* ---------- Modal */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0, 0, 0, .25); color: var(--ink); }
dialog.wide { width: min(760px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(17, 17, 17, .45); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--line-2); }
.modal-head h2 { font-size: 17px; }
.modal-body { padding: 20px 22px; max-height: 68vh; overflow: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 22px; border-top: 1px solid var(--line-2); background: #fbfbfa; border-radius: 0 0 14px 14px; }
.modal-foot .left { margin-right: auto; }
.x { border: 0; background: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); }

.picker-search { margin-bottom: 14px; }
.picker-cat { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; margin: 14px 0 6px; }
.picker-item { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; width: 100%; text-align: left; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; margin-bottom: 6px; font: inherit; color: inherit; }
.picker-item:hover { border-color: var(--accent); background: var(--accent-soft); }
.picker-item strong { font-weight: 600; }
.picker-item .desc { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }

/* ---------- Misc */
.alert { padding: 10px 14px; border-radius: 8px; background: #f0efeb; margin-bottom: 14px; font-size: 13px; }
.alert-error { background: var(--accent-soft); color: var(--accent-ink); }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 10px; font-weight: 600; opacity: 0; pointer-events: none; transition: .2s; z-index: 100; }
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.error { background: var(--accent); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); padding: 0 20px; }
.tabs button { border: 0; background: none; font: inherit; font-weight: 600; color: var(--muted); padding: 12px 10px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.active { color: var(--ink); border-color: var(--accent); }
.tab-panel[hidden] { display: none; }

/* ---------- Auth */
.auth-page { align-items: center; justify-content: center; background: #111; padding: 20px; }
.auth-card { background: #fff; border-radius: 16px; padding: 34px; width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; }
.auth-card.wide { max-width: 720px; }
.auth-card h1 { font-size: 20px; }
.auth-logo { width: 140px; margin-bottom: 6px; }
.auth-card .form-grid { margin-bottom: 12px; }
