:root {
  --bg: #0a0a0a;
  --panel: #111111;
  --panel-2: #161616;
  --line: #2a2418;
  --line-gold: #3d3520;
  --text: #ececec;
  --muted: #8a8478;
  --gold: #c9a84c;
  --gold-bright: #e4c76a;
  --gold-dim: #8a7340;
  --danger: #c45c5c;
  --radius: 6px;
  --radius-pill: 999px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  min-height: 100vh;
  font-size: 14px;
}

a {
  color: inherit;
  text-decoration: none;
}

.page {
  max-width: 1480px;
  margin: 0 auto;
  padding: 0 24px 32px;
}

/* ── Top bar ── */

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 18px 0 20px;
  gap: 16px;
}

.brand {
  font-size: 1.05rem;
  color: var(--gold);
  font-weight: 500;
  letter-spacing: 0.02em;
}

.topnav {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.topnav a {
  padding: 7px 16px;
  border-radius: var(--radius-pill);
  color: var(--gold);
  font-size: 0.88rem;
  border: 1px solid transparent;
  transition: background 0.15s, color 0.15s;
}

.topnav a:hover {
  color: var(--gold-bright);
}

.topnav a.active {
  background: var(--gold);
  color: #111;
  font-weight: 500;
}

.userbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  font-size: 0.88rem;
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--panel-2);
  border: 1px solid var(--line-gold);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  color: var(--gold);
  font-weight: 600;
  text-transform: uppercase;
}

.userbar-name {
  color: var(--text);
}

.userbar a {
  color: var(--muted);
}

.userbar a:hover {
  color: var(--gold);
}

.main-content {
  padding-top: 4px;
}

/* ── Section titles ── */

