:root {
  color-scheme: light;
  --bg: #f5f1e8;
  --panel: #fffdf8;
  --panel-2: #f8f4ec;
  --line: #dfd6c6;
  --line-strong: #c8bba5;
  --text: #201b16;
  --muted: #75685a;
  --accent: #99582a;
  --accent-2: #7f4f24;
  --danger: #b42318;
  --ok: #137547;
  --shadow: 0 18px 40px rgba(63, 42, 25, 0.12);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: radial-gradient(circle at top, #fff7eb 0, var(--bg) 42%); color: var(--text); }
body { font-size: 14px; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.flash {
  position: fixed;
  top: 18px;
  right: 20px;
  z-index: 30;
  min-width: 220px;
  max-width: 420px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(32, 27, 22, 0.92);
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-10px);
  transition: opacity 0.18s, transform 0.18s;
}
.flash.show { opacity: 1; transform: translateY(0); }
.flash.success { background: rgba(19, 117, 71, 0.94); }
.flash.error { background: rgba(180, 35, 24, 0.94); }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(24, 16, 10, 0.42);
  backdrop-filter: blur(4px);
}

.modal-card {
  width: min(420px, 100%);
  background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(250,245,238,0.98));
  border: 1px solid rgba(153, 88, 42, 0.16);
  border-radius: 20px;
  padding: 22px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
}

.modal-card h3 { margin: 0; font-size: 22px; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(420px, 100%);
  background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(250,245,238,0.98));
  border: 1px solid rgba(153, 88, 42, 0.16);
  border-radius: 24px;
  padding: 28px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
}

.brand-kicker, .page-kicker {
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

.auth-card h1, .brand-title, .topbar h2 {
  margin: 0;
  font-size: 30px;
  line-height: 1.05;
}

.auth-hint, .auth-note { color: var(--muted); line-height: 1.6; }
.auth-card label, .stack-form label { display: grid; gap: 6px; }
.auth-card span, .stack-form span { font-size: 12px; color: var(--muted); }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 11px 12px;
  color: var(--text);
}

textarea { resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(153, 88, 42, 0.12);
}

.btn-primary, .btn-ghost {
  border: none;
  border-radius: 12px;
  padding: 11px 14px;
  font-weight: 700;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
}

.btn-primary.small, .btn-ghost.small { padding: 8px 11px; font-size: 13px; }
.btn-ghost {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
}
.btn-ghost.danger { color: var(--danger); }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px 1fr;
}

.sidebar {
  background: linear-gradient(180deg, #241a14, #3a271b);
  color: #f9efe3;
  padding: 24px 18px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 20px;
}

.sidebar-head { display: grid; gap: 6px; }
.nav-list { display: grid; gap: 8px; align-content: start; }
.nav-btn {
  text-align: left;
  border: 1px solid transparent;
  background: rgba(255,255,255,0.05);
  color: inherit;
  border-radius: 14px;
  padding: 12px 14px;
}
.nav-btn.active {
  background: rgba(255,255,255,0.12);
  border-color: rgba(255,255,255,0.12);
}
.current-admin { color: rgba(255,255,255,0.72); margin-bottom: 10px; }

.content {
  padding: 22px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 18px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.view { display: none; gap: 16px; align-content: start; }
.view.active { display: grid; }

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
}

.metric-card, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.metric-card {
  padding: 18px;
  display: grid;
  gap: 8px;
}
.metric-card strong { font-size: 28px; }
.metric-card span { color: var(--muted); }

.panel { padding: 18px; }
.panel-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.panel-title-row h3 { margin: 0; }
.panel.two-col { display: grid; grid-template-columns: 1.1fr 1fr; gap: 18px; }
.cards-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: 16px; }
.settings-grid { align-items: start; }
.stack-form { display: grid; gap: 12px; }
.filter-row { display: grid; grid-template-columns: 1.3fr 180px auto; gap: 10px; }

.plan-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  background: linear-gradient(180deg, #fffdf8, #f9f3ea);
  display: grid;
  gap: 12px;
}
.plan-card h4 { margin: 0; font-size: 18px; }
.plan-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.plan-fields .full { grid-column: 1 / -1; }
.engine-checks { display: flex; flex-wrap: wrap; gap: 8px 10px; }
.engine-checks label { display: inline-flex; align-items: center; gap: 6px; }
.engine-checks input { width: auto; }

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; }
.table-actions { display: flex; gap: 8px; align-items: center; }
.status-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  background: var(--panel-2);
}
.status-pill.ok { color: var(--ok); }
.status-pill.warn { color: #9a6700; }
.status-pill.bad { color: var(--danger); }
.muted { color: var(--muted); }

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { grid-template-rows: auto auto auto; }
  .nav-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .panel.two-col, .filter-row { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .content { padding: 14px; }
  .nav-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .plan-fields { grid-template-columns: 1fr; }
}
