:root {
  --ink: #17221c;
  --muted: #68756d;
  --surface: #ffffff;
  --canvas: #f4f6f2;
  --line: #dfe5df;
  --green: #146b45;
  --green-dark: #0d4a30;
  --green-soft: #e0f2e8;
  --amber: #c87813;
  --amber-soft: #fff1d6;
  --red: #b53333;
  --red-soft: #fde9e7;
  --shadow: 0 18px 45px rgba(25, 48, 34, 0.08);
  --radius: 18px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--canvas); }
body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% -20%, rgba(85, 170, 113, 0.15), transparent 30rem),
    var(--canvas);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

a { color: var(--green); text-decoration: none; }
a:hover { color: var(--green-dark); }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: .4rem; font-size: clamp(2rem, 3.6vw, 3.4rem); letter-spacing: -.055em; line-height: 1.04; }
h2 { margin-bottom: .85rem; font-size: 1.2rem; letter-spacing: -.02em; }
code { padding: .12rem .35rem; border-radius: 6px; background: #edf1ed; }

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  min-height: 70px;
  padding: 0 clamp(1rem, 3vw, 2.5rem);
  border-bottom: 1px solid rgba(223, 229, 223, .9);
  background: rgba(250, 252, 249, .88);
  backdrop-filter: blur(16px);
}

