:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #f8faf9;
  --border: #dce2e5;
  --border-strong: #c8d0d4;
  --text: #172026;
  --muted: #66737b;
  --primary: #147d64;
  --primary-hover: #0f6752;
  --primary-soft: #e7f4ef;
  --accent: #245f82;
  --warning: #9a6400;
  --warning-soft: #fff4d6;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --shadow: 0 12px 32px rgba(23, 32, 38, 0.1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body { min-width: 320px; background: var(--bg); }
button, input, textarea, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted-text { color: var(--muted); font-size: 13px; }
.danger-text { color: var(--danger) !important; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #eef2f3;
}
.login-panel {
  width: min(100%, 400px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 34px;
}
.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  color: white;
  background: var(--primary);
  border-radius: 8px;
}
.brand-mark svg { width: 25px; height: 25px; }
.brand-mark.small { width: 32px; height: 32px; flex: 0 0 auto; }
.brand-mark.small svg { width: 18px; height: 18px; }
.login-heading { margin: 22px 0 26px; }
.brand-name, .eyebrow { margin: 0; color: var(--primary); font-size: 12px; font-weight: 700; text-transform: uppercase; }
.login-heading h1 { margin: 5px 0 0; font-size: 25px; line-height: 1.25; }
.form-stack { display: grid; gap: 16px; }
label { display: grid; gap: 7px; font-size: 13px; font-weight: 650; color: #344149; }
input, textarea, select {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
input, select { height: 40px; padding: 0 12px; }
textarea { resize: vertical; min-height: 118px; padding: 11px 12px; line-height: 1.55; }
input:focus, textarea:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(20, 125, 100, 0.12); }
.form-error { min-height: 18px; margin: -4px 0 0; color: var(--danger); font-size: 13px; }

.button, .icon-button, .nav-button {
  border: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.button { min-height: 38px; padding: 0 14px; border-radius: 6px; font-size: 13px; font-weight: 700; }
.button svg { width: 17px; height: 17px; }
.button.primary { color: #fff; background: var(--primary); }
.button.primary:hover { background: var(--primary-hover); }
.button.secondary { color: #344149; background: #fff; border: 1px solid var(--border-strong); }
.button.secondary:hover { background: var(--surface-soft); }
.button.danger { color: #fff; background: var(--danger); }
.button.wide { width: 100%; height: 43px; }
.icon-button { width: 34px; height: 34px; padding: 0; color: #526169; background: transparent; border-radius: 6px; }
.icon-button:hover { color: var(--text); background: #edf1f2; }
.icon-button svg { width: 17px; height: 17px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 220px minmax(0, 1fr); }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  color: #edf7f4;
  background: #17332f;
  border-right: 1px solid #254640;
  padding: 18px 12px;
}
.sidebar-brand { height: 46px; display: flex; align-items: center; gap: 10px; padding: 0 7px; font-weight: 760; }
.main-nav { display: grid; gap: 5px; margin-top: 24px; }
.nav-button { justify-content: flex-start; width: 100%; height: 42px; padding: 0 12px; color: #bad0ca; background: transparent; border-radius: 6px; font-size: 14px; font-weight: 650; }
.nav-button:hover { color: #fff; background: #244841; }
.nav-button.active { color: #fff; background: #2c5b51; }
.nav-button svg { width: 18px; height: 18px; }
.sidebar-footer { margin-top: auto; min-height: 48px; display: flex; align-items: center; gap: 8px; border-top: 1px solid #315048; padding: 14px 6px 0; }
.sidebar-footer .icon-button { color: #bad0ca; }
.signed-user { min-width: 0; flex: 1; display: flex; align-items: center; gap: 8px; color: #d9e7e3; font-size: 13px; }
.signed-user span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.signed-user svg { width: 18px; height: 18px; flex: 0 0 auto; }

.main-area { min-width: 0; }
.topbar { height: 78px; display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 0 28px; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar h2 { margin: 3px 0 0; font-size: 20px; }
.topbar-actions { display: flex; align-items: center; gap: 9px; }
.toggle-control { position: relative; display: inline-flex; align-items: center; gap: 9px; min-height: 38px; cursor: pointer; }
.toggle-label { display: grid; gap: 1px; color: #344149; font-size: 12px; font-weight: 700; line-height: 1.15; }
.toggle-label small { color: var(--muted); font-size: 10px; font-weight: 600; }
.toggle-control input { position: absolute; z-index: 1; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.toggle-track { width: 36px; height: 20px; flex: 0 0 auto; padding: 2px; border-radius: 10px; background: #aab4b8; transition: background 140ms ease; }
.toggle-track span { display: block; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.24); transition: transform 140ms ease; }
.toggle-control input:checked + .toggle-track { background: var(--primary); }
.toggle-control input:checked + .toggle-track span { transform: translateX(16px); }
.toggle-control input:focus-visible + .toggle-track { outline: 3px solid rgba(20, 125, 100, 0.2); outline-offset: 2px; }
.toggle-control input:disabled + .toggle-track { opacity: 0.55; cursor: wait; }
.toggle-control input:disabled { cursor: wait; }
.stats-band { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); background: var(--surface); border-bottom: 1px solid var(--border); padding: 16px 28px; }
.stats-band > div { min-width: 0; display: flex; align-items: baseline; justify-content: space-between; gap: 16px; padding: 3px 22px; border-right: 1px solid var(--border); }
.stats-band > div:first-child { padding-left: 0; }
.stats-band > div:last-child { border-right: 0; padding-right: 0; }
.stats-band span { color: var(--muted); font-size: 13px; }
.stats-band strong { font-size: 22px; }
.view-section { padding: 20px 28px 28px; }
.filterbar { min-height: 44px; display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.filterbar > .muted-text { margin-left: auto; }
.search-field { width: min(430px, 100%); position: relative; display: block; }
.search-field svg { position: absolute; left: 12px; top: 11px; width: 17px; height: 17px; color: #78858c; pointer-events: none; }
.search-field input { padding-left: 38px; }
.filterbar select { width: 220px; }

.mail-workspace { height: calc(100vh - 236px); min-height: 480px; display: grid; grid-template-columns: minmax(330px, 43%) minmax(0, 1fr); background: var(--surface); border: 1px solid var(--border); border-radius: 7px; overflow: hidden; }
.message-list-pane { min-width: 0; border-right: 1px solid var(--border); overflow: auto; }
.message-list { min-height: 100%; }
.message-row { width: 100%; min-height: 94px; display: grid; grid-template-columns: 42px minmax(0, 1fr); gap: 11px; padding: 15px 16px; text-align: left; color: inherit; background: #fff; border: 0; border-bottom: 1px solid #e6eaec; }
.message-row:hover { background: #f7faf9; }
.message-row.active { background: var(--primary-soft); box-shadow: inset 3px 0 0 var(--primary); }
.sender-avatar { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; color: #fff; background: var(--accent); font-size: 13px; font-weight: 800; }
.message-main { min-width: 0; }
.message-meta, .message-subject-line { display: flex; align-items: center; gap: 10px; }
.message-meta strong, .message-subject-line strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-meta strong { min-width: 0; flex: 1; font-size: 13px; }
.message-meta time { flex: 0 0 auto; color: var(--muted); font-size: 11px; }
.message-subject-line { margin-top: 5px; }
.message-subject-line strong { font-size: 13px; }
.message-row.unread .message-subject-line strong, .message-row.unread .message-meta strong { font-weight: 800; }
.message-snippet { margin: 5px 0 0; overflow: hidden; color: var(--muted); font-size: 12px; line-height: 1.4; white-space: nowrap; text-overflow: ellipsis; }
.account-chip { display: inline-block; max-width: 150px; margin-top: 8px; overflow: hidden; color: #45616d; font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.message-reader { min-width: 0; overflow: auto; background: #fff; }
.reader-empty, .empty-state { min-height: 280px; display: grid; place-items: center; align-content: center; gap: 12px; color: #849096; }
.reader-empty svg, .empty-state svg { width: 34px; height: 34px; stroke-width: 1.5; }
.reader-content { padding: 26px 30px 36px; }
.reader-toolbar { min-height: 35px; display: flex; justify-content: flex-end; gap: 8px; }
.reader-content h3 { margin: 18px 0 15px; font-size: 22px; line-height: 1.35; overflow-wrap: anywhere; }
.reader-from { display: flex; gap: 12px; align-items: center; padding-bottom: 20px; border-bottom: 1px solid var(--border); }
.reader-from .sender-avatar { flex: 0 0 auto; }
.reader-address { min-width: 0; }
.reader-address strong, .reader-address span { display: block; overflow-wrap: anywhere; }
.reader-address span { margin-top: 3px; color: var(--muted); font-size: 12px; }
.reader-account { margin-left: auto; color: var(--muted); font-size: 12px; text-align: right; }
.reader-body { margin: 24px 0 0; color: #26343b; font: 14px/1.75 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.reader-body a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.code-bar { display: flex; align-items: center; gap: 10px; margin: 20px 0 0; padding: 12px 14px; background: var(--warning-soft); border: 1px solid #ead49b; border-radius: 6px; }
.code-bar code { font-size: 20px; font-weight: 800; letter-spacing: 2px; }

.table-wrap { min-height: 260px; background: var(--surface); border: 1px solid var(--border); border-radius: 7px; overflow: auto; }
.account-table { width: 100%; min-width: 1060px; border-collapse: collapse; table-layout: fixed; }
.account-table th, .account-table td { padding: 13px 15px; border-bottom: 1px solid #e6eaec; text-align: left; vertical-align: middle; }
.account-table th { color: var(--muted); background: #f8faf9; font-size: 11px; font-weight: 750; text-transform: uppercase; }
.account-table td { font-size: 13px; }
.account-table th:nth-child(1) { width: 20%; }
.account-table th:nth-child(2) { width: 14%; }
.account-table th:nth-child(3) { width: 15%; }
.account-table th:nth-child(4) { width: 11%; }
.account-table th:nth-child(5) { width: 9%; }
.account-table th:nth-child(6) { width: 15%; }
.account-table th:nth-child(7) { width: 16%; }
.account-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.sk-cell { display: flex; align-items: center; justify-content: space-between; gap: 4px; }
.sk-state { color: var(--muted); font-size: 11px; white-space: nowrap; }
.sk-state.saved { color: #0d725b; font-weight: 750; }
.sk-actions { display: flex; flex: 0 0 auto; }
.sk-actions .icon-button { width: 30px; height: 30px; }
.remark-cell { color: #526169; overflow-wrap: anywhere; }
.status-badge { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; padding: 4px 7px; border-radius: 999px; font-size: 11px; font-weight: 750; }
.status-badge::before { content: ""; width: 6px; height: 6px; flex: 0 0 auto; border-radius: 50%; background: currentColor; }
.status-healthy { color: #0d725b; background: var(--primary-soft); }
.status-syncing, .status-pending { color: #8a5a00; background: var(--warning-soft); }
.status-error { color: var(--danger); background: var(--danger-soft); }
.account-error { display: block; max-width: 220px; margin-top: 5px; color: var(--danger); font-size: 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-actions { display: flex; align-items: center; gap: 2px; }
.row-actions .icon-button.danger-action:hover { color: var(--danger); background: var(--danger-soft); }

.api-surface { max-width: 1080px; background: var(--surface); border: 1px solid var(--border); border-radius: 7px; overflow: hidden; }
.api-section { padding: 22px 24px; border-bottom: 1px solid var(--border); }
.api-section:last-child { border-bottom: 0; }
.api-section-heading { min-height: 38px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.api-section-heading > div { min-width: 0; display: grid; gap: 5px; }
.api-section-heading strong { font-size: 14px; }
.section-label { color: var(--muted); font-size: 11px; font-weight: 750; text-transform: uppercase; }
.api-section-heading code { overflow: hidden; color: #244c43; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.api-key-row { max-width: 720px; display: grid; grid-template-columns: minmax(0, 1fr) 34px 34px; align-items: end; gap: 6px; margin-top: 18px; }
.api-key-row label { min-width: 0; }
.api-key-row input { width: 100%; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.api-table-wrap { margin-top: 16px; overflow: auto; }
.api-table { width: 100%; border-collapse: collapse; }
.api-table th, .api-table td { padding: 11px 12px; border-bottom: 1px solid #e6eaec; text-align: left; }
.api-table th { color: var(--muted); background: #f8faf9; font-size: 11px; }
.api-table td { font-size: 13px; }
.api-table tbody tr:last-child td { border-bottom: 0; }
.api-table code { color: #33434a; font-size: 12px; }
.method-badge { display: inline-flex; min-width: 48px; justify-content: center; padding: 4px 6px; border-radius: 5px; font-size: 10px; font-weight: 800; }
.method-badge.get { color: #17608a; background: #e5f3fa; }
.method-badge.patch { color: #7b5200; background: var(--warning-soft); }
.method-badge.post { color: #0d725b; background: var(--primary-soft); }
.api-example-section pre { margin: 16px 0 0; padding: 16px 18px; overflow: auto; color: #eaf3f0; background: #19332e; border-radius: 6px; font: 12px/1.65 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.dialog { width: min(92vw, 620px); max-height: 88vh; padding: 0; border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(12, 20, 24, 0.52); }
.dialog form { padding: 22px; }
.compact-dialog { width: min(92vw, 460px); }
.dialog-header { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.dialog-header h3 { margin: 3px 0 0; font-size: 20px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }
.dialog-copy { color: var(--muted); font-size: 14px; line-height: 1.6; }
.secret-editor-row { display: grid; grid-template-columns: minmax(0, 1fr) 34px; align-items: end; gap: 6px; }
.secret-editor-row label { min-width: 0; }
.secret-editor-row input { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.segmented { width: fit-content; display: flex; border: 1px solid var(--border-strong); border-radius: 6px; overflow: hidden; margin-bottom: 16px; }
.segmented button { height: 34px; padding: 0 14px; border: 0; border-right: 1px solid var(--border-strong); background: #fff; color: var(--muted); font-size: 12px; font-weight: 700; }
.segmented button:last-child { border-right: 0; }
.segmented button.active { color: #fff; background: var(--primary); }
.textarea-label { margin-bottom: 14px; }
.import-result { margin-top: 14px; padding: 10px 12px; border-radius: 6px; color: #284a40; background: var(--primary-soft); font-size: 12px; line-height: 1.5; }
.import-result.error { color: var(--danger); background: var(--danger-soft); }

.toast { position: fixed; right: 24px; bottom: 24px; z-index: 20; min-width: 240px; max-width: min(420px, calc(100vw - 48px)); padding: 12px 15px; color: #fff; background: #26343b; border-radius: 6px; box-shadow: var(--shadow); font-size: 13px; opacity: 0; pointer-events: none; transform: translateY(10px); transition: opacity 150ms ease, transform 150ms ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--danger); }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 72px minmax(0, 1fr); }
  .sidebar-brand > span:last-child, .nav-button span, .signed-user span { display: none; }
  .sidebar-brand, .nav-button { justify-content: center; }
  .sidebar-footer { justify-content: center; }
  .signed-user { flex: 0 0 auto; }
  .stats-band > div { display: grid; gap: 4px; }
  .mail-workspace { grid-template-columns: minmax(300px, 45%) minmax(0, 1fr); }
  .account-table { min-width: 1060px; }
}

@media (max-width: 720px) {
  .app-shell { display: block; padding-bottom: 62px; }
  .sidebar { position: fixed; z-index: 10; top: auto; bottom: 0; left: 0; right: 0; width: auto; height: 62px; flex-direction: row; padding: 7px 10px; border: 0; border-top: 1px solid #315048; }
  .sidebar-brand, .sidebar-footer { display: none; }
  .main-nav { width: 100%; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 0; }
  .nav-button { justify-content: center; height: 47px; }
  .nav-button span { display: inline; }
  .topbar { height: auto; min-height: 78px; align-items: flex-start; padding: 15px 16px; }
  .topbar-actions { flex-wrap: wrap; justify-content: flex-end; }
  .toggle-label { display: none; }
  .topbar-actions .button span { display: none; }
  .topbar-actions .button { width: 38px; padding: 0; }
  .stats-band { grid-template-columns: repeat(2, 1fr); padding: 12px 16px; }
  .stats-band > div { border-right: 0; border-bottom: 1px solid var(--border); padding: 9px 12px; }
  .stats-band > div:nth-child(odd) { padding-left: 0; border-right: 1px solid var(--border); }
  .stats-band > div:nth-child(n+3) { border-bottom: 0; }
  .view-section { padding: 14px 12px 18px; }
  .filterbar { align-items: stretch; flex-wrap: wrap; }
  .search-field { width: 100%; }
  .filterbar select { width: 100%; }
  .filterbar > .muted-text { width: 100%; margin-left: 0; }
  .mail-workspace { height: auto; min-height: 560px; grid-template-columns: 1fr; }
  .message-list-pane { max-height: 410px; border-right: 0; border-bottom: 1px solid var(--border); }
  .message-reader { min-height: 440px; }
  .reader-content { padding: 20px 18px 28px; }
  .reader-from { align-items: flex-start; }
  .reader-account { max-width: 140px; }
  .account-table { min-width: 1060px; }
  .api-section { padding: 18px 14px; }
  .api-section-heading { align-items: flex-start; }
  .api-key-row { grid-template-columns: minmax(0, 1fr) 34px 34px; }
  .api-table { min-width: 660px; }
  .dialog form { padding: 18px; }
  .toast { right: 12px; bottom: 76px; max-width: calc(100vw - 24px); }
}
