/* Wise Mail — one stylesheet, no build step. Tokens first; dark mode swaps them. */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6eb;
  --border-strong: #cfd4dc;
  --text: #1c2129;
  --text-2: #5b6573;
  --text-3: #8a93a1;
  --accent: #1d5bd8;
  --accent-hover: #1749b0;
  --accent-soft: #e8effc;
  --accent-text: #ffffff;
  --danger: #c62f2f;
  --danger-soft: #fdecec;
  --ok: #19794a;
  --ok-soft: #e6f5ec;
  --warn: #9a5b00;
  --warn-soft: #fff4e0;
  --unread: #1c2129;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .18);
  --radius: 10px;
  --radius-sm: 7px;
  --sidebar: 248px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1e232b;
    --border: #2a313b;
    --border-strong: #38414d;
    --text: #e7eaee;
    --text-2: #a3acb9;
    --text-3: #77818f;
    --accent: #5b8cff;
    --accent-hover: #7aa2ff;
    --accent-soft: #1c2a47;
    --accent-text: #0b1020;
    --danger: #ff6b6b;
    --danger-soft: #3a1b1d;
    --ok: #4ccb8a;
    --ok-soft: #13301f;
    --warn: #f0b04a;
    --warn-soft: #33270f;
    --unread: #ffffff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1216;
  --surface: #171b21;
  --surface-2: #1e232b;
  --border: #2a313b;
  --border-strong: #38414d;
  --text: #e7eaee;
  --text-2: #a3acb9;
  --text-3: #77818f;
  --accent: #5b8cff;
  --accent-hover: #7aa2ff;
  --accent-soft: #1c2a47;
  --accent-text: #0b1020;
  --danger: #ff6b6b;
  --danger-soft: #3a1b1d;
  --ok: #4ccb8a;
  --ok-soft: #13301f;
  --warn: #f0b04a;
  --warn-soft: #33270f;
  --unread: #ffffff;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, .55);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 20px; font-weight: 650; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 650; }
p { margin: 0 0 .75em; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
pre { white-space: pre-wrap; word-break: break-all; margin: 0; }
hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 15px; height: 15px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.right { text-align: right; }
.row { display: flex; align-items: center; gap: 8px; }
.row-wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }

/* ---- App shell ------------------------------------------------------------ */
.shell { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); grid-template-rows: 56px minmax(0, 1fr); height: 100vh; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 16px; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 10px; width: calc(var(--sidebar) - 32px); font-weight: 700; font-size: 16px; color: var(--text); flex: none; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; font-weight: 800; font-size: 15px; }
.brand small { font-weight: 500; color: var(--text-3); font-size: 12px; }
.search { flex: 1; max-width: 640px; position: relative; }
.search input { width: 100%; padding: 9px 12px 9px 38px; border-radius: 999px; border: 1px solid transparent; background: var(--surface-2); color: var(--text); font: inherit; }
.search input:focus { outline: none; border-color: var(--accent); background: var(--surface); }
.search .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); }
.userchip { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; text-transform: uppercase; }
.menu-toggle { display: none; }

.sidebar { background: var(--surface); border-right: 1px solid var(--border); overflow-y: auto; padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; }
.sidebar .compose { margin: 4px 6px 12px; justify-content: center; padding: 11px 16px; border-radius: 14px; font-size: 14.5px; }
.nav-link { display: flex; align-items: center; gap: 12px; padding: 7px 12px; border-radius: 8px; color: var(--text-2); font-weight: 500; }
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.nav-link .count { margin-left: auto; font-size: 12px; font-weight: 650; color: var(--text-2); }
.nav-link.active .count { color: var(--accent); }
.nav-section { margin: 14px 12px 4px; font-size: 11.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); }
.nav-sub { padding-left: 24px; }

.apps { display: flex; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 10px; margin: 0 4px 10px; }
.apps a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 4px; border-radius: 7px; font-size: 11.5px; font-weight: 600; color: var(--text-2); }
.apps a:hover { text-decoration: none; color: var(--text); background: var(--surface); }
.apps a.active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }

