/* BD CRM · admin shell
   Dark sidebar + light canvas. Dense, not decorative. */

:root {
  --sidebar: #12141a;
  --sidebar-2: #1a1d24;
  --sidebar-line: #2a2e38;
  --sidebar-text: #d2d6de;
  --sidebar-muted: #8b91a0;
  --accent: #2a9d7c;
  --accent-2: #1e7d62;
  --accent-soft: rgba(42, 157, 124, 0.14);
  --canvas: #f3f4f6;
  --card: #ffffff;
  --ink: #16181d;
  --muted: #5c6470;
  --faint: #8b939e;
  --line: #e4e6ea;
  --line-2: #eceef1;
  --shadow: 0 1px 2px rgba(16, 18, 24, 0.06);
  --shadow-lg: 0 12px 40px rgba(16, 18, 24, 0.16);
  --radius: 8px;
  --radius-sm: 6px;
  --lead: #64748b;
  --talk: #2563eb;
  --won: #059669;
  --lost: #b45309;
  --cloud: #0284c7;
  --pay: #c2410c;
  --ads: #7c3aed;
  --sans: "IBM Plex Sans", "Noto Sans SC", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sidebar-w: 232px;
  --topbar-h: 52px;
  --focus: 0 0 0 3px rgba(42, 157, 124, 0.28);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; }

a { color: var(--accent-2); }

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

.skip {
  position: absolute;
  left: -999px;
  top: 8px;
  background: var(--card);
  padding: 8px 12px;
  z-index: 80;
}
.skip:focus { left: 8px; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ── layout ── */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 18px 14px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  border-right: 1px solid #000;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 8px 18px;
  border-bottom: 1px solid var(--sidebar-line);
  margin-bottom: 14px;
}
.brand svg { flex-shrink: 0; }
.brand-name {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #f4f5f7;
  line-height: 1.2;
}
.brand-sub {
  font-size: 10px;
  color: var(--sidebar-muted);
  margin-top: 3px;
  letter-spacing: 0.01em;
  line-height: 1.4;
  max-width: 170px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--sidebar-muted);
  text-align: left;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 500;
}
.nav-btn svg { opacity: 0.85; flex-shrink: 0; }
.nav-btn:hover { background: var(--sidebar-2); color: var(--sidebar-text); }
.nav-btn.is-active {
  background: var(--sidebar-2);
  color: #f4f5f7;
  box-shadow: inset 2px 0 0 var(--accent);
}
.nav-btn.is-active svg { color: var(--accent); opacity: 1; }

.sidebar-foot {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--sidebar-line);
}
.demo-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: #d6b56a;
  background: rgba(214, 181, 106, 0.1);
  border: 1px solid rgba(214, 181, 106, 0.28);
  border-radius: 999px;
  padding: 3px 9px;
  margin: 0 8px 12px;
}
.demo-pill i {
  width: 6px; height: 6px; border-radius: 50%;
  background: #d6b56a; display: inline-block;
}
.user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-sm);
}
.avatar {
  width: 32px; height: 32px; border-radius: 8px;
  background: #2a9d7c;
  color: #fff;
  display: grid; place-items: center;
  font-weight: 600; font-size: 12px;
  letter-spacing: 0.02em;
}
.user-name { font-weight: 600; color: #f4f5f7; font-size: 13px; }
.user-role { font-size: 11px; color: var(--sidebar-muted); }

.menu-toggle {
  display: none;
  position: fixed;
  top: 10px; left: 10px;
  z-index: 40;
  width: 36px; height: 36px;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 8px;
  cursor: pointer;
}

/* ── main ── */
.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: var(--topbar-h);
  background: var(--card);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.topbar-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}
.env-tag {
  font-size: 11px;
  font-weight: 600;
  color: #8a6d2b;
  background: #f8efd6;
  border: 1px solid #ead9a8;
  border-radius: 999px;
  padding: 2px 8px;
}

.content {
  padding: 20px 24px 0;
  flex: 1;
}

.view { display: none; }
.view.is-on { display: block; }

.page-lead {
  color: var(--muted);
  margin: 0 0 16px;
  font-size: 13px;
}

