/* NeoMail 웹메일. 360px 휴대폰부터 PC 까지. 흰 바탕 + 파란 버튼 (다크 모드 없음). */
:root {
  color-scheme: light;
  font-family: system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  --bg: #fff; --panel: #fff; --text: #1d2228; --muted: #69727d; --line: #e1e4e8; --hover: #eef2f7;
  --accent: #2563eb; --accent-text: #fff; --accent-soft: #e3ecfd; --danger: #c62828; --warn: #b26a00;
  --ok: #2e7d32; --unread: #0f172a; --selected: #dbe7ff; --shadow: 0 1px 3px rgba(0, 0, 0, .08);
  --radius: 8px; --side: 240px; --top: 56px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45; -webkit-text-size-adjust: 100%; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; min-width: 0; max-width: 100%;
  min-height: 38px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=checkbox], input[type=radio] { min-height: 0; padding: 0; box-shadow: none; }
.editor:focus { outline: none; }
textarea { width: 100%; resize: vertical; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; }
code.wrap { word-break: break-all; white-space: pre-wrap; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.center { min-height: 100vh; display: grid; place-content: center; text-align: center; padding: 1rem; }
.loading p { color: var(--muted); }
.empty { color: var(--muted); padding: 2rem 1rem; text-align: center; }
.error { color: var(--danger); }

/* 버튼 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .3em; min-height: 36px; padding: 6px 12px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--text); cursor: pointer;
  text-decoration: none; white-space: nowrap; font-size: .95em;
}
.btn:hover { background: var(--hover); }
.btn:disabled { opacity: .5; cursor: default; }
.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.small { min-height: 30px; padding: 3px 9px; font-size: .85em; }
.btn.wide { width: 100%; }
.icon-btn { background: none; border: 0; cursor: pointer; padding: 6px 8px; border-radius: 6px; font-size: 1.05em; color: inherit; min-width: 36px; min-height: 36px; }
.icon-btn:hover { background: var(--hover); }

/* 로그인 */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 1rem;
  background: #03142a url(/static/login-bg.svg) center / cover no-repeat; }
.login-form { width: 100%; max-width: 360px; background: var(--panel); padding: 28px 24px; border-radius: 12px; box-shadow: 0 12px 40px rgba(0, 0, 0, .35); }
.login-form h1 { margin: 0; font-size: 1.6em; }
.login-form .muted { margin: 4px 0 18px; }
.form-error { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); padding: 8px 10px; border-radius: 6px; }

/* 폼 */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-size: .92em; }
.field input, .field select, .field textarea { font-size: 1rem; width: 100%; }
.card .field > input:not([type=checkbox]), .card .field > select { max-width: 420px; }
.card .field > textarea { max-width: 640px; }
.card .two { max-width: 640px; }
.card .two .field > input { max-width: none; }
.field.end { justify-content: flex-end; }
.check { display: flex; align-items: center; gap: 8px; margin: 8px 0 14px; cursor: pointer; }
.check.small { margin: 0; font-size: .9em; white-space: nowrap; }
.check input { width: 18px; height: 18px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 0 0 14px; }
.inline-form input { flex: 1 1 160px; }
.addr-split { display: flex; gap: 6px; align-items: center; width: 100%; }
.addr-split > input { flex: 1 1 0; width: auto; min-width: 7em; }
.addr-split > select { flex: 1 1 0; width: auto; min-width: 7em; }
.addr-split > span { flex: none; color: var(--muted); }

