@font-face {
  font-family: 'Geist';
  src: url('/fonts/Geist-Regular.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Geist';
  src: url('/fonts/Geist-Medium.woff2') format('woff2');
  font-weight: 500 700;
  font-display: swap;
}

:root {
  --bg: #ffffff;
  --bg-soft: #fafafa;
  --ink: #272727;
  --ink-2: #3a3a3a;
  --muted: #6b6b6b;
  --faint: #9b9b9b;
  --line: #e9e9e9;
  --hover: #f5f5f5;
  --active: #efefef;
  --accent: #272727;
  --accent-ink: #ffffff;
  --danger: #c2372b;
  --danger-soft: #fdf0ee;
  --avatar: #f0f0f0;
  --skeleton: #f2f2f2;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.08);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111111;
    --bg-soft: #161616;
    --ink: #ededed;
    --ink-2: #d6d6d6;
    --muted: #9b9b9b;
    --faint: #6f6f6f;
    --line: #252525;
    --hover: #1b1b1b;
    --active: #222222;
    --accent: #ededed;
    --accent-ink: #111111;
    --danger: #f0705f;
    --danger-soft: #2a1714;
    --avatar: #232323;
    --skeleton: #1d1d1d;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
svg { display: block; flex-shrink: 0; }

/* ---------------------------------------------------------------- base */

.wordmark {
  font-weight: 500;
  font-size: 20px;
  letter-spacing: -0.03em;
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.wordmark span {
  font-weight: 400;
  font-size: 13px;
  letter-spacing: 0;
  color: var(--muted);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg);
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--hover); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent); opacity: 0.9; }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); opacity: 0.9; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: default; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius);
  border: 0;
  background: transparent;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--hover); color: var(--ink); }
.icon-btn.spinning svg { animation: spin 0.8s linear infinite; }

.spinner {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--line);
  border-top-color: var(--ink);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.boot { position: fixed; inset: 0; display: grid; place-items: center; }

/* ---------------------------------------------------------------- login */

.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background: var(--bg-soft);
}
.login-card {
  width: 100%;
  max-width: 360px;
  padding: 32px 28px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.login-card .wordmark { font-size: 26px; }
.login-sub { margin: 8px 0 24px; color: var(--muted); }
.login-sub strong { color: var(--ink); font-weight: 500; }
.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field span { font-size: 13px; font-weight: 500; }
.field input {
  height: 40px;
  padding: 0 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg);
  outline: none;
}
.field input:focus { border-color: var(--ink); box-shadow: 0 0 0 3px var(--active); }
.login-error {
  margin: -6px 0 14px;
  padding: 8px 10px;
  border-radius: var(--radius);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
}

/* ---------------------------------------------------------------- layout */

.app {
  height: 100%;
  display: grid;
  grid-template-columns: 228px minmax(320px, 400px) 1fr;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 20px 12px;
  border-right: 1px solid var(--line);
  background: var(--bg-soft);
  min-height: 0;
}
.sidebar > .wordmark { padding: 2px 10px 0; }
.boxes { display: grid; gap: 2px; }
.box {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink-2);
  text-align: left;
  transition: background 0.15s;
}
.box svg { color: var(--muted); }
.box:hover { background: var(--hover); }
.box.active { background: var(--active); color: var(--ink); font-weight: 500; }
.box.active svg { color: var(--ink); }
.box-label { flex: 1; min-width: 0; display: grid; }
.box-label small { font-size: 12px; color: var(--faint); font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.box-count { font-size: 12px; font-weight: 500; color: var(--ink); font-variant-numeric: tabular-nums; }
.box-sep { height: 1px; background: var(--line); margin: 8px 10px; }
.box-logout { margin-top: auto; color: var(--muted); }

.list-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--line);
}
.mobile-bar, .chips { display: none; }

.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 18px 16px 10px 20px;
}
.list-head h1 { margin: 0; font-size: 18px; font-weight: 500; letter-spacing: -0.02em; }
.list-actions { display: flex; align-items: center; gap: 4px; }

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 16px 10px;
  padding: 0 12px;
  height: 38px;
  border-radius: var(--radius);
  background: var(--hover);
  color: var(--muted);
  border: 1px solid transparent;
}
.search:focus-within { border-color: var(--line); background: var(--bg); }
.search input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; height: 100%; color: var(--ink); }
.search input::placeholder { color: var(--faint); }

.trash-note { margin: 0 20px 8px; font-size: 12px; color: var(--faint); }

.list { flex: 1; overflow-y: auto; overscroll-behavior: contain; }

