:root {
  --bg: #0f1419;
  --panel: #1a2332;
  --border: #2d3a4d;
  --text: #e7ecf3;
  --muted: #8b9bb4;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --danger: #ef4444;
  --ok: #22c55e;
  --radius: 10px;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.9rem; }
.msg { min-height: 1.2em; font-size: 0.9rem; }
.msg.ok { color: var(--ok); }
.msg.err { color: var(--danger); }

.panel {
  max-width: 420px;
  margin: 10vh auto;
  padding: 2rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.panel h1 { margin-top: 0; font-size: 1.4rem; }
.panel.wide { max-width: 560px; }

.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 2rem 1rem 3rem;
}
.auth-panel { margin: 0; width: 100%; }
.pill {
  display: inline-block;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.25rem 0.6rem;
  margin: 0 0 0.75rem;
}
.banner {
  background: rgba(59, 130, 246, 0.12);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.9rem 1rem;
  margin: 1rem 0;
}
.banner strong { display: block; margin-bottom: 0.35rem; }
.stack { display: flex; flex-direction: column; gap: 0.25rem; }
.full { width: 100%; }
.auth-footer { margin-top: 1.5rem; font-size: 0.85rem; }
.auth-footer a { color: var(--accent); }
.link-box, .result-box {
  margin-top: 1rem;
  padding: 0.85rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.85rem;
  word-break: break-all;
}
.link-box a, .result-box a { color: var(--ok); }
.section-title { font-size: 0.95rem; margin: 1.5rem 0 0.5rem; color: var(--muted); }
.domain-list { padding-left: 1.1rem; font-size: 0.85rem; }
.domain-list li { margin: 0.35rem 0; }
code { font-family: ui-monospace, Consolas, monospace; font-size: 0.88em; color: var(--ok); }
label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0.75rem 0;
  font-size: 0.85rem;
  color: var(--muted);
}
input, textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.6rem 0.75rem;
  font: inherit;
}
button {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 0.9rem;
  cursor: pointer;
  font: inherit;
}
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
button.primary:hover { background: var(--accent-hover); }
button.ghost { background: transparent; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-wait {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
}
.spinner {
  width: 0.95rem;
  height: 0.95rem;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
.wait-panel .spinner {
  border-color: rgba(59, 130, 246, 0.35);
  border-top-color: var(--accent);
  width: 1.15rem;
  height: 1.15rem;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.wait-panel {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  margin: 1rem 0 0.25rem;
  padding: 0.85rem 1rem;
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.wait-panel strong { display: block; margin-bottom: 0.2rem; }
.wait-panel p { margin: 0; }
.otp-panel {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.otp-input {
  font-size: 1.35rem;
  letter-spacing: 0.35em;
  text-align: center;
  font-family: ui-monospace, Consolas, monospace;
  font-weight: 600;
}
.otp-reveal {
  font-size: 1.2rem;
  letter-spacing: 0.2em;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  gap: 1rem;
  flex-wrap: wrap;
}
.topbar-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.layout {
  display: grid;
  grid-template-columns: 160px 320px 1fr;
  min-height: calc(100vh - 56px);
}
.list-col {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  min-height: 0;
}
.search-bar {
  display: flex;
  gap: 0.35rem;
  padding: 0.5rem;
  border-bottom: 1px solid var(--border);
  background: #121a24;
}
.search-bar input {
  flex: 1;
  min-width: 0;
  padding: 0.4rem 0.55rem;
  font-size: 0.85rem;
}
.att-list {
  list-style: none;
  padding: 0;
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
}
.att-list li { margin: 0.25rem 0; }
.att-list a { color: var(--accent); }
.label-nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin: 0.5rem 0;
  max-height: 30vh;
  overflow: auto;
}
.label-nav button {
  text-align: left;
  font-size: 0.85rem;
  border-left: 3px solid transparent;
}
.label-nav button.active {
  border-left-color: var(--accent);
  background: rgba(59, 130, 246, 0.12);
}
.label-chip {
  display: inline-block;
  font-size: 0.72rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  margin-right: 0.25rem;
  margin-bottom: 0.25rem;
}
.label-pick {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0.5rem 0;
}
.wysiwyg-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-bottom: 0.35rem;
}
.wysiwyg-editor {
  min-height: 160px;
  max-height: 320px;
  overflow: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  color: var(--text);
  font: inherit;
  line-height: 1.45;
}
.wysiwyg-editor:focus {
  outline: 1px solid var(--accent);
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .folders { display: flex; flex-wrap: wrap; gap: 0.35rem; padding: 0.5rem; }
  .list { max-height: 40vh; overflow: auto; border-bottom: 1px solid var(--border); }
  .list-col { border-right: none; }
}

.folders {
  border-right: 1px solid var(--border);
  padding: 0.75rem;
  background: #121a24;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.folder {
  text-align: left;
  width: 100%;
}
.folder.active {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.15);
}

.list {
  overflow: auto;
  flex: 1;
}
.bulk-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--border);
  background: rgba(59, 130, 246, 0.08);
  font-size: 0.85rem;
}
.msg-row {
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid var(--border);
}
.msg-row .msg-check {
  margin: 0.75rem 0.35rem 0 0.5rem;
  flex-shrink: 0;
}
.msg-row .msg-item {
  flex: 1;
  border-bottom: none;
}
.msg-row.unread .subj { font-weight: 700; }
.msg-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  padding: 0.75rem 0.9rem;
  background: transparent;
}
.msg-item:hover { background: rgba(255,255,255,0.03); }
.msg-item.unread .subj { font-weight: 700; }
.msg-item .from { font-size: 0.85rem; }
.msg-item .subj { display: block; margin: 0.15rem 0; }
.msg-item .snip { font-size: 0.8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-item .when { font-size: 0.75rem; color: var(--muted); }

.reader {
  padding: 1.25rem;
  overflow: auto;
}
.reader h2 { margin: 0 0 0.5rem; font-size: 1.25rem; }
.reader .meta { margin-bottom: 1rem; font-size: 0.9rem; color: var(--muted); }
.reader .body {
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.reader .body.html { white-space: normal; }
.reader-actions { display: flex; gap: 0.5rem; margin: 1rem 0; }

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  padding: 0;
  max-width: 520px;
  width: calc(100% - 2rem);
}
dialog::backdrop { background: rgba(0,0,0,0.55); }
.compose { padding: 1.25rem; }
.compose h2, .compose h3 { margin-top: 0; }
.row { display: flex; gap: 0.5rem; margin-top: 0.75rem; }
.input-with-suffix {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding-right: 0.65rem;
}
.input-with-suffix input {
  border: none;
  background: transparent;
  flex: 1;
  min-width: 0;
}
.input-with-suffix .suffix {
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
}
.admin-section {
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.admin-list {
  margin: 1rem 0;
  font-size: 0.85rem;
  max-height: 160px;
  overflow: auto;
}
.admin-list ul { padding-left: 1.1rem; margin: 0.35rem 0; }
#user-email { margin-left: 0.5rem; }
.row-check {
  flex-direction: row !important;
  align-items: center;
  gap: 0.5rem !important;
  margin: 0.5rem 0;
}
.row-check input[type="checkbox"] { width: auto; }
.row-check select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.4rem 0.55rem;
  font: inherit;
}
.invite-copy {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.35rem;
}
.invite-copy input {
  width: 100%;
  font-size: 0.8rem;
}
.status-pill {
  display: inline-block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.1rem 0.45rem;
  margin-left: 0.25rem;
}
.status-pill.pending { color: var(--accent); }
.status-pill.used { color: var(--ok); }
.status-pill.expired { color: var(--muted); }

/* Full-page admin console */
.admin-body { min-height: 100vh; }
.admin-topbar .pill { margin-left: 0.5rem; vertical-align: middle; }
.button-link {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.9rem;
  color: var(--text);
  background: transparent;
  font: inherit;
}
.button-link:hover { border-color: var(--accent); }
.admin-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: calc(100vh - 56px);
}
.admin-nav {
  background: #121a24;
  border-right: 1px solid var(--border);
  padding: 0.75rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  overflow: auto;
}
.admin-nav-item {
  text-align: left;
  width: 100%;
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
}
.admin-nav-item:hover { color: var(--text); background: rgba(255,255,255,0.03); }
.admin-nav-item.active {
  color: var(--text);
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.12);
}
.admin-main {
  padding: 1.25rem 1.5rem 3rem;
  overflow: auto;
  max-width: 1100px;
}
.admin-panel h1 { margin: 0 0 0.35rem; font-size: 1.45rem; }
.admin-panel h2 { margin: 0 0 0.75rem; font-size: 1.05rem; }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  margin: 1rem 0;
}
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.75rem;
  margin: 1rem 0;
}
.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem;
  text-align: center;
}
.stat-val { font-size: 1.4rem; font-weight: 700; }
.stat-label { font-size: 0.75rem; color: var(--muted); margin-top: 0.2rem; }
.table-wrap { overflow: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
.data-table th, .data-table td {
  text-align: left;
  padding: 0.5rem 0.55rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.data-table th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
.mono-sm { font-family: ui-monospace, Consolas, monospace; font-size: 0.8rem; }
.plain-list { padding-left: 1.15rem; margin: 0.5rem 0; }
.plain-list li { margin: 0.35rem 0; }
.ok-item { color: var(--ok); }
.bad-item { color: var(--muted); }
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin: 0.75rem 0;
}
.filter-row label { margin: 0; min-width: 140px; }
.filter-row select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.4rem 0.55rem;
  font: inherit;
  margin-top: 0.25rem;
}
.cap-ready { color: var(--ok); }
.cap-partial { color: #eab308; }
.cap-blocked { color: #f97316; }
.cap-oos { color: var(--muted); }
.cap-notes { max-width: 280px; font-size: 0.8rem; }
.card-note { margin: 0.5rem 0 1rem; padding: 0.75rem 1rem; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; }
@media (max-width: 800px) {
  .admin-layout { grid-template-columns: 1fr; }
  .admin-nav { flex-direction: row; flex-wrap: wrap; border-right: none; border-bottom: 1px solid var(--border); }
  .admin-nav-item { width: auto; }
}
