:root {
  color-scheme: light dark;
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-muted: #f0f0ed;
  --border: #dddcd7;
  --text: #1c1c1a;
  --text-muted: #65645e;
  --accent: #1f5fbf;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --danger-surface: #fbeceb;
  --ok: #1d7a46;
  --ok-surface: #e6f4ec;
  --warn: #8a5a00;
  --warn-surface: #f9f0dc;
  font-family:
    system-ui,
    -apple-system,
    "Segoe UI",
    "Noto Sans TC",
    "PingFang TC",
    "Microsoft JhengHei",
    sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141413;
    --surface: #1d1d1b;
    --surface-muted: #272725;
    --border: #363633;
    --text: #ececea;
    --text-muted: #a3a29c;
    --accent: #7aa9ee;
    --accent-text: #0d1c33;
    --danger: #f2877f;
    --danger-surface: #3a1f1d;
    --ok: #71c996;
    --ok-surface: #1a3024;
    --warn: #e2b862;
    --warn-surface: #352a14;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

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

button {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  cursor: pointer;
  white-space: nowrap;
}

button:hover:not(:disabled) {
  background: var(--surface-muted);
}

button:disabled {
  opacity: 0.55;
  cursor: default;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
}

button.primary:hover:not(:disabled) {
  background: var(--accent);
  opacity: 0.9;
}

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

button.danger:hover:not(:disabled) {
  background: var(--danger-surface);
}

button.small {
  min-height: 30px;
  padding: 0 10px;
  font-size: 13px;
}

input,
select {
  width: 100%;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
}

label {
  display: block;
  margin-bottom: 14px;
  font-size: 13px;
  font-weight: 600;
}

label > input,
label > select,
label > .with-action {
  margin-top: 5px;
  font-weight: 400;
}

.with-action {
  display: flex;
  gap: 8px;
}

.hint {
  margin: -8px 0 14px;
  font-size: 13px;
  color: var(--text-muted);
}

.muted {
  color: var(--text-muted);
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
}

.error {
  margin: 0 0 14px;
  padding: 9px 12px;
  border-radius: 7px;
  background: var(--danger-surface);
  color: var(--danger);
  font-size: 14px;
}

/* Sign-in */

.login {
  display: flex;
  min-height: 100dvh;
  padding: 16px;
  align-items: center;
  justify-content: center;
}

.login form {
  width: 100%;
  max-width: 360px;
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

.login h1 {
  margin: 0 0 4px;
  font-size: 20px;
}

.login p {
  margin: 0 0 22px;
  color: var(--text-muted);
  font-size: 14px;
}

.login button {
  width: 100%;
  margin-top: 4px;
}

/* Shell */

header {
  display: flex;
  min-height: 56px;
  padding: 0 24px;
  align-items: center;
  gap: 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

header strong {
  font-size: 16px;
}

nav {
  display: flex;
  flex: 1;
  gap: 4px;
}

nav button {
  border-color: transparent;
  background: transparent;
  color: var(--text-muted);
}

nav button[aria-current="page"] {
  background: var(--surface-muted);
  color: var(--text);
  font-weight: 600;
}

.who {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--text-muted);
}

main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 24px;
}

.toolbar {
  display: flex;
  margin-bottom: 16px;
  align-items: center;
  gap: 12px;
}

.toolbar h2 {
  flex: 1;
  margin: 0;
  font-size: 18px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

table {
  width: 100%;
  border-collapse: collapse;
}

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

tbody tr:last-child td {
  border-bottom: 0;
}

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

td.actions {
  width: 1%;
}

.action-row {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.secondary-line {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
}

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 99px;
  background: var(--surface-muted);
  font-size: 12px;
  white-space: nowrap;
}

.badge.ok {
  background: var(--ok-surface);
  color: var(--ok);
}

.badge.off {
  background: var(--danger-surface);
  color: var(--danger);
}

.badge.pending {
  background: var(--warn-surface);
  color: var(--warn);
}

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

dialog {
  width: min(420px, calc(100vw - 32px));
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
}

dialog::backdrop {
  background: rgb(0 0 0 / 0.45);
}

dialog h3 {
  margin: 0 0 16px;
  font-size: 17px;
}

dialog p {
  margin: 0 0 16px;
}

.dialog-actions {
  display: flex;
  margin-top: 20px;
  justify-content: flex-end;
  gap: 8px;
}

.secret {
  display: block;
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: 7px;
  background: var(--surface-muted);
  overflow-wrap: anywhere;
}

@media (max-width: 720px) {
  header {
    padding: 10px 16px;
    flex-wrap: wrap;
    gap: 8px 12px;
  }

  header strong {
    flex: 1;
  }

  nav {
    order: 3;
    flex-basis: 100%;
  }

  main {
    padding: 16px;
  }

  .table-wrap {
    border: 0;
    background: transparent;
  }

  thead {
    display: none;
  }

  table,
  tbody,
  tr,
  td {
    display: block;
    width: 100%;
  }

  tr {
    margin-bottom: 12px;
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
  }

  td,
  tbody tr:last-child td {
    padding: 8px 0;
    border-bottom: 0;
  }

  td.actions {
    width: 100%;
  }

  .action-row {
    flex-wrap: wrap;
    justify-content: flex-start;
  }
}
