:root {
  --bg: #eef2ec;
  --surface: #ffffff;
  --surface-soft: #f7f8f5;
  --ink: #17231d;
  --muted: #66736c;
  --line: #d9dfda;
  --line-strong: #c8d0ca;
  --green: #1d6b4f;
  --green-dark: #134936;
  --green-soft: #e2efe8;
  --lime: #b7d59d;
  --danger: #a33b35;
  --danger-soft: #f7e5e3;
  --sidebar: #0d1712;
  --sidebar-ink: #eef5f0;
  --sidebar-muted: #91a49a;
  --shadow: 0 10px 30px rgba(30, 48, 38, 0.08);
  --radius: 14px;
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.mobile-only { display: none; }

.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 30;
  display: flex;
  width: 258px;
  flex-direction: column;
  padding: 22px 18px 18px;
  background: var(--sidebar);
  color: var(--sidebar-ink);
  border-right: 1px solid rgba(255,255,255,.07);
}
.brand-row { display: flex; align-items: center; gap: 12px; min-height: 46px; }
.brand-row > div:nth-child(2) { display: grid; }
.brand-row strong { font-size: 18px; letter-spacing: -.02em; }
.brand-row small { color: var(--sidebar-muted); margin-top: 2px; }
.brand-mark {
  position: relative;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 11px;
  background: #12231a;
}
.brand-mark span { position: absolute; display: block; border-radius: 999px; background: var(--lime); }
.brand-mark span:nth-child(1) { width: 7px; height: 20px; left: 10px; bottom: 8px; transform: rotate(-18deg); }
.brand-mark span:nth-child(2) { width: 7px; height: 15px; left: 19px; bottom: 8px; transform: rotate(23deg); }
.brand-mark span:nth-child(3) { width: 14px; height: 6px; left: 12px; top: 8px; transform: rotate(12deg); }

