:root {
  --paper: #f4efe4;
  --paper-light: #fffaf0;
  --ink: #20342c;
  --ink-muted: #66746d;
  --apple: #c9362b;
  --apple-dark: #8f211b;
  --leaf: #1f6048;
  --leaf-light: #dce9da;
  --gold: #d7a643;
  --line: #d9d0bf;
  --shadow: 0 24px 70px rgb(56 43 27 / 14%);
  --serif: "Iowan Old Style", "Palatino Linotype", "Noto Serif SC", serif;
  --sans: "Avenir Next", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--paper); }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(115deg, rgb(255 255 255 / 44%), transparent 42%),
    repeating-linear-gradient(90deg, transparent 0 39px, rgb(95 72 43 / 3%) 40px),
    var(--paper);
  font-family: var(--sans);
}

button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }

.ambient {
  position: fixed;
  z-index: -1;
  width: 360px;
  height: 360px;
  border-radius: 50%;
  filter: blur(4px);
  opacity: .2;
}

.ambient-one { top: -140px; right: -80px; background: var(--apple); }
.ambient-two { bottom: -190px; left: -80px; background: var(--leaf); }

.eyebrow {
  margin: 0 0 8px;
  color: var(--apple);
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .18em;
}

.brand-mark {
  display: grid;
  width: 76px;
  height: 76px;
  place-items: center;
  color: #fff;
  border-radius: 42% 46% 50% 48%;
  background: var(--apple);
  box-shadow: inset -8px -8px 0 rgb(94 20 16 / 14%);
  font: 700 2.15rem/1 var(--serif);
  transform: rotate(-3deg);
}

.brand-mark-small { width: 44px; height: 44px; font-size: 1.2rem; }

.login-shell { display: grid; min-height: 100vh; padding: 28px; place-items: center; }

.login-card {
  position: relative;
  width: min(100%, 450px);
  padding: 50px;
  overflow: hidden;
  border: 1px solid rgb(143 33 27 / 18%);
  border-radius: 6px 50px 6px 6px;
  background: rgb(255 250 240 / 92%);
  box-shadow: var(--shadow);
}

.login-card::after {
  position: absolute;
  top: -45px;
  right: -35px;
  width: 150px;
  height: 150px;
  border: 22px solid rgb(31 96 72 / 9%);
  border-radius: 50%;
  content: "";
}

.login-card h1, .hero-panel h1, .panel-heading h2, .dialog-heading h2 {
  margin: 0;
  font-family: var(--serif);
}

.login-card h1 { margin-top: 26px; font-size: clamp(2.8rem, 9vw, 4.6rem); line-height: .9; }
.login-copy { max-width: 30ch; margin: 20px 0 32px; color: var(--ink-muted); line-height: 1.8; }

.login-form { display: grid; gap: 11px; }
.login-form label, dialog label { color: var(--ink-muted); font-size: .84rem; font-weight: 700; }

input, textarea, select {
  min-height: 44px;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 7px;
  outline: none;
  background: #fffdf7;
}

input, textarea { padding: 10px 13px; }
textarea { width: 100%; resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--leaf); box-shadow: 0 0 0 3px rgb(31 96 72 / 13%); }

.button {
  min-height: 40px;
  padding: 9px 15px;
  color: var(--ink);
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  font-size: .86rem;
  font-weight: 800;
  transition: transform .16s ease, background-color .16s ease, color .16s ease;
}

