/* D7: 빌드 단계가 없는 순수 CSS. 외부 글꼴과 외부 요청이 없고 시스템 글꼴만 사용합니다. */
:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --line: #d9dde3;
  --text: #1c2430;
  --muted: #5d6877;
  --accent: #2f5fd0;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --unread: #1c2430;
  --ok: #1b7a43;
  --radius: 6px;
  --font: "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --panel: #1c2027;
    --panel-2: #242a33;
    --line: #333a45;
    --text: #e6e9ee;
    --muted: #9aa5b4;
    --accent: #6e93f0;
    --accent-text: #0e1522;
    --danger: #f2877f;
    --unread: #ffffff;
    --ok: #62c88a;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

button {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 12px;
  cursor: pointer;
}
button:hover { background: var(--panel-2); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
a.btnlink {
  display: inline-block; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 6px 12px; color: var(--text); text-decoration: none;
}
a.btnlink:hover { background: var(--panel-2); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--danger); }
button:disabled { opacity: 0.55; cursor: default; }

input[type="text"], input[type="password"], input[type="search"], input[type="email"], select, textarea {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 7px 10px;
}
textarea { resize: vertical; min-height: 220px; }

.center-card {
  max-width: 420px;
  margin: 8vh auto;
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.center-card h1 { margin: 0 0 6px; font-size: 20px; }
.center-card p.lead { margin: 0 0 18px; color: var(--muted); }
.field { margin-bottom: 14px; }
.field label { display: block; margin-bottom: 4px; font-weight: 600; font-size: 13px; }
.hint { color: var(--muted); font-size: 12px; margin-top: 3px; }
.error { color: var(--danger); margin: 8px 0; min-height: 1.4em; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* 메인 레이아웃 */
.shell { display: grid; grid-template-rows: auto 1fr; height: 100vh; height: 100dvh; }
.topbar {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.topbar .brand { font-weight: 700; margin-right: 6px; }
.topbar select { width: auto; max-width: 340px; }
.topbar .search { flex: 1 1 200px; max-width: 420px; }
.topbar .spacer { flex: 1; }
.topbar .who { color: var(--muted); font-size: 13px; }

.body { display: grid; grid-template-columns: 190px minmax(280px, 400px) 1fr; min-height: 0; }
.side { padding: 12px; background: var(--panel); border-right: 1px solid var(--line); overflow: auto; }
.side .compose-btn { width: 100%; margin-bottom: 12px; padding: 9px; }
.folder {
  display: flex; justify-content: space-between; width: 100%;
  border: 0; background: transparent; text-align: left; padding: 7px 10px; border-radius: var(--radius);
}
.folder.active { background: var(--panel-2); font-weight: 700; }
.folder .count { color: var(--accent); font-weight: 700; }

.list { border-right: 1px solid var(--line); overflow: auto; background: var(--panel); min-height: 0; }
.item {
  display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line);
  border-radius: 0; background: transparent; padding: 10px 14px;
}
.item:hover { background: var(--panel-2); }
.item.selected { background: var(--panel-2); box-shadow: inset 3px 0 0 var(--accent); }
.item .l1 { display: flex; justify-content: space-between; gap: 8px; }
.item .from { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .date { color: var(--muted); font-size: 12px; white-space: nowrap; }
.item .subj { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .snip { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item.unread .from, .item.unread .subj { font-weight: 700; color: var(--unread); }
.item.unread .from::before { content: "\25CF\00a0"; color: var(--accent); }
.empty { padding: 28px 16px; color: var(--muted); text-align: center; }
.pager { display: flex; justify-content: space-between; padding: 10px 14px; }

.view { overflow: auto; padding: 16px 20px; min-height: 0; }
.view h2 { margin: 0 0 8px; font-size: 18px; word-break: break-word; }
.meta { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.meta div { word-break: break-word; }
.meta b { color: var(--text); font-weight: 600; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0 14px; }
.notice { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; margin-bottom: 12px; }
.frame {
  width: 100%; min-height: 55vh; border: 1px solid var(--line); border-radius: var(--radius); background: #ffffff;
}
pre.text { white-space: pre-wrap; word-break: break-word; font-family: var(--font); margin: 0; padding: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.atts { margin-top: 14px; }
.atts ul { list-style: none; padding: 0; margin: 6px 0 0; }
.atts li { padding: 4px 0; }
.back { display: none; }

/* 쓰기 창 */
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); display: flex; align-items: flex-start; justify-content: center; padding: 3vh 12px; overflow: auto; z-index: 10; }
.dialog { width: 100%; max-width: 760px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 18px; }
.dialog h2 { margin: 0 0 12px; font-size: 17px; }

/* 관리 화면 */
.page { max-width: 1000px; margin: 0 auto; padding: 18px 14px 40px; }
.page h1 { font-size: 20px; margin: 0 0 4px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin: 14px 0; }
.card h2 { margin: 0 0 10px; font-size: 16px; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.tablewrap { overflow-x: auto; }
.linkbox { margin-top: 10px; padding: 10px; background: var(--panel-2); border-radius: var(--radius); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 10px; background: var(--panel-2); font-size: 12px; border: 1px solid var(--line); }
.tag.ok { color: var(--ok); }
.tag.off { color: var(--danger); }

#toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 8px;
  opacity: 0; pointer-events: none; transition: opacity 0.2s; max-width: 90vw; z-index: 20;
}
#toast.show { opacity: 1; }

/* 좁은 화면: 한 번에 한 칸만 보여 줍니다 */
@media (max-width: 860px) {
  .body { grid-template-columns: 1fr; }
  .side { display: flex; gap: 6px; flex-wrap: wrap; border-right: 0; border-bottom: 1px solid var(--line); padding: 8px 12px; }
  .side .compose-btn { width: auto; margin: 0; }
  .folder { width: auto; gap: 8px; }
  .list, .view { border-right: 0; }
  .shell:not(.view-open) .view { display: none; }
  .shell.view-open .list, .shell.view-open .side { display: none; }
  .back { display: inline-block; }
  .topbar .search { flex-basis: 100%; max-width: none; order: 5; }
}