/* 머리 줄 */
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--top); display: flex; align-items: center; gap: 10px; padding: 0 12px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 1.15em; color: var(--text); text-decoration: none; width: calc(var(--side) - 60px); }
.brand { display: flex; align-items: center; width: auto; min-width: calc(var(--side) - 60px); max-width: 380px; flex-shrink: 0; }
.brand-wrap { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.brand-logo { height: 30px; width: auto; max-width: 140px; object-fit: contain; display: block; }
.brand-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.login-brand .brand-wrap { flex-direction: column; align-items: flex-start; gap: 10px; }
.login-brand .brand-logo { height: 48px; max-width: 220px; }
/* 관리자: 로고 미리보기 */
.logo-preview { display: flex; align-items: center; justify-content: center; width: 260px; max-width: 100%; height: 110px;
  border: 1px dashed var(--line); border-radius: var(--radius); background: #fafbfc; margin: 6px 0 12px; }
.logo-preview img { max-height: 80px; max-width: 220px; object-fit: contain; }
.setting-note { font-size: .82em; color: var(--muted); margin-top: 3px; }
.setting-note .tag { display: inline-block; background: var(--accent-soft); color: var(--accent); border-radius: 4px; padding: 0 6px; margin-right: 4px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: .92em; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }
.top-search { flex: 1; max-width: 640px; }
.top-search input { width: 100%; border-radius: 20px; padding: 8px 14px; background: var(--bg); }
.who { color: var(--muted); font-size: .9em; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-btn { display: none; }

/* 몸통 */
.shell { display: flex; min-height: calc(100vh - var(--top)); }
.sidebar {
  width: var(--side); flex: none; padding: 12px 8px; border-right: 1px solid var(--line); background: var(--panel);
  position: sticky; top: var(--top); height: calc(100vh - var(--top)); overflow-y: auto;
}
.compose-btn { margin-bottom: 12px; min-height: 42px; }
.mailbox-nav { list-style: none; margin: 0; padding: 0; }
.mailbox-nav.secondary { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.nav-link {
  display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 7px 10px; border-radius: 6px;
  color: var(--text); text-decoration: none; min-height: 36px;
}
.nav-link:hover { background: var(--hover); }
.nav-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.mb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.depth-1 .nav-link { padding-left: 24px; } .depth-2 .nav-link { padding-left: 38px; }
.depth-3 .nav-link, .depth-4 .nav-link { padding-left: 52px; }
.badge { background: var(--accent); color: var(--accent-text); border-radius: 10px; padding: 0 7px; font-size: .78em; font-weight: 700; }
.count { color: var(--muted); font-size: .85em; }
.quota { margin-top: 16px; padding: 0 10px; }
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin: 4px 0; }
.bar span { display: block; height: 100%; background: var(--accent); }
.bar.big { height: 10px; margin: 0 0 18px; }
.bar span.warn { background: var(--danger); }
.scrim { display: none; }
.content { flex: 1; min-width: 0; padding: 14px 18px 40px; outline: none; }
.view-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.view-head h2 { margin: 0; font-size: 1.3em; }

/* 도구 줄 */
.toolbar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 10px; }
.toolbar .spacer { flex: 1; }
.check-all { display: inline-flex; align-items: center; padding: 0 6px; }
.check-all input { width: 18px; height: 18px; }
.move-select { min-height: 36px; }

/* 메일 목록 */
.msg-list { list-style: none; margin: 0; padding: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.msg-row {
  display: grid; grid-template-columns: 30px 30px minmax(120px, 200px) 1fr auto; align-items: center; gap: 6px;
  padding: 6px 10px; border-bottom: 1px solid var(--line); cursor: pointer; min-height: 44px;
}
.msg-row:last-child { border-bottom: 0; }
.msg-row:hover { background: var(--hover); }
.msg-row.selected { background: var(--selected); }
.msg-row.unread .col-from, .msg-row.unread .subj { font-weight: 700; color: var(--unread); }
.msg-row input[type=checkbox] { width: 18px; height: 18px; }
.col-from, .col-subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col-subject .preview { color: var(--muted); }
.col-meta { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: .85em; white-space: nowrap; }
.col-meta .size { min-width: 56px; text-align: right; }
.star { background: none; border: 0; cursor: pointer; color: var(--muted); font-size: 1.1em; padding: 4px; }
.star.on { color: #e0a800; }
.tag { background: var(--accent-soft); color: var(--accent); border-radius: 4px; padding: 0 6px; margin-right: 6px; font-size: .8em; }
.mark { color: var(--muted); margin-right: 4px; }
.pager { display: flex; gap: 10px; align-items: center; justify-content: center; margin-top: 12px; }

/* 읽기 */
.read-view { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.read-subject { margin: 6px 0 10px; font-size: 1.35em; overflow-wrap: anywhere; }
.read-head { border-bottom: 1px solid var(--line); padding-bottom: 10px; margin-bottom: 10px; font-size: .93em; }
.addr-line { display: flex; gap: 10px; padding: 2px 0; overflow-wrap: anywhere; }
.addr-line .label { color: var(--muted); flex: none; width: 72px; }
.mail-frame { width: 100%; min-height: 200px; border: 0; background: #fff; border-radius: 4px; display: block; }
.plain { white-space: pre-wrap; overflow-wrap: anywhere; font-family: inherit; margin: 0; }
.notice { background: var(--accent-soft); padding: 8px 12px; border-radius: 6px; margin-bottom: 10px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.notice.warn { background: color-mix(in srgb, var(--warn) 15%, transparent); }
.attachments { margin-bottom: 12px; }
.attachments h3 { font-size: .95em; margin: 0 0 6px; }
.attachments ul { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.attachments li { border: 1px solid var(--line); border-radius: 6px; padding: 5px 9px; }
.att { text-decoration: none; overflow-wrap: anywhere; }
details.more { position: relative; }
details.more summary { list-style: none; }
details.more summary::-webkit-details-marker { display: none; }
details.more .menu {
  position: absolute; right: 0; top: 40px; z-index: 10; background: var(--panel); border: 1px solid var(--line);
  border-radius: 6px; box-shadow: var(--shadow); display: flex; flex-direction: column; min-width: 180px;
}
details.more .menu a, details.more .menu button { padding: 9px 12px; text-align: left; background: none; border: 0; color: var(--text); text-decoration: none; cursor: pointer; }
details.more .menu a:hover, details.more .menu button:hover { background: var(--hover); }

/* 쓰기 */
.compose { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.compose-fields .row { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); padding: 4px 0; }
.compose-fields .row > span { width: 86px; flex: none; color: var(--muted); font-size: .9em; }
.compose-fields input, .compose-fields select { border: 0; width: 100%; padding: 8px 4px; background: transparent; box-shadow: none !important; }
.compose-fields .row:focus-within { border-bottom-color: var(--accent); }
.compose { max-width: 1000px; }
.addr-input { position: relative; flex: 1; min-width: 0; }
.suggest {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 20; list-style: none; margin: 0; padding: 4px 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px; box-shadow: var(--shadow); max-height: 260px; overflow: auto;
}
.suggest li { padding: 7px 10px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggest li.active, .suggest li:hover { background: var(--hover); }
.editor-tools { display: flex; flex-wrap: wrap; gap: 2px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.editor-tools button { background: none; border: 1px solid transparent; border-radius: 4px; min-width: 34px; min-height: 34px; cursor: pointer; }
.editor-tools button:hover { background: var(--hover); border-color: var(--line); }
.editor { min-height: 260px; padding: 10px 4px; overflow-wrap: anywhere; overflow-x: auto; }
.editor blockquote { margin: 0 0 0 .4em; padding-left: .8em; border-left: 3px solid var(--line); color: var(--muted); }
.editor img { max-width: 100%; }
.quote-head { color: var(--muted); margin-top: 8px; }
.signature { color: var(--muted); }
.dropzone { border: 2px dashed var(--line); border-radius: 8px; padding: 12px; text-align: center; color: var(--muted); margin: 8px 0; }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.att-list { list-style: none; padding: 0; margin: 0 0 8px; display: flex; flex-direction: column; gap: 4px; }
.att-list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; border: 1px solid var(--line); border-radius: 6px; padding: 2px 4px 2px 10px; overflow-wrap: anywhere; }
.att-list li.uploading { color: var(--muted); }
.compose-actions { margin: 10px 0 0; }

/* 검색 */
.search-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 14px; }
.search-view .msg-list { margin-bottom: 10px; }

/* 목록형 화면 */
.plain-list { list-style: none; padding: 0; margin: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.plain-list > li { padding: 10px 12px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.plain-list > li:last-child { border-bottom: 0; }
.mb-row .mb-name { flex: 1; min-width: 140px; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.contact-row .c-name { font-weight: 600; min-width: 100px; }
.contact-row .c-email { flex: 1; min-width: 160px; overflow-wrap: anywhere; }

/* 설정 카드 */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 20px; margin-bottom: 14px; max-width: 760px; }
.card h3 { margin: 0 0 12px; font-size: 1.05em; }
.filter-row { display: grid; grid-template-columns: 120px 90px 1fr 180px 36px; gap: 6px; margin-bottom: 6px; align-items: center; }
.steps { padding-left: 1.2em; }
.steps li { margin-bottom: 10px; }
.secret code { display: inline-block; font-size: 1.15em; letter-spacing: .05em; padding: 6px 10px; background: var(--bg); border-radius: 6px; margin-top: 6px; word-break: break-all; }
textarea.uri { font-family: ui-monospace, Menlo, monospace; font-size: .85em; margin-top: 6px; }

/* 관리자 */
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tab { padding: 8px 12px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.inline-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0 12px; max-width: none; }
.inline-grid h3, .inline-grid .form-actions, .inline-grid .check { grid-column: 1 / -1; }
.inline-grid .field:has(.addr-split) { grid-column: span 2; }
.inline-grid .field > input, .inline-grid .field > select { max-width: none; }
@media (max-width: 760px) { .inline-grid .field:has(.addr-split) { grid-column: 1 / -1; } }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.stat-label { color: var(--muted); font-size: .85em; }
.stat-value { font-size: 1.25em; font-weight: 700; margin-top: 2px; }
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; }
table.grid { width: 100%; border-collapse: collapse; font-size: .9em; }
table.grid th, table.grid td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.grid th { color: var(--muted); font-weight: 600; white-space: nowrap; }
table.grid tr:last-child td { border-bottom: 0; }
.target-list { list-style: none; padding: 0; margin: 0; }
.target-list li { padding: 2px 0; overflow-wrap: anywhere; }
.pill { display: inline-block; font-size: .78em; padding: 1px 8px; border-radius: 10px; background: var(--hover); margin: 0 4px 2px 0; white-space: nowrap; }
.pill.ok, .pill.delivered, .pill.sent, .pill.active { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.pill.fail, .pill.failed, .pill.rejected, .pill.deleted, .pill.locked, .pill.bounced { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.pill.warn, .pill.deferred, .pill.junk, .pill.inactive { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.pill.admin, .pill.totp, .pill.queued, .pill.sending { background: var(--accent-soft); color: var(--accent); }
.bar-cell { display: flex; align-items: center; gap: 6px; min-width: 120px; }
.mini-bar { display: inline-block; height: 8px; border-radius: 4px; min-width: 2px; max-width: 120px; flex: none; }
.mini-bar.in { background: var(--accent); } .mini-bar.out { background: var(--ok); }
.apidocs { max-width: 1100px; margin: 0 auto; padding: 20px; }
.apidocs table { width: 100%; border-collapse: collapse; }
.apidocs td, .apidocs th { border-bottom: 1px solid var(--line); padding: 6px; text-align: left; }

/* 알림 */
.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px); }
.toast { background: #222b36; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: 0 4px 12px rgba(0, 0, 0, .25); }
.toast.error { background: var(--danger); }

/* 태블릿·휴대폰 */
@media (max-width: 900px) {
  .msg-row { grid-template-columns: 28px 28px 1fr auto; }
  .msg-row .col-subject { grid-column: 3 / 5; grid-row: 2; }
  .msg-row .col-meta .size { display: none; }
  .filter-row { grid-template-columns: 1fr 1fr; }
  .filter-row input { grid-column: 1 / -1; }
}
@media (max-width: 760px) {
  :root { --top: 52px; }
  .menu-btn { display: inline-block; }
  .brand { width: auto; }
  .who { display: none; }
  .sidebar {
    position: fixed; left: 0; top: var(--top); bottom: 0; height: auto; z-index: 40; width: min(82vw, 290px);
    transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow);
  }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: var(--top) 0 0 0; background: rgba(0, 0, 0, .35); z-index: 35; }
  .content { padding: 10px 8px 60px; }
  .read-view { padding: 10px; }
  .compose { padding: 8px; }
  .compose-fields .row > span { width: 64px; font-size: .85em; }
  .two { grid-template-columns: 1fr; }
  .addr-line .label { width: 60px; }
  .card { padding: 12px; }
  .toolbar .btn { padding: 6px 9px; }
  .toolbar .check.small { order: 10; }
  /* 관리자 표: 좁은 화면에서는 칸마다 줄로 */
  table.grid thead { display: none; }
  table.grid, table.grid tbody, table.grid tr, table.grid td { display: block; width: 100%; }
  table.grid tr { border-bottom: 1px solid var(--line); padding: 6px 0; }
  table.grid td { border: 0; padding: 3px 10px; }
  table.grid td[data-label]::before { content: attr(data-label); display: block; color: var(--muted); font-size: .8em; }
}
@media print {
  .topbar, .sidebar, .toolbar, .toasts { display: none !important; }
  .content { padding: 0; }
}