/* ── kpi ── */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.kpi {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px 13px;
  box-shadow: var(--shadow);
}
.kpi-label {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.kpi-value {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.03em;
  margin: 6px 0 2px;
  font-variant-numeric: tabular-nums;
}
.kpi-hint {
  font-size: 11px;
  color: var(--faint);
}
.kpi-hint.up { color: var(--won); }
.kpi-hint.down { color: #b45309; }

/* ── panels ── */
.grid-2 {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}
.grid-2.eq { grid-template-columns: 1fr 1fr; }

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px 14px;
}
.panel h2 {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.panel h2 span.sub {
  font-weight: 400;
  color: var(--faint);
  font-size: 12px;
}

/* funnel */
.funnel { display: flex; flex-direction: column; gap: 10px; }
.funnel-row {
  display: grid;
  grid-template-columns: 52px 1fr 64px;
  gap: 10px;
  align-items: center;
  font-size: 12px;
}
.funnel-row .lab { color: var(--muted); }
.funnel-row .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  font-weight: 500;
}
.track {
  height: 8px;
  background: var(--line-2);
  border-radius: 99px;
  overflow: hidden;
}
.fill { height: 100%; border-radius: 99px; }
.fill.lead { background: var(--lead); }
.fill.talk { background: var(--talk); }
.fill.won { background: var(--won); }
.fill.lost { background: #d6d3d1; }

/* mix */
.mix { display: flex; flex-direction: column; gap: 12px; }
.mix-bar {
  display: flex;
  height: 10px;
  border-radius: 99px;
  overflow: hidden;
  background: var(--line-2);
}
.mix-seg { height: 100%; }
.mix-seg.cloud { background: var(--cloud); }
.mix-seg.pay { background: var(--pay); }
.mix-seg.ads { background: var(--ads); }
.mix-legend {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.mix-item {
  display: grid;
  grid-template-columns: 10px 1fr auto auto;
  gap: 8px;
  align-items: center;
  font-size: 12px;
}
.dot { width: 8px; height: 8px; border-radius: 50%; }
.dot.cloud { background: var(--cloud); }
.dot.pay { background: var(--pay); }
.dot.ads { background: var(--ads); }
.mix-item .amt {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

/* activity */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  display: grid;
  grid-template-columns: 14px 1fr;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line-2);
}
.timeline li:last-child { border-bottom: 0; }
.tl-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  margin-top: 5px;
}
.tl-dot.sign { background: var(--won); }
.tl-dot.call { background: var(--talk); }
.tl-dot.meet { background: var(--pay); }
.tl-dot.mail { background: var(--cloud); }
.tl-text { color: var(--ink); }
.tl-meta { color: var(--faint); font-size: 11px; margin-top: 2px; }

.upcoming { list-style: none; margin: 0; padding: 0; }
.upcoming li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line-2);
  cursor: pointer;
}
.upcoming li:last-child { border-bottom: 0; }
.upcoming li:hover .up-name { color: var(--accent-2); }
.up-name { font-weight: 500; }
.up-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.up-date {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.up-date.warn { color: #b45309; font-weight: 600; }

/* ── filters / table ── */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}
.search {
  flex: 1;
  min-width: 200px;
  max-width: 320px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0 10px 0 32px;
  background: var(--card) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%238b939e' stroke-width='1.6'><circle cx='7' cy='7' r='5'/><path d='M11 11l3 3'/></svg>") 8px 50% no-repeat;
  color: var(--ink);
}
.search:focus { border-color: var(--accent); box-shadow: var(--focus); outline: none; }

select.flt, .btn {
  height: 34px;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: var(--radius-sm);
  padding: 0 10px;
  color: var(--ink);
  cursor: pointer;
}
.btn:hover { background: var(--canvas); }
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}
.btn-primary {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}
.btn-primary:hover { background: #2a2e38; }

.table-wrap {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: auto;
}
table.grid {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.grid th {
  text-align: left;
  font-weight: 500;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #fafbfc;
  white-space: nowrap;
  position: sticky;
  top: 0;
}
table.grid td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-2);
  vertical-align: middle;
}
table.grid tbody tr:nth-child(even) { background: #fafbfc; }
table.grid tbody tr { cursor: pointer; }
table.grid tbody tr:hover { background: #eef7f3; }
table.grid tbody tr:focus { background: #eef7f3; outline: none; }
table.grid .amt {
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  text-align: right;
}
table.grid .co {
  font-weight: 600;
}
table.grid .co small {
  display: block;
  font-weight: 400;
  color: var(--muted);
  font-size: 12px;
}
.muted { color: var(--muted); }
.right { text-align: right; }
.empty {
  padding: 36px 16px;
  text-align: center;
  color: var(--muted);
}

/* pills */
.pill {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.pill.lead { background: #f1f5f9; color: #475569; }
.pill.talk { background: #eff6ff; color: #1d4ed8; }
.pill.won  { background: #ecfdf5; color: #047857; }
.pill.lost { background: #fff7ed; color: #c2410c; }
.pill.cloud { background: #e0f2fe; color: #0369a1; }
.pill.pay   { background: #ffedd5; color: #c2410c; }
.pill.ads   { background: #ede9fe; color: #6d28d9; }

/* ── kanban ── */
.board {
  display: grid;
  grid-template-columns: repeat(4, minmax(220px, 1fr));
  gap: 12px;
  align-items: start;
  min-height: 420px;
}
.col {
  background: #eceef2;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  min-height: 360px;
  padding: 10px;
}
.col.is-over { outline: 2px dashed var(--accent); outline-offset: -2px; background: #e4f4ee; }
.col-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 4px 10px;
  font-weight: 600;
  font-size: 12px;
}
.col-hd .n {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 7px;
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
}
.deal {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 11px;
  margin-bottom: 8px;
  cursor: grab;
  box-shadow: var(--shadow);
}
.deal:active { cursor: grabbing; }
.deal:focus-visible { outline: 2px solid var(--accent); }
.deal-name { font-weight: 600; font-size: 13px; }
.deal-meta { color: var(--muted); font-size: 12px; margin: 4px 0 8px; }
.deal-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
}
.deal-amt { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ── drawer ── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(16, 18, 24, 0.32);
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.16s ease;
}
.overlay.is-on { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(440px, 100vw);
  background: var(--card);
  z-index: 60;
  transform: translateX(100%);
  transition: transform 0.2s ease;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.drawer.is-on { transform: translateX(0); }
.drawer-hd {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--line);
}
.drawer-hd h2 { margin: 0; font-size: 16px; }
.drawer-hd .legal { color: var(--muted); font-size: 12px; margin-top: 2px; }
.icon-btn {
  width: 32px; height: 32px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  color: var(--muted);
}
.icon-btn:hover { background: var(--canvas); color: var(--ink); }
.drawer-body {
  overflow: auto;
  padding: 16px 18px 28px;
  flex: 1;
}
.kv {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 6px 10px;
  font-size: 13px;
  margin-bottom: 16px;
}
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.sec { margin: 18px 0 8px; font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; }
.contact {
  padding: 10px 0;
  border-bottom: 1px solid var(--line-2);
}
.contact:last-child { border-bottom: 0; }
.contact .nm { font-weight: 600; }
.contact .tt { color: var(--muted); font-size: 12px; }
.contact a { color: var(--ink); text-decoration: none; }
.contact a:hover { color: var(--accent-2); text-decoration: underline; }

.note {
  padding: 10px 0;
  border-bottom: 1px solid var(--line-2);
}
.note .who { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.note p { margin: 0; }

.note-form textarea {
  width: 100%;
  min-height: 72px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  resize: vertical;
  background: #fafbfc;
}
.note-form textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
.note-form .row {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}

.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  font-size: 11px;
  background: var(--canvas);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  color: var(--muted);
}

.footer {
  padding: 18px 24px 22px;
  color: var(--faint);
  font-size: 11px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.footer button {
  background: none;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(16,18,24,.4);
  z-index: 25;
}

@media (max-width: 1100px) {
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-2.eq { grid-template-columns: 1fr; }
  .board { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    z-index: 30;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    width: var(--sidebar-w);
  }
  .sidebar.is-open { transform: translateX(0); }
  .menu-toggle { display: grid; place-items: center; }
  .topbar { padding-left: 52px; }
  .content { padding: 16px 14px 0; }
  .board { grid-template-columns: 1fr; }
  .kpi-value { font-size: 22px; }
  .sidebar-backdrop.is-on { display: block; }
}

[hidden] { display: none !important; }

table.grid th.right { text-align: right; }

@media (prefers-reduced-motion: reduce) {
  .drawer, .overlay, .sidebar { transition: none; }
}

.deal[draggable="true"] { user-select: none; }
