/* ================= Tsubaki Mail — design tokens ================= */

:root {
  --bg: #f7f4ee;
  --bg-soft: #efeae0;
  --card: #ffffff;
  --ink: #26211c;
  --muted: #8a8174;
  --dim: #a89e8f;
  --border: #e7e0d3;
  --accent: #c0392f;        /* 椿紅 */
  --accent-hover: #a12c24;
  --accent-soft: #fbeae8;
  --gold: #f2c14e;
  --ok-bg: #eef7ee;  --ok-ink: #2d6a37;  --ok-border: #cde5cf;
  --err-bg: #fdefed; --err-ink: #9c2b22; --err-border: #f3d1cd;
  --warn-bg: #fdf6e4; --warn-ink: #8a6413; --warn-border: #f0e2b6;
  --shadow: 0 1px 2px rgba(38, 33, 28, 0.05), 0 8px 24px rgba(38, 33, 28, 0.06);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15120f;
    --bg-soft: #1c1814;
    --card: #211d18;
    --ink: #ece6dc;
    --muted: #9c927f;
    --dim: #786f5f;
    --border: #322c24;
    --accent: #e05c50;
    --accent-hover: #ef766b;
    --accent-soft: #3a2320;
    --ok-bg: #1d2b1e;  --ok-ink: #8fcf98;  --ok-border: #2d4630;
    --err-bg: #331d1a; --err-ink: #f0968d; --err-border: #553029;
    --warn-bg: #31290f; --warn-ink: #e3c36a; --warn-border: #4d4119;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Inter", "Noto Sans JP", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 17px; font-weight: 700; margin: 0 0 14px; }
h3 { font-size: 14px; font-weight: 600; margin: 0 0 10px; color: var(--muted); }
code {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
  background: var(--bg-soft);
  padding: 2px 7px;
  border-radius: 6px;
}

/* ================= logo ================= */
.logo-mark { width: 30px; height: 30px; flex: none; }
.logo-mark circle { fill: var(--accent); }
.logo-mark .logo-core { fill: var(--gold); }

/* ================= buttons ================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  background: var(--bg-soft);
  color: var(--ink);
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: transparent; border-color: var(--border); color: var(--muted); }
.btn.ghost:hover { background: var(--bg-soft); color: var(--ink); }
.btn.danger { background: transparent; border-color: var(--err-border); color: var(--err-ink); }
.btn.danger:hover { background: var(--err-bg); }
.btn.small { padding: 6px 13px; font-size: 13px; }
.btn.tiny { padding: 3px 10px; font-size: 12px; border-radius: 8px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.6; cursor: default; }

/* ================= forms ================= */
input[type="text"], input[type="email"], input[type="password"], input[type="search"], input[type="number"], select {
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 13px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
}
input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.stack { display: flex; flex-direction: column; gap: 8px; }
.stack label { font-size: 13px; font-weight: 600; color: var(--muted); margin-top: 6px; }
.stack .btn { margin-top: 12px; align-self: flex-start; }
.stack .btn.wide { align-self: stretch; }
.row-form { display: flex; gap: 10px; margin-bottom: 18px; }
.row-form input { max-width: 300px; }
.inline { display: inline; }

/* ================= auth pages ================= */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background:
    radial-gradient(1200px 600px at 85% -10%, var(--accent-soft), transparent 60%),
    var(--bg);
}
.auth-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 40px 36px 28px;
  width: 100%;
  max-width: 410px;
  box-shadow: var(--shadow);
}
.auth-card.center { text-align: center; }
.auth-brand { text-align: center; margin-bottom: 24px; }
.auth-brand .logo-mark { width: 44px; height: 44px; }
.auth-brand h1 { margin: 10px 0 2px; font-size: 22px; }
.sub { color: var(--muted); font-size: 14px; margin: 0; }
.auth-foot { text-align: center; font-size: 13px; margin-top: 22px; color: var(--muted); }
.err-code { font-size: 54px; margin: 12px 0 0; color: var(--accent); }

/* ================= topbar ================= */
.topbar {
  display: flex;
  align-items: center;
  gap: 26px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 clamp(16px, 4vw, 32px);
  height: 58px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 700; font-size: 16px; }
