:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --sidebar: #0e1c2f;
  --sidebar-2: #13243c;
  --sidebar-hover: #1a3252;
  --sidebar-active: #1e3f66;
  --line-sidebar: rgba(255, 255, 255, 0.08);
  --text-on-dark: #e8eef6;
  --muted-on-dark: #8ea0b8;
  --accent: #1d4e89;
  --accent-hover: #163d6c;
  --accent-soft: #e8f0f8;
  --text: #1c2430;
  --text-2: #5b6675;
  --text-3: #8a94a3;
  --line: #e4e8ee;
  --ok: #217a45;
  --ok-bg: #eaf6ee;
  --warn: #9a6700;
  --warn-bg: #f8f1de;
  --danger: #b42318;
  --danger-bg: #f8eaea;
  --info: #1d4e89;
  --info-bg: #e8f0f8;
  --radius: 8px;
  --sidebar-w: 220px;
  --topbar-h: 56px;
  --ai-w: 352px;
  --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
}

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

button { cursor: pointer; }
a { color: inherit; }

/* ——— Login ——— */
.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 32px 16px;
  background: var(--sidebar);
}

.login__card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: 12px;
  padding: 36px 32px 28px;
  border: 1px solid var(--line);
}

.login__brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}

.login__brand h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.login__brand p {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-2);
}

.login__hint {
  margin: 0 0 20px;
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.6;
}

.login__meta {
  display: grid;
  gap: 8px;
  padding: 12px 14px;
  background: var(--bg);
  border-radius: 8px;
  margin-bottom: 20px;
  font-size: 12px;
  color: var(--text-2);
}

.login__meta span { color: var(--text); font-weight: 600; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border-radius: 6px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 500;
  background: var(--surface);
  color: var(--text);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
  height: 40px;
}

.btn-primary:hover { background: var(--accent-hover); }

.btn-ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--text-2);
}

.btn-ghost:hover { background: var(--bg); color: var(--text); }

.btn-text {
  background: transparent;
  color: var(--accent);
  height: auto;
  padding: 0;
}

.btn-sm { height: 30px; padding: 0 10px; font-size: 12px; }

.login__foot {
  margin: 18px 0 0;
  text-align: center;
  font-size: 12px;
  color: var(--text-3);
}

.login__foot a { color: var(--text-2); text-decoration: none; }
.login__foot a:hover { color: var(--accent); }

/* ——— App shell ——— */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr var(--ai-w);
  grid-template-rows: var(--topbar-h) 1fr;
  height: 100%;
  min-height: 100vh;
}

.app.ai-collapsed {
  grid-template-columns: var(--sidebar-w) 1fr;
}

.sidebar {
  grid-row: 1 / span 2;
  background: var(--sidebar);
  color: var(--text-on-dark);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line-sidebar);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--topbar-h);
  padding: 0 16px;
  border-bottom: 1px solid var(--line-sidebar);
}

.brand__mark {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.brand__name {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.06em;
}

.brand__sub {
  font-size: 10px;
  letter-spacing: 0.14em;
  color: var(--muted-on-dark);
  margin-top: 1px;
}

.nav {
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.nav__label {
  font-size: 11px;
  color: var(--muted-on-dark);
  padding: 10px 10px 6px;
  letter-spacing: 0.08em;
}

.nav__item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted-on-dark);
  font-size: 13px;
  text-align: left;
}

.nav__item svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.nav__item:hover { background: var(--sidebar-hover); color: var(--text-on-dark); }

.nav__item.is-active {
  background: var(--sidebar-active);
  color: #fff;
}

.nav__badge {
  margin-left: auto;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: #c2410c;
  color: #fff;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
}

.sidebar__user {
  padding: 12px 14px 16px;
  border-top: 1px solid var(--line-sidebar);
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #2a4d73;
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}

.sidebar__user small {
  display: block;
  color: var(--muted-on-dark);
  font-size: 11px;
  margin-top: 2px;
}

.topbar {
  grid-column: 2;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.app.ai-collapsed .topbar { grid-column: 2 / span 1; }

.crumb {
  font-size: 13px;
  color: var(--text-2);
  white-space: nowrap;
}

.crumb strong { color: var(--text); font-weight: 600; }

.search {
  flex: 1;
  max-width: 420px;
  height: 34px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text-3);
}