.section-title {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
  margin: 0 0 14px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-head .section-title {
  margin: 0;
}

/* ── Three-column workspace ── */

.workspace {
  display: grid;
  grid-template-columns: 280px minmax(320px, 1fr) minmax(360px, 1.1fr);
  gap: 20px;
  min-height: calc(100vh - 120px);
}

.col {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.col-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

/* ── Mailbox column ── */

.generate-block {
  margin-bottom: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.generate-block label {
  margin-bottom: 8px;
}

.inline-form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.input-sm {
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  border: 1px solid var(--line-gold);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
}

table .input-sm {
  width: 140px;
  flex: none;
  margin-bottom: 0;
}

.input-sm:focus {
  outline: none;
  border-color: var(--gold-dim);
}

.mailbox-scroll {
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 2px;
}

.mailbox-tile-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mailbox-tile {
  display: block;
  padding: 10px 12px;
  border: 1px solid var(--line-gold);
  border-radius: var(--radius);
  background: var(--panel-2);
  transition: border-color 0.15s, background 0.15s;
}

.mailbox-tile:hover {
  border-color: var(--gold-dim);
}

.mailbox-tile.active {
  border-color: var(--gold);
  background: #1c1810;
}

.mailbox-email {
  display: block;
  font-size: 0.82rem;
  word-break: break-all;
  color: var(--text);
}

.mailbox-meta {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 4px;
}

.mailbox-tools {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

/* ── Inbox / message list ── */

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

.selected-mailbox-label {
  flex: 1;
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.message-scroll {
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 2px;
}

.message-tile {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line-gold);
  border-radius: var(--radius);
  background: var(--panel-2);
  transition: border-color 0.15s, background 0.15s;
}

.message-tile:hover {
  border-color: var(--gold-dim);
}

.message-tile.active {
  border-color: var(--gold);
  background: #1c1810;
}

.message-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius);
  background: var(--bg);
  border: 1px solid var(--line-gold);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  color: var(--gold);
  flex-shrink: 0;
}

.message-tile-body {
  min-width: 0;
  flex: 1;
}

.message-subject {
  display: block;
  font-size: 0.88rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.message-preview {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.message-date {
  display: block;
  font-size: 0.72rem;
  color: var(--gold-dim);
  margin-top: 4px;
}

/* ── Message view column ── */

.message-view-panel {
  flex: 1;
  overflow-y: auto;
}

.message-view-card {
  background: var(--panel-2);
  border: 1px solid var(--line-gold);
  border-radius: var(--radius);
  padding: 18px;
  min-height: 200px;
}

.message-view-head h2 {
  margin: 0 0 8px;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text);
}

.message-view-meta {
  margin: 0 0 18px;
  font-size: 0.8rem;
  color: var(--muted);
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.message-view-body {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.88rem;
  color: #c8c4bc;
  line-height: 1.6;
}

/* ── Buttons ── */

button,
.btn {
  padding: 7px 14px;
  border: 1px solid var(--line-gold);
  border-radius: var(--radius);
  background: var(--panel-2);
  color: var(--gold);
  cursor: pointer;
  font-size: 0.82rem;
  transition: border-color 0.15s, background 0.15s;
}

button:hover,
.btn:hover {
  border-color: var(--gold-dim);
  background: #1c1810;
}

.btn-primary {
  background: var(--gold);
  border-color: var(--gold);
  color: #111;
  font-weight: 500;
}

.btn-primary:hover {
  background: var(--gold-bright);
  border-color: var(--gold-bright);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 0.78rem;
}

.btn-text {
  background: none;
  border: none;
  color: var(--gold-dim);
  cursor: pointer;
  font-size: 0.78rem;
  padding: 0;
}

.btn-text:hover {
  color: var(--gold);
}

.btn-text.danger:hover {
  color: var(--danger);
}

.btn-refresh {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--line-gold);
  border-radius: var(--radius);
  background: var(--panel-2);
  color: var(--gold);
  font-size: 0.8rem;
}

.btn-refresh:hover {
  border-color: var(--gold);
  background: #1c1810;
}

/* ── Notices & empty states ── */

.notice {
  margin-bottom: 16px;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--line-gold);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.85rem;
}

.notice code {
  color: var(--gold-bright);
  font-family: Consolas, monospace;
}

.empty {
  color: var(--muted);
  font-size: 0.85rem;
  padding: 20px 0;
  text-align: center;
}

.empty.centered {
  margin: auto;
}

.error-msg {
  color: var(--danger);
  padding: 12px 0;
  font-size: 0.85rem;
}

.flash {
  margin-bottom: 14px;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  background: var(--panel);
  border: 1px solid var(--line);
}

.flash.success {
  border-color: var(--line-gold);
  color: var(--gold);
}

.flash.error {
  border-color: #4a2020;
  color: var(--danger);
}

/* ── Forms (auth, settings) ── */

label {
  display: block;
  margin-bottom: 6px;
  color: var(--gold-dim);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

input[type="text"],
input[type="password"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line-gold);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  margin-bottom: 14px;
  font-size: 0.9rem;
}

input:focus {
  outline: none;
  border-color: var(--gold-dim);
}

.auth-wrap {
  min-height: 70vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
}

.auth-card h2 {
  margin: 0 0 22px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
}

.muted {
  color: var(--muted);
  font-size: 0.85rem;
}

.muted a:hover {
  color: var(--gold);
}

/* ── Admin ── */

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}

.card h2 {
  margin: 0 0 16px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

th,
td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
}

th {
  color: var(--gold-dim);
  font-weight: 500;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ── Scrollbars ── */

.mailbox-scroll::-webkit-scrollbar,
.message-scroll::-webkit-scrollbar,
.message-view-panel::-webkit-scrollbar {
  width: 6px;
}

.mailbox-scroll::-webkit-scrollbar-thumb,
.message-scroll::-webkit-scrollbar-thumb,
.message-view-panel::-webkit-scrollbar-thumb {
  background: var(--line-gold);
  border-radius: 3px;
}

/* ── Responsive ── */

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto 1fr;
  }

  .col-mailboxes {
    grid-column: 1 / -1;
    max-height: 280px;
  }

  .col-mailboxes .col-panel {
    flex-direction: row;
    gap: 16px;
  }

  .generate-block {
    margin: 0;
    padding: 0;
    border: none;
    flex-shrink: 0;
    width: 200px;
  }

  .mailbox-scroll {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .mailbox-tile {
    min-width: 200px;
  }
}

@media (max-width: 720px) {
  .topbar {
    grid-template-columns: 1fr;
    text-align: center;
  }

  .topnav {
    flex-wrap: wrap;
  }

  .userbar {
    justify-content: center;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .col-mailboxes .col-panel {
    flex-direction: column;
  }

  .mailbox-scroll {
    flex-direction: column;
    overflow-x: hidden;
    overflow-y: auto;
  }
}