.brand { display: inline-flex; align-items: center; gap: .7rem; color: var(--ink); font-weight: 760; letter-spacing: -.025em; }
.brand-mark { display: grid; width: 34px; height: 34px; place-items: center; border-radius: 10px; color: white; background: var(--green); box-shadow: 0 8px 18px rgba(20, 107, 69, .25); }
.nav { display: flex; justify-content: center; gap: .2rem; }
.nav a { padding: .55rem .8rem; border-radius: 9px; color: #465249; font-size: .92rem; font-weight: 600; }
.nav a:hover { background: var(--green-soft); color: var(--green-dark); }
.nav-toggle { display: none; border: 0; background: none; font-size: 1.4rem; }
.user-menu { display: flex; align-items: center; gap: .8rem; color: var(--muted); font-size: .88rem; }
.user-menu form { margin: 0; }
.link-button { padding: 0; border: 0; color: var(--green); background: none; cursor: pointer; font: inherit; font-weight: 650; }

.shell { width: min(1180px, calc(100% - 2rem)); margin: 0 auto; padding: clamp(2rem, 5vw, 4.5rem) 0 5rem; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 2rem; }
.page-heading h1 { margin-bottom: 0; }
.eyebrow { margin-bottom: .45rem; color: var(--green); font-size: .73rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.muted { color: var(--muted); }

.card {
  padding: clamp(1.15rem, 2.8vw, 1.75rem);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.card-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.card-heading h2 { margin-bottom: 0; }

.button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  padding: .65rem 1rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  background: white;
  cursor: pointer;
  font: inherit;
  font-size: .9rem;
  font-weight: 720;
  transition: transform .15s ease, box-shadow .15s ease;
}
.button:hover { transform: translateY(-1px); box-shadow: 0 8px 18px rgba(25, 48, 34, .1); }
.button.primary { border-color: var(--green); color: white; background: var(--green); }
.button.primary:hover { color: white; background: var(--green-dark); }
.button.ghost { background: transparent; }
.button-row { display: flex; gap: .7rem; }

.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 1.25rem; }
.stat { min-height: 130px; padding: 1.35rem; border: 1px solid var(--line); border-radius: var(--radius); background: white; box-shadow: var(--shadow); }
.stat span { display: block; margin-bottom: 1.1rem; color: var(--muted); font-size: .88rem; }
.stat strong { font-size: 2.5rem; letter-spacing: -.06em; }
.stat.accent { border-color: #ecd39f; background: var(--amber-soft); }
.stat.accent strong { color: #80500d; }
.two-column { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, .9fr); gap: 1.25rem; }
.two-column.align-start { align-items: start; }

.table-wrap { overflow-x: auto; }
.card.table-wrap { padding: 0; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { padding: .85rem 1rem; color: var(--muted); background: #f9faf8; font-size: .7rem; letter-spacing: .08em; text-align: left; text-transform: uppercase; }
td { padding: .95rem 1rem; border-top: 1px solid var(--line); vertical-align: middle; }
td strong, td small { display: block; }
td small { margin-top: .12rem; color: var(--muted); }
.number { white-space: nowrap; font-variant-numeric: tabular-nums; }
.danger { color: var(--red); font-weight: 750; }
.success-text { color: var(--green); font-weight: 750; }
.row-warning { background: #fffaf0; }
.actions { display: flex; gap: .75rem; white-space: nowrap; }
.empty { padding: 2rem !important; color: var(--muted); text-align: center; }

.activity-list { margin: 1rem 0 0; padding: 0; list-style: none; }
.activity-list li { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: .8rem; padding: .85rem 0; border-top: 1px solid var(--line); }
.activity-list li div { display: flex; flex-direction: column; }
.activity-list li span, .activity-list time { color: var(--muted); font-size: .8rem; }
.movement-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 5px var(--green-soft); }
.movement-dot.negative { background: var(--amber); box-shadow: 0 0 0 5px var(--amber-soft); }

.tag { display: inline-flex; align-items: center; padding: .2rem .5rem; border-radius: 999px; color: var(--green-dark); background: var(--green-soft); font-size: .72rem; font-weight: 750; }
.notice { margin-bottom: 1.25rem; padding: 1rem 1.15rem; border-left: 4px solid var(--amber); border-radius: 0 12px 12px 0; background: var(--amber-soft); }
.notice.success { border-color: var(--green); background: var(--green-soft); }
.error-panel { margin-bottom: 1rem; border-color: #efb4ad; background: var(--red-soft); }

.search { display: flex; gap: .6rem; margin-bottom: 1rem; }
.search input { flex: 1; }
input, select, textarea {
  width: 100%;
  margin-top: .35rem;
  padding: .72rem .8rem;
  border: 1px solid #cbd4cd;
  border-radius: 10px;
  color: var(--ink);
  background: white;
  font: inherit;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(20, 107, 69, .12); }
input[type="checkbox"] { width: auto; margin-right: .5rem; }
.form-stack { display: grid; gap: 1rem; }
.form-stack label { color: #344039; font-size: .84rem; font-weight: 680; }
.form-stack label small { display: block; margin-top: .3rem; color: var(--muted); font-weight: 400; }
.form-wide { width: min(760px, 100%); }
.errorlist { margin: .35rem 0 0; padding-left: 1.1rem; color: var(--red); font-size: .8rem; }

.auth-card { display: grid; grid-template-columns: 1.15fr .85fr; align-items: center; gap: clamp(2rem, 7vw, 7rem); min-height: calc(100vh - 180px); }
.auth-card > div p:last-child { max-width: 35rem; font-size: 1.05rem; }

.assistant-form { display: grid; gap: 1rem; margin-bottom: 1.25rem; }
.assistant-form textarea { min-height: 110px; resize: vertical; font-size: 1.05rem; }
.assistant-controls { display: flex; justify-content: flex-end; gap: .7rem; }
.assistant-controls select { width: auto; min-width: 230px; margin: 0; }
.assistant-form > p { margin: -.5rem 0 0; font-size: .8rem; text-align: right; }
.answer-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(280px, .75fr); gap: 1.25rem; align-items: start; }
.answer-text { line-height: 1.72; }
.sources ol { margin: .75rem 0 0; padding-left: 1.25rem; }
.sources li { padding: .8rem 0; border-top: 1px solid var(--line); }
.sources li strong, .sources li small { display: block; }
.sources li small { margin: .15rem 0 .4rem; color: var(--muted); }
.sources li p { margin: 0; color: #4d5a52; font-size: .83rem; }

.messages { display: grid; gap: .5rem; margin-bottom: 1rem; }
.message { padding: .8rem 1rem; border-radius: 10px; background: #e9eef7; }
.message.success { color: var(--green-dark); background: var(--green-soft); }
.message.error { color: #802c2c; background: var(--red-soft); }
.message.info { background: #e7eff8; }

@media (max-width: 820px) {
  .topbar { grid-template-columns: 1fr auto; }
  .nav-toggle { display: block; }
  .nav { position: absolute; top: 70px; right: 1rem; display: none; width: min(280px, calc(100vw - 2rem)); padding: .6rem; border: 1px solid var(--line); border-radius: 14px; background: white; box-shadow: var(--shadow); }
  .nav.open { display: grid; }
  .user-menu { display: none; }
  .stats-grid { grid-template-columns: 1fr; }
  .stat { min-height: auto; }
  .two-column, .answer-grid, .auth-card { grid-template-columns: 1fr; }
  .auth-card { min-height: auto; }
}

@media (max-width: 560px) {
  .shell { width: min(100% - 1rem, 1180px); padding-top: 1.5rem; }
  .page-heading { align-items: flex-start; flex-direction: column; }
  .page-heading .button { width: 100%; }
  .search { flex-direction: column; }
  .assistant-controls { align-items: stretch; flex-direction: column; }
  .assistant-controls select { width: 100%; }
}

