:root {
  --ink: #171717;
  --ink-subtle: #475569;
  --surface: #ffffff;
  --surface-muted: #e8ecf0;
  --surface-soft: #f7f8fa;
  --accent: #a16207;
  --accent-strong: #854d0e;
  --success: #166534;
  --danger: #b91c1c;
  --warning-bg: #fef3c7;
  --danger-bg: #fef2f2;
  --border: #cbd5e1;
  --focus: #2563eb;
  --radius: 2px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
  --space-8: 32px;
  --shadow: 0 1px 0 rgba(23, 23, 23, 0.12);
  color-scheme: light;
  font-family: Arial, Helvetica, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--surface-soft); }
body { margin: 0; min-height: 100dvh; color: var(--ink); background: var(--surface-soft); font-size: 16px; line-height: 1.5; }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.45; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.skip-link { position: fixed; top: 8px; left: 8px; z-index: 1000; padding: 10px 14px; color: white; background: var(--ink); transform: translateY(-150%); }
.skip-link:focus { transform: translateY(0); }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.25rem, 2vw, 1.75rem); line-height: 1.2; letter-spacing: -0.025em; }
h2 { margin-bottom: 0; font-size: 1rem; line-height: 1.25; text-transform: uppercase; letter-spacing: 0.045em; }
.muted { margin: var(--space-1) 0 0; color: var(--ink-subtle); font-size: 0.875rem; overflow-wrap: anywhere; }

