:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #172026;
  --muted: #66727f;
  --line: #dfe5ea;
  --brand: #116a7b;
  --brand-strong: #0b4f5c;
  --accent: #a24f34;
  --ok: #247a52;
  --warn: #9a6200;
  --danger: #b42318;
  --shadow: 0 14px 34px rgba(28, 39, 49, 0.08);
  --soft-shadow: 0 1px 2px rgba(23, 32, 38, 0.05), 0 18px 42px rgba(23, 32, 38, 0.07);
}

* {
  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;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease, transform 0.12s ease;
}

button:hover {
  border-color: #aeb9c3;
  box-shadow: 0 1px 2px rgba(23, 32, 38, 0.08);
}

button:active {
  transform: translateY(1px);
}

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 #15333b;
  background: #10242b;
  color: #eef7f8;
  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: #9fb8bf;
  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;
  color: #c9dbe0;
  padding: 10px 12px;
}

.sidebar nav button.active {
  background: #e9f6ef;
  color: #0b4f5c;
  font-weight: 700;
  box-shadow: inset 3px 0 0 #29a17a;
}

.sidebar-status {
  display: grid;
  gap: 5px;
  border: 1px solid #25454d;
  border-radius: 8px;
  background: #142f36;
  margin-top: 18px;
  padding: 12px;
}

.sidebar-status span {
  color: #9fb8bf;
  font-size: 12px;
}

.sidebar-status strong {
  color: #eef7f8;
}

.logout-button {
  width: 100%;
  margin-top: 18px;
  border-color: #31545d;
  background: #17343c;
  color: #dcebed;
}

.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: 1fr;
  gap: 18px;
  align-items: start;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: linear-gradient(180deg, #fff, #fbfcfd);
  padding: 16px;
  box-shadow: var(--soft-shadow);
}

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(auto-fit, minmax(116px, 1fr));
  gap: 10px;
  min-width: 0;
  width: 100%;
}

.metric {
  min-height: 70px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff, #fbfcfd);
  padding: 12px;
  box-shadow: 0 1px 2px rgba(23, 32, 38, 0.04);
}

.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;
}

.toolbar {
  position: sticky;
  top: 0;
  z-index: 3;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  padding: 10px;
  box-shadow: 0 8px 18px rgba(23, 32, 38, 0.06);
  backdrop-filter: blur(10px);
}

.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(--soft-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;
}

.sold-tag {
  display: block;
  width: fit-content;
  margin-top: 6px;
  border-radius: 999px;
  background: #eaf7ef;
  color: #137a3a;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 700;
}

.banned-tag {
  display: block;
  width: fit-content;
  margin-top: 6px;
  border-radius: 999px;
  background: #ffe9e9;
  color: #b42318;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 700;
}

.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 solid #cfd8df;
  border-radius: 8px;
  background: #f8fbfa;
  padding: 8px 10px;
  box-shadow: 0 1px 2px rgba(23, 32, 38, 0.04);
}

.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);
  box-shadow: var(--soft-shadow);
}

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: #f8fafb;
  font-weight: 700;
  position: sticky;
  top: 0;
  z-index: 1;
}

tbody tr:hover {
  background: #f6fbfb;
}

.row-actions button,
.link-actions button {
  min-height: 30px;
  padding: 0 9px;
  font-size: 12px;
}

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;
}

.public-shell .empty {
  display: grid;
  gap: 8px;
  color: var(--muted);
  text-align: center;
}

.public-shell .empty strong {
  color: var(--ink);
  font-size: 16px;
}

.public-shell .empty span {
  max-width: 440px;
  margin: 0 auto;
  line-height: 1.7;
}

.inbox-header {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto auto;
  align-items: stretch;
  gap: 16px;
  padding: 18px;
}

.inbox-title {
  display: grid;
  align-content: center;
  min-width: 0;
}

.inbox-title h1 {
  font-size: 25px;
  line-height: 1.2;
}

.inbox-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(92px, 1fr));
  gap: 8px;
  align-items: stretch;
}

.inbox-stat {
  display: grid;
  gap: 5px;
  min-width: 92px;
  border: 1px solid #e7edf1;
  border-radius: 8px;
  background: #f8fafb;
  padding: 10px 12px;
}