.search svg,
.icon-btn svg,
.nav__item svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.search input {
  border: 0;
  outline: 0;
  background: transparent;
  width: 100%;
  font-size: 13px;
  color: var(--text);
}

.topbar__right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.chip {
  font-size: 11px;
  color: var(--text-2);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-2);
  display: grid;
  place-items: center;
  font-size: 18px;
  line-height: 1;
  flex-shrink: 0;
}

.icon-btn:hover { background: var(--bg); color: var(--text); }
.icon-btn.is-on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.main {
  grid-column: 2;
  overflow: auto;
  padding: 20px 24px 32px;
}

.app.ai-collapsed .main { grid-column: 2; }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.page-head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.page-head p {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text-2);
}

.page-actions { display: flex; gap: 8px; flex-shrink: 0; }
.page-actions .btn { white-space: nowrap; }

/* ——— Cards / grids ——— */
.kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  width: 100%;
  font: inherit;
  color: inherit;
  text-align: left;
}

.kpi__label {
  font-size: 12px;
  color: var(--text-2);
}

.kpi__value {
  margin-top: 8px;
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.kpi__hint {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-3);
}

.kpi__hint.up { color: var(--ok); }
.kpi__hint.down { color: var(--danger); }
.kpi__hint.warn { color: var(--warn); }

.split {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 12px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 0;
}

.card__head h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.card__body { padding: 12px 16px 16px; }

.list { display: flex; flex-direction: column; gap: 8px; }

.list-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.list-row:last-child { border-bottom: 0; padding-bottom: 0; }

.list-row button.link {
  border: 0;
  background: none;
  padding: 0;
  color: var(--text);
  text-align: left;
  font-weight: 500;
}

.list-row button.link:hover { color: var(--accent); }

.list-row .meta {
  margin-top: 3px;
  color: var(--text-3);
  font-size: 12px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 5px;
  flex-shrink: 0;
  background: var(--text-3);
}

.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.danger { background: var(--danger); }
.dot.info { background: var(--info); }

.badge {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}

.badge-info { background: var(--info-bg); color: var(--info); }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-muted { background: var(--bg); color: var(--text-2); }

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.tabs {
  display: flex;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface);
}

.tabs button {
  height: 32px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  font-size: 12px;
  color: var(--text-2);
  border-right: 1px solid var(--line);
}

.tabs button:last-child { border-right: 0; }
.tabs button.is-on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.field {
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  font-size: 13px;
  color: var(--text);
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.data th {
  text-align: left;
  font-weight: 500;
  color: var(--text-2);
  font-size: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}

table.data td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: #f7f9fc; }
table.data tbody tr.is-clickable { cursor: pointer; }

.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 12px; }

/* ——— Org ——— */
.org-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 12px;
  min-height: 520px;
}

.tree-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  border: 0;
  background: transparent;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text);
  text-align: left;
}

.tree-item:hover { background: var(--bg); }
.tree-item.is-on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tree-item span { color: var(--text-3); font-size: 12px; font-weight: 400; }

/* ——— Projects ——— */
.projects {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.project {
  padding: 16px 18px;
}

.project__top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.project h3 { margin: 0; font-size: 15px; }
.project p { margin: 6px 0 12px; font-size: 13px; color: var(--text-2); line-height: 1.5; }

.bar {
  height: 8px;
  background: #e7edf3;
  border-radius: 99px;
  overflow: hidden;
}

.bar > i {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
}

.bar.warn > i { background: var(--warn); }
.bar.ok > i { background: var(--ok); }

.project__meta {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-3);
}

/* ——— Reports ——— */
.charts {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 12px;
}

.chart-caption {
  margin: 8px 0 0;
  font-size: 11px;
  color: var(--text-3);
}

.bars { display: flex; flex-direction: column; gap: 10px; }

.bars__row {
  display: grid;
  grid-template-columns: 72px 1fr 36px;
  gap: 8px;
  align-items: center;
  font-size: 12px;
  color: var(--text-2);
}

.bars__row b { font-weight: 500; color: var(--text); text-align: right; }

/* ——— Settings ——— */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.setting-row:last-child { border-bottom: 0; }
.setting-row p { margin: 4px 0 0; color: var(--text-3); font-size: 12px; }

.toggle {
  width: 36px;
  height: 20px;
  border-radius: 99px;
  border: 0;
  background: #cbd5e1;
  position: relative;
}

