/* Gmail / Roundcube(Elastic) 식 3단 레이아웃: 폴더 사이드바 · 목록 · 읽기 */
:root {
  --bg: #f6f8fc; --surface: #fff; --fg: #1f1f1f; --muted: #5f6368; --line: #e3e5e8; --hover: #f2f4f8;
  --primary: #0b57d0; --primary-fg: #fff; --primary-soft: #d3e3fd; --compose: #c2e7ff; --compose-fg: #001d35;
  --danger: #b3261e; --ok: #146c2e; --shadow: 0 1px 2px rgba(0,0,0,.08), 0 2px 8px rgba(0,0,0,.06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131314; --surface: #1e1f20; --fg: #e3e3e3; --muted: #9aa0a6; --line: #333537; --hover: #2a2b2d;
    --primary: #a8c7fa; --primary-fg: #062e6f; --primary-soft: #0842a0; --compose: #004a77; --compose-fg: #c2e7ff;
    --danger: #f2b8b5; --ok: #6dd58c; --shadow: 0 1px 2px rgba(0,0,0,.5), 0 4px 12px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 14px/1.5 "Google Sans", Roboto, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Segoe UI", sans-serif; }
.ico { width: 20px; height: 20px; fill: currentColor; flex: none; }
[hidden] { display: none !important; }
h2 { font-size: 18px; font-weight: 500; margin: 0; } h3 { font-size: 15px; font-weight: 500; margin: 0 0 8px; }

/* 상단 바 */
.topbar { height: 60px; display: flex; align-items: center; justify-content: space-between; padding: 0 20px 0 16px; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 20px; color: var(--muted); }
.brand .ico { width: 28px; height: 28px; color: var(--primary); }
.acct-pick { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; margin: 0; }
.acct-pick select { width: auto; margin: 0; border-radius: 20px; padding: 6px 14px; background: var(--surface); color: var(--fg); font-weight: 500; }

.shell { display: grid; grid-template-columns: 240px minmax(0, 1fr); height: calc(100vh - 60px); }
@media (max-width: 800px) { .shell { grid-template-columns: 68px minmax(0, 1fr); } .side-item { font-size: 0; gap: 0; justify-content: center; padding: 0; } .compose-btn { font-size: 0; gap: 0; justify-content: center; padding: 0; width: 48px; height: 48px; border-radius: 16px; } }

/* 사이드바 */
.sidebar { padding: 4px 12px 12px 8px; overflow-y: auto; }
.compose-btn { display: flex; align-items: center; gap: 12px; height: 56px; padding: 0 24px 0 16px; margin: 4px 0 16px; border: 0; border-radius: 16px; background: var(--compose); color: var(--compose-fg); font: 500 14px inherit; font-family: inherit; cursor: pointer; box-shadow: var(--shadow); }
.compose-btn:hover { box-shadow: 0 2px 4px rgba(0,0,0,.2), 0 4px 12px rgba(0,0,0,.12); }
.side-item { display: flex; align-items: center; gap: 16px; width: 100%; height: 36px; padding: 0 16px 0 20px; border: 0; border-radius: 0 18px 18px 0; background: none; color: var(--fg); font: inherit; cursor: pointer; text-align: left; }
.side-item:hover { background: var(--hover); }
.side-item.active { background: var(--primary-soft); font-weight: 600; }
.side-sep { height: 1px; background: var(--line); margin: 10px 16px; }

/* 본문 영역 */
.main { margin: 0 16px 16px 0; background: var(--surface); border-radius: 16px; overflow: hidden; min-width: 0; }
.tab { height: 100%; }
.pane3 { display: grid; grid-template-columns: minmax(320px, 42%) minmax(0, 1fr); }
@media (max-width: 1000px) { .pane3 { grid-template-columns: 1fr; grid-template-rows: 45% 55%; } }
.page { overflow-y: auto; padding: 0 24px 24px; }
.pane-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 8px; position: sticky; top: 0; background: var(--surface); z-index: 2; }
.page .pane-head { padding-left: 0; padding-right: 0; }

