:root {
  --bg: #eef2f7;
  --panel: #ffffff;
  --ink: #1e293b;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-2: #0d9488;
  --line: #e2e8f0;
  --sidebar: #f8fafc;
  --sidebar-ink: #334155;
  --sidebar-muted: #94a3b8;
  --sidebar-hover: #f1f5f9;
  --sidebar-active: #eff6ff;
  --sidebar-active-ink: #1d4ed8;
  --header-bg: linear-gradient(90deg, #1e4db7 0%, #2563eb 100%);
  --header-ink: #f8fafc;
  --danger: #dc2626;
  --radius: 10px;
  --shadow: 0 8px 24px rgba(30, 41, 59, .06);
  --header-h: 52px;
  --nav-w: 232px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; font-size: 16px; }
a { color: var(--accent); }
:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 65%, white);
  outline-offset: 2px;
}
::selection { background: color-mix(in srgb, var(--accent) 28%, white); }
#app-shell { min-height: 100%; display: grid; grid-template-rows: var(--header-h) 1fr; }
.app-header {
  display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
  padding: 0 1rem; background: var(--header-bg); color: var(--header-ink);
  position: sticky; top: 0; z-index: 30;
  box-shadow: 0 1px 0 rgba(255,255,255,.08);
}
.app-header .brand { font-weight: 700; letter-spacing: .02em; }
.app-header .brand small { display: block; font-weight: 400; opacity: .75; font-size: .72rem; }
.app-header a { color: var(--header-ink); text-decoration: none; opacity: .92; }
.app-header a:hover { opacity: 1; text-decoration: underline; }
.app-header .spacer { flex: 1; }
.app-header .org-name { font-size: .85rem; opacity: .92; max-width: 8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-header .org-breadcrumb {
  font-size: .78rem; opacity: .9; max-width: 16rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--header-ink);
}
.app-header .org-breadcrumb span { opacity: .65; margin: 0 .2rem; }
.app-header select#orgSwitch { background: #fff; color: var(--ink); max-width: 9.5rem; }
.app-header input, .app-header button, .app-header select {
  border-radius: 8px; border: 1px solid transparent; padding: .4rem .65rem; min-height: 36px;
}
.app-header button { background: rgba(255,255,255,.18); color: #fff; cursor: pointer; border: 1px solid rgba(255,255,255,.25); }
.app-header button:hover { background: rgba(255,255,255,.28); }
.app-body { display: grid; grid-template-columns: var(--nav-w) 1fr; min-height: calc(100vh - var(--header-h)); }
.side-nav {
  background: var(--sidebar); color: var(--sidebar-ink);
  padding: .65rem .45rem 1.5rem;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  box-shadow: inset -1px 0 0 rgba(148, 163, 184, .25);
}
.nav-search-wrap { padding: .15rem .35rem .55rem; }
.nav-search-wrap input {
  width: 100%; border: 1px solid var(--line); border-radius: 8px;
  padding: .4rem .55rem; background: #fff; color: var(--ink); font-size: .85rem;
}
.side-nav .group {
  margin: .9rem .55rem .3rem; font-size: .7rem; font-weight: 650;
  letter-spacing: .04em; text-transform: uppercase; color: var(--sidebar-muted);
}
.side-nav .group.nav-hidden, .side-nav a.nav-hidden { display: none; }
.side-nav a {
  display: block; color: inherit; text-decoration: none; padding: .5rem .75rem;
  border-radius: 8px; margin: .12rem .2rem;
  transition: background .15s ease, color .15s ease;
}
.side-nav a:hover {
  background: var(--sidebar-hover); color: var(--ink);
}
.side-nav a.active {
  background: var(--sidebar-active); color: var(--sidebar-active-ink);
  font-weight: 650;
  box-shadow: inset 3px 0 0 var(--accent);
}
.content {
  padding: 1rem 1.1rem 2rem; overflow-x: hidden;
  background: linear-gradient(180deg, #f5f7fb 0%, var(--bg) 120px);
}
.panel {
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--line);
  padding: 1rem 1.1rem; margin-bottom: 1rem;
}
.panel h2 { margin: 0 0 .75rem; font-size: 1.15rem; }
.panel p.lead { margin: 0 0 1rem; color: var(--muted); }
.row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; }
.field { display: flex; flex-direction: column; gap: .25rem; min-width: 140px; flex: 1; }
.field label { font-size: .8rem; color: var(--muted); }
.field input, .field select, .toolbar input, .toolbar select {
  border: 1px solid var(--line); border-radius: 8px; padding: .45rem .6rem; background: #fff;
}
.btn {
  border: 0; border-radius: 8px; padding: .5rem .85rem; background: var(--accent); color: #fff;
  cursor: pointer; touch-action: manipulation; min-height: 40px;
}
.btn.secondary { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: var(--danger); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.grid-cards {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .75rem;
}
.stat {
  background: linear-gradient(145deg, #f8fafc, #f1f5f9); border: 1px solid var(--line);
  border-radius: 10px; padding: .85rem; min-width: 0;
}
.stat .k { font-size: .8rem; color: var(--muted); }
.stat .v {
  font-size: 1.2rem; font-weight: 700; margin-top: .2rem;
  word-break: break-word; overflow-wrap: anywhere; line-height: 1.35;
  max-height: 4.2em; overflow: hidden;
}
.stat .v.chips {
  display: flex; flex-wrap: wrap; gap: .3rem; align-items: center;
  max-height: 5.5em; overflow: auto; font-size: .85rem; font-weight: 600;
}
.chip {
  display: inline-flex; align-items: center; max-width: 100%;
  padding: .12rem .45rem; border-radius: 999px;
  background: #e8f1ff; color: var(--accent); font-size: .75rem; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chip.muted { background: #eef2f7; color: var(--muted); }
.cell-clip {
  max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cell-wrap { max-width: 360px; word-break: break-word; overflow-wrap: anywhere; white-space: normal; }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; table-layout: fixed; }
table.data th, table.data td { border-bottom: 1px solid var(--line); padding: .55rem .4rem; text-align: left; vertical-align: top; }
table.data th { color: var(--muted); font-weight: 600; }
pre.out, .out {
  background: #f6f8fb; border: 1px solid var(--line); border-radius: 8px;
  padding: .75rem; overflow: auto; font-size: .8rem; max-height: 360px; white-space: pre-wrap;
}
.login-gate {
  max-width: 420px; margin: 3rem auto; background: var(--panel); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.4rem; border: 1px solid var(--line);
}
.toast {
  position: fixed; right: 1rem; bottom: 1rem; background: #1e293b; color: #fff;
  padding: .7rem 1rem; border-radius: 10px; z-index: 50; display: none;
}
.toast.show { display: block; }
.toast.err { background: #b42318; }
.login-gate code { background:#eef2f7; padding:0 .3rem; border-radius:4px; }
.badge { display: inline-block; padding: .15rem .45rem; border-radius: 999px; background: #e8f1ff; color: var(--accent); font-size: .75rem; }
.result-box {
  background: #f7fafc; border: 1px solid var(--line); border-radius: 10px;
  padding: .75rem .9rem; margin-top: .75rem;
}
.result-box .ok { color: var(--accent-2); font-weight: 600; }
.result-box .warn { color: #b54708; font-weight: 600; }
.toolbar-card {
  background: #f8fafc; border: 1px solid var(--line); border-radius: 8px;
  padding: .4rem .55rem; margin-bottom: .45rem;
}
.toolbar-card h3 { margin: 0 0 .28rem; font-size: .84rem; }
.filter-chips { display: flex; flex-wrap: wrap; gap: .28rem; margin: .3rem 0 .15rem; }
.filter-chips button {
  border: 1px solid var(--line); background: #fff; border-radius: 999px;
  padding: .12rem .55rem; font-size: .78rem; cursor: pointer; color: inherit;
}
.filter-chips button.active { background: #e8f1ff; border-color: #9ec5fe; color: var(--accent); }
.table-scroll { overflow: auto; max-height: 28rem; border: 1px solid var(--line); border-radius: 8px; }
/* sticky thead */
table.data thead th {
  position: sticky; top: 0; z-index: 1; background: #f4f7fb;
  box-shadow: inset 0 -1px 0 var(--line);
}
.status-tabs { display: flex; flex-wrap: wrap; gap: .28rem; margin: .2rem 0 .35rem; }
.status-tabs .status-tab {
  border: 1px solid var(--line); background: #fff; border-radius: 8px 8px 0 0;
  padding: .22rem .65rem; font-size: .8rem; cursor: pointer; min-height: 32px; color: inherit;
}
.status-tabs .status-tab.active {
  color: var(--accent); font-weight: 700; box-shadow: inset 0 -2px 0 var(--accent);
}
.list-toolbar {
  display: flex; flex-wrap: wrap; gap: .35rem; align-items: center;
  padding: .28rem .4rem; margin-bottom: .35rem;
  background: #f4f7fb; border: 1px solid var(--line); border-radius: 8px;
}
.list-toolbar .btn { min-height: 32px; padding: .22rem .6rem; font-size: .82rem; }
.quick-links { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: .5rem; margin-top: .85rem; }
.quick-links a {
  display: block; padding: .65rem .7rem; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; text-decoration: none; color: var(--ink); font-weight: 650;
}
.quick-links a small { display: block; font-weight: 400; color: var(--muted); margin-top: .12rem; font-size: .75rem; }
.fav-tiles {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: .55rem;
}
.fav-tile {
  display: flex; flex-direction: column; align-items: center; gap: .4rem;
  padding: .7rem .4rem; border-radius: 12px; background: #fff; border: 1px solid var(--line);
  text-decoration: none; color: var(--ink); font-size: .8rem; font-weight: 600; text-align: center;
  cursor: grab;
}
.fav-tile:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.fav-tile.dragging { opacity: .45; border-style: dashed; }
.fav-tile.drag-over { border-color: var(--accent); background: var(--sidebar-active); }
.fav-ico {
  width: 40px; height: 40px; border-radius: 10px;
  background: linear-gradient(145deg, #dbeafe, #93c5fd);
}
.fav-tile.tone-orange .fav-ico { background: linear-gradient(145deg, #ffedd5, #fb923c); }
.fav-tile.tone-pink .fav-ico { background: linear-gradient(145deg, #fce7f3, #f472b6); }
.fav-tile.tone-cyan .fav-ico { background: linear-gradient(145deg, #cffafe, #22d3ee); }
.fav-tile.tone-green .fav-ico { background: linear-gradient(145deg, #d1fae5, #34d399); }
.fav-tile.tone-blue .fav-ico { background: linear-gradient(145deg, #dbeafe, #60a5fa); }
:root[data-theme="sky-blue"] {
  --accent: #2563eb; --sidebar: #f8fafc; --sidebar-ink: #334155;
  --sidebar-active: #eff6ff; --sidebar-active-ink: #1d4ed8;
  --header-bg: linear-gradient(90deg, #1e4db7 0%, #2563eb 100%);
}
:root[data-theme="eye-gold"] {
  --accent: #b45309; --sidebar: #fffbeb; --sidebar-ink: #78350f;
  --sidebar-hover: #fef3c7; --sidebar-active: #fef3c7; --sidebar-active-ink: #92400e;
  --sidebar-muted: #d97706;
  --header-bg: linear-gradient(90deg, #b45309 0%, #d97706 100%);
  --header-ink: #fffbeb;
}
:root[data-theme="classic-purple"] {
  --accent: #7c3aed; --sidebar: #faf5ff; --sidebar-ink: #5b21b6;
  --sidebar-hover: #f3e8ff; --sidebar-active: #f3e8ff; --sidebar-active-ink: #6d28d9;
  --sidebar-muted: #a78bfa;
  --header-bg: linear-gradient(90deg, #6d28d9 0%, #7c3aed 100%);
  --header-ink: #faf5ff;
}
.msg-link { color: inherit; text-decoration: none; position: relative; margin-right: .35rem; }
.msg-bell { font-size: 1rem; line-height: 1; }
.msg-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.1rem; height: 1.1rem; padding: 0 .25rem; margin-left: .15rem;
  border-radius: 999px; background: #e11d48; color: #fff; font-size: .65rem; font-weight: 700;
  vertical-align: super;
}
.home-panels { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .75rem; margin-top: .85rem; }
.home-card {
  background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: .75rem .85rem;
}
.home-card h4 { margin: 0 0 .45rem; font-size: .92rem; }
.home-card ul { margin: 0; padding-left: 1.1rem; color: var(--muted); font-size: .84rem; }
.home-card .kpi-row { display: flex; gap: .75rem; flex-wrap: wrap; }
.home-card .kpi-row span { font-size: .82rem; color: var(--ink); }
.home-card .kpi-row b { font-size: 1.05rem; margin-right: .2rem; }
.org-tree { font-size: .84rem; line-height: 1.55; }
.org-tree details { margin-left: .55rem; }
.org-tree summary { cursor: pointer; }
.timeline { border-left: 2px solid var(--line); margin: .55rem 0 .2rem .35rem; padding-left: .75rem; }
.tl-item { margin: .28rem 0; font-size: .86rem; }
.tl-item span { color: var(--muted); margin-left: .35rem; }
.bos-layout-fields { display: flex; flex-wrap: wrap; gap: .45rem; margin-top: .45rem; }
.empty-state { text-align: center; padding: 1.1rem .6rem 1.2rem; color: var(--muted); }
.empty-art {
  width: 72px; height: 52px; margin: 0 auto .45rem; border-radius: 10px;
  background:
    radial-gradient(circle at 22px 18px, #c5d7f2 0 8px, transparent 9px),
    linear-gradient(#d7e3f4, #d7e3f4) 18px 34px / 36px 4px no-repeat,
    linear-gradient(#e7eef8, #e7eef8);
  border: 1px dashed #c5d4e8;
}
.empty-title { color: var(--ink); font-weight: 700; margin-bottom: .2rem; }
.section-title { margin: 1rem 0 .45rem; font-size: 1rem; }
.tabs { display:flex; flex-wrap:wrap; gap:.35rem; margin-bottom:.85rem; border-bottom:1px solid var(--line); padding-bottom:.45rem; }
.tabs button {
  border:1px solid var(--line); background:#fff; color:var(--ink); border-radius:8px 8px 0 0;
  padding:.45rem .8rem; cursor:pointer; min-height:36px;
}
.tabs button.active { background:var(--accent); color:#fff; border-color:var(--accent); }
.tab-pane { display:none; }
.tab-pane.active { display:block; }
.cash-pane { display:none; }
.cash-pane.active { display:block; }
.designer-frame { width:100%; min-height:720px; border:1px solid var(--line); border-radius:10px; background:#fff; }
.form-actions { display:flex; flex-wrap:wrap; gap:.5rem; margin-top:.65rem; }
@media (max-width: 900px) {
  .app-body { grid-template-columns: 1fr; }
  .side-nav {
    display: flex; gap: .25rem; overflow-x: auto; padding: .5rem;
    position: sticky; top: var(--header-h); z-index: 20;
    border-right: 0; border-bottom: 1px solid var(--line);
    background: var(--sidebar);
  }
  .side-nav .group { display: none; }
  .side-nav a { white-space: nowrap; margin: 0; }
  .content { padding: .75rem; }
  .field { min-width: 100%; }
  .btn, .field input, .field select { width: 100%; }
  .app-header .org-breadcrumb { display: none; }
}
