/* CRM — Perrugi · FSS · Devisu */
:root {
  --bg: #f4f3ef;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --line: #e4e1da;
  --line-strong: #d3cfc6;
  --ink: #1c1b22;
  --ink-2: #4a4852;
  --muted: #7a7783;
  --accent: #1c1b22;
  --ok: #0f7a52;
  --err: #b4232f;
  --warn: #a86200;
  --co: #1c1b22;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(28, 27, 34, .06), 0 1px 1px rgba(28, 27, 34, .04);
  --shadow-lift: 0 10px 24px rgba(28, 27, 34, .14), 0 2px 6px rgba(28, 27, 34, .08);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 14px/1.45 var(--font);
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
}
a { color: inherit; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
h1 { font-size: 22px; font-weight: 650; display: flex; align-items: center; gap: 10px; }
h2 { font-size: 14px; font-weight: 650; }
.h3 { font-size: 15px; margin-top: 6px; }
p { margin: 0; }
code { font: 12.5px var(--mono); background: rgba(28,27,34,.06); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--ink);
  color: #fff;
  border-bottom: 3px solid var(--co);
}
.topbar-inner {
  display: flex; align-items: center; gap: 18px;
  padding: 0 20px; height: 56px;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; text-decoration: none; font-size: 15px; letter-spacing: .02em; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px; flex: none;
  background:
    linear-gradient(#fff,#fff) 5px 6px / 12px 2.5px no-repeat,
    linear-gradient(#fff,#fff) 5px 10px / 9px 2.5px no-repeat,
    linear-gradient(#fff,#fff) 5px 14px / 6px 2.5px no-repeat,
    var(--co);
}
.area-admin .brand-mark { background-color: #6b6875; }
.brand-tag { font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; background: rgba(255,255,255,.14); padding: 2px 6px; border-radius: 4px; }

.company-tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.company-tabs a {
  --tab: #888;
  display: flex; align-items: center; gap: 7px;
  padding: 7px 12px; border-radius: 8px;
  color: rgba(255,255,255,.72); text-decoration: none; font-weight: 550; white-space: nowrap;
}
.company-tabs a:hover { color: #fff; background: rgba(255,255,255,.07); }
.company-tabs a.active { color: #fff; background: rgba(255,255,255,.12); }
.company-tabs .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--tab); box-shadow: 0 0 0 2px rgba(255,255,255,.15); }
.area-admin .company-tabs .dot { background: #fff; }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.search { position: relative; display: flex; align-items: center; }
.search svg { position: absolute; left: 10px; width: 15px; height: 15px; fill: none; stroke: rgba(255,255,255,.55); stroke-width: 1.8; stroke-linecap: round; pointer-events: none; }
.search input {
  width: 240px; height: 34px; padding: 0 12px 0 32px;
  border-radius: 8px; border: 1px solid rgba(255,255,255,.14);
  background: rgba(255,255,255,.08); color: #fff; font: inherit;
  transition: width .15s, background .15s;
}
.search input::placeholder { color: rgba(255,255,255,.5); }
.search input:focus { outline: none; width: 300px; background: rgba(255,255,255,.14); border-color: rgba(255,255,255,.3); }

.avatar {
  display: inline-grid; place-items: center; flex: none;
  width: 30px; height: 30px; border-radius: 50%;
  background: #e9e6df; color: var(--ink-2);
  font-size: 11.5px; font-weight: 700; letter-spacing: .02em;
}
.avatar.sm { width: 22px; height: 22px; font-size: 9.5px; }
.topbar .avatar { background: rgba(255,255,255,.16); color: #fff; }

.usermenu { position: relative; }
.usermenu summary { list-style: none; display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 4px 6px; border-radius: 8px; }
.usermenu summary::-webkit-details-marker { display: none; }
.usermenu summary:hover { background: rgba(255,255,255,.07); }
.usermenu-name { font-weight: 550; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.usermenu-panel {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 230px;
  background: var(--surface); color: var(--ink); border-radius: var(--radius);
  box-shadow: var(--shadow-lift); border: 1px solid var(--line); padding: 6px; z-index: 30;
}
.usermenu-head { padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; display: grid; }
.usermenu-head span { color: var(--muted); font-size: 12.5px; }
.usermenu-panel a, .usermenu-panel button {
  display: block; width: 100%; text-align: left; padding: 8px 10px; border-radius: 6px;
  text-decoration: none; font: inherit; color: inherit; background: none; border: 0; cursor: pointer;
}
.usermenu-panel a:hover, .usermenu-panel button:hover { background: var(--surface-2); }
.usermenu-panel form { margin: 0; }

/* ---------- Layout ---------- */
.main { padding: 24px 20px 60px; max-width: 1280px; margin: 0 auto; }
.main-wide { max-width: none; }
.narrow { max-width: 720px; margin: 0 auto; }
.narrow.wide-ish { max-width: 920px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin-top: 4px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.back { display: inline-block; color: var(--muted); text-decoration: none; font-size: 13px; margin-bottom: 6px; }
.back:hover { color: var(--ink); }
.co-dot { width: 12px; height: 12px; border-radius: 4px; background: var(--co); display: inline-block; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.panel.empty { color: var(--muted); text-align: center; padding: 40px 20px; }
.panel h2 { margin-bottom: 12px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.panel-head h2 { margin: 0; }
.stack { display: grid; gap: 14px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s, transform .05s;
}
.btn:hover { background: var(--surface-2); border-color: #bfbab0; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.primary:hover { background: #33313c; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: rgba(28,27,34,.06); }
.btn.danger { color: var(--err); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.block { width: 100%; height: 40px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }

.seg { display: inline-flex; background: #e9e6df; border-radius: 8px; padding: 3px; }
.seg a { padding: 5px 12px; border-radius: 6px; text-decoration: none; color: var(--ink-2); font-weight: 600; font-size: 13px; }
.seg a.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* ---------- Forms ---------- */
.field { display: grid; gap: 5px; min-width: 0; margin: 0; border: 0; padding: 0; }
.field > span, .field > legend { font-size: 12.5px; font-weight: 600; color: var(--ink-2); padding: 0; }
.field legend { margin-bottom: 8px; }
.req { color: var(--err); font-weight: 700; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); padding: 7px 10px; min-height: 36px;
}
textarea { resize: vertical; line-height: 1.5; }
select { padding-right: 28px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--co) 35%, transparent); outline-offset: 0; border-color: var(--co); }
.has-error input, .has-error select, .has-error textarea { border-color: var(--err); }
.err { color: var(--err); font-size: 12.5px; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.form-grid .wide { grid-column: span 2; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid.top-row { margin-bottom: 14px; padding-bottom: 14px; border-bottom: 1px dashed var(--line); }
.form-actions { display: flex; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.input-group { display: flex; gap: 6px; }
.input-group input { font-family: var(--mono); }

.filters { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.filters input[type=search] { flex: 1 1 280px; }
.filters select { width: auto; min-width: 170px; }
.filter-inline select { width: auto; height: 34px; min-height: 34px; padding-top: 0; padding-bottom: 0; }

.company-checks { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.company-check {
  --c: #888;
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  border: 1px solid var(--line-strong); border-radius: 8px; padding: 8px 12px; font-weight: 600;
  user-select: none;
}
.company-check input { width: 16px; height: 16px; min-height: 0; margin: 0; accent-color: var(--c); }
.company-check .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c); }
.company-check:has(input:checked) { border-color: var(--c); background: color-mix(in srgb, var(--c) 8%, white); }
.switch { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; cursor: pointer; }
.switch input { width: 16px; height: 16px; min-height: 0; margin-top: 2px; flex: none; accent-color: var(--ink); }
.switch span { color: var(--ink-2); }

/* ---------- Flash ---------- */
.flashes { display: grid; gap: 8px; margin-bottom: 16px; }
.flash { padding: 10px 14px; border-radius: var(--radius-sm); border: 1px solid; font-weight: 500; }
.flash-ok { background: #ecf7f1; border-color: #bfe3d0; color: #0b5c3e; }
.flash-err { background: #fdf0f0; border-color: #f2c7c9; color: #8e1b25; }
.main .flashes { position: fixed; right: 20px; bottom: 20px; z-index: 50; max-width: 380px; animation: flash-in .2s ease-out; }
.main .flashes .flash { box-shadow: var(--shadow-lift); }
@keyframes flash-in { from { transform: translateY(8px); opacity: 0; } }

/* ---------- Badges ---------- */
.badge, .co-badge, .tag {
  display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
  font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px;
}
.badge { --c: #888; color: color-mix(in srgb, var(--c) 82%, black); background: color-mix(in srgb, var(--c) 13%, white); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--c); }
.co-badge { --c: #888; color: var(--c); border: 1px solid color-mix(in srgb, var(--c) 40%, white); background: var(--surface); margin: 1px 2px 1px 0; }
.tag { background: #eeece6; color: var(--ink-2); }
.tag.dark { background: var(--ink); color: #fff; }
.tag.warn { background: #fdf1e0; color: var(--warn); }

/* ---------- Table ---------- */
.table-wrap { padding: 0; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 11.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 11px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr[data-href] { cursor: pointer; }
.table tbody tr:hover td { background: var(--surface-2); }
.table tr.inactive td { opacity: .55; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-link { font-weight: 600; text-decoration: none; }
.row-link:hover { text-decoration: underline; }
.user-cell { display: flex; gap: 10px; align-items: center; }
.chip-filter { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.chip-filter a { --c: var(--ink); display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 99px; border: 1px solid var(--line-strong); text-decoration: none; font-weight: 600; font-size: 13px; background: var(--surface); }
.chip-filter a .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.chip-filter a.active { background: var(--ink); color: #fff; border-color: var(--ink); }

/* ---------- Board (kanban) ---------- */
.board {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(250px, 1fr);
  gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: start;
  min-height: calc(100vh - 200px);
}
.col {
  --st: #888;
  background: #ebe8e1; border-radius: var(--radius); padding: 0 8px 8px;
  display: flex; flex-direction: column; max-height: calc(100vh - 190px); min-width: 0;
}
.col-head {
  display: flex; align-items: center; gap: 7px; padding: 12px 4px 10px;
  position: sticky; top: 0; background: inherit; border-radius: var(--radius) var(--radius) 0 0;
  border-top: 3px solid var(--st); margin: 0 -8px; padding-left: 12px; padding-right: 8px;
}
.col-head h2 { font-size: 13px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.st-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--st); flex: none; }
.col-count { font-size: 12px; font-weight: 700; color: var(--ink-2); background: rgba(255,255,255,.7); border-radius: 99px; padding: 0 7px; }
.col-sum { margin-left: auto; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.col-add { margin-left: 2px; width: 22px; height: 22px; display: grid; place-items: center; border-radius: 6px; text-decoration: none; color: var(--muted); font-weight: 700; font-size: 16px; line-height: 1; }
.col-sum:empty + .col-add { margin-left: auto; }
.col-add:hover { background: rgba(255,255,255,.8); color: var(--ink); }
.cards { display: flex; flex-direction: column; gap: 7px; overflow-y: auto; min-height: 60px; padding: 2px; flex: 1; }
.col-closed { background: #e6e3dc; }
.col-closed .card { opacity: .85; }

.card {
  display: grid; gap: 4px; padding: 10px 11px 9px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  text-decoration: none; box-shadow: var(--shadow); cursor: grab;
  border-left: 3px solid var(--st);
  transition: box-shadow .12s, border-color .12s;
}
.card:hover { box-shadow: var(--shadow-lift); border-color: var(--line-strong); border-left-color: var(--st); }
.card-title { font-weight: 650; font-size: 13.5px; line-height: 1.3; overflow-wrap: anywhere; }
.card-sub { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-meta { display: flex; align-items: center; gap: 6px; margin-top: 3px; font-size: 12px; color: var(--ink-2); }
.card-value { font-weight: 600; font-variant-numeric: tabular-nums; }
.card-age { margin-left: auto; color: var(--muted); }
.card-age.stale { color: var(--warn); font-weight: 600; }
.card-ghost { opacity: .35; background: #fff; }
.card-chosen { box-shadow: var(--shadow-lift); }
.card-drag { transform: rotate(2deg); }
.board.saving { cursor: progress; }

/* ---------- Lead detail ---------- */
.lead-layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; align-items: start; }
.lead-side { display: grid; gap: 16px; position: sticky; top: 76px; }
.status-pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pill {
  --c: #888;
  border: 1px solid color-mix(in srgb, var(--c) 35%, white); background: var(--surface);
  color: color-mix(in srgb, var(--c) 85%, black); font: inherit; font-size: 12.5px; font-weight: 600;
  padding: 5px 10px; border-radius: 99px; cursor: pointer;
}
.pill:hover { background: color-mix(in srgb, var(--c) 10%, white); }
.pill.current { background: var(--c); border-color: var(--c); color: #fff; cursor: default; opacity: 1; }

.note-form textarea { min-height: 70px; }
.note-actions { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; }
.timeline { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 0; max-height: 640px; overflow-y: auto; }
.timeline li { position: relative; padding: 0 0 14px 18px; border-left: 2px solid var(--line); margin-left: 6px; }
.timeline li:last-child { padding-bottom: 0; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--line-strong); border: 2px solid var(--surface); }
.tl-note::before { background: var(--co) !important; }
.tl-status::before { background: #2563eb !important; }
.tl-created::before { background: var(--ok) !important; }
.tl-head { display: flex; align-items: center; gap: 7px; font-size: 13px; }
.tl-head time { margin-left: auto; color: var(--muted); font-size: 12px; }
.tl-body { margin-top: 6px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; white-space: normal; overflow-wrap: anywhere; }
.tl-line { font-size: 13px; color: var(--ink-2); overflow-wrap: anywhere; }
.tl-line .old { color: var(--muted); text-decoration: line-through; text-decoration-color: rgba(0,0,0,.25); }
.tl-line .new { color: var(--ink); font-weight: 600; }
.tl-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.danger-zone { display: flex; align-items: center; gap: 10px; margin-top: 4px; }

/* ---------- Auth ---------- */
.is-bare { background: var(--ink); }
.bare-main { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.bare-main .flashes { width: 100%; max-width: 400px; }
.auth { width: 100%; display: grid; place-items: center; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border-radius: 14px; padding: 30px; box-shadow: 0 30px 60px rgba(0,0,0,.35); display: grid; gap: 14px; }
.auth-card.wide { max-width: 560px; }
.auth-card h1 { font-size: 22px; }
.auth-brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.auth-foot { font-size: 12.5px; text-align: center; }
.checks { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; font-size: 13px; }
.checks .ok { color: var(--ok); }
.checks .bad { color: var(--err); font-weight: 600; }

.empty-state { max-width: 520px; margin: 60px auto; text-align: center; display: grid; gap: 12px; justify-items: center; }
.empty-state h1 { justify-content: center; }
.is-bare .empty-state { background: var(--surface); padding: 30px; border-radius: 14px; }

/* ---------- Responsive ---------- */
@media (max-width: 1000px) {
  .lead-layout { grid-template-columns: 1fr; }
  .lead-side { position: static; }
  .form-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 760px) {
  .topbar-inner { height: auto; flex-wrap: wrap; padding: 10px 14px; gap: 10px; }
  .company-tabs { order: 3; width: 100%; }
  .search input, .search input:focus { width: 150px; }
  .usermenu-name { display: none; }
  .main { padding: 16px 14px 60px; }
  .form-grid, .grid-2 { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
  .board { grid-auto-columns: 82vw; scroll-snap-type: x mandatory; }
  .col { scroll-snap-align: start; }
  .page-head { align-items: flex-start; }
}
