:root {
  --bg: #f0f4f9;
  --surface: #ffffff;
  --surface-soft: #f7faff;
  --sidebar-bg: #111f38;
  --sidebar-hover: #1d3154;
  --sidebar-active: #2557c7;
  --text: #162844;
  --text-muted: #5a6f8a;
  --border: #d5e0ee;
  --border-soft: #e6eef7;
  --primary: #2557c7;
  --primary-hover: #1c44a3;
  --primary-soft: #e8f0ff;
  --green: #147a52;
  --green-soft: #dff5eb;
  --gold: #9a5b13;
  --gold-soft: #fff2db;
  --purple: #64379e;
  --purple-soft: #f0e8ff;
  --teal: #0f6b61;
  --teal-soft: #ddf5f2;
  --red: #c23030;
  --red-soft: #fdeaea;
  --shadow: 0 8px 24px rgba(17, 31, 56, 0.08);
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  overflow: hidden;
}

h1, h2, h3, h4, p { margin: 0; }
small, .muted { color: var(--text-muted); font-size: 12px; }

button, input, select, textarea {
  font: inherit;
  color: inherit;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 7px 11px;
  outline: none;
  transition: border-color .15s, background .15s, box-shadow .15s;
}
button { cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; }
button:hover:not(:disabled) { border-color: var(--primary); }
button:disabled { opacity: .45; cursor: not-allowed; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 87, 199, .14); }

