/*
 * Cartero stylesheet. Hand-written, no build step: edit and reload.
 *
 * Colors are tokens on :root; the .dark class on <html> (toggled by Alpine,
 * see layouts/page.templ) swaps them for the dark palette.
 */

:root {
  --bg: #f9fafb;
  --surface: #ffffff;
  --surface-sunken: #f9fafb;
  --surface-hover: #f3f4f6;
  --surface-strong: #e5e7eb;
  --border: #e5e7eb;
  --border-subtle: #f3f4f6;
  --input-border: #d1d5db;

  --text: #111827;
  --text-2: #374151;
  --text-body: #1f2937;
  --text-muted: #6b7280;
  --text-faint: #9ca3af;
  --text-disabled: #d1d5db;

  --accent: #4f46e5;
  --accent-hover: #6366f1;
  --accent-text: #4f46e5;
  --accent-soft: #eef2ff;
  --accent-soft-text: #4338ca;
  --accent-badge: #e0e7ff;
  --row-active: #eef2ff;

  --danger: #dc2626;
  --danger-hover: #ef4444;
  --danger-text: #b91c1c;
  --danger-text-strong: #991b1b;
  --danger-soft: #fef2f2;
  --danger-soft-hover: #fee2e2;
  --danger-icon: #f87171;

  --success-text: #16a34a;
  --success-dot: #22c55e;
  --off-dot: #d1d5db;
  --switch-off: #e5e7eb;

  --warn-bg: #fffbeb;
  --warn-border: #fde68a;
  --warn-text: #92400e;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --radius: 0.375rem;
  --radius-lg: 0.5rem;
  --radius-xl: 0.75rem;

  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  color-scheme: light;
}

.dark {
  --bg: #030712;
  --surface: #111827;
  --surface-sunken: #1f2937;
  --surface-hover: #1f2937;
  --surface-strong: #374151;
  --border: #1f2937;
  --border-subtle: rgb(31 41 55 / 0.8);
  --input-border: #374151;

  --text: #f3f4f6;
  --text-2: #d1d5db;
  --text-body: #e5e7eb;
  --text-muted: #9ca3af;
  --text-faint: #6b7280;
  --text-disabled: #4b5563;

  --accent-text: #818cf8;
  --accent-soft: rgb(99 102 241 / 0.1);
  --accent-soft-text: #a5b4fc;
  --accent-badge: rgb(49 46 129 / 0.4);
  --row-active: rgb(49 46 129 / 0.3);

  --danger-text: #fca5a5;
  --danger-text-strong: #fca5a5;
  --danger-soft: rgb(127 29 29 / 0.3);
  --danger-soft-hover: rgb(127 29 29 / 0.5);

  --success-text: #4ade80;
  --off-dot: #4b5563;
  --switch-off: #374151;

  --warn-bg: rgb(120 53 15 / 0.2);
  --warn-border: rgb(120 53 15 / 0.4);
  --warn-text: #fcd34d;

  color-scheme: dark;
}

