:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #172026;
  --muted: #66727f;
  --line: #dfe5ea;
  --brand: #116a7b;
  --brand-strong: #0b4f5c;
  --accent: #b8552e;
  --ok: #247a52;
  --warn: #9a6200;
  --danger: #b42318;
  --shadow: 0 14px 34px rgba(28, 39, 49, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  cursor: pointer;
  white-space: nowrap;
}

button:hover {
  border-color: #aeb9c3;
}

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

.primary {
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
}

.primary:hover {
  border-color: var(--brand-strong);
  background: var(--brand-strong);
}

.danger {
  border-color: #f4c4c0;
  color: var(--danger);
}

input,
select {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
}

.admin-page #app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
}

.admin-page.login-mode #app {
  display: grid;
  grid-template-columns: 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  border-right: 1px solid var(--line);
  background: #ffffff;
  padding: 22px 16px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 30px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.sidebar nav {
  display: grid;
  gap: 6px;
}

.sidebar nav button {
  justify-content: flex-start;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 10px 12px;
}

.sidebar nav button.active {
  background: #eaf4f5;
  color: var(--brand-strong);
  font-weight: 700;
}

.sidebar-status {
  display: grid;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfc;
  margin-top: 18px;
  padding: 12px;
}

.sidebar-status span {
  color: var(--muted);
  font-size: 12px;
}

.sidebar-status strong {
  color: var(--brand-strong);
}

.logout-button {
  width: 100%;
  margin-top: 18px;
  color: var(--muted);
}

.login-shell {
  width: 100%;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(17, 106, 123, 0.10), rgba(184, 85, 46, 0.08)),
    var(--bg);
}

.login-panel {
  width: min(460px, 100%);
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 28px;
}

.login-card-head {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 22px;
}

.login-card-head h1 {
  margin: 2px 0 6px;
}

.login-card-head p {
  color: var(--muted);
  margin: 0;
}

.login-form {
  display: grid;
  gap: 14px;
}

.login-form label {
  display: grid;
  gap: 7px;
}

.login-form label span {
  color: var(--muted);
  font-size: 13px;
}

.login-error {
  margin: 14px 0 0;
  color: var(--danger);
}

.main {
  min-width: 0;
  padding: 22px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  gap: 18px;
  align-items: start;
  margin-bottom: 18px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 4px;
  font-size: 26px;
}

h2 {
  font-size: 20px;
}

h3 {
  font-size: 15px;
}

.topbar p,
.panel p {
  color: var(--muted);
  margin-bottom: 0;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(6, minmax(96px, 1fr));
  gap: 10px;
}

.metric {
  min-height: 70px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 12px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
}

.section {
  display: grid;
  gap: 14px;
}

.section.narrow {
  max-width: 900px;
}

.section-title,
.toolbar,
.bulkbar,
.pager,
.header-actions,
.link-actions,
.row-actions,
.quick-actions,
.inline-form {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.section-title {
  justify-content: space-between;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(260px, 0.6fr);
  gap: 14px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 18px;
  box-shadow: var(--shadow);
}

.mini-list {
  display: grid;
  gap: 8px;
}

.security-list {
  display: grid;
  gap: 9px;
  margin-bottom: 16px;
}

.security-list div,
.audit-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding: 9px 0;
}

.security-list div:last-child,
.audit-row:last-child {
  border-bottom: 0;
}

.security-list span,
.audit-row span {
  color: var(--muted);
}

.audit-list {
  display: grid;
}

.cleanup-tag {
  display: block;
  width: fit-content;
  margin-top: 6px;
  border-radius: 999px;
  background: #fff3d8;
  color: var(--warn);
  padding: 2px 8px;
  font-size: 12px;
}

.mini-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
}

.mini-row:last-child {
  border-bottom: 0;
}

.mini-row strong,
.mini-row span {
  display: block;
}

.mini-row span:not(.pill) {
  color: var(--muted);
  font-size: 13px;
}

.search {
  min-width: min(420px, 100%);
  flex: 1;
}

.bulkbar {
  min-height: 44px;
  border: 1px dashed #c9d2d9;
  border-radius: 8px;
  background: #fff;
  padding: 8px 10px;
}

.bulkbar span {
  color: var(--muted);
  margin-right: 6px;
}

