:root {
  --bg: #f6f8fc; --panel: #fff; --text: #1f1f1f; --muted: #5f6368; --line: #e5e7eb;
  --accent: #3b5bdb; --accent-text: #fff; --accent-soft: #e2e8ff; --accent-ink: #1e3a8a;
  --danger: #d93025; --ok: #188038; --hover: rgba(60,64,67,.08); --row-read: #f2f5fb;
  --star: #f4b400; --shadow: 0 1px 2px rgba(60,64,67,.3), 0 1px 3px 1px rgba(60,64,67,.15);
  --radius: 16px; --top-h: 64px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418; --panel: #1b1f24; --text: #e8eaed; --muted: #9aa0a6; --line: #2d3238;
    --accent: #8ea2ff; --accent-text: #0b1437; --accent-soft: #2a3358; --accent-ink: #dbe2ff;
    --danger: #f28b82; --ok: #81c995; --hover: rgba(232,234,237,.08); --row-read: #181c21;
    --shadow: 0 1px 2px rgba(0,0,0,.6), 0 1px 3px 1px rgba(0,0,0,.3);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 1.375rem; font-weight: 500; margin: 0 0 1rem; }
h2 { font-size: 1.05rem; font-weight: 600; margin: 0 0 .75rem; }
input { width: 100%; padding: .7rem .8rem; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--text); font: inherit; font-size: 16px; }
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
label { display: block; font-weight: 600; font-size: .875rem; }
label input, label .addr { margin-top: .35rem; font-weight: 400; }
.stack > * + * { margin-top: 1rem; }
.row { display: flex; gap: .5rem; }
.inline { display: inline; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; margin: 0 0 .5rem; }
.error { color: var(--danger); }
.ok { color: var(--ok); }
.error-box { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); padding: .6rem .8rem; border-radius: 8px; }
.code { font-family: ui-monospace, Consolas, monospace; letter-spacing: .05em; }
.cf-turnstile { min-height: 65px; }

/* 아이콘·버튼 */
.ic { width: 20px; height: 20px; fill: currentColor; flex: none; }
.icon-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0; }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.disabled { opacity: .35; cursor: default; }
.icon-btn.disabled:hover { background: none; }
.icon-btn .ic { width: 22px; height: 22px; }
.star.on, .star.on:hover { color: var(--star); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .6rem 1.2rem; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); color: var(--text); font: inherit; font-weight: 500; cursor: pointer; min-height: 40px; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }
.danger-text { color: var(--danger) !important; }

/* 아바타 */
.avatar { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; color: #fff; font-weight: 600; font-size: .95rem; flex: none; user-select: none; }
.avatar.lg { width: 40px; height: 40px; font-size: 1.1rem; }
.avatar.me { width: 32px; height: 32px; }

/* ---------- 로그인·가입 ---------- */
.auth-body { background: var(--bg); }
.auth { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; gap: 20px; }
.auth-brand { display: flex; align-items: center; gap: .6rem; color: var(--text); font-size: 1.4rem; font-weight: 600; }
.logo { width: 36px; height: 36px; flex: none; }
.card { width: 100%; max-width: 448px; background: var(--panel); border-radius: 28px; padding: 36px 40px; box-shadow: var(--shadow); }
.card h1 { font-size: 1.75rem; font-weight: 400; margin-bottom: .35rem; }
.card .sub { color: var(--muted); margin: 0 0 1.5rem; }
.card-actions { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-top: 1.5rem !important; }
.addr { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); overflow: hidden; }
.addr:focus-within { outline: 2px solid var(--accent); outline-offset: -1px; }
.addr input { border: 0; margin: 0; border-radius: 0; outline: none; }
.addr span { padding: 0 .8rem; color: var(--muted); white-space: nowrap; }

