: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;
}

.advanced-head,
.mobile-cards,
.editor-close {
  display: none;
}

.ops-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.ops-card {
  display: grid;
  gap: 5px;
  min-height: 78px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  text-align: left;
}

.ops-card strong {
  font-size: 15px;
}

.ops-card span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.admin-product-card {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.admin-product-thumb {
  display: grid;
  width: 74px;
  height: 74px;
  place-items: center;
  overflow: hidden;
  border-radius: 8px;
  background: #f1ece3;
  color: var(--accent-strong);
  font-weight: 900;
}

.admin-product-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.admin-product-main {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.admin-product-title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.admin-product-title strong {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 15px;
}

.admin-product-title span {
  white-space: nowrap;
  font-weight: 900;
}

.admin-product-meta,
.admin-product-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.admin-product-meta span {
  padding: 4px 7px;
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.danger-text {
  color: var(--danger) !important;
}

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;
  }

  .mobile-cards {
    display: grid;
    gap: 10px;
    margin-bottom: 14px;
  }

  .advanced-editor {
    border-top: 1px solid var(--line);
    padding-top: 12px;
  }

  .advanced-head {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
    color: var(--muted);
    font-size: 12px;
  }

  .advanced-head strong {
    color: var(--ink);
    font-size: 14px;
  }

  .editor-panel {
    display: none;
  }

  .editor-panel.is-open {
    position: fixed;
    z-index: 20;
    left: 0;
    right: 0;
    bottom: 0;
    display: block;
    max-height: min(82vh, 720px);
    overflow: auto;
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -18px 50px rgba(31, 26, 18, 0.18);
  }

  .editor-close {
    display: inline-flex;
    float: right;
    align-items: center;
  }

  .form-grid,
  .detail-list {
    max-height: 54vh;
  }

  .editor-panel .actions {
    position: sticky;
    bottom: -16px;
    margin: 12px -16px -16px;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: var(--panel);
  }

  .editor-panel .actions button {
    flex: 1 1 140px;
    min-height: 48px;
  }
}

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

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

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

  .side {
    padding: 12px;
  }

  .nav {
    display: flex;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .nav a {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .page-head,
  .panel {
    padding: 14px;
  }

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

  .metric strong {
    font-size: 20px;
  }

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

  .toolbar input {
    max-width: none;
  }

  .admin-product-card {
    grid-template-columns: 64px minmax(0, 1fr);
  }

  .admin-product-thumb {
    width: 64px;
    height: 64px;
  }

  .admin-product-actions button {
    min-height: 42px;
  }
}
