:root {
  --bg: #f6f5f0;
  --surface: #fffdfa;
  --surface-2: #f0efe7;
  --text: #252622;
  --muted: #72766d;
  --line: #dfddd3;
  --primary: #176b5c;
  --danger: #b54040;
  --shadow: 0 18px 45px rgba(42, 38, 31, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans TC", "Microsoft JhengHei", Arial, sans-serif;
  overflow-x: hidden;
}

.shell {
  min-height: 100vh;
  width: 100%;
}

.topbar {
  align-items: center;
  background: rgba(255, 253, 250, 0.94);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  padding: 16px 28px;
  position: sticky;
  top: 0;
  z-index: 10;
}

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

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

.topbar span,
p {
  color: var(--muted);
}

main {
  display: grid;
  gap: 18px;
  margin: 0 auto;
  max-width: 1180px;
  padding: 28px;
  width: 100%;
}

.call-page {
  max-width: 860px;
}

.call-grid {
  display: grid;
  gap: 12px;
  margin: 18px 0;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 0;
  padding: 18px;
}

.hero-panel {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1fr);
}

h1,
h2 {
  margin: 0 0 10px;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 20px;
}

.grid-two {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr));
  min-width: 0;
}

.workflow {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 250px), 1fr));
  min-width: 0;
}

.step-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  min-height: 104px;
  padding: 16px;
}

.step-card b {
  font-size: 17px;
}

.step-card span,
small,
.section-note {
  color: var(--muted);
}

.section-note {
  margin: -2px 0 6px;
}

.form-grid,
.form-row,
.login-row {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.form-row,
.login-row {
  align-items: end;
  grid-template-columns: minmax(0, 1fr) auto;
}

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

#adminPasswordForm h2,
#adminPasswordForm .section-note,
#adminPasswordForm button {
  grid-column: 1 / -1;
}

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

small {
  font-size: 12px;
  line-height: 1.45;
}

.wide,
.helper {
  grid-column: 1 / -1;
}

.helper {
  background: #fff7df;
  border: 1px solid #ead7a7;
  border-radius: 6px;
  margin: 0;
  padding: 10px;
}

a {
  color: var(--primary);
}

details.panel {
  padding: 0;
}

details > summary {
  align-items: center;
  cursor: pointer;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  list-style: none;
  padding: 18px;
}

details > summary::-webkit-details-marker {
  display: none;
}

details > summary span {
  color: var(--text);
  font-size: 20px;
  font-weight: 700;
}

details > summary::after {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  content: "展開";
  font-size: 13px;
  padding: 4px 10px;
}

details[open] > summary::after {
  content: "收合";
}

.advanced-panel form {
  border-top: 1px solid var(--line);
  padding: 0 18px 18px;
}

.password-toggle {
  max-width: 240px;
}

.store-advanced-fields {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 0;
}

.store-advanced-fields > summary {
  align-items: center;
  cursor: pointer;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  list-style: none;
  padding: 14px 16px;
}

.store-advanced-fields > summary::-webkit-details-marker {
  display: none;
}

.store-advanced-fields > summary span {
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
}

.store-advanced-fields > summary small {
  text-align: right;
}

.store-advanced-fields label {
  padding: 0 16px 14px;
}

input,
select {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  min-height: 38px;
  padding: 8px 10px;
  width: 100%;
}

button,
.button {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  min-height: 38px;
  padding: 8px 12px;
}

.call-page-link {
  align-items: center;
  display: inline-flex;
  grid-column: 1 / -1;
  justify-content: center;
  text-decoration: none;
}

.top-call-link {
  align-items: center;
  display: inline-flex;
  text-decoration: none;
  white-space: nowrap;
}

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

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

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.section-head {
  align-items: start;
  display: flex;
  gap: 16px;
  justify-content: space-between;
}

.toggle {
  align-items: center;
  display: flex;
  gap: 8px;
  white-space: nowrap;
}

.toggle input {
  min-height: 0;
  width: auto;
}

.table-wrap {
  max-width: 100%;
  overflow-x: auto;
}

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

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

th {
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

td input,
td select {
  min-width: 130px;
}

.key-value {
  color: var(--primary);
  font-family: Consolas, "Courier New", monospace;
  font-weight: 700;
  white-space: nowrap;
}

.status {
  border-radius: 999px;
  display: inline-block;
  font-size: 13px;
  padding: 3px 8px;
}

.status-unused {
  background: #e7f5ef;
  color: #176b5c;
}

.status-used {
  background: #edf1fb;
  color: #2d55a1;
}

.status-expired,
.status-revoked {
  background: #f8eaea;
  color: #9b2f2f;
}

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

.toast {
  background: var(--text);
  border-radius: 8px;
  bottom: 22px;
  box-shadow: var(--shadow);
  color: #fff;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  position: fixed;
  right: 22px;
  z-index: 99;
}

.hidden {
  display: none;
}

@media (max-width: 900px) {
  main {
    padding: 18px;
  }

  .hero-panel,
  .workflow,
  .grid-two,
  #adminPasswordForm,
  .form-row,
  .login-row,
  .section-head {
    grid-template-columns: 1fr;
  }

  .section-head {
    display: grid;
  }
}
