:root {
  --bg: #f3f5f9;
  --card: #fff;
  --line: #e5e9f0;
  --line-soft: #eef1f6;
  --ink: #1a2233;
  --muted: #707b8c;
  --muted-soft: #99a2b3;
  --brand: #4f56e8;
  --brand-d: #3d43c9;
  --brand-soft: #eef0fd;
  --ok-bg: #e6f7ee;
  --ok-ink: #16794a;
  --err-bg: #fdecec;
  --err-ink: #c0392b;
  --shadow-sm: 0 1px 2px rgba(20, 26, 43, 0.05);
  --shadow-md: 0 8px 24px -8px rgba(20, 26, 43, 0.14);
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.6 "Pretendard", system-ui, -apple-system, "Segoe UI", "Apple SD Gothic Neo",
        "Malgun Gothic", sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* 상단바 */
.topbar {
  display: flex; align-items: center; gap: 20px;
  background: rgba(255, 255, 255, 0.85); backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--line);
  padding: 12px 24px; position: sticky; top: 0; z-index: 5;
}
.brand {
  font-weight: 800; font-size: 16px; color: var(--ink);
  display: flex; align-items: center; gap: 8px; letter-spacing: -0.2px;
}
.topbar nav { display: flex; gap: 4px; align-items: center; }
.topbar nav > a {
  color: var(--muted); font-weight: 600; font-size: 13.5px;
  padding: 8px 12px; border-radius: 8px; transition: background .15s, color .15s;
}
.topbar nav > a:hover { background: var(--line-soft); color: var(--ink); text-decoration: none; }
.topbar .user {
  margin-left: auto; color: var(--muted-soft); font-size: 13px;
  display: flex; align-items: center; gap: 14px;
}
.topbar .user a { color: var(--muted); font-weight: 500; }
.topbar .user a:hover { color: var(--brand); text-decoration: none; }

.btn-compose {
  background: var(--brand); color: #fff !important; padding: 8px 16px;
  border-radius: 9px; font-weight: 600; font-size: 13.5px;
  box-shadow: var(--shadow-sm); transition: background .15s, transform .1s, box-shadow .15s;
}
.btn-compose:hover {
  background: var(--brand-d); text-decoration: none;
  box-shadow: 0 6px 16px -4px rgba(79, 86, 232, 0.45); transform: translateY(-1px);
}

.container { max-width: 980px; margin: 28px auto; padding: 0 16px; }

.alert {
  padding: 12px 16px; border-radius: 10px; margin-bottom: 18px;
  font-size: 13.5px; font-weight: 500;
}
.alert.ok { background: var(--ok-bg); color: var(--ok-ink); }
.alert.error { background: var(--err-bg); color: var(--err-ink); }

