:root {
  color-scheme: dark;
  --bg: #0b1020;
  --panel: #121a2f;
  --panel-2: #18233d;
  --text: #e8eefc;
  --muted: #9fb0d0;
  --accent: #6ea8ff;
  --accent-2: #5b8def;
  --border: rgba(255, 255, 255, 0.08);
  --danger: #ff7b7b;
  --ok: #3dd68c;
  --warn: #f5c84c;
  --unread: #6ea8ff;
  --sidebar: 180px;
  --list: 300px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: radial-gradient(circle at top, #172554 0%, var(--bg) 45%);
  color: var(--text);
  font-size: 14px;
}

.login-body {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 8vh 1rem;
}

.panel {
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}

.login-box { max-width: 420px; width: 100%; }
.login-box h1 { margin: 0; font-size: 1.8rem; letter-spacing: -0.02em; }
.subtitle { color: var(--muted); margin: 0.35rem 0 1.25rem; }
label { display: block; margin-bottom: 0.25rem; color: var(--muted); font-size: 0.8rem; }

input[type="password"],
input[type="text"],
input[type="email"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0a1224;
  color: var(--text);
  font: inherit;
}

textarea { min-height: 120px; resize: vertical; }

button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  margin-top: 0.85rem;
  padding: 0.45rem 0.75rem;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  font: inherit;
  font-size: 0.85rem;
}

button.ghost, .btn.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

button.danger {
  background: transparent;
  border: 1px solid rgba(255, 123, 123, 0.45);
  color: var(--danger);
}

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

.error { color: var(--danger); margin-top: 0.75rem; }
.muted { color: var(--muted); }
.field-hint {
  display: block;
  margin-top: 0.3rem;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.35;
}

.app {
  display: grid;
  grid-template-columns: var(--sidebar) var(--list) 1fr;
  grid-template-rows: auto 1fr;
  height: 100vh;
  max-height: 100vh;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.45rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: rgba(12, 18, 36, 0.92);
  backdrop-filter: blur(8px);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.brand h1 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: -0.02em;
}

.brand .tag {
  color: var(--muted);
  font-size: 0.72rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.topbar-actions input[type="search"] {
  width: min(220px, 36vw);
  margin: 0;
  padding: 0.4rem 0.55rem;
}

.topbar-actions button { margin-top: 0; }

.sidebar, .msg-list, .reader {
  overflow: auto;
  border-right: 1px solid var(--border);
  background: rgba(10, 16, 32, 0.55);
}

.reader { border-right: 0; }

.sidebar { padding: 0.55rem 0.4rem; }
.sidebar h2 {
  margin: 0 0 0.4rem;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 0 0.35rem;
}

.nav-item {
  display: block;
  width: 100%;
  text-align: left;
  margin: 0 0 0.2rem;
  padding: 0.4rem 0.5rem;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 0.82rem;
}

.nav-item:hover { background: rgba(255, 255, 255, 0.04); }
.nav-item.active {
  border-color: rgba(110, 168, 255, 0.35);
  background: rgba(110, 168, 255, 0.12);
}

.nav-item .hint {
  display: block;
  color: var(--muted);
  font-size: 0.68rem;
  margin-top: 0.1rem;
  word-break: break-all;
  line-height: 1.25;
}

.msg-list { display: flex; flex-direction: column; }
.list-head {
  padding: 0.45rem 0.65rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.4rem;
}
.list-head h2 { margin: 0; font-size: 0.85rem; }
.list-head .muted { font-size: 0.75rem; }

.msg-row {
  display: block;
  width: 100%;
  text-align: left;
  margin-top: 0;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  background: transparent;
  color: inherit;
  padding: 0.45rem 0.65rem;
  cursor: pointer;
  font: inherit;
  font-weight: 400;
  gap: 0;
}

.msg-row:hover { background: rgba(255, 255, 255, 0.03); }
.msg-row.active { background: rgba(110, 168, 255, 0.1); }
.msg-row.unread .subject { color: var(--unread); font-weight: 700; }

.msg-row .meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.7rem;
  margin-bottom: 0.1rem;
  line-height: 1.3;
}
.msg-row .meta .from {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.msg-row .meta .date {
  flex-shrink: 0;
}
.msg-row .subject {
  font-size: 0.85rem;
  margin-bottom: 0.1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}
.msg-row .preview {
  color: var(--muted);
  font-size: 0.72rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}
.msg-row .account-chip {
  display: inline-block;
  margin-top: 0.2rem;
  font-size: 0.65rem;
  color: var(--accent);
  border: 1px solid rgba(110, 168, 255, 0.25);
  border-radius: 999px;
  padding: 0.05rem 0.4rem;
  line-height: 1.3;
}

.reader { padding: 0.75rem 0.9rem 1.25rem; }
.reader-empty {
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 160px;
  font-size: 0.9rem;
}

.reader-header h2 {
  margin: 0 0 0.35rem;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
  line-height: 1.3;
}
.reader-meta {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
  margin-bottom: 0.65rem;
}
.reader-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}
.reader-actions button { margin-top: 0; }

.reader-body {
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
  line-height: 1.5;
  word-break: break-word;
  font-size: 0.9rem;
}
.reader-body pre {
  white-space: pre-wrap;
  font-family: inherit;
  margin: 0;
}
.reader-body iframe {
  width: 100%;
  min-height: 280px;
  border: 0;
  background: #fff;
  border-radius: 8px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 50;
}
.modal-backdrop:not([hidden]) {
  display: flex;
}
.modal-backdrop[hidden] {
  display: none !important;
}
.modal {
  width: min(560px, 100%);
  max-height: 90vh;
  overflow: auto;
}
.modal h2 { margin: 0 0 0.75rem; font-size: 1.1rem; }
.form-row { margin-bottom: 0.55rem; }
.form-actions {
  display: flex;
  gap: 0.45rem;
  justify-content: flex-end;
  margin-top: 0.25rem;
}
.form-actions button { margin-top: 0; }

.status-bar {
  padding: 0.45rem 0.65rem;
  color: var(--muted);
  font-size: 0.75rem;
}

@media (max-width: 960px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto minmax(180px, 32vh) 1fr;
    height: auto;
    max-height: none;
    min-height: 100vh;
  }
  .sidebar, .msg-list { border-right: 0; border-bottom: 1px solid var(--border); }
  .sidebar { display: flex; flex-wrap: wrap; gap: 0.25rem; align-items: flex-start; }
  .sidebar h2 { width: 100%; }
  .nav-item { width: auto; }
}
