:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1d2330;
  --muted: #6b7280;
  --line: #e4e7ec;
  --brand: #2f6fed;
  --brand-dark: #2258c4;
  --danger: #d93a3a;
  --ok: #1f9d55;
  --warn: #c98a00;
  --unread: #eef4ff;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Segoe UI", sans-serif; background: var(--bg); color: var(--text); font-size: 15px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; margin: 8px 0 0; }
button { font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid var(--line); background: #fff; padding: 7px 14px; }
button:hover { background: #f0f2f5; }
button.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
button.primary:hover { background: var(--brand-dark); }
button.danger { color: var(--danger); border-color: #f1c4c4; }
button.danger:hover { background: #fdeeee; }
button.ok { color: var(--ok); border-color: #bfe5cf; }
button.ghost { background: transparent; border-color: transparent; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); }
textarea { min-height: 260px; resize: vertical; }
label { display: block; margin-bottom: 12px; font-size: 14px; color: var(--muted); }
label > input, label > select, label > textarea { margin-top: 5px; color: var(--text); }

/* 로그인 */
.login-wrap { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 360px; background: var(--card); padding: 32px 28px; border-radius: 14px; box-shadow: 0 6px 30px rgba(0,0,0,.08); }
.login-card h1 { margin: 0 0 4px; font-size: 24px; }
.login-card button { width: 100%; margin-top: 6px; padding: 10px; }

/* 상단바 */
.topbar { height: 54px; display: flex; align-items: center; gap: 12px; padding: 0 16px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar strong { font-size: 17px; }
.who { margin-left: auto; font-size: 14px; }
.icon-btn { display: none; border: none; background: none; font-size: 20px; padding: 4px 8px; }

/* 레이아웃 */
.layout { display: flex; min-height: calc(100vh - 54px); }
.sidebar { width: 230px; flex-shrink: 0; background: var(--card); border-right: 1px solid var(--line); padding: 14px 10px; }
.sidebar .compose { width: 100%; margin-bottom: 14px; padding: 10px; }
.sidebar a { display: flex; justify-content: space-between; align-items: center; padding: 9px 12px; border-radius: 8px; color: var(--text); text-decoration: none; margin-bottom: 2px; }
.sidebar a:hover { background: #f0f2f5; }
.sidebar a.active { background: var(--unread); color: var(--brand); font-weight: 600; }
.sidebar .section { font-size: 12px; color: var(--muted); margin: 16px 12px 6px; }
.badge { background: var(--brand); color: #fff; border-radius: 10px; font-size: 12px; padding: 1px 8px; font-weight: 600; }
.badge.warn { background: var(--warn); }
.main { flex: 1; padding: 20px; min-width: 0; }

/* 카드, 표 */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin-bottom: 16px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar h2 { margin: 0 auto 0 0; font-size: 19px; }
.toolbar input[type=search] { width: 240px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; font-size: 14px; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
tr.row { cursor: pointer; }
tr.row:hover td { background: #fafbfc; }
tr.unread td { background: var(--unread); font-weight: 600; }
td.subject { max-width: 0; width: 55%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.subject .preview { color: var(--muted); font-weight: 400; margin-left: 6px; }
td.from { width: 20%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
td.date { white-space: nowrap; color: var(--muted); width: 1%; }
td.chk, th.chk { width: 1%; }
td.chk input, th.chk input { width: auto; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }
.pager { display: flex; justify-content: center; gap: 8px; margin-top: 12px; }

.status { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 10px; font-weight: 600; white-space: nowrap; }
.status.pending { background: #fff4d6; color: #8a6100; }
.status.sent { background: #dff4e7; color: #17733f; }
.status.rejected { background: #fde3e3; color: #a12828; }
.status.failed { background: #fde3e3; color: #a12828; }
.status.sending { background: #e5edff; color: #2449a8; }
.tag { font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; margin-left: 6px; font-weight: 400; }

/* 메일 보기 */
.msg-head h2 { margin: 0 0 10px; font-size: 20px; word-break: break-word; }
.msg-meta { font-size: 14px; color: var(--muted); line-height: 1.7; word-break: break-all; }
.msg-meta b { color: var(--text); font-weight: 500; }
.msg-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 0; }
.msg-body { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 16px; }
.msg-body pre { white-space: pre-wrap; word-break: break-word; font-family: inherit; margin: 0; }
.msg-body iframe { width: 100%; border: none; min-height: 400px; background: #fff; }
.attach { margin-top: 14px; font-size: 14px; }
.attach span { display: inline-block; border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; margin: 4px 6px 0 0; }
.notice { background: #fff8e1; border: 1px solid #f3e0a6; border-radius: 8px; padding: 10px 12px; font-size: 14px; margin-top: 12px; }
.notice.red { background: #fdeeee; border-color: #f1c4c4; }

/* 폼 */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.from-row { display: flex; align-items: center; gap: 6px; }
.from-row input { flex: 1; }
.inline { display: flex; gap: 6px; align-items: center; }
.inline select, .inline input { width: auto; padding: 5px 8px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.stat .n { font-size: 24px; font-weight: 700; }
.stat .l { font-size: 13px; color: var(--muted); }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #1d2330; color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 14px; z-index: 100; max-width: 90%; }
.toast.err { background: var(--danger); }

/* 모바일 */
@media (max-width: 760px) {
  .icon-btn { display: block; }
  .sidebar { position: fixed; top: 54px; left: 0; bottom: 0; z-index: 9; transform: translateX(-100%); transition: transform .2s; box-shadow: 4px 0 20px rgba(0,0,0,.08); }
  .sidebar.open { transform: none; }
  .main { padding: 12px; }
  .form-grid { grid-template-columns: 1fr; }
  td.from { display: none; }
  th.from { display: none; }
  td.subject { width: auto; }
  .toolbar input[type=search] { width: 100%; }
  .who { display: none; }
  .table-wrap { overflow-x: auto; }
}
