:root {
  --bg: #f3f6f5;
  --surface: #ffffff;
  --surface-2: #eef3f1;
  --text: #14211e;
  --muted: #5c6d68;
  --line: #dbe4e1;
  --brand: #0f766e;
  --brand-ink: #ffffff;
  --band: #0b3b37;
  --band-text: #e6f4f1;
  --accent: #fbbf24;
  --accent-soft: #fff7e0;
  --accent-ink: #6b4a00;
  --danger: #b42318;
  --shadow: 0 1px 2px rgb(16 40 36 / 6%), 0 8px 24px rgb(16 40 36 / 7%);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1614;
    --surface: #17211f;
    --surface-2: #202c29;
    --text: #e8f0ee;
    --muted: #9db0ab;
    --line: #2c3a37;
    --brand: #2dd4bf;
    --brand-ink: #06231f;
    --band: #0a2522;
    --accent-soft: #33290f;
    --accent-ink: #fcd97a;
    --danger: #f97066;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 25%);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

.sprite { display: none; }
.icon {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.topbar { background: var(--band); color: var(--band-text); }
.topbar-in {
  max-width: 880px;
  margin: 0 auto;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { display: inline-flex; align-items: center; gap: 8px; font-size: 19px; font-weight: 600; letter-spacing: -.01em; }
.brand .icon { width: 22px; height: 22px; color: var(--accent); }
.brand b { color: var(--accent); font-weight: 600; margin-left: -8px; }
.ghost {
  background: none;
  border: 1px solid rgb(255 255 255 / 25%);
  border-radius: 8px;
  padding: 5px 12px;
  color: inherit;
  font-size: 13px;
}
.ghost:hover { background: rgb(255 255 255 / 10%); }

.wrap { max-width: 880px; margin: 0 auto; padding: 0 16px 40px; }

.hero, .login { text-align: center; padding-top: 36px; }
h1 { margin: 0; font-size: clamp(26px, 5vw, 36px); line-height: 1.2; letter-spacing: -.02em; font-weight: 700; }
.lead { margin: 8px 0 22px; color: var(--muted); }

.address {
  display: block;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: 15px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  font-size: clamp(16px, 3.6vw, 20px);
  font-weight: 600;
  overflow-wrap: anywhere;
  transition: border-color .15s;
}
.address:hover { border-color: var(--brand); }

.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; margin: 14px 0 26px; }
.actions button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  background: none;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  font-size: 14px;
}
.actions button:hover { background: var(--surface-2); color: var(--text); }

.edit {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px;
  max-width: 520px;
  margin: 12px auto 0;
}
.edit input, .edit select, .login-card input {
  min-width: 0;
  padding: 9px 11px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.edit input { flex: 1 1 130px; }
.edit select { flex: 0 1 auto; max-width: 100%; }
.at { color: var(--muted); }

.primary {
  padding: 9px 15px;
  background: var(--brand);
  color: var(--brand-ink);
  border: 0;
  border-radius: 8px;
  font-weight: 600;
}
.primary:hover { filter: brightness(1.08); }
.ghost-dark {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: none;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.ghost-dark:hover { background: var(--surface-2); }
.danger { color: var(--danger); }

.error { flex-basis: 100%; min-height: 1.2em; margin: 4px 0 0; color: var(--danger); font-size: 13px; }

.login-card {
  display: grid;
  gap: 10px;
  max-width: 380px;
  margin: 0 auto;
  padding: 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  text-align: left;
}
.login-card label { font-size: 13px; font-weight: 600; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
.tabs { display: flex; gap: 4px; min-width: 0; }
.tab {
  padding: 5px 11px;
  background: none;
  border: 0;
  border-radius: 7px;
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}
.tab.on { background: var(--surface-2); color: var(--text); font-weight: 600; }
.count {
  display: inline-block;
  min-width: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: var(--brand);
  color: var(--brand-ink);
  font-size: 12px;
  text-align: center;
}
.refresh {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  background: none;
  border: 0;
  border-radius: 7px;
  font-size: 14px;
  white-space: nowrap;
}
.refresh:hover { background: var(--surface-2); }
.refresh.spin .icon { animation: spin .7s linear; }
@keyframes spin { to { transform: rotate(360deg); } }

.empty { padding: 56px 16px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--text); font-weight: 600; margin-bottom: 2px; }
.pulse {
  display: block;
  width: 12px;
  height: 12px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: var(--brand);
  animation: pulse 1.6s ease-out infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--brand) 45%, transparent); }
  100% { box-shadow: 0 0 0 18px transparent; }
}

.row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 12px;
  align-items: center;
  width: 100%;
  padding: 13px 16px;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
  cursor: pointer;
}
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--surface-2); }
.row-from { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-time { justify-self: end; color: var(--muted); font-size: 13px; white-space: nowrap; }
.row .code-pill { justify-self: end; }
.row-subject { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.code-pill {
  padding: 2px 10px;
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 60%, transparent);
  border-radius: 7px;
  color: var(--accent-ink);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.code-pill:hover { filter: brightness(.97); }

article { padding: 14px 16px 18px; }
.detail-head { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
h2 { margin: 0 0 3px; font-size: 19px; line-height: 1.3; overflow-wrap: anywhere; }
.meta { margin: 0 0 12px; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.code-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
  padding: 12px 14px;
  background: var(--accent-soft);
  border-radius: 10px;
  color: var(--accent-ink);
}
.code-label { display: block; font-size: 12px; }
.code-banner strong { font-size: 26px; line-height: 1.2; letter-spacing: .06em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
iframe {
  display: block;
  width: 100%;
  height: 460px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
pre {
  margin: 0;
  padding: 12px;
  max-height: 460px;
  overflow: auto;
  background: var(--surface-2);
  border-radius: 10px;
  font: 14px/1.5 "Segoe UI", system-ui, sans-serif;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.foot { margin: 14px 0 0; text-align: center; color: var(--muted); font-size: 13px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translate(-50%, 16px);
  padding: 8px 15px;
  background: var(--text);
  color: var(--surface);
  border-radius: 8px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s, transform .15s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 480px) {
  .hero, .login { padding-top: 24px; }
  .actions button { padding: 7px 8px; font-size: 13px; }
  .refresh span { display: none; }
  iframe { height: 380px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