.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-soft { background: var(--primary-soft); color: var(--primary); border-color: transparent; font-weight: 600; }
.btn-soft:hover:not(:disabled) { background: #d9e7ff; border-color: transparent; }
.btn-success { background: var(--green); color: #fff; border-color: var(--green); font-weight: 600; }
.btn-success:hover:not(:disabled) { background: #0f6241; border-color: #0f6241; }
.btn-danger { background: var(--red-soft); color: var(--red); border-color: transparent; }
.btn-danger:hover:not(:disabled) { background: #fad4d4; border-color: transparent; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { background: var(--border-soft); color: var(--text); border-color: transparent; }
.btn-sm { padding: 4px 9px; font-size: 12px; border-radius: 6px; }
.btn-icon { width: 28px; height: 28px; padding: 0; border-radius: 6px; font-size: 13px; }

/* App Shell */
.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  height: 100vh;
  width: 100vw;
}

/* Sidebar */
.sidebar {
  background: var(--sidebar-bg);
  color: #dbe6f7;
  display: flex;
  flex-direction: column;
  height: 100vh;
  border-right: 1px solid rgba(255,255,255,.08);
  overflow: hidden;
}
.brand {
  padding: 18px 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, #3b76f6, #18a596);
  color: #fff;
  font-weight: 800;
  font-size: 15px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.brand-text h1 { font-size: 15px; color: #fff; letter-spacing: .2px; }
.brand-text span { font-size: 11px; color: #8da4c8; display: block; }

.sidebar-admin-bar {
  padding: 10px 12px;
  background: rgba(37, 87, 199, .18);
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.sidebar-admin-bar span { font-size: 12px; color: #b7d0ff; font-weight: 600; }

.nav-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px;
}
.nav-section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: #7c95bc;
  padding: 6px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 11px;
  margin-bottom: 4px;
  border-radius: 9px;
  color: #cbd8ee;
  cursor: pointer;
  transition: background .15s, color .15s;
  user-select: none;
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; font-weight: 600; }
.nav-item.hidden-item { opacity: .48; border: 1px dashed rgba(255,255,255,.2); }
.nav-item .nav-icon { font-size: 15px; width: 20px; text-align: center; flex-shrink: 0; }
.nav-item .nav-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-badge {
  background: #e05252;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 99px;
}
.nav-controls {
  display: flex;
  gap: 2px;
}
.nav-controls button {
  background: rgba(255,255,255,.1);
  border: 0;
  color: #fff;
  width: 22px;
  height: 22px;
  padding: 0;
  font-size: 11px;
  border-radius: 5px;
}
.nav-controls button:hover { background: rgba(255,255,255,.24); }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid rgba(255,255,255,.08);
  background: rgba(0,0,0,.15);
}
.user-card {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 8px;
}
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #2b4570;
  color: #fff;
  font-weight: 700;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.user-meta { flex: 1; min-width: 0; }
.user-meta b { display: block; font-size: 13px; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta span { font-size: 11px; color: #9cb3d6; }
.role-pill {
  display: inline-block;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 99px;
  font-weight: 700;
  margin-left: 4px;
}
.role-admin { background: #3b76f6; color: #fff; }
.role-user { background: #18996e; color: #fff; }
.role-boss { background: #d48a20; color: #fff; }

/* Main area */
.main-wrap {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-width: 0;
  overflow: hidden;
}
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-left h2 { font-size: 18px; }
.demo-pill {
  background: var(--gold-soft);
  color: var(--gold);
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 99px;
}
.topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.content-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 18px 22px 32px;
}

/* Cards & Panels */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

/* Product / Sub Tabs */
.tabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.tab-btn {
  background: #e4ecf8;
  border-color: transparent;
  color: #395070;
  font-weight: 600;
  padding: 7px 15px;
  border-radius: 9px;
}
.tab-btn.active {
  background: var(--primary);
  color: #fff;
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  position: relative;
  overflow: hidden;
}
.kpi-card::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--primary);
}
.kpi-card.green::before { background: var(--green); }
.kpi-card.gold::before { background: #d88924; }
.kpi-card.teal::before { background: var(--teal); }
.kpi-label { font-size: 12px; color: var(--text-muted); }
.kpi-value { font-size: 26px; font-weight: 800; margin: 4px 0 2px; color: var(--text); }
.kpi-sub { font-size: 12px; color: var(--text-muted); }

/* Charts Layout */
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
.grid-asym { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 14px; margin-bottom: 14px; }

.ring-wrap { display: flex; flex-direction: column; align-items: center; padding: 10px 0; }
.ring {
  width: 144px;
  height: 144px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  position: relative;
  background: conic-gradient(var(--primary) var(--share, 60%), #e4ebf5 0);
}
.ring::before {
  content: "";
  position: absolute;
  inset: 16px;
  background: var(--surface);
  border-radius: 50%;
}
.ring-inner { position: relative; text-align: center; }
.ring-inner b { display: block; font-size: 28px; line-height: 1.1; }

.bar-row { margin-top: 10px; }
.bar-track { height: 8px; background: #e8eff8; border-radius: 99px; overflow: hidden; margin-top: 5px; }
.bar-fill { height: 100%; border-radius: 99px; transition: width .3s; }

.plot-bars {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 2px 4px;
}
.plot-col {
  flex: 1;
  min-width: 78px;
  text-align: center;
  padding: 8px 6px;
  border-radius: 9px;
  border: 1px solid var(--border-soft);
  background: var(--surface-soft);
}
.plot-pair {
  height: 92px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 6px;
  margin: 8px 0 6px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 2px;
}
.plot-pair i { display: block; width: 16px; border-radius: 4px 4px 0 0; }
.bar-goal { background: #bfd2ef; }
.bar-actual { background: var(--primary); }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; min-width: 860px; }
th, td { padding: 10px 11px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
th { background: #f2f6fd; font-size: 13px; color: #364c6b; font-weight: 700; white-space: nowrap; }
tbody tr:hover { background: #f7faff; }

/* Tags */
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.tag-blue { background: var(--primary-soft); color: var(--primary); }
.tag-green { background: var(--green-soft); color: var(--green); }
.tag-gold { background: var(--gold-soft); color: var(--gold); }
.tag-purple { background: var(--purple-soft); color: var(--purple); }
.tag-teal { background: var(--teal-soft); color: var(--teal); }
.tag-gray { background: #edf1f6; color: #475a75; }
.tag-red { background: var(--red-soft); color: var(--red); }

/* Cards list */
.cards-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.item-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-soft);
  padding: 12px 14px;
}
.item-card.project-card { background: var(--surface); border-top: 3px solid var(--primary); }
.meta-box {
  background: #f1f6fe;
  border-radius: 8px;
  padding: 8px 10px;
  margin: 8px 0;
  font-size: 13px;
}
.meta-box p { margin: 3px 0; }

/* Annotation Drawer */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 31, 56, .35);
  z-index: 40;
}
.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(420px, 94vw);
  background: var(--surface);
  z-index: 41;
  box-shadow: -8px 0 30px rgba(17, 31, 56, .18);
  display: flex;
  flex-direction: column;
}
.drawer-header {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 18px;
}
.note-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  margin-bottom: 10px;
  background: var(--surface-soft);
}
.note-card.resolved { opacity: .75; background: #f8fbf9; }

/* Dialogs */
dialog {
  width: min(620px, calc(100% - 24px));
  max-height: 90vh;
  border: 0;
  border-radius: 14px;
  padding: 20px;
  box-shadow: 0 18px 48px rgba(17, 31, 56, .25);
  color: var(--text);
}
dialog::backdrop { background: rgba(17, 31, 56, .48); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; color: #314664; }
.form-grid .wide { grid-column: 1 / -1; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* Toast */
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: #142645;
  color: #fff;
  padding: 9px 16px;
  border-radius: 99px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,.22);
  z-index: 90;
  animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

.hidden { display: none !important; }

@media (max-width: 960px) {
  .app-shell { grid-template-columns: 210px minmax(0, 1fr); }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-asym, .grid-2, .cards-2 { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
  body { overflow: auto; }
  .app-shell { grid-template-columns: 1fr; height: auto; }
  .sidebar { height: auto; }
  .main-wrap { height: auto; }
  .form-grid { grid-template-columns: 1fr; }
}


/* Point-and-Click Pin Annotation Mode */
.pin-banner {
  background: linear-gradient(90deg, #fff5e2, #ffebc7);
  border-bottom: 1px solid #f0c97d;
  color: #7c470b;
  padding: 8px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  font-weight: 600;
}
.content-scroll { position: relative; }
body.pin-mode-active #mainContent { cursor: crosshair; }
body.pin-mode-active #mainContent .panel:hover,
body.pin-mode-active #mainContent .kpi-card:hover,
body.pin-mode-active #mainContent .item-card:hover,
body.pin-mode-active #mainContent .plot-col:hover,
body.pin-mode-active #mainContent tr:hover,
body.pin-mode-active #mainContent button:hover {
  outline: 2px dashed #d88924;
  outline-offset: 2px;
}
.pin-layer {
  position: absolute;
  top: 0; left: 0; right: 0;
  pointer-events: none;
  z-index: 25;
}
.pin-marker {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 28px;
  height: 28px;
  border-radius: 50% 50% 50% 0;
  background: #e06d1b;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  display: grid;
  place-items: center;
  border: 2px solid #fff;
  box-shadow: 0 4px 12px rgba(224, 109, 27, .45);
  pointer-events: auto;
  cursor: pointer;
  transition: transform .15s;
}
.pin-marker:hover { transform: translate(-50%, -50%) scale(1.16); z-index: 30; }
.pin-marker.resolved { background: #147a52; box-shadow: 0 4px 12px rgba(20, 122, 82, .35); }
.pin-marker.pulse { animation: pinPulse 1.1s ease 3; }
@keyframes pinPulse {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50% { transform: translate(-50%, -50%) scale(1.38); box-shadow: 0 0 0 10px rgba(224, 109, 27, .25); }
}
.pin-popover {
  position: fixed;
  z-index: 60;
  width: min(340px, calc(100vw - 24px));
  background: #fff;
  border: 1px solid #d5e0ee;
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(17, 31, 56, .24);
  padding: 13px 14px;
}
.pin-target-chip {
  background: #fff3dd;
  color: #8a4f0e;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  margin: 6px 0 8px;
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