/* 메일 목록 */
.list-pane { border-right: 1px solid var(--line); overflow-y: auto; min-height: 0; }
.mail-row { display: grid; grid-template-columns: 150px minmax(0, 1fr) auto; gap: 12px; align-items: baseline; padding: 10px 16px; border-bottom: 1px solid var(--line); cursor: pointer; }
.mail-row:hover { background: var(--hover); }
.mail-row.active { background: var(--primary-soft); }
.mail-row .who { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mail-row .subj { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mail-row .when { color: var(--muted); font-size: 12px; white-space: nowrap; }
.empty { padding: 48px 24px; text-align: center; color: var(--muted); }

/* 읽기 패널 */
.read-pane { overflow-y: auto; padding: 20px 28px; min-height: 0; }
.read-empty { height: 100%; display: grid; place-items: center; color: var(--muted); }
.read-pane h2 { font-size: 22px; font-weight: 400; margin-bottom: 12px; }
.sender-line { display: flex; gap: 12px; align-items: center; margin-bottom: 4px; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 600; font-size: 16px; flex: none; }
.sender-line .name { font-weight: 600; } .sender-line .addr { color: var(--muted); font-size: 12px; }
.detail-meta { color: var(--muted); font-size: 12px; margin: 8px 0 12px 52px; white-space: pre-wrap; word-break: break-word; }
.read-actions { display: flex; gap: 8px; margin: 0 0 12px 52px; }
.read-pane iframe { width: 100%; height: 520px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }

/* 폼 요소 */
label { display: block; margin-bottom: 12px; color: var(--muted); font-size: 12px; }
input, select, textarea { display: block; width: 100%; margin-top: 4px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--fg); font: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
textarea { font-family: ui-monospace, Menlo, monospace; font-size: 12px; resize: vertical; }
button { font: inherit; border-radius: 20px; padding: 7px 18px; cursor: pointer; border: 1px solid var(--line); background: var(--surface); color: var(--primary); }
button:hover { background: var(--hover); }
button.primary { background: var(--primary); color: var(--primary-fg); border-color: var(--primary); font-weight: 500; }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--danger); } button.block { width: 100%; }
button.ghost { border: 0; background: none; color: var(--muted); } button.ghost:hover { background: var(--hover); }
button:disabled { opacity: .5; cursor: default; }
.icon-btn { display: grid; place-items: center; width: 32px; height: 32px; padding: 0; border: 0; border-radius: 50%; background: none; color: inherit; }
.row { display: flex; gap: 12px; } .row > * { flex: 1; min-width: 0; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; } .actions.left { justify-content: flex-start; margin: 0; }
.result { margin-top: 12px; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); white-space: pre-wrap; word-break: break-word; }
.result.ok { border-color: var(--ok); color: var(--ok); } .result.err { border-color: var(--danger); color: var(--danger); }
.hint { color: var(--muted); font-size: 12px; margin: 4px 0 12px; }
code { background: var(--hover); padding: 1px 6px; border-radius: 4px; font-size: 12px; }
.card { border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
table { width: 100%; border-collapse: collapse; } th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; word-break: break-word; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
.tag { display: inline-block; padding: 1px 10px; border-radius: 10px; font-size: 12px; border: 1px solid var(--line); }
.tag.ok { color: var(--ok); border-color: var(--ok); } .tag.err { color: var(--danger); border-color: var(--danger); }
.acc-form { margin-top: 12px; }

/* 양식 화면 */
.tpl-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 20px; }
@media (max-width: 900px) { .tpl-layout { grid-template-columns: 1fr; } }
.list { list-style: none; margin: 12px 0 0; padding: 0; }
.list li { padding: 8px 12px; border-radius: 12px; cursor: pointer; display: flex; flex-direction: column; }
.list li small { color: var(--muted); } .list li:hover { background: var(--hover); } .list li.active { background: var(--primary-soft); }

/* 에디터 (GrapesJS 래퍼) */
.html-editor { margin-bottom: 12px; }
.mode-switch { display: flex; gap: 6px; margin-bottom: 10px; }
.mode-switch button { color: var(--fg); } .mode-switch button.active { background: var(--primary-soft); border-color: transparent; font-weight: 600; }
.editor-box textarea { margin: 0; } .editor-box iframe { width: 100%; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.gjs-host { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }

/* 편지쓰기 창 */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: grid; place-items: center; z-index: 50; padding: 16px; }
.compose-window { width: min(1100px, 100%); max-height: 100%; display: flex; flex-direction: column; background: var(--surface); border-radius: 16px; box-shadow: 0 8px 32px rgba(0,0,0,.3); overflow: hidden; }
.cw-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px 10px 20px; background: var(--hover); font-weight: 500; }
.cw-body { padding: 4px 20px 8px; overflow-y: auto; }
.cw-foot { display: flex; align-items: center; gap: 16px; padding: 12px 20px; border-top: 1px solid var(--line); }
.send-btn { padding: 9px 28px; }
.field { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); }
.field > span { width: 64px; color: var(--muted); font-size: 12px; flex: none; }
.field input { border: 0; border-radius: 0; margin: 0; padding: 10px 4px; background: none; }
.field input:focus { outline: 0; }
.inline-opts { display: flex; gap: 16px; padding: 6px 0; flex: 1; } .inline-opts label { margin: 0; display: flex; align-items: center; gap: 8px; }
.inline-opts select { width: auto; margin: 0; padding: 4px 10px; }
#c-editor { margin-top: 12px; }
.vars-box { margin-bottom: 8px; color: var(--muted); } .vars-box summary { cursor: pointer; padding: 4px 0; }