/* 로그인 */
.login-shell {
  min-height: calc(100vh - 60px);
  display: flex; align-items: center; justify-content: center;
  padding: 32px 16px;
}
.login-box {
  width: 100%; max-width: 380px; background: var(--card);
  border: 1px solid var(--line-soft); border-radius: 18px;
  padding: 36px 32px 30px; box-shadow: var(--shadow-md);
}
.login-box-wide { max-width: 440px; }
.login-badge {
  width: 48px; height: 48px; border-radius: 13px;
  background: linear-gradient(140deg, var(--brand), #7b7ff2);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; margin: 0 auto 18px; box-shadow: 0 8px 20px -6px rgba(79, 86, 232, 0.55);
}
.login-box h1 {
  margin: 0 0 4px; font-size: 20px; text-align: center; letter-spacing: -0.3px;
}
.login-sub {
  margin: 0 0 24px; text-align: center; color: var(--muted); font-size: 13px;
}
.login-box label, .compose label {
  display: block; margin-bottom: 16px; font-size: 13px; font-weight: 600; color: var(--muted);
}
.login-box input, .compose input, .compose textarea {
  width: 100%; margin-top: 6px; padding: 11px 13px; font-size: 14.5px;
  border: 1.5px solid var(--line); border-radius: 10px; color: var(--ink);
  background: #fbfcfe; transition: border-color .15s, box-shadow .15s, background .15s;
  font-family: inherit;
}
.login-box input:focus, .compose input:focus, .compose textarea:focus {
  outline: none; border-color: var(--brand); background: #fff;
  box-shadow: 0 0 0 3.5px var(--brand-soft);
}
.login-row {
  display: flex; align-items: center; justify-content: space-between;
  margin: -4px 0 20px; font-size: 13px;
}
.checkline {
  display: flex; align-items: center; gap: 7px; color: var(--muted); cursor: pointer;
  font-weight: 500; user-select: none;
}
.checkline input[type="checkbox"] {
  width: 15px; height: 15px; accent-color: var(--brand); cursor: pointer;
}
.login-box button, .compose button { width: 100%; padding: 12px; font-size: 14.5px; }
.login-box button { margin-top: 4px; }

button {
  background: var(--brand); color: #fff; border: 0; border-radius: 10px;
  padding: 10px 18px; font-size: 15px; font-weight: 600; cursor: pointer;
  transition: background .15s, transform .1s;
}
button:hover { background: var(--brand-d); }
button:active { transform: translateY(1px); }
.hint { color: var(--muted-soft); font-size: 12px; margin-top: 16px; text-align: center; }

/* 목록 */
.listhead { display: flex; align-items: baseline; gap: 12px; margin-bottom: 14px; }
.listhead h1 { font-size: 19px; margin: 0; letter-spacing: -0.2px; }
.count { color: var(--muted-soft); font-size: 13px; }
.maillist {
  width: 100%; border-collapse: collapse; background: var(--card);
  border: 1px solid var(--line-soft); border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.maillist td { padding: 13px 16px; border-bottom: 1px solid var(--line-soft); font-size: 14px; }
.maillist tr:last-child td { border-bottom: 0; }
.maillist tr:hover { background: #f8f9fd; }
.c-from {
  width: 220px; color: var(--muted); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 220px;
}
.c-subj a { color: var(--ink); }
.c-date {
  width: 130px; text-align: right; color: var(--muted-soft); font-size: 12.5px;
  white-space: nowrap;
}
.maillist tr.unseen { position: relative; }
.maillist tr.unseen .c-from, .maillist tr.unseen .c-subj a { font-weight: 700; color: var(--ink); }
.maillist tr.unseen .c-subj a::before {
  content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--brand); margin-right: 9px; vertical-align: middle;
}
.maillist tr:not(.unseen) .c-subj a::before {
  content: ""; display: inline-block; width: 7px; margin-right: 9px;
}
.empty {
  color: var(--muted-soft); padding: 48px 20px; text-align: center; background: var(--card);
  border: 1px solid var(--line-soft); border-radius: var(--radius); font-size: 14px;
}

/* 보기 */
.mailview {
  background: var(--card); border: 1px solid var(--line-soft);
  border-radius: var(--radius); padding: 26px 28px; box-shadow: var(--shadow-sm);
}
.mv-actions { display: flex; gap: 10px; margin-bottom: 16px; }
.mv-actions a:first-child { color: var(--muted); font-weight: 600; align-self: center; }
.btn {
  background: var(--brand-soft); color: var(--brand); padding: 6px 14px;
  border-radius: 8px; font-weight: 600; font-size: 13px; transition: background .15s;
}
.btn:hover { background: #e0e3fb; text-decoration: none; }
.mailview h1 { font-size: 19px; margin: 6px 0 16px; letter-spacing: -0.2px; }
.mv-meta {
  font-size: 13px; color: var(--muted); display: grid; gap: 5px;
  background: #fafbfd; border: 1px solid var(--line-soft); border-radius: 10px;
  padding: 12px 14px;
}
.mv-meta b { color: var(--ink); display: inline-block; width: 70px; font-weight: 600; }
.mailview hr { border: none; border-top: 1px solid var(--line-soft); margin: 18px 0; }
.mv-body {
  white-space: pre-wrap; word-break: break-word; font: inherit;
  margin: 0; color: var(--ink);
}

/* 작성 */
.compose {
  background: var(--card); border: 1px solid var(--line-soft);
  border-radius: var(--radius); padding: 26px 28px; box-shadow: var(--shadow-sm);
}
.compose button { width: auto; }
.compose textarea { resize: vertical; font: inherit; }
.form-actions { display: flex; align-items: center; gap: 16px; }
.from-note { color: var(--muted-soft); font-size: 13px; }

/* 회원가입 */
.btn-signup {
  display: block; text-align: center; margin-top: 12px; padding: 11px;
  border-radius: 10px; background: var(--brand-soft); color: var(--brand) !important;
  font-weight: 600; font-size: 14px; transition: background .15s;
}
.btn-signup:hover { background: #e0e3fb; text-decoration: none; }
.id-check-row { display: flex; gap: 8px; margin-top: 6px; }
.id-check-row input { margin-top: 0; flex: 1; }
.id-check-row button {
  flex-shrink: 0; width: auto; padding: 0 14px; font-size: 13px;
  background: var(--ink); white-space: nowrap;
}
.id-check-row button:hover { background: #333c4d; }
.id-check-msg { display: block; margin-top: 6px; font-size: 12.5px; font-weight: 600; }
.id-check-msg.ok { color: var(--ok-ink); }
.id-check-msg.err { color: var(--err-ink); }

/* 관리자 페이지 */
.admin-section-gap { margin-top: 36px; }
.admintable {
  width: 100%; border-collapse: collapse; background: var(--card);
  border: 1px solid var(--line-soft); border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow-sm); font-size: 13.5px;
}
.admintable th, .admintable td {
  padding: 11px 14px; border-bottom: 1px solid var(--line-soft); text-align: left;
  vertical-align: middle;
}
.admintable th {
  background: #fafbfd; color: var(--muted); font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .3px;
}
.admintable tr:last-child td { border-bottom: 0; }
.admintable tr:hover td { background: #f8f9fd; }
.c-actions { white-space: nowrap; }
.inline-form { display: inline-block; margin-right: 6px; }
.admintable .btn { font-size: 12.5px; padding: 5px 11px; }
.btn-ok { background: var(--ok-bg); color: var(--ok-ink) !important; }
.btn-ok:hover { background: #d3f0de; }
.btn-danger { background: var(--err-bg); color: var(--err-ink) !important; }
.btn-danger:hover { background: #fbdada; }
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700;
}
.badge-ok { background: var(--ok-bg); color: var(--ok-ink); }
.badge-off { background: var(--err-bg); color: var(--err-ink); }
.reset-pass-box code {
  background: rgba(255,255,255,.6); padding: 2px 8px; border-radius: 6px;
  font-weight: 700; letter-spacing: .5px;
}
