:root {
  --bg: #0b0d12;
  --panel: #12151c;
  --panel-2: #171b24;
  --accent: #6d7cff;
  --accent-dim: rgba(109, 124, 255, 0.16);
  --accent-glow: rgba(109, 124, 255, 0.38);
  --text: #e8eaef;
  --muted: #8b90a0;
  --faint: #5c6272;
  --line: #1e2330;
  --line-2: #2a3142;
  --ok: #3dd68c;
  --warn: #f5c14a;
  --bad: #ff6b7a;
  --sidebar-w: 220px;
  --drawer-w: 420px;
  --top: 52px;
  --font: "Sora", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --radius: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body, #app { height: 100%; height: 100dvh; }
body {
  font: 13px/1.45 var(--font);
  background: var(--bg);
  color: var(--text);
  letter-spacing: -0.01em;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100%;
}

.sidebar {
  background: #0e1117;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 16px 12px 12px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 18px;
}
.mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(160deg, #8b97ff, #5463e8);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.08), 0 8px 18px var(--accent-glow);
  display: grid;
  place-items: center;
}
.mark svg { display: block; }
.brand-name {
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.08em;
}
.brand-sub {
  font-size: 10px;
  color: var(--faint);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 8px 10px;
  border-radius: 8px;
}
.nav-btn:hover { background: var(--panel-2); color: var(--text); }
.nav-btn.active {
  background: var(--accent-dim);
  color: #dfe3ff;
}
.nav-btn .ico { width: 16px; opacity: 0.9; }
.nav-btn .count {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--faint);
}
.nav-btn.active .count { color: var(--accent); }

.sidebar-foot {
  margin-top: auto;
  padding: 12px 8px 4px;
  border-top: 1px solid var(--line);
}
.user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 4px 8px;
}
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #2c3348;
  color: #cdd3ff;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 600;
}
.user-name { font-weight: 500; }
.user-role { font-size: 11px; color: var(--faint); }
.reset {
  width: 100%;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 8px;
  padding: 7px 8px;
  margin-top: 6px;
}
.reset:hover { border-color: var(--line-2); color: var(--text); }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar {
  height: var(--top);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 13, 18, 0.86);
  backdrop-filter: blur(10px);
}
.crumb { color: var(--faint); font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; min-width: 88px; }
.search {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  height: 34px;
  max-width: 520px;
}
.search input {
  flex: 1;
  background: transparent;
  border: 0;
  outline: none;
  color: var(--text);
}
.search kbd, .hint kbd, .palette kbd {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--faint);
  border: 1px solid var(--line-2);
  border-radius: 4px;
  padding: 1px 5px;
  background: #0d1016;
}
.top-actions { margin-left: auto; display: flex; gap: 8px; }
.btn {
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 12px;
  height: 34px;
}
.btn:hover { border-color: #3a4358; }
.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: #0b0d12;
  font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--bad); border-color: #3a2430; }

