:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e3e6ea;
  --text: #16181d;
  --muted: #666c75;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --danger: #b4232b;
  --ok: #157f3d;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 18, 23, 0.06), 0 8px 24px rgba(16, 18, 23, 0.05);
}

:root[data-theme='dark'] {
  --bg: #000000;
  --surface: #0a0b0d;   /* barely lifted so cards still read as cards on black */
  --border: #23262c;
  --text: #f2f3f5;
  --muted: #959ba5;
  --accent: #5b8cff;
  --accent-text: #05070f;
  --danger: #ff6b6b;
  --ok: #4ade80;
  --shadow: 0 0 0 1px rgba(255, 255, 255, 0.02), 0 10px 30px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }

/* Elements below set their own display, which would otherwise beat [hidden]. */
[hidden] { display: none !important; }

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

html[dir='rtl'] body { font-family: 'Segoe UI', Tahoma, system-ui, sans-serif; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: -0.01em; }
.logo {
  display: grid;
  place-items: center;
  width: 28px; height: 28px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
}

.topbar-actions { display: flex; align-items: center; gap: 8px; }

main { max-width: 1080px; margin: 0 auto; padding: 20px 16px 48px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.address-card { margin-bottom: 18px; }
.label { margin: 0 0 8px; color: var(--muted); font-size: 13px; }

.address-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.address {
  flex: 1 1 260px;
  min-width: 0;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: clamp(16px, 2.6vw, 22px);
  padding: 10px 12px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: var(--bg);
}

.address-tools { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

.btn {
  font: inherit;
  padding: 9px 14px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.06s ease, background 0.15s ease, opacity 0.15s ease;
}
.btn:hover { background: var(--bg); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }

.icon-btn {
  font: inherit;
  width: 34px; height: 34px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

select {
  font: inherit;
  padding: 8px 10px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.qrbox { margin-top: 14px; display: grid; place-items: center; padding: 14px; background: #fff; border-radius: 10px; }
.qrbox canvas, .qrbox img { display: block; }

.expiry { display: flex; align-items: center; gap: 10px; margin-top: 14px; color: var(--muted); font-size: 14px; }
.expiry strong { color: var(--text); font-variant-numeric: tabular-nums; font-size: 16px; }
.expiry.expired strong { color: var(--danger); }

.columns { display: grid; grid-template-columns: minmax(0, 360px) minmax(0, 1fr); gap: 18px; align-items: start; }

.list-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.list-head h2 { margin: 0; font-size: 16px; }
.badge {
  background: var(--accent);
  color: var(--accent-text);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 12px;
  font-weight: 700;
}
.poll-state { margin-inline-start: auto; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); opacity: 0.35; }
.poll-state.active { opacity: 1; }

.messages { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 60vh; overflow: auto; }
.messages li { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; cursor: pointer; }
.messages li:hover { background: var(--bg); }
.messages li.selected { border-color: var(--accent); }
.messages li.unread { border-inline-start: 3px solid var(--accent); }
.msg-from { font-weight: 600; font-size: 13px; overflow-wrap: anywhere; }
.msg-subject { font-size: 14px; margin-top: 2px; overflow-wrap: anywhere; }
.msg-date { font-size: 12px; color: var(--muted); margin-top: 3px; }

.empty { color: var(--muted); font-size: 14px; text-align: center; padding: 22px 8px; margin: 0; }

.view-card { min-height: 320px; }
.view-head h3 { margin: 0 0 6px; font-size: 18px; overflow-wrap: anywhere; }
.meta { margin: 0 0 8px; font-size: 13px; display: flex; gap: 10px; flex-wrap: wrap; }
.dim { color: var(--muted); }
.auth { margin: 0 0 8px; font-size: 12px; color: var(--muted); font-family: ui-monospace, monospace; }
.view-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.attach { margin: 0 0 10px; font-size: 13px; color: var(--muted); border: 1px dashed var(--border); border-radius: 8px; padding: 8px 10px; }

#body {
  width: 100%;
  min-height: 420px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #ffffff;
}

.disclaimer { color: var(--muted); font-size: 13px; text-align: center; margin: 22px auto 0; max-width: 60ch; }

.toast {
  position: fixed;
  inset-inline: 16px;
  bottom: 18px;
  margin: 0 auto;
  max-width: 420px;
  background: var(--text);
  color: var(--bg);
  padding: 10px 14px;
  border-radius: 10px;
  text-align: center;
  font-size: 14px;
  box-shadow: var(--shadow);
}

@media (max-width: 820px) {
  .columns { grid-template-columns: 1fr; }
  .messages { max-height: 40vh; }
  #body { min-height: 320px; }
}
