:root {
  --bg: #f4f5f3;
  --surface: #ffffff;
  --surface-soft: #f8f9f7;
  --ink: #171a18;
  --muted: #6d746f;
  --line: #dde1dd;
  --line-strong: #c8cec9;
  --green: #16734a;
  --green-soft: #e8f4ed;
  --blue: #2366a8;
  --blue-soft: #eaf2f9;
  --amber: #946200;
  --amber-soft: #fbf1d6;
  --red: #b63b35;
  --red-soft: #f9e9e7;
  --sidebar: #202521;
  --sidebar-muted: #a9b2ab;
  --radius: 8px;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); color: var(--ink); font-family: Inter, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; }
body { min-height: 100vh; margin: 0; }
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { border: 0; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }

.access-gate { display: grid; min-height: 100vh; place-content: center; justify-items: center; padding: 28px; text-align: center; }
.gate-mark, .brand-mark { display: grid; place-items: center; background: var(--ink); color: white; font-weight: 750; }
.gate-mark { width: 52px; height: 52px; margin-bottom: 20px; border-radius: var(--radius); }
.access-gate strong { font-size: 1.1rem; }
.access-gate p { margin: 8px 0 20px; color: var(--muted); font-size: .84rem; }

.app { min-height: 100vh; }
.topbar { position: fixed; z-index: 20; top: 0; right: 0; left: 0; display: flex; height: 64px; align-items: center; justify-content: space-between; border-bottom: 1px solid #303631; background: var(--sidebar); color: white; padding: 0 24px; }
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark { width: 34px; height: 34px; border: 1px solid #4a544c; border-radius: 6px; background: #2c332d; font-size: .72rem; }
.brand > span:last-child { display: flex; flex-direction: column; gap: 2px; }
.brand strong { font-size: .84rem; font-weight: 680; }
.brand small { color: var(--sidebar-muted); font-size: .62rem; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.admin-email { max-width: 220px; overflow: hidden; color: #d9ded9; font-size: .72rem; text-overflow: ellipsis; white-space: nowrap; }

.workspace { display: grid; min-height: 100vh; grid-template-columns: 220px minmax(0, 1fr); padding-top: 64px; }
.sidebar { position: fixed; top: 64px; bottom: 0; left: 0; display: flex; width: 220px; flex-direction: column; justify-content: space-between; border-right: 1px solid #303631; background: var(--sidebar); padding: 24px 14px 18px; color: white; }
.sidebar nav { display: grid; gap: 5px; }
.nav-item { display: grid; min-height: 44px; cursor: pointer; grid-template-columns: 29px 1fr; align-items: center; border-radius: 6px; background: transparent; color: var(--sidebar-muted); padding: 0 12px; text-align: left; transition: background 150ms ease, color 150ms ease; }
.nav-item:hover { background: #2a302b; color: white; }
.nav-item.active { background: #edf4ef; color: #183426; }
.nav-index { font-family: var(--mono); font-size: .6rem; opacity: .65; }
.nav-item span:last-child { font-size: .78rem; font-weight: 620; }
.sidebar-foot { display: flex; align-items: center; gap: 8px; border-top: 1px solid #343b35; color: var(--sidebar-muted); padding: 16px 10px 0; font-size: .65rem; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #52c785; box-shadow: 0 0 0 3px rgba(82, 199, 133, .12); }

.content { min-width: 0; grid-column: 2; padding: 40px clamp(24px, 4vw, 56px) 64px; }
.view { display: none; max-width: 1440px; margin: 0 auto; }
.view.active { display: block; animation: view-in 180ms ease both; }
.page-heading { display: flex; min-height: 60px; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.eyebrow { margin: 0 0 6px; color: var(--green); font-family: var(--mono); font-size: .62rem; font-weight: 700; letter-spacing: 0; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.8rem, 3vw, 2.55rem); font-weight: 680; letter-spacing: 0; line-height: 1.05; }
h2 { margin-bottom: 0; font-size: 1rem; letter-spacing: 0; }
.heading-actions { display: flex; align-items: center; gap: 12px; }
.date-label { color: var(--muted); font-family: var(--mono); font-size: .68rem; }

.button { display: inline-flex; min-height: 36px; align-items: center; justify-content: center; cursor: pointer; border-radius: 6px; padding: 0 14px; font-size: .72rem; font-weight: 650; transition: background 140ms ease, border-color 140ms ease, color 140ms ease, opacity 140ms ease; }
.button:disabled { cursor: not-allowed; opacity: .45; }
.button.primary { background: var(--ink); color: white; }
.button.primary:hover:not(:disabled) { background: #303632; }
.button.secondary { border: 1px solid var(--line-strong); background: var(--surface); color: #343a36; }
.button.secondary:hover:not(:disabled) { border-color: #9da59f; background: var(--surface-soft); }
.button.quiet { border: 1px solid transparent; background: transparent; color: inherit; }
.topbar .button.quiet { color: #c4ccc6; }
.topbar .button.quiet:hover { background: #303731; color: white; }
.button.danger { border: 1px solid #e4b9b5; background: white; color: var(--red); }
.button.danger:hover:not(:disabled) { background: var(--red-soft); }
.button.full { width: 100%; }
.text-button { cursor: pointer; background: transparent; color: var(--green); font-size: .72rem; font-weight: 650; }
.text-button:hover { text-decoration: underline; }
.icon-button { display: grid; width: 34px; height: 34px; cursor: pointer; place-items: center; border-radius: 6px; background: var(--surface-soft); color: var(--muted); font-size: 1.25rem; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); margin-bottom: 20px; }
.metric { min-width: 0; padding: 22px 24px; border-right: 1px solid var(--line); }
.metric:last-child { border-right: 0; }
.metric span, .metric small { display: block; color: var(--muted); font-size: .67rem; }
.metric strong { display: block; margin: 9px 0 7px; font-family: var(--mono); font-size: 2rem; font-weight: 650; line-height: 1; }
.metric small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.panel-heading { display: flex; min-height: 72px; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--line); padding: 14px 20px; }
.panel-heading p { margin: 5px 0 0; color: var(--muted); font-size: .67rem; }
.table-panel { overflow: hidden; }
.table-wrap { position: relative; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { height: 42px; background: var(--surface-soft); color: var(--muted); font-size: .62rem; font-weight: 650; text-align: left; white-space: nowrap; }
th, td { padding: 10px 16px; border-bottom: 1px solid var(--line); }
td { height: 58px; color: #39403b; font-size: .71rem; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbfa; }
.cell-primary { display: block; max-width: 320px; overflow: hidden; color: var(--ink); font-weight: 620; text-overflow: ellipsis; white-space: nowrap; }
.cell-secondary { display: block; margin-top: 4px; color: var(--muted); font-family: var(--mono); font-size: .59rem; }
.prompt-cell { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.action-cell { text-align: right; }
.action-cell .button { min-height: 30px; padding: 0 10px; }
.badge { display: inline-flex; min-height: 23px; align-items: center; border-radius: 999px; padding: 3px 8px; font-size: .61rem; font-weight: 680; white-space: nowrap; }
.badge.good { background: var(--green-soft); color: var(--green); }
.badge.info { background: var(--blue-soft); color: var(--blue); }
.badge.warn { background: var(--amber-soft); color: var(--amber); }
.badge.bad { background: var(--red-soft); color: var(--red); }
.badge.neutral { background: #ecefed; color: #59605b; }
.empty { padding: 52px 24px; color: var(--muted); font-size: .75rem; text-align: center; }

.toolbar { display: grid; grid-template-columns: minmax(240px, 1fr) 180px auto; align-items: end; gap: 12px; margin-bottom: 14px; }
.toolbar.compact { display: flex; justify-content: space-between; }
.search-field, .select-field, .form-field { display: flex; flex-direction: column; gap: 6px; }
.search-field span, .select-field span, .form-field span { color: var(--muted); font-size: .62rem; font-weight: 650; }
input, select { width: 100%; min-height: 39px; border: 1px solid var(--line-strong); border-radius: 6px; outline: none; background: var(--surface); color: var(--ink); padding: 0 11px; font-size: .72rem; }
input:focus, select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(22, 115, 74, .1); }
.result-count { align-self: center; justify-self: end; color: var(--muted); font-size: .68rem; }
.pagination { display: flex; min-height: 55px; align-items: center; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--line); padding: 8px 14px; }
.pagination span { min-width: 62px; color: var(--muted); font-family: var(--mono); font-size: .64rem; text-align: center; }

.modal-backdrop { position: fixed; z-index: 50; inset: 0; display: grid; place-items: center; background: rgba(19, 23, 20, .46); padding: 20px; }
.modal { width: min(100%, 430px); border-radius: var(--radius); background: var(--surface); box-shadow: 0 24px 70px rgba(0, 0, 0, .22); padding: 24px; }
.modal-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.modal-heading h2 { font-size: 1.35rem; }
.form-field small { color: var(--muted); font-size: .62rem; }
.form-field + .button { margin-top: 20px; }
.invite-result { border-top: 1px solid var(--line); margin-top: 22px; padding-top: 20px; }
.invite-result > span, .invite-result > small { display: block; color: var(--muted); font-size: .64rem; }
.invite-result code { display: block; overflow-wrap: anywhere; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-soft); margin: 8px 0 12px; padding: 13px; font-family: var(--mono); font-size: .72rem; line-height: 1.5; }
.invite-result > small { margin-top: 9px; text-align: center; }
.toast { position: fixed; z-index: 80; right: 22px; bottom: 22px; max-width: min(380px, calc(100vw - 44px)); border-radius: 6px; background: var(--ink); color: white; padding: 12px 16px; font-size: .72rem; box-shadow: 0 12px 36px rgba(0,0,0,.2); }
.toast.error { background: #8f2f2a; }

@keyframes view-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
@media (max-width: 980px) {
  .workspace { grid-template-columns: 1fr; padding-top: 114px; }
  .sidebar { position: fixed; z-index: 15; top: 64px; right: 0; bottom: auto; width: auto; height: 50px; border-right: 0; border-bottom: 1px solid #303631; padding: 6px 16px; }
  .sidebar nav { display: flex; gap: 4px; overflow-x: auto; }
  .nav-item { min-width: max-content; min-height: 36px; grid-template-columns: 1fr; padding: 0 13px; text-align: center; }
  .nav-index, .sidebar-foot { display: none; }
  .content { grid-column: 1; padding-top: 30px; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
}
@media (max-width: 680px) {
  .topbar { height: 58px; padding: 0 14px; }
  .brand small, .admin-email, .topbar-actions a { display: none; }
  .workspace { padding-top: 108px; }
  .sidebar { top: 58px; height: 50px; padding-right: 10px; padding-left: 10px; }
  .sidebar nav { width: 100%; }
  .nav-item { flex: 1; padding: 0 8px; }
  .nav-item span:last-child { font-size: .68rem; }
  .content { padding: 24px 12px 44px; }
  .page-heading { min-height: 54px; align-items: flex-start; margin-bottom: 22px; }
  .date-label { display: none; }
  h1 { font-size: 1.8rem; }
  .metric { padding: 18px 16px; }
  .metric strong { font-size: 1.65rem; }
  .toolbar { grid-template-columns: 1fr 130px; }
  .result-count { grid-column: 1 / -1; justify-self: start; }
  .panel-heading { padding-right: 14px; padding-left: 14px; }
  th, td { padding-right: 12px; padding-left: 12px; }
  .pagination { justify-content: center; }
}
@media (max-width: 430px) {
  .metric-grid { grid-template-columns: 1fr; }
  .metric { border-right: 0; border-bottom: 1px solid var(--line); }
  .metric:nth-child(3) { border-bottom: 1px solid var(--line); }
  .metric:last-child { border-bottom: 0; }
  .toolbar { grid-template-columns: 1fr; }
  .result-count { grid-column: auto; }
  .toolbar.compact { flex-direction: column; align-items: flex-start; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
