:root {
  --bg: #f6f6f4;
  --panel: #ffffff;
  --panel-2: #fafaf9;
  --line: #e7e5e4;
  --line-strong: #d6d3d1;
  --text: #1c1917;
  --muted: #78716c;
  --faint: #a8a29e;
  --accent: #1c1917;
  --accent-text: #ffffff;
  --focus: #2563eb;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 4px 16px rgb(0 0 0 / 0.04);
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111110;
    --panel: #1a1a19;
    --panel-2: #20201e;
    --line: #2c2b29;
    --line-strong: #3a3936;
    --text: #eeeeec;
    --muted: #a3a29d;
    --faint: #6f6e69;
    --accent: #eeeeec;
    --accent-text: #111110;
    --focus: #60a5fa;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 24px rgb(0 0 0 / 0.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- controls ---------- */

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 14px;
  border: 1px solid var(--line-strong); border-radius: 8px;
  background: var(--panel); cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.primary:hover { opacity: 0.9; }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.small { height: 28px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: default; }

.input, select.input, textarea.input {
  width: 100%; height: 36px; padding: 0 11px;
  border: 1px solid var(--line-strong); border-radius: 8px;
  background: var(--panel);
}
textarea.input { height: auto; min-height: 80px; padding: 9px 11px; resize: vertical; }
.input:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 20%, transparent); }

.field { display: grid; gap: 5px; }
.field > span { font-size: 12px; color: var(--muted); font-weight: 500; }