.environment-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 22px 0 18px;
  padding: 10px 12px;
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 10px;
  color: #c9d7cf;
  font-size: 13px;
  background: rgba(255,255,255,.025);
}
.status-dot { width: 8px; height: 8px; flex: 0 0 auto; border-radius: 50%; background: #5ed39a; box-shadow: 0 0 0 4px rgba(94,211,154,.08); }
.status-dot.offline { background: #d96e65; box-shadow: 0 0 0 4px rgba(217,110,101,.08); }

.main-nav { overflow-y: auto; padding-right: 3px; }
.nav-label { margin: 20px 10px 8px; color: #687a70; font-size: 10px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.nav-item {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 10px;
  padding: 10px 11px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: #b7c5bd;
  text-align: left;
  font-size: 14px;
}
.nav-item:hover { color: #f4f8f5; background: rgba(255,255,255,.045); }
.nav-item.active { color: #f7fbf8; background: rgba(183,213,157,.12); }
.nav-icon { display: inline-grid; width: 18px; place-items: center; color: #8fb49b; }

.sidebar-footer { margin-top: auto; padding-top: 18px; border-top: 1px solid rgba(255,255,255,.08); }
.database-state { display: flex; align-items: center; gap: 10px; padding: 4px 4px; }
.database-state > div { min-width: 0; display: grid; }
.database-state strong { font-size: 12px; color: #dce7e0; }
.database-state small { margin-top: 2px; color: #75887e; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-scrim { display: none; }

.workspace { min-height: 100vh; margin-left: 258px; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 84px;
  padding: 15px clamp(20px, 3vw, 44px);
  border-bottom: 1px solid rgba(193,203,196,.85);
  background: rgba(238,242,236,.92);
  backdrop-filter: blur(12px);
}
.topbar-left { display: flex; align-items: center; gap: 14px; }
.topbar h1 { margin: 2px 0 0; font-size: 26px; letter-spacing: -.035em; }
.topbar-actions { display: flex; gap: 9px; }
.menu-button { display: none; }
.eyebrow { margin: 0; color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
.page-view { padding: 30px clamp(20px, 3vw, 44px) 50px; }

.button, .icon-button {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
}
.button {
  min-height: 40px;
  padding: 9px 14px;
  border-radius: 9px;
  font-weight: 700;
  font-size: 13px;
}
.button:hover { transform: translateY(-1px); box-shadow: 0 5px 15px rgba(27,49,37,.08); }
.button.primary { background: var(--green); border-color: var(--green); color: white; }
.button.primary:hover { background: var(--green-dark); }
.button.subtle { background: rgba(255,255,255,.7); }
.button.danger { color: var(--danger); border-color: #e0b9b5; background: #fff8f7; }
.icon-button { width: 38px; height: 38px; border-radius: 9px; display: inline-grid; place-items: center; font-size: 20px; }

.hero-panel {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(250px, .5fr);
  gap: 32px;
  padding: 34px;
  border-radius: 18px;
  background: linear-gradient(125deg, #183327 0%, #0e1e17 75%);
  color: white;
  box-shadow: var(--shadow);
  overflow: hidden;
  position: relative;
}
.hero-panel::after {
  content: "";
  position: absolute;
  right: -80px;
  bottom: -120px;
  width: 280px;
  height: 280px;
  border: 1px solid rgba(183,213,157,.2);
  border-radius: 50%;
  box-shadow: 0 0 0 35px rgba(183,213,157,.035), 0 0 0 70px rgba(183,213,157,.025);
}
.hero-panel .eyebrow { color: #a9c8b5; }
.hero-panel h2 { max-width: 760px; margin: 10px 0 12px; font-size: clamp(27px, 4vw, 46px); line-height: 1.04; letter-spacing: -.045em; }
.hero-copy { max-width: 680px; margin: 0; color: #b9c9c0; font-size: 15px; line-height: 1.7; }
.hero-meta { z-index: 1; align-self: end; display: grid; grid-template-columns: 1fr 1fr; gap: 7px 18px; padding: 18px; border: 1px solid rgba(255,255,255,.12); border-radius: 12px; background: rgba(255,255,255,.045); }
.hero-meta span { color: #8fa49a; font-size: 11px; }
.hero-meta strong { font-size: 12px; text-align: right; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 15px; margin: 18px 0; }
.metric-card, .panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 5px 20px rgba(30,48,38,.045); }
.metric-card { min-height: 145px; padding: 20px; }
.metric-card .metric-top { display: flex; align-items: center; justify-content: space-between; }
.metric-card .metric-icon { display: grid; width: 34px; height: 34px; place-items: center; border-radius: 10px; background: var(--green-soft); color: var(--green-dark); font-weight: 900; }
.metric-card .metric-label { color: var(--muted); font-size: 12px; font-weight: 700; }
.metric-card strong { display: block; margin-top: 22px; font-size: 31px; letter-spacing: -.045em; }
.metric-card small { display: block; margin-top: 5px; color: var(--muted); }
.skeleton { position: relative; overflow: hidden; background: #f7f9f7; }
.skeleton::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, rgba(255,255,255,.8), transparent); animation: shimmer 1.4s infinite; }
@keyframes shimmer { to { transform: translateX(100%); } }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(280px, .7fr); gap: 18px; margin-bottom: 18px; }
.panel { padding: 22px; }
.panel-heading, .table-meta { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.panel-heading h3, .table-meta h2 { margin: 5px 0 0; font-size: 18px; letter-spacing: -.025em; }
.panel-note { color: var(--muted); font-size: 11px; }
.chart-wrap { min-height: 280px; margin-top: 12px; }
#activityChart { width: 100%; height: 280px; overflow: visible; }
.chart-axis { stroke: #e1e6e2; stroke-width: 1; }
.chart-line { fill: none; stroke: var(--green); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.chart-area { fill: url(#activityGradient); }
.chart-point { fill: white; stroke: var(--green); stroke-width: 2; }
.chart-label { fill: #7a8880; font-size: 10px; }
.chart-value { fill: #324138; font-size: 10px; font-weight: 700; }
.empty-state { padding: 34px 14px; color: var(--muted); text-align: center; }

.leaderboard-list { margin-top: 12px; }
.leaderboard-row { display: grid; grid-template-columns: 30px 1fr auto; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid #edf0ed; }
.leaderboard-row:last-child { border-bottom: 0; }
.rank { display: grid; width: 25px; height: 25px; place-items: center; border-radius: 7px; background: var(--surface-soft); color: var(--muted); font-size: 11px; font-weight: 800; }
.leaderboard-name { min-width: 0; font-weight: 700; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leaderboard-score { color: var(--green-dark); font-size: 12px; font-weight: 800; }
.volume-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-top: 16px; }
.volume-item { padding: 14px; border: 1px solid #e3e7e4; border-radius: 10px; background: var(--surface-soft); }
.volume-item span { display: block; color: var(--muted); font-size: 11px; text-transform: capitalize; }
.volume-item strong { display: block; margin-top: 6px; font-size: 20px; }

.table-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; padding: 14px; }
.search-box { display: flex; flex: 1; max-width: 540px; align-items: center; gap: 8px; min-height: 42px; padding: 0 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-soft); }
.search-box input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--ink); }
.toolbar-group { display: flex; align-items: center; gap: 10px; }
.toolbar-group label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
select, input, textarea { border: 1px solid var(--line-strong); border-radius: 8px; background: white; color: var(--ink); }
select { min-height: 38px; padding: 0 28px 0 10px; }
.table-card { padding: 0; overflow: hidden; }
.table-meta { padding: 22px; border-bottom: 1px solid var(--line); }
.record-count { align-self: center; padding: 8px 11px; border-radius: 8px; background: var(--green-soft); color: var(--green-dark); font-size: 12px; }
.table-scroll { width: 100%; overflow: auto; }
table { width: 100%; min-width: 900px; border-collapse: collapse; }
th, td { padding: 13px 14px; border-bottom: 1px solid #e8ece9; text-align: left; vertical-align: top; font-size: 12px; }
th { position: sticky; top: 0; z-index: 1; background: #f7f9f7; color: #596860; font-size: 10px; letter-spacing: .08em; text-transform: uppercase; white-space: nowrap; }
td { max-width: 320px; color: #354239; }
td .cell-content { display: block; max-height: 58px; overflow: hidden; line-height: 1.45; word-break: break-word; }
.boolean-pill, .status-pill { display: inline-flex; align-items: center; min-height: 24px; padding: 3px 8px; border-radius: 999px; font-size: 10px; font-weight: 800; }
.boolean-pill.true { color: #176448; background: #e1f1e9; }
.boolean-pill.false { color: #8f3d36; background: #f6e6e4; }
.status-pill { color: #5a6546; background: #eef0dc; text-transform: capitalize; }
.row-actions { display: flex; gap: 6px; white-space: nowrap; }
.row-actions button { min-height: 30px; padding: 5px 8px; border-radius: 7px; border: 1px solid var(--line); background: white; color: var(--ink); font-size: 11px; }
.row-actions button.delete { color: var(--danger); }
.pagination { display: flex; align-items: center; justify-content: flex-end; gap: 12px; padding: 14px 18px; }
.pagination span { color: var(--muted); font-size: 12px; }

.modal-backdrop { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; background: rgba(8,15,11,.64); backdrop-filter: blur(4px); }
.modal-card { width: min(760px, 100%); max-height: 90vh; overflow: auto; padding: 24px; border-radius: 16px; background: white; box-shadow: 0 30px 80px rgba(0,0,0,.3); }
.compact-modal { width: min(430px, 100%); }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.modal-header h2 { margin: 5px 0 0; font-size: 22px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.field { display: grid; gap: 6px; }
.field.full-width { grid-column: 1 / -1; }
.field > span { color: #526158; font-size: 11px; font-weight: 800; letter-spacing: .04em; }
.field input, .field textarea, .field select { width: 100%; min-height: 42px; padding: 9px 10px; outline: none; }
.field textarea { min-height: 108px; resize: vertical; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(29,107,79,.1); }
.field-meta { color: #89938d; font-size: 10px; }
.form-help { color: var(--muted); font-size: 12px; line-height: 1.6; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 150; max-width: 360px; padding: 13px 15px; border-radius: 10px; background: #15241c; color: white; box-shadow: var(--shadow); font-size: 13px; }
.toast.error { background: #7b2f2a; }

@media (max-width: 1120px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .volume-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 820px) {
  .mobile-only { display: inline-grid; }
  .sidebar { transform: translateX(-100%); transition: transform .22s ease; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-scrim { position: fixed; inset: 0; z-index: 25; display: none; background: rgba(5,10,7,.5); }
  .sidebar-scrim.open { display: block; }
  .workspace { margin-left: 0; }
  .menu-button { display: inline-grid; }
  .topbar { min-height: 76px; padding: 12px 16px; }
  .topbar h1 { font-size: 21px; }
  .page-view { padding: 20px 15px 38px; }
  .hero-panel { grid-template-columns: 1fr; padding: 26px 22px; }
  .hero-meta { max-width: 420px; }
  .table-toolbar { align-items: stretch; flex-direction: column; }
  .search-box { max-width: none; }
  .toolbar-group { justify-content: space-between; }
}

@media (max-width: 560px) {
  .topbar-actions .subtle { display: none; }
  .metric-grid, .volume-grid { grid-template-columns: 1fr; }
  .metric-card { min-height: 128px; }
  .hero-panel h2 { font-size: 31px; }
  .hero-meta { grid-template-columns: 1fr auto; }
  .panel { padding: 17px; }
  .table-card { padding: 0; }
  .table-meta { padding: 17px; }
  .form-grid { grid-template-columns: 1fr; }
  .field.full-width { grid-column: auto; }
  .modal-card { padding: 18px; }
}