.content {
  flex: 1;
  overflow: auto;
  padding: 18px 20px 28px;
  min-height: 0;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.kpi {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 14px 10px;
  min-height: 118px;
}
.kpi-label { color: var(--muted); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; }
.kpi-val {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 500;
  margin: 8px 0 4px;
  letter-spacing: -0.03em;
}
.kpi-delta { font-size: 11px; color: var(--ok); }
.kpi-delta.down { color: var(--bad); }
.spark { width: 100%; height: 36px; display: block; margin-top: 4px; }

.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 12px; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-h {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.list { display: flex; flex-direction: column; }
.row-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  background: transparent;
  width: 100%;
  text-align: left;
  border-left: 0;
  border-right: 0;
  border-top: 0;
  border-radius: 0;
}
.row-item:last-child { border-bottom: 0; }
.row-item:hover { background: var(--panel-2); }
.row-item .t { font-weight: 500; }
.row-item .s { color: var(--faint); font-size: 12px; margin-top: 2px; }
.tag {
  font-family: var(--mono);
  font-size: 10px;
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--accent-dim);
  color: #c5ccff;
  white-space: nowrap;
}
.tag.warn { background: rgba(245, 193, 74, 0.12); color: #f5c14a; }
.tag.bad { background: rgba(255, 107, 122, 0.12); color: #ff6b7a; }
.tag.ok { background: rgba(61, 214, 140, 0.12); color: #3dd68c; }
.tag.muted { background: #1a1f2a; color: var(--muted); }

.kanban {
  display: grid;
  grid-template-columns: repeat(7, minmax(210px, 1fr));
  gap: 10px;
  min-width: 1540px;
  align-items: start;
}
.col {
  background: #0e1218;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  min-height: calc(100vh - 110px);
}
.col.over { outline: 1px dashed var(--accent); outline-offset: -2px; }
.col-h {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 10px 8px;
  position: sticky;
  top: 0;
  background: #0e1218;
  z-index: 1;
}
.col-h b { font-weight: 500; font-size: 12px; }
.col-h span { font-family: var(--mono); font-size: 10px; color: var(--faint); }
.deal {
  margin: 0 8px 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  cursor: grab;
  text-align: left;
  width: calc(100% - 16px);
  display: block;
}
.deal:hover { border-color: #3a4460; }
.deal:active { cursor: grabbing; }
.deal .amt { font-family: var(--mono); color: #cfd6ff; margin-top: 6px; }
.deal .meta { display: flex; justify-content: space-between; color: var(--faint); font-size: 11px; margin-top: 8px; }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th {
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--faint);
  font-weight: 500;
  background: #10141b;
  position: sticky;
  top: 0;
}
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--panel-2); }
td.mono, .mono { font-family: var(--mono); }
.health { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.health.green { background: var(--ok); }
.health.amber { background: var(--warn); }
.health.red { background: var(--bad); }

.timeline { display: flex; flex-direction: column; gap: 0; }
.act {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  margin-top: 5px;
}
.act .when { color: var(--faint); font-family: var(--mono); font-size: 11px; }

.form { display: grid; gap: 8px; padding: 14px; }
.form.inline { grid-template-columns: 1fr 1fr; }
label { display: grid; gap: 5px; color: var(--muted); font-size: 11px; }
label.span2 { grid-column: 1 / -1; }
input, select, textarea {
  background: #0d1016;
  border: 1px solid var(--line-2);
  border-radius: 7px;
  padding: 8px 9px;
  outline: none;
}
textarea { min-height: 72px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }

.charts { display: grid; grid-template-columns: 1.3fr 0.9fr; gap: 12px; }
.chart-box { padding: 8px 12px 16px; }
.legend { display: flex; flex-wrap: wrap; gap: 10px 16px; padding: 0 14px 14px; color: var(--muted); font-size: 12px; }
.swatch { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }

.seq-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.seq { padding: 14px; }
.seq h3 { font-size: 14px; font-weight: 500; margin-bottom: 4px; }
.steps { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.step {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px;
  background: #0e1218;
  border-radius: 8px;
  border: 1px solid var(--line);
}
.n {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--accent-dim);
  color: #c5ccff;
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-size: 11px;
}

.drawer-back {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 10, 0.55);
  z-index: 20;
}
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: var(--drawer-w);
  height: 100%;
  background: var(--panel);
  border-left: 1px solid var(--line);
  z-index: 21;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}
.drawer-h {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--line);
}
.drawer-h h2 { font-size: 16px; font-weight: 600; }
.drawer-b { flex: 1; overflow: auto; }
.drawer-f {
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.section { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.section h4 { font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--faint); margin-bottom: 10px; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 8px; }
.kv dt { color: var(--faint); }
.mini { padding: 8px 0; border-bottom: 1px solid var(--line); }
.mini:last-child { border-bottom: 0; }

.palette-back {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 10, 0.62);
  z-index: 30;
  display: flex;
  justify-content: center;
  padding-top: 12vh;
}
.palette {
  width: min(560px, calc(100% - 32px));
  background: #141822;
  border: 1px solid var(--line-2);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
  height: fit-content;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
}
.palette input {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  padding: 14px 16px;
  font-size: 14px;
  background: transparent;
}
.palette-list { overflow: auto; }
.pal-item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 10px 16px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--text);
}
.pal-item.active, .pal-item:hover { background: var(--accent-dim); }
.pal-item .hint { color: var(--faint); }

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #1a2030;
  border: 1px solid var(--line-2);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 8px;
  z-index: 40;
  box-shadow: var(--shadow);
  font-size: 12px;
}

.empty { color: var(--faint); padding: 20px; text-align: center; }

@media (max-width: 1100px) {
  .kpis, .grid-2, .charts, .seq-grid { grid-template-columns: 1fr; }
  .form.inline { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .sidebar {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .brand { padding: 0 4px 0 0; }
  .brand-sub { display: none; }
  .nav {
    flex-direction: row;
    overflow-x: auto;
    width: 100%;
    order: 3;
    scrollbar-width: none;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav-btn { width: auto; flex: none; white-space: nowrap; }
  .nav-btn .count { display: none; }
  .sidebar-foot { display: none; }
  .topbar { flex-wrap: wrap; height: auto; gap: 8px; padding: 8px 10px; }
  .crumb { min-width: 0; }
  .search { max-width: none; width: 100%; order: 3; }
  .drawer, .drawer-b {
    width: 100%;
    max-width: 100%;
  }
  .drawer {
    right: 0;
    left: 0;
  }
}