.toggle.is-on { background: var(--accent); }

.toggle i {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
}

.toggle.is-on i { left: 19px; }

/* ——— Drawer ——— */
.drawer-mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.28);
  z-index: 40;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(420px, 100%);
  height: 100%;
  background: var(--surface);
  border-left: 1px solid var(--line);
  z-index: 41;
  display: flex;
  flex-direction: column;
}

.drawer__head {
  height: 56px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.drawer__head h3 { margin: 0; font-size: 15px; }
.drawer__body { padding: 16px 18px; overflow: auto; flex: 1; }
.kv { display: grid; grid-template-columns: 88px 1fr; gap: 8px 12px; font-size: 13px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; }
.drawer__foot {
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ——— AI panel ——— */
.ai {
  grid-column: 3;
  grid-row: 1 / span 2;
  background: var(--surface);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.app.ai-collapsed .ai { display: none; }

.ai__head {
  height: var(--topbar-h);
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.ai__head h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.ai__head span {
  display: block;
  font-size: 11px;
  color: var(--text-3);
  font-weight: 400;
  margin-top: 2px;
}

.ai__msgs {
  flex: 1;
  overflow: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg {
  max-width: 100%;
  font-size: 13px;
  line-height: 1.55;
}

.msg.user { align-self: flex-end; }

.msg__bubble {
  display: inline-block;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  white-space: pre-wrap;
}

.msg.user .msg__bubble {
  background: var(--accent);
  color: #fff;
}

.msg__who {
  font-size: 11px;
  color: var(--text-3);
  margin-bottom: 4px;
}

.suggest {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 14px 10px;
}

.suggest button {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  color: var(--text-2);
}

.suggest button:hover { border-color: var(--accent); color: var(--accent); }

.ai__form {
  padding: 10px 12px 14px;
  border-top: 1px solid var(--line);
}

.ai__form form {
  display: flex;
  gap: 8px;
}

.ai__form textarea {
  flex: 1;
  resize: none;
  height: 64px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
  outline: none;
}

.ai__form textarea:focus { border-color: var(--accent); }

.ai__form .btn-primary { width: auto; height: 64px; padding: 0 14px; }

.ai__note {
  margin: 8px 2px 0;
  font-size: 11px;
  color: var(--text-3);
}

.typing {
  font-size: 12px;
  color: var(--text-3);
  padding: 0 4px;
}

.empty {
  padding: 28px 12px;
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
}

/* ——— Responsive ——— */
@media (max-width: 1200px) {
  .app { grid-template-columns: 72px 1fr var(--ai-w); }
  .brand__text, .nav__item span:not(.nav__badge), .sidebar__user div, .nav__label { display: none; }
  .nav__item { justify-content: center; }
  .nav__badge { display: none; }
  .sidebar__user { justify-content: center; }
  .kpis, .projects, .charts, .settings-grid, .split, .org-layout { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .app,
  .app.ai-collapsed {
    grid-template-columns: 1fr;
    grid-template-rows: 56px 48px 1fr;
  }
  .app .sidebar,
  .app.ai-collapsed .sidebar {
    grid-row: 2;
    grid-column: 1;
    flex-direction: row;
    overflow-x: auto;
    height: 48px;
    min-height: 48px;
    border-right: 0;
    border-bottom: 1px solid var(--line-sidebar);
  }
  .brand, .sidebar__user, .nav__label { display: none; }
  .nav { flex-direction: row; padding: 6px; gap: 4px; flex: none; }
  .nav__item { width: auto; padding: 0 12px; }
  .nav__item span { display: inline; }
  .nav__badge { display: inline-block; }
  .app .topbar,
  .app.ai-collapsed .topbar {
    grid-row: 1;
    grid-column: 1;
  }
  .app .main,
  .app.ai-collapsed .main {
    grid-row: 3;
    grid-column: 1;
    padding: 16px;
  }
  .ai {
    position: fixed;
    inset: 0 0 0 auto;
    width: min(360px, 100%);
    z-index: 30;
    grid-column: auto;
    grid-row: auto;
  }
  .app.ai-collapsed .ai { display: none; }
  .crumb { display: none; }
  .page-head { flex-direction: column; align-items: flex-start; }
  .search { max-width: none; }
  article.card { overflow-x: auto; }
  table.data { min-width: 720px; }
}