.bulk-spacer {
  flex: 1;
  min-width: 20px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

table {
  width: 100%;
  min-width: 1180px;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

th {
  color: #40505c;
  background: #f9fbfc;
  font-weight: 700;
}

tr:last-child td {
  border-bottom: 0;
}

.note-cell {
  max-width: 180px;
  white-space: normal;
}

.pill,
.folder {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
  font-style: normal;
  font-weight: 700;
}

.pill.ok {
  background: #e9f6ef;
  color: var(--ok);
}

.pill.muted {
  background: #edf0f2;
  color: #596674;
}

.pill.warn {
  background: #fff3d8;
  color: var(--warn);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.form-grid label {
  display: grid;
  gap: 6px;
}

.form-grid label span {
  color: var(--muted);
  font-size: 13px;
}

.wide {
  grid-column: 1 / -1;
}

.result-panel {
  margin-top: 14px;
}

.result-list {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}

.result-list dt {
  color: var(--muted);
}

.result-list dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.muted-text {
  color: var(--muted);
  margin-bottom: 0;
}

.secret {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.settings-list {
  display: grid;
  gap: 10px;
}

.settings-list div {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 8px 0;
}

.settings-list span {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.switch-line {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  color: var(--ink);
}

.log-box {
  min-height: 240px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101820;
  color: #d9e7ee;
  padding: 14px;
}

.empty,
.fatal {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  padding: 24px;
  text-align: center;
}

.empty.compact {
  padding: 14px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 20;
  border-radius: 8px;
  background: #172026;
  color: #fff;
  padding: 10px 14px;
  box-shadow: var(--shadow);
}

.public-shell {
  width: min(1220px, calc(100% - 28px));
  margin: 0 auto;
  padding: 24px 0;
}

.inbox-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}

.eyebrow {
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
}

.inbox-header h1 {
  margin: 4px 0;
  overflow-wrap: anywhere;
}

.inbox-header p {
  color: var(--muted);
  margin-bottom: 0;
}

.inbox-layout {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.mail-list,
.mail-detail {
  min-height: 600px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.mail-list {
  display: grid;
  align-content: start;
}

.mail-item {
  display: grid;
  gap: 5px;
  width: 100%;
  min-height: 112px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  padding: 12px;
  text-align: left;
  background: #fff;
}

.mail-item.active {
  background: #eaf4f5;
}

.mail-item strong,
.mail-item span,
.mail-item small {
  overflow: hidden;
  text-overflow: ellipsis;
}

.mail-item span,
.mail-item small {
  color: var(--muted);
}

.mail-item em {
  color: var(--brand-strong);
  font-style: normal;
  font-weight: 800;
}

.folder {
  width: fit-content;
  background: #f3e8df;
  color: #7b3f1e;
}

.mail-detail {
  padding: 20px;
}

.detail-head {
  border-bottom: 1px solid var(--line);
  margin-bottom: 14px;
  padding-bottom: 12px;
}

.detail-head h2 {
  margin: 10px 0;
  overflow-wrap: anywhere;
}

.detail-head p {
  color: var(--muted);
  margin-bottom: 4px;
  overflow-wrap: anywhere;
}

.code-box {
  display: flex;
  gap: 12px;
  align-items: center;
  width: fit-content;
  border: 1px solid #b8d7c8;
  border-radius: 8px;
  background: #e9f6ef;
  color: var(--ok);
  padding: 10px 12px;
  margin-bottom: 14px;
}

.code-box span {
  color: #3a7659;
}

.code-box strong {
  font-size: 24px;
}

.mail-body {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  line-height: 1.6;
}

mark {
  border-radius: 4px;
  background: #ffe08a;
  padding: 1px 3px;
}

.error-banner {
  border: 1px solid #f4c4c0;
  border-radius: 8px;
  background: #fff0ee;
  color: var(--danger);
  padding: 12px;
  margin-bottom: 14px;
}

.hero-empty {
  margin-top: 20vh;
}

@media (max-width: 1100px) {
  .admin-page #app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .sidebar nav {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .topbar,
  .dashboard-grid,
  .inbox-layout {
    grid-template-columns: 1fr;
  }

  .metrics {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 700px) {
  .main,
  .public-shell {
    padding: 14px;
    width: 100%;
  }

  .sidebar nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .form-grid,
  .settings-list div,
  .result-list {
    grid-template-columns: 1fr;
  }

  .inbox-header {
    align-items: stretch;
    flex-direction: column;
  }

  .header-actions {
    width: 100%;
  }

  .header-actions button {
    flex: 1;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