.quota { margin-top: auto; padding: 12px; border-top: 1px solid var(--border); }
.meter { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: 6px 0 4px; }
.meter span { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.meter.warn span { background: var(--warn); }
.meter.full span { background: var(--danger); }

.main { overflow-y: auto; min-width: 0; }
.page { padding: 20px 24px 40px; max-width: 1280px; }
.page-narrow { max-width: 820px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }

/* ---- Controls ------------------------------------------------------------- */
.btn { display: inline-flex; align-items: center; gap: 7px; padding: 7px 13px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; line-height: 1.3; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:focus-visible, .icon-btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: 4px 9px; font-size: 13px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; border: 0; background: transparent; color: var(--text-2); cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.toolbar { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.toolbar form { display: contents; }

label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 5px; }
.field { margin-bottom: 14px; }
.hint { font-size: 12.5px; color: var(--text-2); margin-top: 4px; }
.error-text { font-size: 12.5px; color: var(--danger); margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], input[type=date], input[type=time], select, textarea {
  width: 100%; padding: 8px 11px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font: inherit;
}
textarea { resize: vertical; min-height: 120px; line-height: 1.55; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.input-group { display: flex; align-items: stretch; }
.input-group input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-group .addon { display: flex; align-items: center; padding: 0 11px; border: 1px solid var(--border-strong); border-left: 0; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }

/* ---- Surfaces ------------------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px 20px; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.stat { padding: 16px 18px; }
.stat .label { font-size: 12.5px; color: var(--text-2); font-weight: 550; }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-accent { background: var(--accent-soft); color: var(--accent); }

.flash { display: flex; gap: 10px; align-items: flex-start; padding: 11px 14px; border-radius: var(--radius-sm); margin-bottom: 16px; font-weight: 500; }
.flash-ok { background: var(--ok-soft); color: var(--ok); }
.flash-error { background: var(--danger-soft); color: var(--danger); }
.flash-warn { background: var(--warn-soft); color: var(--warn); }

table.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; font-weight: 650; color: var(--text-2); text-transform: uppercase; letter-spacing: .03em; padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

.pager { display: flex; align-items: center; gap: 8px; justify-content: flex-end; padding: 10px 14px; color: var(--text-2); font-size: 13px; }

dialog { border: 1px solid var(--border); border-radius: 14px; padding: 0; background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); width: min(480px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(15, 18, 22, .45); }
dialog form.dialog-body { padding: 20px; margin: 0; }
dialog .dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.empty { text-align: center; padding: 56px 20px; color: var(--text-2); }
.empty .icon { width: 40px; height: 40px; color: var(--text-3); margin-bottom: 8px; stroke-width: 1.4; }

/* ---- Mail ----------------------------------------------------------------- */
.mail-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.mail-list-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.mail-row { display: grid; grid-template-columns: 28px minmax(140px, 220px) minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 9px 14px; border-bottom: 1px solid var(--border); color: var(--text-2); cursor: pointer; }
.mail-row:last-child { border-bottom: 0; }
.mail-row:hover { background: var(--surface-2); text-decoration: none; box-shadow: inset 3px 0 0 var(--accent); }
.mail-row.unread { color: var(--unread); }
.mail-row.unread .from, .mail-row.unread .subject { font-weight: 700; }
.mail-row .from { color: var(--text); }
.mail-row .subject { color: var(--text); }
.mail-row .preview { color: var(--text-3); }
.mail-row .date { font-size: 12.5px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.mail-row.unread .date { font-weight: 700; color: var(--text); }
.flag-on { color: #e2a400; }
.flag-on .icon { fill: #e2a400; }

.reader { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.reader-head { padding: 18px 22px 12px; border-bottom: 1px solid var(--border); }
.reader-head h1 { font-size: 21px; margin-bottom: 14px; word-break: break-word; }
.sender { display: flex; gap: 12px; align-items: flex-start; }
.sender .avatar { width: 40px; height: 40px; font-size: 15px; }
.recipients { font-size: 13px; color: var(--text-2); }
.reader-frame { display: block; width: 100%; height: 70vh; min-height: 360px; border: 0; background: #fff; border-radius: 0 0 var(--radius) var(--radius); resize: vertical; overflow: auto; }
.images-bar { display: flex; align-items: center; gap: 10px; padding: 8px 22px; background: var(--warn-soft); color: var(--warn); font-size: 13px; }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 22px; border-bottom: 1px solid var(--border); }
.attachment { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; max-width: 280px; color: var(--text); }
.attachment:hover { background: var(--surface-2); text-decoration: none; }

.compose-card .field-inline { display: grid; grid-template-columns: 64px minmax(0, 1fr); align-items: center; gap: 8px; border-bottom: 1px solid var(--border); padding: 4px 18px; }
.compose-card .field-inline label { margin: 0; color: var(--text-2); font-weight: 500; }
.compose-card .field-inline input, .compose-card .field-inline select { border: 0; box-shadow: none; padding: 9px 0; background: transparent; }
.compose-card textarea { border: 0; box-shadow: none; border-radius: 0; min-height: 46vh; padding: 16px 18px; }
.compose-foot { display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-top: 1px solid var(--border); flex-wrap: wrap; }

/* ---- Drive ---------------------------------------------------------------- */
.crumbs { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; font-size: 18px; font-weight: 600; }
.crumbs a { color: var(--text-2); padding: 2px 6px; border-radius: 6px; }
.crumbs a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.crumbs .sep { color: var(--text-3); }
.crumbs .here { padding: 2px 6px; }
.file-name { display: flex; align-items: center; gap: 12px; color: var(--text); font-weight: 500; min-width: 0; }
.file-name:hover { text-decoration: none; color: var(--accent); }
.file-icon { width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; flex: none; background: var(--surface-2); color: var(--text-2); }
.file-icon.folder { background: #fff3d6; color: #b07800; }
.file-icon.image { background: #e7f6ee; color: #1b8a52; }
.file-icon.pdf { background: #fdeaea; color: #c43232; }
.file-icon.doc { background: #e7effd; color: #2459c9; }
.file-icon.sheet { background: #e4f5ea; color: #16794a; }
.file-icon.video { background: #f0e9fd; color: #6c3fd1; }
.file-icon.zip { background: #f2ece4; color: #7a5a2f; }
:root[data-theme="dark"] .file-icon.folder { background: #3a2f12; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .file-icon:not(.folder) { filter: saturate(.8) brightness(.9); } :root:not([data-theme="light"]) .file-icon.folder { background: #3a2f12; } }
.dropzone { position: fixed; inset: 0; display: none; place-items: center; background: color-mix(in srgb, var(--accent) 14%, transparent); border: 3px dashed var(--accent); z-index: 50; font-size: 20px; font-weight: 700; color: var(--accent); pointer-events: none; }
body.dragging .dropzone { display: grid; }
.progress { position: fixed; right: 20px; bottom: 20px; width: 320px; padding: 14px 16px; z-index: 60; display: none; }
.progress.show { display: block; }

/* ---- Calendar ------------------------------------------------------------- */
.cal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.cal-head, .cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-head div { padding: 8px 10px; font-size: 12px; font-weight: 650; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--border); }
.cal-day { min-height: 116px; padding: 6px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cal-day:nth-child(7n) { border-right: 0; }
.cal-day.other { background: var(--surface-2); }
.cal-day.other .daynum { color: var(--text-3); }
.cal-day .daynum { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; font-size: 13px; font-weight: 600; color: var(--text); }
.cal-day .daynum:hover { background: var(--surface-2); text-decoration: none; }
.cal-day.today .daynum { background: var(--accent); color: var(--accent-text); }
.event-chip { display: block; padding: 2px 6px; border-radius: 5px; font-size: 12px; color: var(--text); background: color-mix(in srgb, var(--c, var(--accent)) 16%, var(--surface)); border-left: 3px solid var(--c, var(--accent)); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.event-chip:hover { text-decoration: none; background: color-mix(in srgb, var(--c, var(--accent)) 26%, var(--surface)); }
.event-chip.allday { background: var(--c, var(--accent)); color: #fff; border-left-color: transparent; }
.event-chip .time { color: var(--text-2); font-variant-numeric: tabular-nums; margin-right: 3px; }
.more { font-size: 12px; color: var(--text-2); padding-left: 6px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--c, var(--accent)); flex: none; }
.agenda-item { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); color: var(--text); }
.agenda-item:last-child { border-bottom: 0; }
.agenda-item:hover { text-decoration: none; }
.agenda-date { width: 46px; text-align: center; flex: none; }
.agenda-date b { display: block; font-size: 20px; line-height: 1.1; }
.agenda-date span { font-size: 11px; text-transform: uppercase; color: var(--text-2); font-weight: 650; }

/* ---- Auth pages ----------------------------------------------------------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background:
  radial-gradient(1200px 600px at 10% -10%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 60%),
  radial-gradient(900px 500px at 110% 110%, color-mix(in srgb, var(--accent) 12%, transparent), transparent 60%), var(--bg); }
.auth-card { width: min(400px, 100%); padding: 32px 30px; }
.auth-card .brand { width: auto; margin-bottom: 22px; }
.auth-card h1 { font-size: 22px; margin-bottom: 4px; }
.auth-domains { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; margin-top: 18px; }

/* ---- Small screens -------------------------------------------------------- */
@media (max-width: 900px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .mail-row { grid-template-columns: 24px minmax(0, 1fr) auto; }
  .mail-row .from { grid-column: 2; }
  .mail-row .date { grid-column: 3; grid-row: 1; }
  .mail-row .body { grid-column: 2 / -1; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; top: 56px; bottom: 0; left: 0; width: min(290px, 86vw); z-index: 40; transform: translateX(-102%); transition: transform .18s ease; box-shadow: var(--shadow-lg); }
  body.nav-open .sidebar { transform: none; }
  .menu-toggle { display: inline-grid; }
  .brand { width: auto; }
  .brand small, .userchip .who { display: none; }
  .page { padding: 16px 16px 32px; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .cal-day { min-height: 74px; padding: 3px; }
  .event-chip { font-size: 10.5px; padding: 1px 3px; }
  .event-chip .time { display: none; }
  .hide-sm { display: none !important; }
  .search { max-width: none; }
}
