:root {
  color-scheme: light;
  --bg: #f7f4ef;
  --panel: #ffffff;
  --panel-soft: #fbfaf7;
  --ink: #26231f;
  --muted: #746d63;
  --line: #e5ded3;
  --accent: #4f8b74;
  --accent-strong: #2f6b57;
  --warn: #a15a28;
  --danger: #9f3939;
  --ok: #2f765d;
  --shadow: 0 18px 50px rgba(60, 45, 25, 0.08);
  font-family: Inter, "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

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

button {
  border: 0;
  cursor: pointer;
}

.login-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-panel h1,
.page-head h1 {
  margin: 0;
  font-size: 26px;
  line-height: 1.2;
  letter-spacing: 0;
}

.login-panel p,
.page-head p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.field {
  display: grid;
  gap: 7px;
  margin-top: 20px;
}

.field label,
.form-grid label,
.json-editor label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.field input,
.toolbar input,
.toolbar select,
.json-editor textarea,
.form-field input,
.form-field select,
.form-field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

.field input,
.toolbar input,
.toolbar select,
.form-field input,
.form-field select {
  height: 42px;
  padding: 0 12px;
}

.json-editor textarea {
  min-height: 300px;
  padding: 12px;
  resize: vertical;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
}

.form-grid {
  display: grid;
  gap: 12px;
  max-height: calc(100vh - 260px);
  overflow: auto;
  padding-right: 4px;
}

.form-field {
  display: grid;
  gap: 6px;
}

.form-field span,
.detail-row span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.form-field textarea {
  min-height: 90px;
  padding: 11px 12px;
  resize: vertical;
}

.form-switch select {
  border-color: #b8d6c8;
  background: #f3faf6;
  font-weight: 800;
}

.detail-list {
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 260px);
  overflow: auto;
}

.detail-row {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.detail-row strong {
  overflow-wrap: anywhere;
  font-size: 13px;
}

.primary,
.secondary,
.danger {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 6px;
  font-weight: 800;
}

.primary {
  background: var(--accent);
  color: #fff;
}

.primary:hover {
  background: var(--accent-strong);
}

.secondary {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
}

.danger {
  background: #f7e9e5;
  color: var(--danger);
}

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

.side {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  border-right: 1px solid var(--line);
  background: #fffdf9;
  padding: 18px 14px;
}

.brand {
  padding: 10px 10px 18px;
}

.brand strong {
  display: block;
  font-size: 18px;
}

.brand span {
  color: var(--muted);
  font-size: 12px;
}

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

.nav a {
  display: block;
  padding: 10px 12px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 750;
  text-decoration: none;
}

.nav a.active,
.nav a:hover {
  background: #eef5f1;
  color: var(--accent-strong);
}

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

.topbar,
.page-head,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

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

.topbar small {
  color: var(--muted);
}

.page-head {
  padding: 20px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  gap: 16px;
  margin-top: 16px;
}

.panel {
  min-width: 0;
  padding: 16px;
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

.tabs,
.toolbar,
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.tabs {
  margin-bottom: 12px;
}

.tab {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--muted);
  font-weight: 750;
}

.tab.active {
  border-color: #b8d6c8;
  background: #eef7f2;
  color: var(--accent-strong);
}

.toolbar {
  margin-bottom: 12px;
}

.toolbar input {
  max-width: 260px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
  background: #fff;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

th {
  position: sticky;
  top: 0;
  background: #fbfaf7;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

tr:hover td {
  background: #fbfaf7;
}

.cell-text {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 750;
}

.status.ok {
  background: #e9f5ee;
  color: var(--ok);
}

.status.error {
  background: #f8e9e7;
  color: var(--danger);
}

.empty {
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 14px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.metric strong {
  display: block;
  margin-top: 6px;
  font-size: 24px;
}

.read-only-note {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
}

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

  .side {
    position: relative;
    height: auto;
  }

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

  .content-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .main {
    padding: 14px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .nav {
    grid-template-columns: 1fr;
  }
}