.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--c, var(--faint)); }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 8px; border-radius: 999px;
  font-size: 12px; font-weight: 500;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted);
}
.badge.stage-new { color: #2563eb; }
.badge.stage-contacted { color: #7c3aed; }
.badge.stage-qualified { color: var(--warn); }
.badge.stage-customer { color: var(--ok); }
.badge.stage-lost { color: var(--faint); }
.badge.kind-bug { color: var(--danger); }
.badge.kind-idea { color: #7c3aed; }
.badge.kind-praise { color: var(--ok); }
.badge.kind-question { color: #2563eb; }

/* ---------- sign-in ---------- */

.auth {
  min-height: 100%; display: grid; place-items: center; padding: 24px 16px;
}
.auth-card {
  width: 100%; max-width: 360px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); padding: 28px;
}
.auth-card h1 { margin: 14px 0 4px; font-size: 20px; letter-spacing: -0.01em; }
.auth-card p { margin: 0 0 22px; color: var(--muted); }
.auth-card form { display: grid; gap: 14px; }
.auth-card .btn { height: 38px; justify-content: center; margin-top: 4px; }
.auth-error { color: var(--danger); font-size: 13px; min-height: 18px; margin: -4px 0 0; }

.logo {
  display: inline-grid; place-items: center;
  width: 32px; height: 32px; border-radius: 9px;
  background: var(--accent); color: var(--accent-text);
  font-weight: 700; font-size: 15px; letter-spacing: -0.02em;
}

/* ---------- app layout ---------- */

.layout { display: grid; grid-template-columns: 232px 1fr; height: 100%; }

.sidebar {
  display: flex; flex-direction: column; gap: 18px;
  padding: 16px 12px; border-right: 1px solid var(--line); background: var(--panel);
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 6px; font-weight: 600; }
.nav-title { padding: 0 8px 4px; font-size: 11px; font-weight: 600; color: var(--faint); text-transform: uppercase; letter-spacing: 0.06em; }
.nav { display: grid; gap: 1px; }
.nav a {
  display: flex; align-items: center; gap: 9px;
  height: 32px; padding: 0 8px; border-radius: 7px;
  text-decoration: none; color: var(--muted);
}
.nav a:hover { background: var(--panel-2); color: var(--text); }
.nav a.active { background: var(--panel-2); color: var(--text); font-weight: 500; box-shadow: inset 0 0 0 1px var(--line); }
.nav a .count { margin-left: auto; font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; }
.nav a .count.hot { color: var(--danger); font-weight: 600; }
.nav svg { width: 16px; height: 16px; flex: none; }
.sidebar-foot {
  margin-top: auto; display: flex; align-items: center; gap: 8px;
  padding: 10px 8px 0; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px;
}
.sidebar-foot .who { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.topbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 14px 24px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.topbar h2 { margin: 0 auto 0 0; font-size: 17px; letter-spacing: -0.01em; }
.topbar .search { width: 220px; }
.content { flex: 1; overflow: auto; padding: 20px 24px 40px; }

.menu-btn { display: none; }

/* ---------- stats ---------- */

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.stat span { color: var(--muted); font-size: 12px; }

/* ---------- pipeline ---------- */

.board { display: grid; grid-template-columns: repeat(5, minmax(210px, 1fr)); gap: 12px; align-items: start; }
.column { min-width: 0; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; min-height: 160px; }
.column.drop { border-color: var(--focus); background: color-mix(in srgb, var(--focus) 6%, var(--panel-2)); }
.column-head { display: flex; align-items: center; gap: 8px; padding: 4px 6px 10px; font-weight: 600; font-size: 13px; }
.column-head .n { color: var(--faint); font-weight: 500; }
.column-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 11px; cursor: pointer; box-shadow: 0 1px 1px rgb(0 0 0 / 0.03);
}
.card:hover { border-color: var(--line-strong); }
.card.dragging { opacity: 0.4; }
.card-title { font-weight: 500; margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-meta { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.card-meta .sep { color: var(--faint); }
.card-meta .val { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--text); }
.column-empty { color: var(--faint); font-size: 12px; text-align: center; padding: 18px 0; }

/* ---------- tables ---------- */

.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; font-weight: 500; color: var(--muted); background: var(--panel-2); position: sticky; top: 0; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--panel-2); }
tbody tr:last-child td { border-bottom: none; }
td.muted { color: var(--muted); }
td.num { font-variant-numeric: tabular-nums; text-align: right; }

.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.chip {
  height: 28px; padding: 0 11px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--panel); color: var(--muted); font-size: 13px;
}
.chip.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

/* ---------- feedback ---------- */

.fb-list { display: grid; gap: 10px; max-width: 860px; }
.fb {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; display: grid; gap: 8px;
}
.fb.is-new { border-left: 3px solid var(--focus); }
.fb-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.fb-head .when { margin-left: auto; }
.fb-msg { white-space: pre-wrap; word-break: break-word; }
.fb-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.fb-foot .actions { margin-left: auto; display: flex; gap: 6px; }
.stars { color: var(--warn); letter-spacing: 1px; }

.empty {
  text-align: center; color: var(--muted); padding: 60px 20px;
  border: 1px dashed var(--line-strong); border-radius: var(--radius);
}
.empty b { display: block; color: var(--text); margin-bottom: 4px; }

/* ---------- drawer & dialog ---------- */

.scrim { position: fixed; inset: 0; background: rgb(0 0 0 / 0.25); z-index: 20; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(480px, 100%); z-index: 21;
  background: var(--panel); border-left: 1px solid var(--line); box-shadow: var(--shadow);
  display: flex; flex-direction: column;
}
.drawer-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.drawer-head h3 { margin: 0 auto 0 0; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-body { flex: 1; overflow: auto; padding: 18px; display: grid; gap: 18px; align-content: start; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.section-title { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin: 0 0 8px; }
.timeline { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.timeline li { display: grid; grid-template-columns: 12px 1fr; gap: 10px; font-size: 13px; }
.timeline li::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--line-strong); margin-top: 6px; }
.timeline li.note::before { background: var(--focus); }
.timeline li.stage::before { background: var(--warn); }
.timeline .t { color: var(--faint); font-size: 12px; }
.timeline .b { white-space: pre-wrap; word-break: break-word; }
.note-form { display: grid; gap: 8px; }
.note-form .input { min-height: 64px; }
.note-form .btn { justify-self: end; }
.drawer-foot { display: flex; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }
.drawer-foot .spacer { flex: 1; }

dialog {
  border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(460px, calc(100% - 32px));
  background: var(--panel); color: var(--text); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgb(0 0 0 / 0.3); }
dialog form { display: grid; gap: 12px; padding: 20px; }
dialog h3 { margin: 0 0 4px; font-size: 16px; }
dialog .row-end { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.form-error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 0; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 40;
  background: var(--accent); color: var(--accent-text); padding: 9px 16px; border-radius: 8px; font-size: 13px;
  box-shadow: var(--shadow);
}

/* ---------- small screens ---------- */

@media (max-width: 1100px) {
  .board { grid-template-columns: repeat(5, 240px); }
}

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 30;
    transform: translateX(-100%); transition: transform 0.18s ease;
  }
  .sidebar.open { transform: none; box-shadow: var(--shadow); }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 12px 16px; }
  .topbar .search { order: 5; width: 100%; }
  .content { padding: 16px 16px 40px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: 1fr; }
}