/* ---------- Reset ---------- */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; border: 0 solid; }
html { -webkit-text-size-adjust: 100%; font-family: var(--font-sans); line-height: 1.5; }
body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}
h1, h2, h3 { font-size: inherit; font-weight: inherit; }
a { color: inherit; text-decoration: inherit; }
ul { list-style: none; }
svg, iframe { display: block; }
button, input, select { font: inherit; color: inherit; background: transparent; }
button { cursor: pointer; }
input::placeholder { color: var(--text-faint); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

[x-cloak] { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border-width: 0;
}
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Icons ---------- */

.icon-xs { width: 0.875rem; height: 0.875rem; flex: none; }
.icon-sm { width: 1rem; height: 1rem; flex: none; }
.icon { width: 1.25rem; height: 1.25rem; flex: none; }
.icon-lg { width: 1.5rem; height: 1.5rem; flex: none; }

/* ---------- Layout ---------- */

.container { margin-inline: auto; max-width: 80rem; padding-inline: 1rem; }
@media (min-width: 640px) { .container { padding-inline: 1.5rem; } }
@media (min-width: 1024px) { .container { padding-inline: 2rem; } }

.app-main { padding-block: 1.5rem; }

.auth-main {
  display: flex; flex-direction: column; justify-content: center;
  min-height: 100vh; padding: 3rem 1.5rem;
}
.auth-box { width: 100%; max-width: 24rem; margin-inline: auto; }
.auth-box + .auth-box { margin-top: 2rem; }
.auth-logo { width: 2.5rem; height: 2.5rem; margin-inline: auto; color: var(--accent-text); }

/* ---------- Navbar ---------- */

.navbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.navbar-inner {
  display: flex; align-items: center; justify-content: space-between;
  padding-block: 1rem;
}
.brand-wrap { flex: 1; display: flex; align-items: center; }
.brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 600; color: var(--text); }
.brand-logo { width: 1.5rem; height: 1.5rem; color: var(--accent-text); }
.nav-links, .nav-actions { display: none; }
.nav-link { font-size: 0.875rem; font-weight: 500; color: var(--text-2); }
.nav-link:hover { color: var(--text); }
.menu-btn { margin: -0.625rem; padding: 0.625rem; border-radius: var(--radius); color: var(--text-2); }
.mobile-menu { border-top: 1px solid var(--border); padding: 0.75rem 1rem; }
.mobile-menu > * + * { margin-top: 0.25rem; }
.mobile-link {
  display: block; padding: 0.5rem 0.75rem; border-radius: var(--radius);
  font-weight: 500; color: var(--text-2);
}
.mobile-link:hover { background: var(--surface-hover); }
.mobile-menu-footer { padding-top: 0.5rem; }

@media (min-width: 1024px) {
  .nav-links { display: flex; gap: 2rem; }
  .nav-actions { display: flex; flex: 1; justify-content: flex-end; align-items: center; gap: 1rem; }
  .menu-btn, .mobile-menu { display: none !important; }
}

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0.5rem; border-radius: var(--radius); color: var(--text-muted);
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text-2); }

/* ---------- Typography ---------- */

.page-title { font-size: 1.5rem; line-height: 2rem; font-weight: 600; letter-spacing: -0.025em; }
.page-subtitle { margin-top: 0.25rem; font-size: 0.875rem; color: var(--text-muted); }
.auth-title { margin-top: 1.5rem; text-align: center; font-size: 1.5rem; line-height: 2rem; font-weight: 700; letter-spacing: -0.025em; }
.section-title { font-size: 0.875rem; font-weight: 600; }
.label { display: block; font-size: 0.875rem; font-weight: 500; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.25rem;
  padding: 0.375rem 0.75rem; border-radius: var(--radius);
  font-size: 0.75rem; line-height: 1rem; font-weight: 500;
  transition: background-color 0.15s, color 0.15s;
}
.btn-primary { background: var(--accent); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface-hover); color: var(--text-2); }
.btn-secondary:hover { background: var(--surface-strong); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-danger-soft { background: var(--danger-soft); color: var(--danger-text); padding: 0.375rem 0.625rem; }
.btn-danger-soft:hover { background: var(--danger-soft-hover); }
.btn-lg { gap: 0.375rem; padding: 0.5rem 0.875rem; font-size: 0.875rem; line-height: 1.25rem; font-weight: 600; }
.btn-block { width: 100%; }
.btn-pill { border-radius: 9999px; padding: 0.25rem 0.75rem; }

.link-btn { font-size: 0.75rem; font-weight: 500; color: var(--accent-text); }
.link-btn:hover { text-decoration: underline; }

/* ---------- Forms ---------- */

.input, .select {
  display: block; border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font-size: 0.875rem; line-height: 1.25rem;
  padding: 0.375rem 0.75rem;
  outline: 1px solid var(--input-border); outline-offset: -1px;
}
.input { width: 100%; }
.input:focus, .select:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.dark .select, .dark .inbox-search .input { background: var(--surface-sunken); }
.select { padding-inline: 0.5rem; }

.input-with-icon { position: relative; flex: 1; }
.input-with-icon > .input { padding: 0.5rem 0.75rem 0.5rem 2.5rem; }
.input-icon {
  position: absolute; inset-block: 0; left: 0; display: flex; align-items: center;
  padding-left: 0.75rem; color: var(--text-faint); pointer-events: none;
}

.checkbox { width: 1rem; height: 1rem; accent-color: var(--accent); flex: none; }

.form-stack > * + * { margin-top: 1.5rem; }
.field-control { margin-top: 0.5rem; }

.add-row { margin-top: 0.5rem; display: flex; flex-direction: column; gap: 0.5rem; }
@media (min-width: 640px) { .add-row { flex-direction: row; } }

/* ---------- Cards ---------- */

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-xl); box-shadow: var(--shadow-sm); overflow: hidden;
}
.card-body { padding: 1rem; }
.card-header { padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); }
@media (min-width: 640px) {
  .card-body { padding: 1.25rem; }
  .card-header { padding-inline: 1.25rem; }
}

