:root {
  --bg: #f7f8f5;
  --panel: #ffffff;
  --ink: #20231f;
  --muted: #667064;
  --line: #dce2d8;
  --teal: #0f8b8d;
  --teal-dark: #0a6769;
  --coral: #d96c4a;
  --gold: #b58a22;
  --blue: #3867b7;
  --danger: #b83434;
  --shadow: 0 16px 40px rgba(32, 35, 31, 0.08);
  --radius: 8px;
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

[hidden] {
  display: none !important;
}

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

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
  background: #f0f3ed;
  border-right: 1px solid var(--line);
  padding: 24px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}

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

.brand-mark {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  border-radius: var(--radius);
  background: var(--ink);
  color: white;
  font-weight: 800;
}

.brand span,
.muted {
  color: var(--muted);
}

.brand span {
  display: block;
  font-size: 12px;
  margin-top: 2px;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-item,
.tool-card {
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
}

.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-radius: var(--radius);
  text-align: left;
}

.nav-item:hover,
.nav-item.is-active {
  background: var(--panel);
  border-color: var(--line);
  box-shadow: 0 4px 16px rgba(32, 35, 31, 0.05);
}

.main {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  margin-bottom: 24px;
}

.topbar h1 {
  margin: 2px 0 0;
  font-size: 30px;
  line-height: 1.15;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.segmented {
  display: inline-flex;
  background: #e8ede4;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 3px;
}

.segmented button {
  min-width: 42px;
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 6px;
  padding: 7px 9px;
}

.segmented button.is-active {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 2px 10px rgba(32, 35, 31, 0.08);
}

.user-pill {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric,
.work-surface,
.login-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.metric {
  padding: 18px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 10px;
}

.metric strong {
  font-size: 28px;
  letter-spacing: 0;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 26px;
}

.tool-card {
  min-height: 138px;
  display: grid;
  justify-items: start;
  gap: 8px;
  padding: 20px;
  background: var(--panel);
  border-color: var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: left;
}

.tool-card:hover {
  border-color: rgba(15, 139, 141, 0.35);
  transform: translateY(-1px);
}

.tool-card span:not(.icon) {
  color: var(--muted);
}

.section-head,
.toolbar,
.form-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.section-head {
  margin: 18px 0 12px;
}

.section-head h2 {
  margin: 0;
  font-size: 20px;
}

.work-surface {
  padding: 20px;
  margin-bottom: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.form-grid.one {
  grid-template-columns: minmax(0, 1fr);
  margin-top: 16px;
}

.span-2 {
  grid-column: 1 / -1;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
textarea,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfa;
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
}

textarea {
  resize: vertical;
  line-height: 1.55;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 139, 141, 0.14);
}

.form-actions {
  margin-top: 16px;
}

.primary-button,
.secondary-button,
.ghost-button,
.icon-button {
  min-height: 38px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 13px;
  color: var(--ink);
}

.primary-button {
  background: var(--teal);
  border-color: var(--teal);
  color: white;
}

.primary-button:hover {
  background: var(--teal-dark);
}

.secondary-button {
  background: var(--panel);
}

.ghost-button {
  background: transparent;
}

.icon-button {
  width: 38px;
  padding: 0;
  background: var(--panel);
}

.record-list {
  display: grid;
  gap: 12px;
}

.record,
.result-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.record {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
}

.record h3,
.result-card h3 {
  margin: 0 0 8px;
  font-size: 17px;
  letter-spacing: 0;
}

.record-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #edf3f1;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 700;
}

.badge.gold {
  background: #fbf4dd;
  color: var(--gold);
}

.badge.coral {
  background: #fff0eb;
  color: var(--coral);
}

.result-shell {
  display: grid;
  gap: 14px;
}

.result-grid {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
  gap: 14px;
}

.score-box {
  min-height: 160px;
  display: grid;
  place-items: center;
  background: #eef7f6;
  border: 1px solid rgba(15, 139, 141, 0.18);
  border-radius: var(--radius);
}

.score-box strong {
  font-size: 42px;
  color: var(--teal-dark);
}

.copy-block {
  position: relative;
  padding: 14px;
  background: #fbfcfa;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  white-space: pre-wrap;
  line-height: 1.55;
}

.copy-tools {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 10px;
}

.pill-list,
.bullet-list {
  display: grid;
  gap: 8px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.pill-list {
  display: flex;
  flex-wrap: wrap;
}

.pill-list li {
  background: #f1f4ef;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
}

.bullet-list li {
  padding-left: 16px;
  position: relative;
}

.bullet-list li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.72em;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--coral);
}

.login-gate {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(247, 248, 245, 0.88);
  backdrop-filter: blur(10px);
}

.login-panel {
  width: min(460px, 100%);
  display: grid;
  gap: 18px;
  padding: 24px;
}

.login-panel h2 {
  margin: 0;
}

.stack {
  display: grid;
  gap: 12px;
}

.account-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 0.5fr);
  gap: 24px;
}

.quota-bar {
  height: 12px;
  background: #e9eee6;
  border-radius: 999px;
  overflow: hidden;
}

.quota-bar span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--teal), var(--coral));
}

.admin-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(340px, 0.9fr);
  gap: 18px;
}

.log-list {
  display: grid;
  gap: 10px;
  max-height: 720px;
  overflow: auto;
}

.log-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: #fbfcfa;
}

.log-item strong {
  display: block;
  margin-bottom: 4px;
}

.toolbar {
  margin-bottom: 14px;
  justify-content: flex-start;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  transform: translateY(16px);
  opacity: 0;
  pointer-events: none;
  transition: 180ms ease;
  background: var(--ink);
  color: white;
  border-radius: var(--radius);
  padding: 12px 14px;
  max-width: min(420px, calc(100vw - 44px));
  box-shadow: var(--shadow);
  z-index: 30;
}

.toast.is-visible {
  transform: translateY(0);
  opacity: 1;
}

.icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.icon.large {
  width: 30px;
  height: 30px;
  color: var(--teal);
}

.icon svg {
  width: 100%;
  height: 100%;
  stroke: currentColor;
}

.loading {
  min-height: 84px;
  display: grid;
  place-items: center;
  color: var(--muted);
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    height: auto;
    position: static;
    padding: 14px;
  }

  .nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .nav-item {
    justify-content: center;
    text-align: center;
  }

  .main {
    padding: 18px;
  }

  .topbar,
  .account-grid,
  .admin-layout,
  .result-grid {
    grid-template-columns: 1fr;
    display: grid;
  }

  .metric-grid,
  .tool-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .top-actions,
  .section-head,
  .toolbar,
  .record {
    align-items: stretch;
    flex-direction: column;
    display: flex;
  }

  .nav,
  .metric-grid,
  .tool-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .topbar h1 {
    font-size: 24px;
  }

  .span-2 {
    grid-column: auto;
  }
}