/* ---------- 앱 레이아웃 ---------- */
.nav-toggle { position: absolute; opacity: 0; pointer-events: none; }
.topbar { position: sticky; top: 0; z-index: 30; height: var(--top-h); display: flex; align-items: center; gap: 8px; padding: 0 16px 0 8px; background: var(--bg); }
.brand { display: flex; align-items: center; gap: .5rem; color: var(--text); font-size: 1.35rem; font-weight: 500; min-width: 190px; padding-left: 4px; }
.brand .logo { width: 34px; height: 34px; }
.search { flex: 1; max-width: 720px; display: flex; align-items: center; background: var(--hover); border-radius: 999px; height: 48px; padding: 0 6px; }
.search:focus-within { background: var(--panel); box-shadow: var(--shadow); }
.search input { border: 0; background: transparent; padding: 0 .4rem; height: 100%; outline: none; }
.search input::-webkit-search-cancel-button { display: none; }
.profile { margin-left: auto; position: relative; }
.profile summary { list-style: none; cursor: pointer; padding: 4px; border-radius: 50%; display: grid; }
.profile summary::-webkit-details-marker { display: none; }
.profile summary:hover { background: var(--hover); }
.profile-menu { position: absolute; right: 0; top: 48px; width: 300px; background: var(--panel); border-radius: 24px; box-shadow: var(--shadow); padding: 20px; display: flex; flex-direction: column; align-items: center; gap: .4rem; text-align: center; z-index: 50; }
.profile-menu .avatar { width: 64px; height: 64px; font-size: 1.6rem; margin-bottom: .3rem; }
.profile-menu .btn { width: 100%; margin-top: .4rem; }
.profile-menu form { width: 100%; }