.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: #303030; color: #fff; padding: 12px 20px; border-radius: 8px; z-index: 100; box-shadow: var(--shadow); }

/* 읽기 창 위치: 우측(기본) / 하단 / 없음 — Gmail 의 reading pane 설정과 같은 방식 */
.topbar-right { display: flex; align-items: center; gap: 16px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 20px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; border-radius: 0; padding: 5px 14px; color: var(--muted); font-size: 12px; }
.seg button.active { background: var(--primary-soft); color: var(--fg); font-weight: 600; }
.layout-below .pane3 { grid-template-columns: 1fr; grid-template-rows: minmax(160px, 38%) minmax(0, 1fr); }
.layout-below .list-pane { border-right: 0; border-bottom: 1px solid var(--line); }
.layout-none .pane3 { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.layout-none .read-pane { display: none; }
.layout-none .pane3.reading .list-pane { display: none; }
.layout-none .pane3.reading .read-pane { display: block; }
.back-btn { display: none; margin: 0 0 8px -8px; }
.layout-none .back-btn { display: inline-block; }
.kv { display: grid; grid-template-columns: 84px minmax(0, 1fr); gap: 2px 12px; margin: 8px 0 12px 52px; font-size: 12px; color: var(--muted); }
.kv dt { color: var(--muted); } .kv dd { margin: 0; color: var(--fg); word-break: break-all; }
.kv dd.err { color: var(--danger); }
.mail-row .tag { margin-right: 6px; padding: 0 8px; }
.read-pane .tag { margin-left: 6px; vertical-align: 1px; }

/* GrapesJS 오른쪽 패널은 폭의 15% 고정이라 좁은 화면에서 버튼이 잘린다 → 최소 폭 보장 */
.html-editor .gjs-pn-views, .html-editor .gjs-pn-views-container { width: max(15%, 150px); }
.html-editor .gjs-cv-canvas { width: calc(100% - max(15%, 150px)); }
.tpl-main { min-width: 0; }
.html-editor .gjs-pn-options { right: max(15%, 150px); }

/* 작성(리치텍스트) 에디터: 받는 사람이 보게 될 흰 종이 위에서 쓴다 */
.rte-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; padding: 6px 8px; border: 1px solid var(--line); border-bottom: 0; border-radius: 8px 8px 0 0; background: var(--hover); }
.rte-toolbar button, .rte-toolbar select, .rte-toolbar .rte-color { height: 30px; min-width: 30px; padding: 0 9px; margin: 0; border: 0; border-radius: 6px; background: none; color: var(--fg); font-size: 13px; line-height: 30px; cursor: pointer; width: auto; display: inline-block; }
.rte-toolbar button:hover, .rte-toolbar select:hover, .rte-toolbar .rte-color:hover { background: var(--line); }
.rte-toolbar select { padding: 0 6px; border: 0; background: transparent; }
.rte-sep { width: 1px; height: 18px; background: var(--line); margin: 0 6px; }
.rte-color { position: relative; font-weight: 700; text-align: center; overflow: hidden; }
.rte-color.hl { color: #f9ab00; }
.rte-color input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; margin: 0; padding: 0; border: 0; }
.rte { background: #fff; color: #1f1f1f; border: 1px solid var(--line); border-radius: 0 0 8px 8px; padding: 16px 18px; overflow: auto; outline: 0;
  font: 16px/1.5 -apple-system, "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", Roboto, sans-serif; }
.rte:focus { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.rte.is-empty::before { content: attr(data-placeholder); color: #9aa0a6; pointer-events: none; position: absolute; }
.rte a { color: #0b57d0; } .rte img { max-width: 100%; }
.rte blockquote { margin: 8px 0 8px 4px; padding-left: 12px; border-left: 3px solid #c4c7c5; color: #5f6368; }
.rte hr { border: 0; border-top: 1px solid #dadce0; margin: 12px 0; }

/* TipTap(ProseMirror) 본문 */
.rte { position: relative; padding: 0; }
.rte .ProseMirror { min-height: 100%; padding: 16px 18px; outline: 0; }
.rte .ProseMirror p { margin: 0; }
.rte .ProseMirror ul, .rte .ProseMirror ol { margin: 4px 0; padding-left: 24px; }
.rte .ProseMirror li > p { margin: 0; }
.rte .ProseMirror mark { color: inherit; border-radius: 2px; }
.rte .ProseMirror img.ProseMirror-selectednode { outline: 2px solid var(--primary); }
.rte.is-empty::before { top: 16px; left: 18px; }
.rte-toolbar button.on { background: var(--primary-soft); color: var(--fg); }
