:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-soft: #eef7f4;
  --surface-warm: #fff7e8;
  --text: #152022;
  --muted: #647276;
  --line: #dce3e6;
  --primary: #2f7f73;
  --primary-soft: #dff2ee;
  --accent: #8a6218;
  --danger: #ba1a1a;
  --warn: #9a6700;
  --ok: #16794f;
  --shadow: rgba(18, 35, 38, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

button.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
  font-weight: 700;
}

button.danger { border-color: #ffd7d7; color: var(--danger); }
button.wide { width: 100%; }
button.icon-button { width: 40px; padding: 0; }

.icon {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}

input, textarea, select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  background: #fff;
  color: var(--text);
}

input[type="checkbox"] {
  width: 18px;
  height: 18px;
  min-height: 0;
  padding: 0;
  margin: 0;
  accent-color: var(--primary);
}

textarea {
  min-height: 112px;
  resize: vertical;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.check-line {
  display: inline-flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 13px;
}

.app-shell { min-height: 100vh; padding-bottom: 74px; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 10px;
  background: rgba(245, 247, 248, 0.94);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(220, 227, 230, 0.8);
}

.app-header h1 { margin: 0; font-size: 22px; letter-spacing: 0; }
.eyebrow { color: var(--primary); font-size: 12px; font-weight: 700; }
.view { display: grid; gap: 12px; padding: 14px; }

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 8;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 8px max(8px, env(safe-area-inset-left)) calc(8px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-right));
  background: rgba(255, 255, 255, 0.97);
  border-top: 1px solid var(--line);
  box-shadow: 0 -8px 24px var(--shadow);
}

.bottom-nav button {
  min-height: 50px;
  display: grid;
  place-items: center;
  gap: 3px;
  border: 0;
  padding: 5px 2px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
}

.bottom-nav .nav-icon { width: 19px; height: 19px; }
.bottom-nav button span { display: block; font-size: 11px; line-height: 14px; }
.bottom-nav button.active { border-radius: 8px; background: var(--primary-soft); color: var(--primary); }

.card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 20px var(--shadow);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 13px;
  border-bottom: 1px solid var(--line);
}

.card-body { display: grid; gap: 12px; padding: 13px; }
.card h2, .card h3 { margin: 0; font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.breakable { overflow-wrap: anywhere; min-width: 0; }
.danger-text b { color: var(--danger); }

.grid { display: grid; gap: 12px; }
.stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stat { padding: 13px; min-height: 96px; display: grid; align-content: space-between; }
.stat-icon { color: var(--primary); }
.stat b { display: block; font-size: 21px; color: var(--primary); overflow-wrap: anywhere; }
.stat span { color: var(--muted); font-size: 12px; }

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  color: var(--muted);
  background: #fff;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.pill.ok { color: var(--ok); border-color: #ccebdc; background: #f0fbf5; }
.pill.warn { color: var(--warn); border-color: #f2dfad; background: #fff8e8; }
.pill.error { color: var(--danger); border-color: #ffd6d6; background: #fff3f3; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-width: 0; }
.top-align { align-items: flex-start; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.compact-actions button { min-height: 36px; padding: 7px 10px; }
.form-stack { display: grid; gap: 12px; }
.form-grid { display: grid; gap: 10px; }
.form-grid.two { grid-template-columns: 1fr; }

.list-stack { gap: 9px; }
.item {
  display: grid;
  gap: 10px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.item.compact { padding: 10px; }
.item.selected { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.item-main { display: grid; gap: 8px; min-width: 0; }
.meta-line { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

.subsection {
  display: grid;
  gap: 10px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; }


.notice {
  display: grid;
  gap: 7px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}
.notice.ok { border-color: #ccebdc; background: #f0fbf5; }
.notice.warn { border-color: #f2dfad; background: #fff8e8; color: var(--warn); }
.notice.error { border-color: #ffd6d6; background: #fff3f3; color: var(--danger); }
.key-list { display: grid; gap: 8px; }
.key-row {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.key-row.active { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.model-actions { align-self: end; }

.model-list { display: grid; gap: 9px; }
.model-row {
  display: grid;
  gap: 9px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.model-enabled { justify-self: start; }

.segmented {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.segmented button { min-height: 36px; border: 0; background: transparent; }
.segmented button.active { background: var(--primary-soft); color: var(--primary); }

.detail-grid { display: grid; gap: 8px; }
.kv {
  display: grid;
  gap: 3px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}
.kv span { color: var(--muted); font-size: 12px; }
.kv strong { font-size: 13px; }
.log-block { display: grid; gap: 7px; }
.log-block h3 { font-size: 13px; }

pre {
  margin: 0;
  max-height: 360px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.login-page { background: linear-gradient(180deg, #eef7f4, #f8fafb 46%, #ffffff); }
.login-shell { min-height: 100vh; display: grid; align-items: center; padding: 18px; }
.login-card {
  width: min(420px, 100%);
  margin: 0 auto;
  display: grid;
  gap: 14px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 18px 44px var(--shadow);
}
.login-card h1 { margin: 0; font-size: 24px; }
.login-card p { margin: 0; color: var(--muted); }
.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 800;
}
.form-error { min-height: 20px; color: var(--danger); }
.toast {
  position: fixed;
  left: 14px;
  right: 14px;
  bottom: 86px;
  z-index: 20;
  display: none;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 16px 34px var(--shadow);
}
.toast.active { display: block; }

@media (min-width: 720px) {
  .form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .model-row { grid-template-columns: 90px minmax(0, 1fr) minmax(0, 1fr) auto; align-items: end; }
  .key-row { grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
}

@media (min-width: 880px) {
  .app-shell { max-width: 1040px; margin: 0 auto; }
  .view { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
  .span-2 { grid-column: span 2; }
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .bottom-nav {
    left: 50%;
    right: auto;
    width: min(620px, calc(100vw - 40px));
    transform: translateX(-50%);
    border: 1px solid var(--line);
    border-radius: 8px 8px 0 0;
  }
}