.shell { display: grid; grid-template-columns: 256px 1fr; min-height: calc(100vh - var(--top-h)); }
.sidebar { padding: 8px 12px 16px 0; display: flex; flex-direction: column; gap: 2px; position: sticky; top: var(--top-h); align-self: start; }
.nav-item { display: flex; align-items: center; gap: 18px; height: 36px; padding: 0 12px 0 26px; border-radius: 0 999px 999px 0; color: var(--text); font-size: .9rem; }
.nav-item:hover { background: var(--hover); }
.nav-item.active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 700; }
.nav-label { flex: 1; }
.count { font-size: .8rem; font-weight: 700; }
.warn-dot { background: var(--danger); color: #fff; border-radius: 999px; min-width: 18px; height: 18px; display: inline-grid; place-items: center; font-size: .7rem; font-weight: 700; }
.nav-sep { height: 1px; background: var(--line); margin: 8px 0 8px 26px; }
.nav-foot { margin: 16px 0 0 26px; font-size: .75rem; color: var(--muted); word-break: break-all; }
.scrim { display: none; }
.content { min-width: 0; padding: 0 16px 16px 0; }

/* ---------- 메일 목록 ---------- */
.mail-pane { background: var(--panel); border-radius: var(--radius); min-height: calc(100vh - var(--top-h) - 16px); overflow: hidden; }
.list-toolbar { display: flex; align-items: center; gap: 4px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.list-title { font-size: 1rem; font-weight: 500; margin: 0 0 0 4px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pager { display: flex; align-items: center; gap: 2px; color: var(--muted); font-size: .8rem; }
.range { margin-right: 6px; white-space: nowrap; }
.mail-list { list-style: none; margin: 0; padding: 0; }
.row { display: flex; align-items: center; border-bottom: 1px solid var(--line); position: relative; }
.row.read { background: var(--row-read); }
.row:hover { box-shadow: inset 1px 0 0 var(--line), inset -1px 0 0 var(--line), 0 1px 2px 0 rgba(60,64,67,.3), 0 1px 3px 1px rgba(60,64,67,.15); z-index: 1; }
.row .star { margin-left: 6px; }
.row-link { flex: 1; min-width: 0; display: grid; grid-template-columns: 200px 1fr auto; align-items: center; gap: 12px; height: 44px; padding-right: 16px; color: var(--text); }
.row-avatar { display: none; }
.sender, .summary { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.snippet { color: var(--muted); }
.row time { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.row.unread .sender, .row.unread .subject, .row.unread time { font-weight: 700; color: var(--text); }
.empty { text-align: center; padding: 80px 24px; color: var(--muted); }
.empty-ic { width: 64px; height: 64px; opacity: .35; }

/* ---------- 메일 보기 ---------- */
.message { padding-bottom: 24px; }
.msg-toolbar { display: flex; align-items: center; gap: 4px; padding: 8px 12px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 2; }
.spacer { flex: 1; }
.msg-subject { font-size: 1.375rem; font-weight: 400; margin: 20px 24px 16px 72px; word-break: break-word; }
.chip { display: inline-block; vertical-align: middle; font-size: .75rem; padding: 2px 8px; border-radius: 4px; background: var(--hover); color: var(--muted); }
.msg-head { display: grid; grid-template-columns: 40px 1fr auto; gap: 16px; align-items: start; padding: 0 24px 0 16px; }
.msg-from { min-width: 0; word-break: break-all; }
.msg-details summary { color: var(--muted); font-size: .8rem; cursor: pointer; }
.msg-date { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.meta { display: grid; grid-template-columns: max-content 1fr; gap: .25rem 1rem; margin: .5rem 0; padding: .75rem; font-size: .8rem; border: 1px solid var(--line); border-radius: 8px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; word-break: break-all; }
.msg-body { padding: 16px 24px 0 72px; }
.safety { display: flex; align-items: center; gap: .4rem; font-size: .8rem; color: var(--muted); margin: 0 0 .75rem; }
.safety .ic { width: 16px; height: 16px; }
.body-text { white-space: pre-wrap; word-break: break-word; font: inherit; font-size: .95rem; margin: 0; }
.body-html { width: 100%; height: 70vh; border: 1px solid var(--line); border-radius: 8px; background: #fff; }

/* ---------- 내 계정 · 초대 코드 ---------- */
.page { background: var(--panel); border-radius: var(--radius); padding: 24px 28px; min-height: calc(100vh - var(--top-h) - 16px); }
.page .card { box-shadow: none; padding: 0; }
.panel { border: 1px solid var(--line); border-radius: 12px; padding: 1.25rem; margin-bottom: 1.25rem; max-width: 820px; }
.narrow { max-width: 360px; }
details { margin-top: .5rem; }
summary { cursor: pointer; color: var(--muted); }
.notice { background: var(--accent-soft); color: var(--accent-ink); border-radius: 12px; padding: .9rem 1.1rem; margin: 0 0 1.25rem; max-width: 820px; }
.notice p { margin: .25rem 0; }
.notice input { margin-top: .3rem; }
.qr { display: block; margin: 1rem 0; background: #fff; border-radius: 8px; image-rendering: pixelated; }
.steps { padding-left: 1.2rem; margin: 0 0 .5rem; }
.steps li + li { margin-top: .25rem; }
.secret { font-size: 1.05rem; word-break: break-all; }
.backup-codes { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(2, max-content); gap: .4rem 2rem; font-size: 1.1rem; margin: 1rem 0; }
.invite-form { max-width: 560px; margin-bottom: 1.25rem; }
.invite-form input { flex: 1; }
.invite-form .btn { white-space: nowrap; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.table th, .table td { text-align: left; padding: .6rem .9rem; border-top: 1px solid var(--line); vertical-align: top; }
.table th { border-top: 0; color: var(--muted); font-weight: 600; }
.ua { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.logout-all { margin-top: 1rem; }
.forgot { margin: .5rem 0 0 !important; font-size: .875rem; }
.recovery-code { font-size: 1.3rem; font-weight: 700; text-align: center; padding: 1rem; border: 2px dashed var(--accent); border-radius: 12px; letter-spacing: .08em; word-break: break-all; }
.help-box { margin-top: 1.5rem; padding: 1rem; border-radius: 12px; background: var(--hover); font-size: .875rem; }
.help-box p { margin: .4rem 0 0; }
.member-reset { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin: 0; }
.check { display: inline-flex; align-items: center; gap: .3rem; font-weight: 400; font-size: .8rem; white-space: nowrap; }
.check input { width: auto; }
.small-cell { font-size: .8rem; white-space: nowrap; }
.role { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .75rem; font-weight: 600; background: var(--hover); color: var(--muted); }
.role.owner { background: var(--accent); color: var(--accent-text); }
.role.admin { background: var(--accent-soft); color: var(--accent-ink); }
.role-change { margin-top: .3rem; }
.role-change input[type=password] { width: 130px; padding: .4rem .6rem; font-size: .8rem; }
.role-change .btn { min-height: 32px; padding: .3rem .8rem; }

/* ---------- 태블릿: 메뉴를 아이콘만 ---------- */
@media (max-width: 1100px) and (min-width: 761px) {
  .shell { grid-template-columns: 72px 1fr; }
  .brand { min-width: 0; }
  .nav-item { padding: 0; width: 48px; height: 32px; margin-left: 12px; justify-content: center; border-radius: 999px; }
  .nav-label, .count, .nav-foot, .nav-item .warn-dot { display: none; }
  .nav-sep { margin-left: 12px; width: 48px; }
  .row-link { grid-template-columns: 150px 1fr auto; }
}

/* ---------- 모바일 ---------- */
@media (max-width: 760px) {
  :root { --top-h: 60px; }
  body { font-size: 15px; }
  .topbar { padding: 8px 12px; gap: 4px; height: var(--top-h); }
  .brand { display: none; }
  .search { height: 44px; box-shadow: var(--shadow); background: var(--panel); max-width: none; }
  .search-btn { display: none; }
  .menu-btn { order: -1; }
  .topbar > .menu-btn { position: absolute; left: 16px; z-index: 2; width: 36px; height: 36px; }
  .search { padding-left: 44px; }
  .profile { position: absolute; right: 16px; }
  .search { padding-right: 44px; }
  .profile-menu { width: min(300px, calc(100vw - 32px)); }

  .shell { display: block; }
  .sidebar { position: fixed; z-index: 60; top: 0; bottom: 0; left: 0; width: 280px; max-width: 85vw; background: var(--panel); padding: 16px 12px 16px 0; transform: translateX(-100%); transition: transform .2s ease; overflow-y: auto; box-shadow: var(--shadow); }
  .nav-toggle:checked ~ .shell .sidebar { transform: none; }
  .nav-toggle:checked ~ .shell .scrim { display: block; position: fixed; inset: 0; z-index: 55; background: rgba(0,0,0,.4); }
  .nav-item { height: 48px; font-size: 1rem; }
  .content { padding: 0; }
  .mail-pane, .page { border-radius: 0; min-height: calc(100vh - var(--top-h)); }
  .page { padding: 20px 16px; }

  .list-toolbar { padding: 4px 8px; }
  .row { align-items: stretch; }
  .row-link { order: 1; display: grid; height: auto; padding: 12px 0 12px 16px; gap: 2px 12px;
    grid-template-columns: 40px 1fr auto; grid-template-areas: "av sender time" "av summary summary"; }
  .row-avatar { display: inline-grid; grid-area: av; width: 40px; height: 40px; font-size: 1.1rem; align-self: start; }
  .sender { grid-area: sender; font-size: 1rem; }
  .row time { grid-area: time; }
  .summary { grid-area: summary; white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .subject { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .snippet { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .row > .inline { order: 2; align-self: flex-end; margin: 0 4px 6px 0; }
  .row .star { margin-left: 0; }
  .row.read { background: var(--panel); }
  .row { border-bottom: 0; }
  .row:hover { box-shadow: none; background: var(--hover); }

  .msg-subject { margin: 16px 16px 12px; font-size: 1.25rem; }
  .msg-head { padding: 0 16px; gap: 12px; }
  .msg-body { padding: 16px 16px 0; }
  .body-html { height: 65vh; }

  .card { padding: 28px 22px; border-radius: 20px; }
  .table th:nth-child(2), .table td:nth-child(2) { display: none; }
  .ua { max-width: 120px; }
}
@media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }
