:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #5f6b7a;
  --border: #dde3ea;
  --primary: #1f6feb;
  --primary-text: #ffffff;
  --unread: #eaf2ff;
  --danger: #c62828;
  --warn-bg: #fff4e5;
  --warn-text: #8a4b00;
  --ok: #1b7f3b;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161c; --surface: #1b2129; --text: #e6ebf1; --muted: #9aa6b4; --border: #2c3540;
    --primary: #4c8dff; --unread: #1c2a40; --danger: #ff6b6b; --warn-bg: #3a2a12; --warn-text: #ffc977; --ok: #5fd58a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12161c; --surface: #1b2129; --text: #e6ebf1; --muted: #9aa6b4; --border: #2c3540;
  --primary: #4c8dff; --unread: #1c2a40; --danger: #ff6b6b; --warn-bg: #3a2a12; --warn-text: #ffc977; --ok: #5fd58a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", Meiryo, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--primary); }
button, input, select { font: inherit; }

header.top {
  position: sticky; top: 0; z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.top-inner {
  max-width: 880px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 12px;
}
.brand { font-weight: 700; font-size: 17px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabs { display: flex; gap: 4px; }
.tab {
  border: 0; background: transparent; color: var(--muted);
  padding: 8px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap;
}
.tab[aria-selected="true"] { background: var(--unread); color: var(--primary); font-weight: 600; }
.badge-count {
  display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 4px;
  border-radius: 10px; background: var(--danger); color: #fff; font-size: 12px; line-height: 20px; text-align: center;
}

main { max-width: 880px; margin: 0 auto; padding: 16px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.card h2 { font-size: 16px; margin: 0 0 12px; }
.card h3 { font-size: 15px; margin: 16px 0 8px; }
.muted { color: var(--muted); font-size: 13px; }
.center { text-align: center; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.grow { flex: 1; min-width: 160px; }
.stack > * + * { margin-top: 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 14px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text);
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

input[type=text], input[type=password], input[type=email], input[type=url], select {
  width: 100%; min-height: 40px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text);
}
label.field { display: block; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.switch { display: flex; align-items: center; gap: 10px; padding: 8px 0; cursor: pointer; }
.switch input { width: 20px; height: 20px; }

.msg-list { list-style: none; margin: 0; padding: 0; }
.msg {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 10px;
}
.msg.unread { background: var(--unread); border-color: var(--primary); }
.msg.highlight { outline: 3px solid var(--primary); }
.msg-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.msg-from { font-weight: 700; overflow-wrap: anywhere; }
.msg-addr { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.msg-time { margin-left: auto; color: var(--muted); font-size: 13px; white-space: nowrap; }
.msg-subject { margin-top: 2px; font-weight: 600; overflow-wrap: anywhere; }
.msg.unread .msg-subject::before { content: "●"; color: var(--primary); margin-right: 6px; font-size: 10px; vertical-align: middle; }
.msg-summary { margin-top: 4px; overflow-wrap: anywhere; }
.msg-foot { margin-top: 8px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tag { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 10px; border: 1px solid var(--border); color: var(--muted); }
.tag.warn { background: var(--warn-bg); color: var(--warn-text); border-color: transparent; }
.notice { background: var(--warn-bg); color: var(--warn-text); border-radius: 8px; padding: 10px 12px; font-size: 14px; }
.ok-text { color: var(--ok); }
.err-text { color: var(--danger); }

table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
table.list th, table.list td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.list th { color: var(--muted); font-weight: 600; font-size: 12px; }
.table-wrap { overflow-x: auto; }
code, .mono { font-family: ui-monospace, Consolas, "Courier New", monospace; overflow-wrap: anywhere; }
.secret-box { background: var(--bg); border: 1px dashed var(--border); border-radius: 8px; padding: 12px; }

dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); max-width: min(560px, calc(100vw - 32px)); width: 100%; }
dialog::backdrop { background: rgba(0, 0, 0, .45); }

dialog.popup { max-width: min(640px, calc(100vw - 32px)); padding: 24px; border: 3px solid var(--primary); }
.popup-title { font-size: 22px; font-weight: 700; overflow-wrap: anywhere; }
.popup-subject { font-size: 18px; font-weight: 600; overflow-wrap: anywhere; }
dialog.popup div { white-space: pre-wrap; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; }

.login-wrap { max-width: 400px; margin: 8vh auto 0; }

@media (max-width: 560px) {
  .top-inner { flex-wrap: wrap; }
  .tabs { width: 100%; }
  .tab { flex: 1; }
  .msg-time { margin-left: 0; width: 100%; }
}