.button { min-height: 44px; border: 1px solid var(--ink); border-radius: var(--radius); padding: 9px 16px; font-weight: 700; transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease; }
.button-primary { color: #fff; background: var(--ink); }
.button-primary:hover { background: #333; }
.button-secondary { color: var(--ink); background: var(--surface); }
.button-secondary:hover, .button-quiet:hover { background: var(--surface-muted); }
.button-quiet { color: var(--ink); background: transparent; border-color: var(--border); }
.button-dark { color: #fff; border-color: #525252; background: #292929; }
.button-dark:hover { background: #3f3f3f; }
.button-accent { color: #fff; border-color: var(--accent); background: var(--accent); text-decoration: none; }
.button-accent:hover { background: var(--accent-strong); }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); min-height: 64px; padding: 10px clamp(16px, 2vw, 28px); border-bottom: 1px solid #333; color: #fff; background: var(--ink); }
.topbar h1 { color: #fff; font-size: 1.45rem; }
.brand-block { display: flex; align-items: baseline; gap: var(--space-3); }
.brand-block span, .topbar-actions span { color: #d4d4d4; font-size: .82rem; }
.topbar-actions { display: flex; align-items: center; gap: var(--space-3); }
.status-strip { min-height: 42px; padding: 10px clamp(16px, 3vw, 40px); border-bottom: 1px solid var(--border); color: var(--ink-subtle); background: var(--surface-muted); font-size: 0.875rem; }
.status-strip.is-error { color: var(--danger); background: var(--danger-bg); }
.status-strip.is-ready { color: var(--success); background: #f0fdf4; }

.dashboard { display: grid; grid-template-columns: minmax(270px, 0.7fr) minmax(0, 2fr); grid-template-areas: "mailbox inbox" "batch batch"; gap: 1px; max-width: 1600px; margin: 0 auto; background: var(--border); border-inline: 1px solid var(--border); }
.mailbox-panel, .inbox-panel, .batch-panel { min-width: 0; padding: var(--space-6); background: var(--surface); }
.mailbox-panel { grid-area: mailbox; }
.inbox-panel { grid-area: inbox; }
.batch-panel { grid-area: batch; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); min-height: 56px; margin-bottom: var(--space-4); }
.compact-heading { min-height: 40px; margin-top: var(--space-6); margin-bottom: var(--space-2); }
.create-shortcut { display: grid; place-items: center; width: 100%; }
.count { min-width: 36px; padding: 4px 8px; text-align: center; color: white; background: var(--ink); font-variant-numeric: tabular-nums; }

label, .field { display: grid; gap: var(--space-2); color: var(--ink-subtle); font-size: 0.78rem; font-weight: 700; letter-spacing: 0.03em; }
input { width: 100%; min-height: 44px; border: 1px solid var(--border); border-radius: var(--radius); padding: 9px 12px; color: var(--ink); background: var(--surface); font-size: 1rem; font-weight: 400; letter-spacing: normal; }
input:hover { border-color: var(--ink-subtle); }
.search-field { margin-bottom: var(--space-3); }
.mailbox-list { display: grid; gap: 1px; max-height: 560px; overflow-y: auto; border: 1px solid var(--border); background: var(--border); }
.mailbox-item { display: grid; align-content: center; min-height: 56px; width: 100%; border: 0; padding: var(--space-2) var(--space-3); text-align: left; color: var(--ink); background: var(--surface); overflow-wrap: anywhere; }
.mailbox-item:hover { background: var(--surface-soft); }
.mailbox-item[aria-selected="true"] { box-shadow: inset 4px 0 0 var(--accent); background: var(--warning-bg); }
.mailbox-item small { color: var(--ink-subtle); }
.mailbox-item.is-failed { color: var(--danger); }
.empty-state { padding: var(--space-6); color: var(--ink-subtle); background: var(--surface-soft); text-align: center; }

.inbox-grid { display: grid; grid-template-columns: minmax(220px, 0.78fr) minmax(280px, 1.22fr); min-height: 460px; border: 1px solid var(--border); }
.inbox-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--space-2); }
.folder-switch { display: flex; }
.folder-button { color: var(--ink); border-color: var(--border); border-radius: 0; background: var(--surface); }
.folder-button + .folder-button { border-left: 0; }
.folder-button.is-active { color: #fff; border-color: var(--ink); background: var(--ink); }
.reset-result { margin: 0 0 var(--space-3); padding: var(--space-3); border-left: 3px solid var(--accent); background: var(--warning-bg); overflow-wrap: anywhere; }
.message-list { min-width: 0; border-right: 1px solid var(--border); }
.message-button { display: grid; gap: 3px; width: 100%; min-height: 76px; border: 0; border-bottom: 1px solid var(--border); padding: var(--space-3); text-align: left; background: var(--surface); }
.message-button:hover { background: var(--surface-soft); }
.message-button[aria-current="true"] { background: var(--warning-bg); box-shadow: inset 4px 0 0 var(--accent); }
.message-subject { font-weight: 700; overflow-wrap: anywhere; }
.message-meta, .message-preview { color: var(--ink-subtle); font-size: 0.8rem; overflow-wrap: anywhere; }
.message-preview { display: -webkit-box; overflow: hidden; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.message-detail { min-width: 0; padding: var(--space-6); background: var(--surface); }
.message-detail h3 { margin-bottom: var(--space-2); font-size: 1.2rem; line-height: 1.3; overflow-wrap: anywhere; }
.message-headers { display: grid; gap: 2px; margin-bottom: var(--space-6); color: var(--ink-subtle); font-size: 0.85rem; overflow-wrap: anywhere; }
.message-body { white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; line-height: 1.65; }
.attachment-list { margin: var(--space-6) 0 0; padding: var(--space-3); border-left: 3px solid var(--accent); background: var(--surface-soft); }
.attachment-list ul { margin: var(--space-2) 0 0; padding-left: 20px; }

.batch-form { display: grid; grid-template-columns: minmax(160px, 2fr) repeat(3, minmax(90px, 0.7fr)) auto; align-items: end; gap: var(--space-3); }
.batch-feedback { min-height: 32px; margin-top: var(--space-4); color: var(--ink-subtle); }
.batch-feedback.is-error { color: var(--danger); }
.table-wrap { max-width: 100%; max-height: 380px; margin-bottom: var(--space-3); overflow: auto; border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; overflow-wrap: anywhere; }
th { position: sticky; top: 0; background: var(--surface-muted); font-size: 0.72rem; letter-spacing: 0.06em; text-transform: uppercase; }
.status-created { color: var(--success); font-weight: 700; }
.status-skipped { color: var(--accent-strong); font-weight: 700; }
.status-failed { color: var(--danger); font-weight: 700; }
.empty-cell { color: var(--ink-subtle); text-align: center; }
.security-note { margin: var(--space-2) 0 0; color: var(--ink-subtle); font-size: 0.8rem; }

.auth-page { display: grid; place-items: center; padding: var(--space-4); background: var(--surface-muted); }
.auth-shell { width: min(100%, 460px); }
.auth-card { border-top: 6px solid var(--ink); padding: clamp(24px, 6vw, 48px); background: var(--surface); box-shadow: var(--shadow); }
.auth-card h1 { margin: var(--space-2) 0 var(--space-3); font-size: clamp(1.75rem, 5vw, 2.5rem); }
.lede { color: var(--ink-subtle); }
.stack-form { display: grid; gap: var(--space-4); margin-top: var(--space-6); }
.alert { margin: var(--space-4) 0; padding: var(--space-3); border-left: 4px solid currentColor; }
.alert-error { color: var(--danger); background: var(--danger-bg); }

@media (max-width: 1023px) {
  .dashboard { grid-template-columns: minmax(220px, 0.65fr) minmax(0, 1.35fr); }
  .inbox-grid { grid-template-columns: 1fr; }
  .message-list { border-right: 0; border-bottom: 1px solid var(--border); max-height: 360px; overflow-y: auto; }
  .batch-form { grid-template-columns: repeat(2, 1fr); }
  .batch-form .button { grid-column: 1 / -1; }
}

@media (max-width: 767px) {
  .topbar { align-items: flex-start; }
  .brand-block, .topbar-actions { align-items: flex-start; flex-direction: column; gap: var(--space-1); }
  .dashboard { display: block; border: 0; }
  .mailbox-panel, .inbox-panel, .batch-panel { padding: var(--space-4); border-bottom: 1px solid var(--border); }
  .mailbox-list { max-height: 300px; }
  .inbox-grid { min-height: 360px; }
  .message-detail { padding: var(--space-4); }
  .inbox-actions { justify-content: flex-start; }
}

@media (max-width: 374px) {
  .topbar { display: grid; }
  .batch-form { grid-template-columns: 1fr; }
}

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