:root {
  --green: #263326;
  --sage: #6a725d;
  --gold: #d8be78;
  --gold-dark: #8b7233;
  --ivory: #f7f4ed;
  --beige: #efe9df;
  --white: #fffdf8;
  --text: #24231f;
  --muted: rgba(36, 35, 31, 0.62);
  --line: rgba(36, 35, 31, 0.14);
  --danger: #a33a2c;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--ivory);
  color: var(--text);
  font: 16px/1.6 "Noto Sans TC", "Inter", system-ui, -apple-system, sans-serif;
}

h1,
h2,
h3 {
  margin: 0;
  color: var(--green);
  line-height: 1.3;
}

.noscript {
  padding: 24px;
}

/* Login */
.login {
  display: grid;
  gap: 18px;
  width: min(100% - 32px, 380px);
  margin: 12vh auto 0;
  padding: 32px 28px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--white);
  box-shadow: 0 24px 60px rgba(36, 35, 31, 0.1);
}

.login h1 {
  font-size: 1.45rem;
}

.login p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

/* Layout */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  align-items: center;
  justify-content: space-between;
  padding: 14px max(16px, calc((100% - 960px) / 2));
  background: var(--green);
  color: var(--white);
}

.topbar h1 {
  color: var(--white);
  font-size: 1.1rem;
}

.topbar-links {
  display: flex;
  gap: 18px;
  align-items: center;
  font-size: 0.9rem;
}

.topbar a,
.link-button {
  color: var(--gold);
  text-decoration: none;
}

.link-button {
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  cursor: pointer;
}

.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 12px max(16px, calc((100% - 960px) / 2)) 0;
  border-bottom: 1px solid var(--line);
  background: var(--beige);
}

.tab {
  flex: none;
  padding: 10px 18px;
  border: 1px solid transparent;
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.tab[aria-selected="true"] {
  border-color: var(--line);
  background: var(--ivory);
  color: var(--green);
}

.panel {
  width: min(100% - 32px, 960px);
  margin: 28px auto 80px;
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.panel-note {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 0.92rem;
}

/* Buttons */
.btn {
  padding: 10px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
  color: var(--green);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.btn:hover {
  border-color: var(--green);
}

.btn.primary {
  border-color: var(--green);
  background: var(--green);
  color: var(--white);
}

.btn.ghost {
  background: none;
}

.btn.danger {
  color: var(--danger);
}

.btn.small {
  padding: 6px 12px;
  font-size: 0.88rem;
}

.btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

/* List */
.list {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.item {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--white);
}

.item.is-off {
  opacity: 0.62;
}

.thumb {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  overflow: hidden;
  border-radius: 8px;
  background: var(--beige);
  color: var(--muted);
  font-size: 1.4rem;
}

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

.item-title {
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--green);
  font-weight: 700;
}

.item-meta {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.badge {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--beige);
  color: var(--gold-dark);
  font-size: 0.72rem;
  font-weight: 700;
  vertical-align: middle;
}

.item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.empty {
  padding: 40px 16px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  color: var(--muted);
  text-align: center;
}

/* Editor */
.editor {
  display: grid;
  gap: 20px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--white);
}

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

.label {
  color: var(--green);
  font-size: 0.92rem;
  font-weight: 700;
}

.hint {
  color: var(--muted);
  font-size: 0.82rem;
}

input[type="text"],
input[type="url"],
input[type="date"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

textarea {
  min-height: 90px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus,
.btn:focus-visible,
.tab:focus-visible {
  outline: 3px solid rgba(216, 190, 120, 0.7);
  outline-offset: 1px;
}

.check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.check input {
  width: 20px;
  height: 20px;
  margin-top: 3px;
}

.check .label {
  font-weight: 700;
}

.repeater {
  display: grid;
  gap: 12px;
}

.repeat-row {
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--ivory);
}

.media-box {
  display: grid;
  gap: 10px;
}

.media-preview {
  display: grid;
  place-items: center;
  min-height: 120px;
  max-width: 420px;
  overflow: hidden;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--beige);
  color: var(--muted);
}

.media-preview img,
.media-preview video {
  display: block;
  width: 100%;
  max-height: 320px;
  object-fit: contain;
}

.media-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.progress {
  max-width: 420px;
  height: 6px;
  overflow: hidden;
  border-radius: 3px;
  background: var(--beige);
}

.progress span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--gold-dark);
  transition: width 120ms linear;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding-top: 8px;
}

.error {
  margin: 0;
  padding: 10px 14px;
  border-radius: 8px;
  background: #f8e3df;
  color: var(--danger);
  font-size: 0.92rem;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 20;
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  border-radius: 8px;
  background: var(--green);
  color: var(--white);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
}

.toast.is-error {
  background: var(--danger);
}

@media (max-width: 640px) {
  .item {
    grid-template-columns: 56px minmax(0, 1fr);
  }

  .thumb {
    width: 56px;
    height: 56px;
  }

  .item-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }

  .editor {
    padding: 18px 16px;
  }
}