.inbox-stat span,
.section-title span {
  color: var(--muted);
  font-size: 12px;
}

.inbox-stat strong {
  font-size: 15px;
  overflow-wrap: anywhere;
}

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

.mail-list,
.mail-detail {
  box-shadow: var(--soft-shadow);
}

.mail-list-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfd;
  padding: 12px 14px;
}

.mail-list-head span {
  color: var(--muted);
}

.mail-item {
  gap: 7px;
  min-height: 124px;
  padding: 14px;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

.mail-item:hover {
  background: #f8fafb;
}

.mail-item.active {
  background: #eef7f8;
  box-shadow: inset 3px 0 0 var(--brand);
}

.mail-item-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.folder {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border: 1px solid #ead6c9;
  border-radius: 999px;
  background: #fff7f1;
  color: #8a4a27;
  font-size: 12px;
  font-weight: 800;
  padding: 2px 8px;
}

.mail-item em {
  justify-self: start;
  border-radius: 6px;
  background: #e8f6ef;
  padding: 3px 8px;
}

.detail-head {
  display: grid;
  gap: 8px;
}

.detail-head h2 {
  font-size: 22px;
  line-height: 1.35;
}

.mail-meta-row {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  color: var(--muted);
}

.mail-meta-row strong {
  color: var(--ink);
  font-weight: 600;
  overflow-wrap: anywhere;
}

.detail-section {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.section-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.mail-body {
  min-height: 180px;
  border: 1px solid #e8edf1;
  border-radius: 8px;
  background: #fbfcfd;
  padding: 14px;
}

.email-render-section .section-title {
  display: none;
}

.email-html-expanded {
  width: 100%;
  border: 1px solid #e8edf1;
  border-radius: 8px;
  background: #fff;
  padding: 16px;
  overflow: visible;
  isolation: isolate;
  position: relative;
  line-height: 1.55;
  color: var(--ink);
}

.email-html-expanded * {
  box-sizing: border-box;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.email-html-expanded img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 0 12px;
  border-radius: 6px;
}

.email-html-expanded table {
  width: auto;
  max-width: 100%;
  border-collapse: collapse;
}

.email-html-expanded p {
  margin: 0 0 12px;
  color: inherit;
}

.email-html-expanded a,
.mail-body a {
  color: var(--brand);
  font-weight: 700;
  overflow-wrap: anywhere;
  text-decoration: none;
}

.email-html-expanded a:hover,
.mail-body a:hover {
  text-decoration: underline;
}

.public-shell-pro {
  padding-top: 18px;
}

.inbox-hero {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  gap: 16px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: linear-gradient(180deg, #ffffff, #f8fbfa);
  box-shadow: var(--soft-shadow);
  padding: 20px;
  margin-bottom: 14px;
}

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

.public-kpis {
  display: grid;
  grid-template-columns: minmax(220px, 1.35fr) repeat(4, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.public-kpi {
  display: grid;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 13px;
  box-shadow: 0 1px 2px rgba(23, 32, 38, 0.04);
}

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

.public-kpi strong {
  overflow-wrap: anywhere;
  font-size: 15px;
}

.code-kpi {
  border-color: #b8d7c8;
  background: #f3fbf6;
}

.code-kpi strong {
  color: var(--ok);
  font-size: 18px;
}

.code-kpi button {
  width: fit-content;
}

.inbox-layout-pro {
  grid-template-columns: minmax(320px, 390px) minmax(0, 1fr);
}

.mail-list-head > div {
  display: grid;
  gap: 2px;
}

.auto-refresh {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.muted-code {
  border-color: var(--line);
  background: #f8fafb;
  color: var(--muted);
}

@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,
  .inbox-header,
  .inbox-hero,
  .public-kpis {
    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;
  }

  .header-actions {
    width: 100%;
  }

  .header-actions button,
  .inbox-actions button {
    flex: 1;
  }

  .inbox-actions {
    width: 100%;
  }

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

  .inbox-summary {
    grid-template-columns: 1fr;
  }

  .mail-list,
  .mail-detail {
    min-height: 0;
  }
}