.stack-lg > * + * { margin-top: 1.5rem; }
.narrow { margin-inline: auto; max-width: 48rem; }

/* ---------- Badges & alerts ---------- */

.badge {
  display: inline-flex; align-items: center; border-radius: 9999px;
  padding: 0.125rem 0.5rem; font-size: 0.75rem; font-weight: 500;
  background: var(--accent-badge); color: var(--accent-soft-text);
}

.alert-error {
  display: flex; align-items: center; gap: 0.75rem;
  margin-bottom: 1rem; padding: 1rem; border-radius: var(--radius);
  background: var(--danger-soft); color: var(--danger-text-strong);
  font-size: 0.875rem; font-weight: 500;
}
.alert-error svg { color: var(--danger-icon); }

.banner-warning {
  display: flex; flex: none; align-items: center; justify-content: space-between; gap: 0.5rem;
  padding: 0.5rem 0.75rem; font-size: 0.75rem;
  background: var(--warn-bg); color: var(--warn-text); border-bottom: 1px solid var(--warn-border);
}
.banner-warning > span { display: flex; align-items: center; gap: 0.375rem; }
.banner-warning button { font-weight: 500; white-space: nowrap; text-decoration: underline; }
.banner-warning button:hover { text-decoration: none; }

/* ---------- Empty states ---------- */

.empty-state { text-align: center; }
.empty-state svg { margin-inline: auto; color: var(--text-disabled); }
.empty-state h3 { margin-top: 0.5rem; font-size: 0.875rem; font-weight: 500; }
.empty-state p { margin-top: 0.25rem; font-size: 0.875rem; color: var(--text-muted); }
.empty-state-icon {
  margin-inline: auto; display: flex; align-items: center; justify-content: center;
  width: 3rem; height: 3rem; border-radius: 9999px;
  background: var(--surface-hover); color: var(--text-faint);
}
.empty-state-icon + h3 { margin-top: 0.75rem; }
.centered { height: 100%; display: flex; align-items: center; justify-content: center; padding: 2rem; }
.icon-hero { width: 3rem; height: 3rem; }
.icon-hero-sm { width: 2.5rem; height: 2.5rem; }

/* ---------- Accounts ---------- */