.button:hover:not(:disabled) { transform: translateY(-1px); }
.button-primary { color: #fff; background: var(--apple); box-shadow: 0 8px 20px rgb(143 33 27 / 18%); }
.button-primary:hover { background: var(--apple-dark); }
.button-outline { border-color: var(--line); background: rgb(255 255 255 / 58%); }
.button-quiet { color: var(--leaf); background: var(--leaf-light); }
.button-danger { color: var(--apple-dark); border-color: rgb(201 54 43 / 24%); }
.button-wide { width: 100%; margin-top: 8px; }

.app-shell { min-height: 100vh; animation: reveal .45s ease both; }
@keyframes reveal { from { opacity: 0; transform: translateY(8px); } }

.topbar {
  display: flex;
  min-height: 76px;
  padding: 14px clamp(20px, 5vw, 70px);
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: rgb(244 239 228 / 88%);
  backdrop-filter: blur(14px);
}

.brand-lockup { display: flex; color: inherit; align-items: center; gap: 12px; text-decoration: none; }
.brand-lockup strong { display: block; font: 700 1.3rem/1.1 var(--serif); }
.brand-lockup small { color: var(--ink-muted); font-size: .68rem; letter-spacing: .08em; }
.topbar-actions, .hero-actions, .batch-actions, .dialog-actions, .folder-tabs { display: flex; flex-wrap: wrap; gap: 9px; }

.workspace { width: min(1440px, 100%); margin: 0 auto; padding: 42px clamp(18px, 5vw, 70px) 80px; }

.hero-panel {
  display: flex;
  padding: clamp(28px, 5vw, 56px);
  align-items: end;
  justify-content: space-between;
  gap: 30px;
  color: #fdf8ed;
  border-radius: 7px 70px 7px 7px;
  background:
    radial-gradient(circle at 90% 10%, rgb(215 166 67 / 38%), transparent 23%),
    linear-gradient(120deg, #1c513e, #173b31);
  box-shadow: var(--shadow);
}

.hero-panel .eyebrow { color: #f1bb58; }
.hero-panel h1 { font-size: clamp(2.5rem, 6vw, 5.5rem); line-height: .95; }
.hero-panel p:last-child { margin-bottom: 0; color: rgb(255 255 255 / 70%); }

.stats-grid { display: grid; margin: 22px 0; gap: 14px; grid-template-columns: repeat(3, 1fr); }
.stat-card { position: relative; min-height: 125px; padding: 24px; overflow: hidden; border: 1px solid var(--line); background: rgb(255 250 240 / 80%); }
.stat-card::after { position: absolute; right: -24px; bottom: -38px; width: 110px; height: 110px; border: 15px solid currentColor; border-radius: 50%; opacity: .07; content: ""; }
.stat-card span { display: block; color: var(--ink-muted); font-size: .78rem; font-weight: 700; letter-spacing: .08em; }
.stat-card strong { font: 700 3rem/1.2 var(--serif); }
.stat-bound { color: var(--leaf); }
.stat-invalid { color: var(--apple); }

.account-panel { border: 1px solid var(--line); background: rgb(255 250 240 / 88%); box-shadow: 0 14px 45px rgb(56 43 27 / 7%); }
.panel-heading, .filter-row { display: flex; padding: 24px 28px; align-items: center; justify-content: space-between; gap: 18px; }
.panel-heading { border-bottom: 1px solid var(--line); }
.panel-heading h2 { font-size: 1.8rem; }
.filter-row { padding-top: 18px; padding-bottom: 18px; }
.search-box { display: flex; width: min(470px, 100%); align-items: center; gap: 12px; color: var(--ink-muted); font-size: .8rem; font-weight: 800; }
.search-box input { width: 100%; }
.page-size { display: flex; align-items: center; gap: 8px; color: var(--ink-muted); font-size: .8rem; }
.page-size select { min-height: 38px; padding: 0 28px 0 10px; }

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 15px 18px; text-align: left; border-top: 1px solid #e7dfd0; white-space: nowrap; }
th { color: var(--ink-muted); background: #f2ebdf; font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; }
td { font-size: .86rem; }
tbody tr { transition: background-color .15s ease; }
tbody tr:hover { background: #fffdf8; }
.account-email { max-width: 330px; overflow: hidden; font-weight: 700; text-overflow: ellipsis; }
.account-actions { display: flex; gap: 5px; }
.table-action { padding: 5px 8px; color: var(--leaf); border: 0; border-bottom: 1px solid transparent; background: transparent; font-size: .76rem; }
.table-action:hover { border-color: var(--leaf); }
.status-badge { display: inline-block; padding: 4px 8px; border-radius: 99px; font-size: .72rem; font-weight: 800; }
.status-badge.is-positive { color: var(--leaf); background: var(--leaf-light); }
.status-badge.is-muted { color: var(--apple-dark); background: #f3ded8; }
.empty-cell { padding: 55px; color: var(--ink-muted); text-align: center; }

.pagination { display: flex; padding: 18px 24px; align-items: center; justify-content: center; gap: 16px; border-top: 1px solid var(--line); }
.pagination span { min-width: 55px; text-align: center; font: 700 .9rem var(--serif); }
.pagination.compact { padding: 10px; }

.app-status { position: fixed; z-index: 30; right: 20px; bottom: 20px; max-width: min(430px, calc(100vw - 40px)); margin: 0; padding: 12px 17px; color: #fff; border-radius: 7px; background: var(--ink); box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translateY(10px); transition: opacity .2s ease, transform .2s ease; }
.app-status:not(:empty) { opacity: 1; transform: translateY(0); }
.app-status[data-tone="success"] { background: var(--leaf); }
.app-status[data-tone="error"] { background: var(--apple-dark); }

dialog { color: var(--ink); border: 0; padding: 0; }
dialog::backdrop { background: rgb(25 35 31 / 58%); backdrop-filter: blur(4px); }
.dialog-card { width: min(620px, calc(100vw - 28px)); padding: 28px; border-radius: 7px 38px 7px 7px; background: var(--paper-light); box-shadow: var(--shadow); }
.dialog-heading { display: flex; align-items: start; justify-content: space-between; gap: 20px; }
.dialog-heading h2 { font-size: 2rem; }
.icon-button { width: 38px; height: 38px; color: var(--ink-muted); border: 1px solid var(--line); border-radius: 50%; background: transparent; font-size: 1.4rem; }
.hint { color: var(--ink-muted); font-size: .84rem; line-height: 1.7; }
code { color: var(--apple-dark); font: .8rem ui-monospace, monospace; }
.or-rule { display: flex; margin: 18px 0; color: var(--ink-muted); align-items: center; gap: 12px; font-size: .75rem; }
.or-rule::before, .or-rule::after { height: 1px; background: var(--line); content: ""; flex: 1; }
.dialog-actions { margin-top: 20px; justify-content: flex-end; }

.secret-list { display: grid; gap: 9px; }
.secret-list div { display: grid; padding: 12px; border: 1px solid var(--line); background: #fffdf8; grid-template-columns: 110px 1fr auto; gap: 10px; align-items: center; }
.secret-list dt { color: var(--ink-muted); font-size: .75rem; }
.secret-list dd { min-width: 0; margin: 0; overflow: hidden; font: .78rem ui-monospace, monospace; text-overflow: ellipsis; white-space: nowrap; }
.secret-list button { color: var(--leaf); border: 0; background: transparent; font-size: .76rem; font-weight: 800; }

.mail-dialog { width: min(1250px, calc(100vw - 28px)); height: min(820px, calc(100vh - 28px)); padding: 24px; background: var(--paper-light); box-shadow: var(--shadow); }
.mail-dialog-heading { padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.mail-tools { display: flex; padding: 14px 0; align-items: end; justify-content: space-between; gap: 18px; }
.verify-tools { display: flex; align-items: center; gap: 8px; }
.verify-tools label { white-space: nowrap; }
.verify-tools input { width: 170px; }
.mail-layout { display: grid; height: calc(100% - 150px); overflow: hidden; border: 1px solid var(--line); grid-template-columns: minmax(250px, 34%) 1fr; }
.mail-layout aside { display: flex; min-height: 0; border-right: 1px solid var(--line); flex-direction: column; }
.mail-list { min-height: 0; overflow-y: auto; flex: 1; }
.mail-list-item { display: grid; width: 100%; padding: 15px; color: var(--ink); border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left; gap: 5px; }
.mail-list-item:hover { background: #f4eddf; }
.mail-subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-sender, .mail-time { color: var(--ink-muted); font-size: .74rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-detail { min-width: 0; min-height: 0; padding: 22px; overflow: auto; }
.mail-detail-header { padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.mail-detail-subject { margin: 0; font: 700 1.5rem var(--serif); }
.mail-detail-sender { color: var(--ink-muted); }
.mail-frame { width: 100%; min-height: 520px; margin-top: 16px; border: 0; background: #fff; }
.mail-plain-text { min-height: 300px; margin: 16px 0 0; padding: 18px; overflow: auto; border: 0; background: #fff; font: .9rem/1.7 ui-monospace, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.empty-state { padding: 30px 16px; color: var(--ink-muted); text-align: center; }

[hidden] { display: none !important; }

@media (max-width: 800px) {
  .topbar { padding-inline: 16px; }
  .topbar-actions #random-unbound { display: none; }
  .workspace { padding: 20px 12px 70px; }
  .hero-panel { align-items: start; border-radius: 7px 42px 7px 7px; flex-direction: column; }
  .stats-grid { grid-template-columns: 1fr; }
  .stat-card { min-height: 94px; }
  .panel-heading, .filter-row { padding: 18px; align-items: stretch; flex-direction: column; }
  .batch-actions .button { flex: 1; }
  .page-size { justify-content: flex-end; }
  .mail-tools { align-items: stretch; flex-direction: column; }
  .verify-tools { display: grid; grid-template-columns: 1fr auto; }
  .verify-tools label { grid-column: 1 / -1; }
  .verify-tools input { width: 100%; }
  .mail-layout { height: calc(100% - 210px); grid-template-columns: 1fr; grid-template-rows: 42% 58%; }
  .mail-layout aside { border-right: 0; border-bottom: 1px solid var(--line); }
  .secret-list div { grid-template-columns: 1fr auto; }
  .secret-list dt { grid-column: 1 / -1; }
}

@media (max-width: 520px) {
  .login-shell { padding: 14px; }
  .login-card { padding: 32px 24px; }
  .brand-lockup small { display: none; }
  .hero-actions, .hero-actions .button { width: 100%; }
  .account-actions { min-width: 235px; }
  .dialog-card { padding: 20px; }
  .mail-dialog { padding: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
