:root {
  --green: #00933b;
  --green-dark: #008d43;
  --green-soft: #199e4f;
  --green-tint: #f2f9f5;
  --gold: #fccc0a;
  --gold-deep: #fdba12;
  --orange: #fb8424;
  --orange-deep: #f68c31;
  --cream: #fffaee;
  --white: #ffffff;
  --surface: #f9f9f9;
  --text: #222222;
  --muted: #666666;
  --line: #d6d6d6;
  --ok: #00933b;
  --bad: #c44536;
  --warn: #fb8424;
  --shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
  --shadow-lg: 0 26px 36px rgba(0, 0, 0, 0.18);
  --sans: "Poppins", "Segoe UI", sans-serif;
  --mono: "Cascadia Code", "Consolas", "Courier New", monospace;
  --radius: 8px;
  --header-h: 72px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--sans);
  background: var(--cream);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  color-scheme: light;
}

.eyebrow {
  margin: 0;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.68rem;
  color: var(--green);
  font-weight: 600;
}
h1, h2 { font-weight: 600; margin: 0.15rem 0 0; letter-spacing: -0.02em; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1rem; }
code, pre, textarea, .mono, select { font-family: var(--mono); }
.hint { color: var(--muted); font-size: 0.85rem; margin: 0.3rem 0 0; }
.hidden { display: none !important; }

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
}
.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--green);
  color: var(--white);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 1.05rem;
  flex: none;
}
.brand-name {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
}
.brand-sub { color: #8a8d8f; }
.brand-source { color: var(--orange); }
.brand-meta { display: grid; gap: 2px; }
.product-name {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.auth-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
  background:
    radial-gradient(900px 420px at 8% -10%, rgba(0, 147, 59, 0.16), transparent 55%),
    radial-gradient(700px 380px at 100% 110%, rgba(252, 204, 10, 0.22), transparent 50%),
    var(--cream);
}
.auth-card {
  width: min(440px, 100%);
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 36px 32px 32px;
  box-shadow: var(--shadow-lg);
  border-top: 6px solid var(--green);
}
.auth-card .brand { margin-bottom: 22px; }
.auth-card h1 { font-size: 1.7rem; margin: 0 0 8px; }
.lede { color: var(--muted); line-height: 1.55; margin: 0 0 8px; }
.auth-card button[type="submit"] { width: 100%; margin-top: 8px; padding: 12px 16px; }

label { display: grid; gap: 6px; margin: 14px 0; font-size: 0.85rem; color: var(--muted); font-weight: 500; }
input, textarea, select, button {
  font: inherit;
  color: var(--text);
  background: var(--white);
  border: 1px solid #999999;
  border-radius: var(--radius);
  padding: 10px 12px;
}
input, textarea, select { background: var(--white); }
input:focus, textarea:focus, select:focus {
  outline: 2px solid rgba(0, 147, 59, 0.28);
  border-color: var(--green);
}
button {
  background: var(--green);
  color: var(--white);
  font-weight: 600;
  border: 0;
  cursor: pointer;
  box-shadow: var(--shadow);
}
button:hover { background: var(--green-dark); }
button:disabled { opacity: 0.6; cursor: not-allowed; }
button.ghost, a.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--text);
  font-weight: 500;
  box-shadow: none;
}
a.ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  padding: 10px 14px;
  line-height: 1.2;
  white-space: nowrap;
}
button.ghost:hover, a.ghost:hover { background: var(--green); color: var(--white); border-color: var(--green); }
button.compact, a.compact {
  padding: 8px 14px;
  font-size: 0.8rem;
  box-shadow: none;
  min-height: 36px;
  line-height: 1.2;
}
.banner {
  padding: 10px 12px;
  border-radius: var(--radius);
}
.banner.error { background: #fdecea; color: var(--bad); }
.panel .banner { margin: 0 0 12px; }

.app-body { background: var(--surface); }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 12px 24px;
  min-height: var(--header-h);
  border-bottom: 3px solid var(--green);
  background: var(--white);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.04);
  position: sticky;
  top: 0;
  z-index: 4;
}
.topbar-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.who { color: var(--muted); font-size: 0.9rem; font-weight: 500; }
.pill {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: var(--surface);
}
.pill.ok { color: var(--green); background: var(--green-tint); border-color: #b7e0c6; }
.pill.bad { color: var(--bad); background: #fdecea; border-color: #f3c0ba; }
.pill.warn { color: #8a5a00; background: #fff6d6; border-color: #fccc0a; }

.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: calc(100vh - var(--header-h));
}
aside {
  border-right: 1px solid var(--line);
  padding: 18px 16px;
  background: var(--green-tint);
}
.aside-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
#entity-filter { width: 100%; background: var(--cream); border-color: var(--line); }
.entity-list { margin-top: 12px; display: grid; gap: 4px; max-height: calc(100vh - 210px); overflow: auto; }
.entity {
  text-align: left;
  background: transparent;
  color: var(--text);
  font-weight: 500;
  padding: 8px 10px;
  box-shadow: none;
  border: 1px solid transparent;
}
.entity:hover { background: var(--green-tint); }
.entity small { display: block; color: var(--muted); font-weight: 400; }
.entity.active {
  background: var(--green-tint);
  border-color: var(--green);
  color: var(--green-dark);
}
.group-label {
  margin: 12px 0 4px;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 600;
}

.workspace { padding: 20px 24px 32px; min-width: 0; }
#panel-ask {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 180px);
}
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 18px;
  background: var(--white);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--line);
  width: fit-content;
  max-width: 100%;
  flex-wrap: wrap;
}
.tab {
  background: transparent;
  color: var(--muted);
  border: 0;
  box-shadow: none;
  font-weight: 500;
  padding: 8px 16px;
}
.tab:hover { background: var(--cream); color: var(--text); }
.tab.active { color: var(--white); background: var(--green); }
.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.toolbar-actions { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.toolbar-actions input { min-width: 180px; background: var(--white); }
#panel-usage .toolbar { align-items: center; gap: 20px; }
#panel-usage .toolbar > div:first-child { flex: 1; min-width: 220px; }
.block-label { display: grid; gap: 6px; margin: 8px 0 14px; color: var(--muted); font-size: 0.85rem; }
.split { display: grid; grid-template-columns: 240px 1fr; gap: 12px; }
.output, .schema, .chat {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  overflow: auto;
  max-height: 58vh;
  box-shadow: var(--shadow);
}
.chat {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
  min-height: 180px;
  max-height: none;
  background: var(--cream);
}
.bubble {
  max-width: 92%;
  padding: 10px 14px;
  border-radius: 12px;
  line-height: 1.5;
  white-space: normal;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}
.bubble-text { white-space: pre-wrap; }
.bubble.user { align-self: flex-end; background: var(--white); border: 1px solid var(--line); }
.bubble.assistant { align-self: flex-start; background: var(--green-tint); border: 1px solid #b7e0c6; }
.feedback {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid #b7e0c6;
}
.feedback-label { color: var(--muted); font-size: 0.78rem; font-weight: 500; }
.feedback-btn {
  background: var(--white);
  color: var(--text);
  border: 1px solid var(--line);
  box-shadow: none;
  font-weight: 500;
  padding: 6px 12px;
  min-height: 32px;
}
.feedback-btn:hover { background: var(--cream); }
.feedback-btn.active[data-rating="up"] {
  background: var(--green);
  color: var(--white);
  border-color: var(--green);
}
.feedback-btn.active[data-rating="down"] {
  background: var(--bad);
  color: var(--white);
  border-color: var(--bad);
}
.feedback-status { color: var(--muted); font-size: 0.75rem; }
.feedback-comment {
  flex: 1 1 100%;
  min-height: 40px;
  background: var(--white);
  font-size: 0.85rem;
}
.history-filters { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; }
.history-filter.active {
  background: var(--green);
  color: var(--white);
  border-color: var(--green);
}
.history-item {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 10px;
}
.history-item:last-child { margin-bottom: 0; }
.history-meta { color: var(--muted); font-size: 0.75rem; margin-bottom: 6px; }
.history-q, .history-a, .history-comment { margin: 0 0 6px; font-size: 0.88rem; }
.history-q { font-weight: 600; }
.history-a, .history-comment { color: var(--muted); white-space: pre-wrap; }
.history-rating {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  margin-left: 6px;
}
.history-rating.up { color: var(--green); background: var(--green-tint); }
.history-rating.down { color: var(--bad); background: #fdecea; }
.history-rating.none { color: var(--muted); background: var(--surface); }
.steps { color: var(--muted); font-size: 0.75rem; margin-top: 8px; font-family: var(--mono); }
.cost-meta { color: var(--muted); font-size: 0.75rem; margin-top: 6px; }
.usage-note { color: var(--muted); font-size: 0.85rem; margin: 0 0 12px; max-width: 78ch; }
.usage-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.usage-card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.usage-card h3 {
  margin: 0 0 8px;
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.usage-card .usd {
  margin: 0;
  font-size: 1.45rem;
  font-weight: 600;
  color: var(--green-dark);
}
.usage-card p { margin: 6px 0 0; font-size: 0.8rem; color: var(--muted); }
@media (max-width: 900px) {
  .usage-cards { grid-template-columns: 1fr; }
}
.ask-form { display: flex; gap: 8px; margin-top: 12px; align-items: end; }
.ask-form textarea { flex: 1; resize: vertical; min-height: 52px; background: var(--white); }
.ask-form button { padding: 12px 22px; }
.key-form {
  display: grid;
  grid-template-columns: 160px 1fr auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
}
.key-once {
  background: var(--white);
  border: 1px solid var(--gold);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 16px;
}
.key-plain {
  font-size: 0.85rem;
  word-break: break-all;
  background: var(--surface);
  padding: 8px 10px;
  border-radius: 6px;
}
.key-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.switch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 12px;
  color: var(--text);
  font-weight: 500;
}
.switch-row input { width: auto; margin: 0; }
#access-restrict-help { margin: -4px 0 12px; max-width: 52rem; }
#access-role-filter { width: min(360px, 100%); margin-bottom: 12px; }
#access-roles, #access-users, #activity-users, #activity-logins, #learning-output { max-height: 42vh; }
.learning-filters {
  display: grid;
  grid-template-columns: repeat(3, minmax(140px, 220px));
  gap: 12px;
  margin: 0 0 14px;
}
.learning-filters .block-label { margin: 0; }
.learning-actions { display: flex; flex-wrap: wrap; gap: 6px; }
@media (max-width: 900px) {
  .learning-filters { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .key-form { grid-template-columns: 1fr; }
}
.schema { color: var(--muted); font-size: 0.78rem; white-space: pre-wrap; box-shadow: none; background: var(--surface); }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  font-family: var(--mono);
  background: var(--white);
}
table.data th, table.data td {
  border-bottom: 1px solid var(--line);
  padding: 8px 10px;
  text-align: left;
  white-space: nowrap;
}
table.data th { color: var(--green-dark); font-weight: 600; background: var(--green-tint); }
.empty, .error-text { color: var(--muted); }
.error-text { color: var(--bad); }

@media (max-width: 900px) {
  .layout, .split { grid-template-columns: 1fr; }
  aside { border-right: 0; border-bottom: 1px solid var(--line); }
  .entity-list { max-height: 220px; }
  .topbar { align-items: flex-start; flex-direction: column; }
}