.account-list > li + li { border-top: 1px solid var(--border-subtle); }
.account-row {
  display: flex; align-items: center; gap: 1rem; padding: 0.75rem 1rem;
  transition: background-color 0.15s;
}
.account-row:hover { background: var(--surface-sunken); }
.dark .account-row:hover { background: rgb(31 41 55 / 0.4); }
@media (min-width: 640px) { .account-row { padding-inline: 1.25rem; } }
.account-avatar {
  display: flex; flex: none; align-items: center; justify-content: center;
  width: 2.5rem; height: 2.5rem; border-radius: 9999px;
  background: var(--accent-soft); color: var(--accent-text);
}
.account-info { min-width: 0; flex: 1; }
.account-email { font-size: 0.875rem; font-weight: 500; }
.account-status {
  margin-top: 0.125rem; display: flex; align-items: center; gap: 0.375rem;
  font-size: 0.75rem; color: var(--text-muted);
}
.account-status::before {
  content: ""; width: 0.375rem; height: 0.375rem; border-radius: 9999px; background: var(--off-dot);
}
.account-status.is-on { color: var(--success-text); }
.account-status.is-on::before { background: var(--success-dot); }
.account-delete { flex: none; padding: 0.5rem; border-radius: var(--radius); color: var(--text-faint); transition: background-color 0.15s, color 0.15s; }
.account-delete:hover { background: var(--danger-soft); color: var(--danger); }
.dark .account-delete:hover { color: #f87171; }
.accounts-card:has(li) .accounts-empty { display: none; }
.accounts-empty { padding: 3.5rem 1.5rem; }

/* Toggle switch */
.switch {
  position: relative; display: inline-flex; flex: none;
  width: 2.75rem; height: 1.5rem; border-radius: 9999px; border: 2px solid transparent;
  background: var(--switch-off); transition: background-color 0.2s ease-in-out;
}
.switch::after {
  content: ""; display: inline-block; width: 1.25rem; height: 1.25rem; border-radius: 9999px;
  background: #fff; box-shadow: var(--shadow); transition: transform 0.2s ease-in-out;
}
.switch.is-on { background: var(--accent); }
.switch.is-on::after { transform: translateX(1.25rem); }

/* ---------- Inbox ---------- */

.inbox {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow); overflow: hidden;
}
.inbox-header {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem;
  padding: 0.75rem 1rem; border-bottom: 1px solid var(--border);
}
.inbox-title { font-size: 1rem; font-weight: 600; }
.inbox-search {
  display: flex; flex: 1; min-width: 200px; flex-wrap: wrap;
  align-items: center; justify-content: flex-end; gap: 0.5rem; margin-left: auto;
}
.inbox-search .input { flex: 1; max-width: 20rem; }
.inline-check { display: flex; align-items: center; gap: 0.375rem; white-space: nowrap; font-size: 0.875rem; color: var(--text-muted); }
.bulk-actions { display: flex; align-items: center; gap: 0.5rem; }
.refresh { display: flex; flex: none; align-items: center; gap: 0.5rem; font-size: 0.75rem; color: var(--text-faint); white-space: nowrap; }
.countdown { display: inline-block; width: 2ch; text-align: right; font-variant-numeric: tabular-nums; }

/* Two panes side by side from 768px up; one at a time below, switched by .show-detail. */
.inbox-panes { display: grid; grid-template-columns: 1fr; height: calc(100dvh - 180px); }
.pane-list { display: flex; flex-direction: column; min-height: 0; }
.pane-detail { display: none; min-height: 0; }
.inbox-panes.show-detail .pane-list { display: none; }
.inbox-panes.show-detail .pane-detail { display: block; }
@media (min-width: 768px) {
  .inbox-panes { grid-template-columns: 2fr 3fr; height: calc(100vh - 180px); }
  .pane-list { border-right: 1px solid var(--border); }
  .inbox-panes .pane-list, .inbox-panes.show-detail .pane-list { display: flex; }
  .inbox-panes .pane-detail, .inbox-panes.show-detail .pane-detail { display: block; }
}

/* Email list */
.email-list { display: flex; flex-direction: column; height: 100%; }
.list-toolbar {
  display: flex; flex: none; align-items: center; gap: 0.75rem;
  padding: 0.5rem 1rem; border-bottom: 1px solid var(--border);
}
.list-toolbar label { display: flex; align-items: center; gap: 0.375rem; font-size: 0.75rem; color: var(--text-muted); }
.selected-count { font-size: 0.75rem; font-weight: 500; color: var(--accent-text); }
.list-scroll { flex: 1; min-height: 0; overflow-y: auto; }