.row {
  display: flex;
  gap: 12px;
  padding: 12px 16px 12px 20px;
  border-bottom: 1px solid var(--line);
  position: relative;
  transition: background 0.1s;
}
.row:hover { background: var(--hover); }
.row.active { background: var(--active); }
.row.unread::before {
  content: '';
  position: absolute;
  left: 7px;
  top: 22px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ink);
}
.row-main { flex: 1; min-width: 0; display: grid; gap: 1px; }
.row-top { display: flex; align-items: baseline; gap: 8px; }
.row-from { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.row-time { font-size: 12px; color: var(--faint); white-space: nowrap; font-variant-numeric: tabular-nums; }
.row-subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.row-snippet {
  color: var(--muted);
  font-size: 13px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 1.45em;
}
.row.unread .row-from, .row.unread .row-subject { color: var(--ink); font-weight: 500; }
.row.unread .row-time { color: var(--ink); }
.row-meta { display: flex; align-items: center; gap: 6px; margin-top: 4px; color: var(--faint); }
.row-meta:empty { display: none; }

.tag {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  background: var(--avatar);
  color: var(--ink-2);
  font-weight: 500;
  font-size: 14px;
  text-transform: uppercase;
}
.avatar-lg { width: 40px; height: 40px; font-size: 16px; }

.list-empty { padding: 48px 24px; text-align: center; color: var(--muted); }
.list-empty svg { margin: 0 auto 12px; color: var(--faint); }
.list-more { padding: 14px; display: flex; justify-content: center; }

.skeleton-row { display: flex; gap: 12px; padding: 14px 16px 14px 20px; border-bottom: 1px solid var(--line); }
.sk { background: var(--skeleton); border-radius: 6px; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }

/* ---------------------------------------------------------------- reader */

.reader { min-width: 0; min-height: 0; overflow-y: auto; background: var(--bg); }

.reader-empty {
  height: 100%;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  color: var(--faint);
  text-align: center;
  padding: 24px;
}

.reader-bar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.reader-bar .back { display: none; }
.reader-bar .spacer { flex: 1; }
.reader-bar .btn { height: 32px; padding: 0 10px; font-size: 13px; }
.reader-bar .btn svg { color: var(--muted); }

.message { max-width: 860px; margin: 0 auto; padding: 24px 28px 48px; }
.msg-subject { margin: 0 0 18px; font-size: 22px; line-height: 1.3; font-weight: 500; letter-spacing: -0.02em; overflow-wrap: anywhere; }
.msg-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 18px; }
.msg-who { flex: 1; min-width: 0; }
.msg-from { overflow-wrap: anywhere; }
.msg-from strong { font-weight: 500; }
.msg-from span { color: var(--muted); }
.msg-to { margin-top: 2px; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.msg-date { font-size: 12.5px; color: var(--faint); white-space: nowrap; text-align: right; }
.msg-date .tag { margin-top: 6px; }

.notice {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  padding: 9px 12px;
  border-radius: var(--radius);
  background: var(--hover);
  color: var(--muted);
  font-size: 13px;
}
.notice span { flex: 1; min-width: 200px; }

.msg-body {
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
}
.msg-body iframe { display: block; width: 100%; height: 200px; border: 0; background: #fff; }
.msg-text {
  margin: 0;
  padding: 18px 20px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: inherit;
  color: #272727;
}
.msg-text a { color: #0b57d0; text-decoration: underline; }
.msg-loading { display: grid; gap: 10px; padding: 20px; }
.msg-error { padding: 20px; color: var(--danger); background: var(--danger-soft); }

.attachments { margin-top: 20px; }
.attachments h3 { margin: 0 0 10px; font-size: 13px; font-weight: 500; color: var(--muted); }
.att-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.att {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  min-width: 0;
}
.att-thumb {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  background: var(--hover);
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 500;
  overflow: hidden;
  text-transform: uppercase;
}
.att-thumb img { width: 100%; height: 100%; object-fit: cover; }
.att-info { flex: 1; min-width: 0; display: grid; }
.att-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; font-size: 13px; }
.att-size { font-size: 12px; color: var(--faint); }
.att-actions { display: flex; }

/* ---------------------------------------------------------------- dialog / toast */

.dialog {
  width: min(400px, calc(100% - 32px));
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg);
  color: var(--ink);
  box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
.dialog h2 { margin: 0 0 6px; font-size: 16px; font-weight: 500; }
.dialog p { margin: 0 0 20px; color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: calc(100% - 32px);
  padding: 10px 10px 10px 16px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: var(--shadow);
  font-size: 13.5px;
}
.toast button {
  border: 0;
  background: transparent;
  color: inherit;
  font-weight: 500;
  text-decoration: underline;
  padding: 4px 6px;
}

/* ---------------------------------------------------------------- responsivo */

@media (max-width: 1100px) {
  .app { grid-template-columns: 200px minmax(300px, 340px) 1fr; }
}

@media (max-width: 860px) {
  .app { display: block; }
  .sidebar { display: none; }
  .list-pane { height: 100%; border-right: 0; padding-top: env(safe-area-inset-top); }
  .mobile-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 12px 4px 16px;
  }
  .chips {
    display: flex;
    gap: 6px;
    padding: 8px 16px 4px;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .chips::-webkit-scrollbar { display: none; }
  .chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 32px;
    padding: 0 12px;
    border-radius: 999px;
    border: 1px solid var(--line);
    white-space: nowrap;
    color: var(--ink-2);
    font-size: 13px;
  }
  .chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
  .chip b { font-weight: 500; font-size: 12px; opacity: 0.8; }
  .list-head { padding: 12px 12px 8px 16px; }
  .list-head h1 { font-size: 16px; }
  .row { padding-left: 18px; padding-right: 14px; }
  .row.unread::before { left: 6px; }
  .trash-note { margin: 0 16px 8px; }

  .reader {
    position: fixed;
    inset: 0;
    z-index: 10;
    transform: translateX(100%);
    transition: transform 0.25s ease;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
  body.reading .reader { transform: none; }
  body.reading .list-pane { visibility: hidden; transition: visibility 0s 0.25s; }
  .reader-bar { padding: 8px 10px; }
  .reader-bar .back { display: inline-grid; }
  .reader-bar .btn .label { display: none; }
  .reader-bar .btn { width: 36px; padding: 0; }
  .message { padding: 18px 16px 40px; }
  .msg-subject { font-size: 19px; }
  .msg-head { flex-wrap: wrap; }
  .msg-date { width: 100%; text-align: left; padding-left: 52px; margin-top: -6px; }
  .msg-text { padding: 14px 16px; }
}

.msg-body:has(.msg-loading), .msg-body:has(.msg-error) { background: var(--bg); }