.brand:hover { text-decoration: none; }
.brand-admin {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 6px;
  padding: 2px 7px;
  margin-left: 7px;
  vertical-align: 2px;
}
.topnav { display: flex; gap: 4px; }
.topnav a {
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  padding: 7px 13px;
  border-radius: 9px;
}
.topnav a:hover { color: var(--ink); background: var(--bg-soft); text-decoration: none; }
.topnav a.on { color: var(--accent); background: var(--accent-soft); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.addr-chip {
  font-size: 13px;
  color: var(--muted);
  background: var(--bg-soft);
  border-radius: 999px;
  padding: 5px 14px;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ================= layout ================= */
.container { max-width: 1020px; margin: 28px auto 60px; padding: 0 clamp(16px, 4vw, 32px); }
.container.narrow { max-width: 720px; }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 26px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.page-head h1 { margin: 0; display: flex; align-items: baseline; gap: 10px; }
.count { color: var(--dim); font-weight: 500; font-size: 13px; }
.badge {
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  border-radius: 999px;
  padding: 2px 10px;
  vertical-align: 3px;
}
.back-link { display: inline-block; font-size: 14px; color: var(--muted); margin-bottom: 14px; }
.back-link:hover { color: var(--accent); }
.hint { color: var(--muted); font-size: 14px; }
.hint-inline { color: var(--dim); font-size: 12px; font-weight: 500; }
.dim { color: var(--dim); font-size: 13px; }
.t-right { text-align: right; }

/* ================= flash ================= */
.flash {
  padding: 11px 15px;
  border-radius: 10px;
  margin: 0 0 16px;
  font-size: 14px;
  border: 1px solid;
}
.flash.ok { background: var(--ok-bg); color: var(--ok-ink); border-color: var(--ok-border); }
.flash.error { background: var(--err-bg); color: var(--err-ink); border-color: var(--err-border); }

/* ================= search ================= */
.search-form { position: relative; flex: 1; max-width: 380px; min-width: 240px; }
.search-form input { padding-left: 38px; padding-right: 34px; border-radius: 999px; }
.search-icon {
  position: absolute;
  left: 13px; top: 50%;
  transform: translateY(-50%);
  width: 16px; height: 16px;
  color: var(--dim);
  pointer-events: none;
}
.search-clear {
  position: absolute;
  right: 11px; top: 50%;
  transform: translateY(-50%);
  color: var(--dim);
  font-size: 17px;
  line-height: 1;
  padding: 3px;
}
.search-clear:hover { color: var(--accent); text-decoration: none; }

/* ================= inbox ================= */
.mail-list {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.mail-row {
  display: flex;
  gap: 14px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  color: var(--ink);
  transition: background 0.1s;
  position: relative;
}
.mail-row:last-child { border-bottom: none; }
.mail-row:hover { background: var(--bg-soft); text-decoration: none; }
.mail-row.unread::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--accent);
}
.avatar {
  width: 40px; height: 40px;
  flex: none;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.avatar.lg { width: 44px; height: 44px; }
.mail-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.mail-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.mail-from { font-size: 13.5px; font-weight: 600; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-row.unread .mail-from { color: var(--ink); }
.mail-when { flex: none; font-size: 12.5px; color: var(--dim); display: flex; align-items: center; gap: 5px; }
.clip { width: 14px; height: 14px; }
.mail-subject { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-row.unread .mail-subject { font-weight: 700; }
.mail-snippet { font-size: 13px; color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.empty-state {
  text-align: center;
  padding: 70px 20px;
  color: var(--muted);
}
.empty-state .logo-mark { width: 40px; height: 40px; opacity: 0.45; margin-bottom: 8px; }
.empty-state .btn { margin-top: 14px; }

/* ================= mail view ================= */
.mail-view { padding: 28px 32px; }
.mail-view-subject { margin: 0 0 18px; font-size: 21px; }
.mail-view-meta {
  display: flex;
  align-items: center;
  gap: 13px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.meta-lines { flex: 1; min-width: 0; }
.meta-from { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; }
.meta-sub { font-size: 12.5px; color: var(--dim); }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; padding: 16px 0 2px; }
.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 7px 13px;
  font-size: 13px;
  color: var(--ink);
  background: var(--bg-soft);
  max-width: 300px;
}
.attachment-chip:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.att-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-size { color: var(--dim); font-size: 12px; flex: none; }
.mail-body { padding-top: 18px; }
.text-mail { white-space: pre-wrap; word-break: break-word; font-family: inherit; font-size: 15px; margin: 0; }
.html-mail {
  width: 100%;
  min-height: 460px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
}
.privacy-note { font-size: 12px; color: var(--dim); margin: 8px 0 0; }

/* ================= tables ================= */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
th { color: var(--dim); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.actions form { margin-left: 6px; }
.pw-cell { white-space: nowrap; }
.pw-cell .secret { font-size: 12px; }
.tag { font-size: 12px; font-weight: 600; border-radius: 6px; padding: 2px 8px; }
.tag.ok { background: var(--ok-bg); color: var(--ok-ink); }
.tag.warn { background: var(--warn-bg); color: var(--warn-ink); }

/* ================= admin ================= */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin: 18px 0 22px;
}
.stat-tile {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}
.stat-num { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.stat-label { font-size: 12.5px; color: var(--muted); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 30px; }
.addr-input { display: flex; align-items: center; gap: 8px; }
.addr-input input { flex: 1; }
.addr-input select { flex: 1; }
.at { color: var(--dim); font-size: 13px; flex: none; }
.pair { display: flex; gap: 14px; }
.pair label { flex: 1; font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
details summary { cursor: pointer; list-style: none; }
details summary::before { content: "▸ "; color: var(--dim); }
details[open] summary::before { content: "▾ "; }
.inline-h { display: inline; }
.narrow-form { max-width: 380px; margin-top: 16px; }
.bulk-actions { display: flex; gap: 10px; margin-bottom: 16px; }

/* ================= settings ================= */
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 10px 16px; margin: 0; font-size: 14px; }
.kv dt { color: var(--muted); font-weight: 600; }
.kv dd { margin: 0; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.secret { letter-spacing: 0.05em; word-break: break-all; }
.code-block {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 13px 16px;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 12.5px;
  overflow-x: auto;
  margin: 6px 0 18px;
}

/* ================= responsive ================= */
@media (max-width: 720px) {
  .two-col { grid-template-columns: 1fr; }
  .topnav { gap: 0; }
  .addr-chip { display: none; }
  .mail-snippet { display: none; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dt { margin-top: 10px; }
  .mail-view { padding: 20px 18px; }
  th, td { padding: 8px 8px; }
}