.email-row {
  display: flex; align-items: flex-start; gap: 0.75rem; padding: 1rem;
  border-bottom: 1px solid var(--border); cursor: pointer; transition: background-color 0.15s;
}
.email-row:hover { background: var(--surface-sunken); }
.dark .email-row:hover { background: rgb(31 41 55 / 0.5); }
.email-row.is-active, .dark .email-row.is-active { background: var(--row-active); }
.email-row > .checkbox { margin-top: 0.25rem; }
.email-summary { min-width: 0; flex: 1; }
.email-line { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.5rem; margin-bottom: 0.25rem; }
.email-from { font-size: 0.875rem; font-weight: 500; color: var(--text-2); }
.email-row.is-unread .email-from { font-weight: 600; color: var(--text); }
.unread-dot {
  display: inline-block; width: 0.5rem; height: 0.5rem; margin-right: 0.5rem;
  border-radius: 9999px; background: var(--accent); vertical-align: middle;
}
.email-time { font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; }
.email-to { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 0.25rem; }
.email-subject { font-size: 0.875rem; color: var(--text-body); }

.pagination {
  display: flex; flex: none; align-items: center; justify-content: space-between; gap: 0.5rem;
  padding: 0.5rem 0.75rem; border-top: 1px solid var(--border); background: var(--surface);
  font-size: 0.75rem; color: var(--text-muted);
}
.page-btn {
  display: inline-flex; align-items: center; gap: 0.25rem; padding: 0.25rem 0.5rem;
  border-radius: var(--radius); font-size: 0.75rem; font-weight: 500; color: var(--text-2);
}
button.page-btn:hover { background: var(--surface-hover); }
.page-btn.is-disabled { cursor: default; color: var(--text-disabled); }

/* Email detail */
.detail { display: flex; flex-direction: column; height: 100%; }
.detail-header { padding: 1rem; border-bottom: 1px solid var(--border); }
.back-btn {
  display: inline-flex; align-items: center; gap: 0.25rem;
  margin: 0 0 0.5rem -0.25rem; font-size: 0.875rem; font-weight: 500; color: var(--accent-text);
}
@media (min-width: 768px) { .back-btn { display: none; } }
.detail-title-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.75rem; margin-bottom: 0.75rem; }
.detail-title { font-size: 1.125rem; line-height: 1.75rem; font-weight: 600; }
.meta { display: grid; grid-template-columns: max-content 1fr; gap: 0.25rem 0.75rem; font-size: 0.875rem; }
.meta dt { font-weight: 500; color: var(--text-muted); }
.meta dd { min-width: 0; }
.meta dd > span { display: block; }
.meta-sub { font-size: 0.75rem; color: var(--text-faint); }

.attachments { margin-top: 0.75rem; display: flex; flex-wrap: wrap; gap: 0.5rem; }
.attachment {
  display: inline-flex; max-width: 100%; align-items: center; gap: 0.375rem;
  padding: 0.375rem 0.625rem; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface-sunken); font-size: 0.75rem; color: var(--text-2);
}
.dark .attachment { border-color: var(--input-border); }
.attachment:hover { background: var(--surface-hover); }
.dark .attachment:hover { background: var(--surface-strong); }
.attachment svg, .attachment-size { color: var(--text-faint); flex: none; }

.detail-body { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.format-bar { display: flex; justify-content: flex-end; padding: 0.5rem 1rem; border-bottom: 1px solid var(--border); }
.segmented { display: inline-flex; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }
.dark .segmented { border-color: var(--input-border); }
.segmented > button {
  padding: 0.375rem 0.75rem; font-size: 0.75rem; font-weight: 500;
  background: var(--surface); color: var(--text-2); transition: background-color 0.15s, color 0.15s;
}
.segmented > button + button { border-left: 1px solid var(--border); }
.dark .segmented > button + button { border-left-color: var(--input-border); }
.segmented > button.is-active { background: var(--accent); color: #fff; }

.email-content { flex: 1; overflow: auto; background: var(--surface); }
.email-html { display: flex; flex-direction: column; height: 100%; }
.email-html iframe { width: 100%; flex: 1; border: 0; background: #fff; }
.email-text {
  padding: 1rem; white-space: pre-wrap; font-family: var(--font-sans);
  font-size: 0.875rem; color: var(--text-body);
}
