:root {
  --bg: #0b0f17;
  --bg-soft: #121826;
  --panel: #161e2e;
  --panel-2: #1c2638;
  --line: #26324a;
  --text: #e8eefb;
  --muted: #93a2bd;
  --accent: #6d5efc;
  --accent-soft: #2a2a5e;
  --ok: #2fbf71;
  --warn: #e0a020;
  --block: #ef4a63;
  --info: #4a9bef;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);

  /* 테마에서 갈아끼우는 표면색 (라이트 테마가 깨지지 않도록 전부 변수화) */
  --input: #0d1320;
  --code-bg: #0d1320;
  --issue-bg: #0f1524;
  --log-bg: #080c14;
  --toast-bg: #1c2638;
  --hover-line: #3a4b70;
  --link: #a99bff;
  --topbar-bg: rgba(11, 15, 23, .85);
  --body-bg: radial-gradient(1200px 600px at 15% -10%, #1a2340 0%, var(--bg) 55%) no-repeat, var(--bg);
  --head-font: inherit;
  --head-weight: 700;
  --mono-font: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --focus-ring: rgba(109, 94, 252, .18);
  --row-hover: rgba(255, 255, 255, .025);
  --drop-bg: rgba(28, 38, 56, .45);
  --drop-over: rgba(109, 94, 252, .1);
  --card-bg: linear-gradient(180deg, var(--panel) 0%, var(--bg-soft) 100%);
  --app-card-bg: linear-gradient(160deg, var(--panel-2), var(--bg-soft));
  --card-shadow: var(--shadow);

  /* 상태 배지/박스 전경색 (라이트 테마에서 대비 확보용) */
  --ok-text: #b9f5d5;
  --warn-text: #ffe2a8;
  --block-text: #ffc2cc;
  --info-text: #c6dcfa;
  --path-text: #b9c6de;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--body-bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}

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

h1, h2, h3 { margin: 0 0 .4rem; line-height: 1.25; letter-spacing: -.01em; font-family: var(--head-font); font-weight: var(--head-weight); }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: .95rem; }
p { margin: .3rem 0; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: .9rem;
  padding: .7rem 1rem;
  background: var(--topbar-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; letter-spacing: -.02em; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.brand small { display: block; font-weight: 400; font-size: .68rem; color: var(--muted); letter-spacing: 0; }
.topbar nav { display: flex; gap: .25rem; margin-left: auto; align-items: center; flex-wrap: wrap; }
.topbar nav a {
  padding: .38rem .7rem; border-radius: 9px; color: var(--muted); font-size: .86rem; font-weight: 600;
}
.topbar nav a:hover { background: var(--panel); text-decoration: none; color: var(--text); }
.topbar nav a.active { background: var(--panel-2); color: var(--text); }
.who { font-size: .76rem; color: var(--muted); padding-left: .6rem; border-left: 1px solid var(--line); }
.who b { color: var(--text); font-weight: 600; display: block; font-size: .8rem; }

/* ---------- layout ---------- */
.wrap { max-width: 1080px; margin: 0 auto; padding: 1.2rem 1rem 4rem; }
.wrap.narrow { max-width: 720px; }
.page-head { display: flex; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin: .4rem 0 1.1rem; }
.page-head .sub { color: var(--muted); font-size: .88rem; }
.spacer { flex: 1; }

.card {
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.05rem 1.1rem;
  box-shadow: var(--card-shadow);
}
.card + .card { margin-top: .9rem; }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; gap: .6rem; margin-bottom: .7rem; }
.card-head h2, .card-head h3 { margin: 0; }

.grid { display: grid; gap: .9rem; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

/* ---------- app cards ---------- */
.app-card {
  position: relative;
  display: flex; flex-direction: column; gap: .5rem;
  padding: 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--app-card-bg);
  color: var(--text);
  transition: transform .14s ease, border-color .14s ease;
}
.app-card:hover { transform: translateY(-2px); border-color: var(--hover-line); text-decoration: none; }
.app-card .badge-app {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  font-weight: 800; font-size: .82rem; color: #fff;
}
.app-card .name { font-weight: 700; font-size: 1rem; }
.app-card .tag { color: var(--muted); font-size: .79rem; }
.app-card .meta { display: flex; gap: .5rem; font-size: .74rem; color: var(--muted); margin-top: .1rem; flex-wrap: wrap; }
.app-card.locked { opacity: .45; }
.app-card .lock { position: absolute; top: .8rem; right: .9rem; color: var(--muted); font-size: .78rem; }

/* ---------- forms ---------- */
label.field { display: block; margin-bottom: .75rem; }
label.field > span { display: block; font-size: .8rem; color: var(--muted); margin-bottom: .3rem; font-weight: 600; }
input[type=text], input[type=password], input[type=email], input[type=search], input[type=number], select, textarea {
  width: 100%; padding: .62rem .75rem; border-radius: 10px;
  border: 1px solid var(--line); background: var(--input); color: var(--text);
  font: inherit; font-size: .92rem; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring); }
textarea { min-height: 84px; resize: vertical; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  padding: .6rem 1rem; border-radius: 10px; border: 1px solid transparent;
  background: var(--accent); color: #fff; font-weight: 700; font-size: .9rem;
  cursor: pointer; font-family: inherit; transition: filter .12s ease, background .12s ease;
  min-height: 42px;
}
.btn:hover { filter: brightness(1.1); }
.btn:disabled { opacity: .5; cursor: not-allowed; filter: none; }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn.ghost:hover { background: var(--panel-2); }
.btn.danger { background: var(--block); }
.btn.small { padding: .35rem .65rem; font-size: .8rem; min-height: 32px; }
.btn.wide { width: 100%; }

.error-box {
  border: 1px solid rgba(239, 74, 99, .45); background: rgba(239, 74, 99, .12);
  color: var(--block-text); padding: .65rem .8rem; border-radius: 10px; font-size: .86rem; margin-bottom: .8rem;
}
.notice-box {
  border: 1px solid rgba(74, 155, 239, .4); background: rgba(74, 155, 239, .1);
  color: var(--info-text); padding: .65rem .8rem; border-radius: 10px; font-size: .86rem; margin-bottom: .8rem;
}

/* ---------- dropzone ---------- */
.dropzone {
  position: relative;
  border: 2px dashed var(--hover-line); border-radius: 16px;
  padding: 2.1rem 1rem; text-align: center; cursor: pointer;
  background: var(--drop-bg);
  transition: border-color .15s ease, background .15s ease;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--drop-over); }
.dropzone .big { font-size: 1rem; font-weight: 700; }
.dropzone .small { color: var(--muted); font-size: .82rem; margin-top: .3rem; }
.dropzone input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }

.file-chip {
  display: flex; align-items: center; gap: .7rem; margin-top: .8rem;
  padding: .7rem .85rem; border-radius: 11px; background: var(--panel-2); border: 1px solid var(--line);
}
.file-chip .fname { font-weight: 600; font-size: .87rem; word-break: break-all; }
.file-chip .fsize { color: var(--muted); font-size: .78rem; }
.file-chip .x { margin-left: auto; }

.progress { height: 10px; border-radius: 99px; background: var(--input); overflow: hidden; border: 1px solid var(--line); }
.progress > i { display: block; height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), #9a8bff); transition: width .18s ease; }
.progress.done > i { background: linear-gradient(90deg, var(--ok), #6ee7a8); }
.progress.fail > i { background: linear-gradient(90deg, var(--block), #ff8798); }
.progress-meta { display: flex; justify-content: space-between; font-size: .78rem; color: var(--muted); margin-top: .4rem; gap: .6rem; }

.stepper { display: flex; gap: .4rem; flex-wrap: wrap; margin: .7rem 0 .2rem; }
.stepper .st {
  font-size: .74rem; padding: .22rem .55rem; border-radius: 99px;
  border: 1px solid var(--line); color: var(--muted); background: var(--input);
}
.stepper .st.on { color: var(--text); border-color: var(--accent); background: var(--accent-soft); }
.stepper .st.ok { color: var(--ok-text); border-color: rgba(47, 191, 113, .5); background: rgba(47, 191, 113, .14); }
.stepper .st.bad { color: var(--block-text); border-color: rgba(239, 74, 99, .5); background: rgba(239, 74, 99, .14); }

/* ---------- tables / lists ---------- */
table.list { width: 100%; border-collapse: collapse; font-size: .86rem; }
table.list th, table.list td { text-align: left; padding: .6rem .7rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list th { color: var(--muted); font-weight: 600; font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; }
table.list tr:last-child td { border-bottom: none; }
table.list tbody tr:hover { background: var(--row-hover); }
.mono { font-family: var(--mono-font); font-size: .78rem; }
.receipt-no { font-family: var(--mono-font); font-weight: 700; letter-spacing: .02em; }

.pill {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .15rem .5rem; border-radius: 99px; font-size: .73rem; font-weight: 700;
  border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}
.pill.ok { color: var(--ok-text); border-color: rgba(47, 191, 113, .45); background: rgba(47, 191, 113, .12); }
.pill.warn { color: var(--warn-text); border-color: rgba(224, 160, 32, .45); background: rgba(224, 160, 32, .12); }
.pill.block { color: var(--block-text); border-color: rgba(239, 74, 99, .45); background: rgba(239, 74, 99, .12); }
.pill.info { color: var(--info-text); border-color: rgba(74, 155, 239, .45); background: rgba(74, 155, 239, .12); }
.pill.muted { color: var(--muted); }

.kv { display: grid; grid-template-columns: 150px 1fr; gap: .35rem .8rem; font-size: .86rem; }
.kv dt { color: var(--muted); font-size: .8rem; }
.kv dd { margin: 0; word-break: break-all; }

.issue { border: 1px solid var(--line); border-radius: 11px; padding: .7rem .85rem; background: var(--issue-bg); }
.issue + .issue { margin-top: .5rem; }
.issue .ih { display: flex; gap: .5rem; align-items: center; font-weight: 700; font-size: .88rem; }
.issue .id { color: var(--muted); font-size: .83rem; margin-top: .2rem; }
.issue .paths { margin: .45rem 0 0; padding-left: 1.1rem; font-size: .79rem; color: var(--path-text); }
.issue.block { border-color: rgba(239, 74, 99, .4); }
.issue.warn { border-color: rgba(224, 160, 32, .38); }

.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; font-size: .88rem; }

.toast {
  position: fixed; left: 50%; bottom: 1.2rem; transform: translateX(-50%);
  background: var(--toast-bg); border: 1px solid var(--line); color: var(--text);
  padding: .7rem 1.1rem; border-radius: 12px; box-shadow: var(--shadow);
  font-size: .88rem; z-index: 90; max-width: 92vw;
}
.toast.hidden { display: none; }

.hint { font-size: .78rem; color: var(--muted); }
.tag-list { display: flex; flex-wrap: wrap; gap: .35rem; }
code.inline { background: var(--code-bg); border: 1px solid var(--line); border-radius: 6px; padding: .05rem .35rem; font-size: .8rem; }

pre.log {
  background: var(--log-bg); border: 1px solid var(--line); border-radius: 10px;
  padding: .8rem; font-size: .76rem; overflow: auto; max-height: 380px; color: var(--path-text);
  font-family: var(--mono-font); line-height: 1.5;
}

.tabs { display: flex; gap: .3rem; border-bottom: 1px solid var(--line); margin-bottom: .9rem; overflow-x: auto; }
.tabs a { padding: .5rem .8rem; font-size: .87rem; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); }
.tabs a:hover { text-decoration: none; color: var(--text); }

.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 1.2rem; }
.login-card { width: 100%; max-width: 400px; }
.login-card .brand { margin-bottom: 1rem; font-size: 1.1rem; }

@media (max-width: 760px) {
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-2 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; gap: .1rem 0; }
  .kv dd { margin-bottom: .5rem; }
  .topbar { padding: .55rem .7rem; gap: .5rem; }
  .topbar nav a { padding: .34rem .55rem; font-size: .8rem; }
  .who { display: none; }
  .wrap { padding: .9rem .75rem 5rem; }
  table.list.responsive thead { display: none; }
  table.list.responsive tr { display: block; border-bottom: 1px solid var(--line); padding: .5rem 0; }
  table.list.responsive td { display: flex; justify-content: space-between; gap: .7rem; border: none; padding: .22rem .7rem; }
  table.list.responsive td::before { content: attr(data-label); color: var(--muted); font-size: .74rem; font-weight: 600; }
  .dropzone { padding: 1.6rem .8rem; }
  h1 { font-size: 1.15rem; }
}

/* ---------- 긴 문자열(SHA-256, 파일명, 접수번호) 넘침 방지 ---------- */
.mono, .receipt-no, code.inline, pre.log {
  overflow-wrap: anywhere;
  word-break: break-word;
}
.notice-box, .error-box, .issue, .file-chip, .progress-meta, #progress-result, #progress-detail, dd {
  overflow-wrap: anywhere;
  min-width: 0;
}
.progress-meta span, #progress-detail { overflow-wrap: anywhere; }
table.list td, table.list th { overflow-wrap: anywhere; }
.card, .grid, .grid > * { min-width: 0; }
body { overflow-x: hidden; }

/* =====================================================================
   테마 레이아웃 — 네비게이션 위치가 실제로 달라진다.
   body[data-nav="top|rail|dock"] 로 전환하며, 색·모서리·글꼴은
   themes.js 가 주입하는 :root 변수가 담당한다.
   ===================================================================== */

body { font-family: var(--body-font, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans KR", sans-serif); }

/* 상태 박스는 테마 대비에 맞춘 변수를 쓴다 */
.error-box { color: var(--block-text); }
.notice-box { color: var(--info-text); }

/* 강조 테두리 발광(네온 테마) */
body[data-glow="1"] .card,
body[data-glow="1"] .app-card { box-shadow: var(--glow); }
body[data-glow="1"] .btn { box-shadow: 0 0 14px rgba(34, 211, 238, .35); }

/* ---------- 좌측 레일 ---------- */
body[data-nav="rail"] { padding-left: 232px; }
body[data-nav="rail"] .topbar {
  position: fixed; top: 0; left: 0; bottom: 0; width: 232px;
  flex-direction: column; align-items: stretch; justify-content: flex-start;
  gap: .35rem; padding: 1.05rem .7rem;
  border-bottom: none; border-right: 1px solid var(--line);
  overflow-y: auto; overflow-x: hidden;
}
body[data-nav="rail"] .topbar .brand { padding: .15rem .35rem .9rem; }
body[data-nav="rail"] .topbar nav {
  flex-direction: column; align-items: stretch; gap: .12rem;
  margin-left: 0; width: 100%; flex-wrap: nowrap;
}
body[data-nav="rail"] .topbar nav a {
  display: block; padding: .5rem .7rem; border-radius: 9px; font-size: .87rem;
}
body[data-nav="rail"] .topbar nav a.active {
  background: var(--accent-soft); color: var(--text);
  box-shadow: inset 3px 0 0 var(--accent);
}
body[data-nav="rail"] .who {
  border-left: none; padding-left: .35rem; margin-top: auto; padding-top: .9rem;
  border-top: 1px solid var(--line);
}
body[data-nav="rail"] .wrap { max-width: 1160px; }

/* ---------- 하단 독 ---------- */
body[data-nav="dock"] { padding-bottom: 76px; }
body[data-nav="dock"] .topbar {
  position: fixed; top: auto; bottom: 0; left: 0; right: 0;
  border-bottom: none; border-top: 1px solid var(--line);
  padding: .45rem .6rem; gap: .4rem;
  justify-content: space-between;
  box-shadow: 0 -8px 24px rgba(0, 0, 0, .28);
}
body[data-nav="dock"] .topbar .brand { display: none; }
body[data-nav="dock"] .topbar nav { margin-left: 0; width: 100%; justify-content: space-around; gap: .1rem; }
body[data-nav="dock"] .topbar nav a { padding: .42rem .5rem; font-size: .8rem; text-align: center; }
body[data-nav="dock"] .topbar nav a.active { background: var(--accent-soft); color: var(--text); }
body[data-nav="dock"] .who { display: none; }
body[data-nav="dock"] .topbar nav form { margin-left: .2rem; }

/* 좁은 화면: 레일/독은 상단 바로 자동 복귀 (가로 스크롤·잘림 방지) */
@media (max-width: 860px) {
  body[data-nav="rail"] { padding-left: 0; }
  body[data-nav="rail"] .topbar {
    position: sticky; top: 0; left: auto; right: auto; bottom: auto;
    width: auto; flex-direction: row; align-items: center;
    border-right: none; border-bottom: 1px solid var(--line);
    padding: .55rem .7rem; overflow: visible;
  }
  body[data-nav="rail"] .topbar .brand { padding: 0; }
  body[data-nav="rail"] .topbar nav {
    flex-direction: row; flex-wrap: wrap; margin-left: auto; width: auto; gap: .2rem;
  }
  body[data-nav="rail"] .topbar nav a { display: inline-block; padding: .34rem .55rem; font-size: .8rem; box-shadow: none; }
  body[data-nav="rail"] .who { margin-top: 0; padding-top: 0; border-top: none; }

  body[data-nav="dock"] { padding-bottom: 0; }
  body[data-nav="dock"] .topbar {
    position: sticky; top: 0; bottom: auto;
    border-top: none; border-bottom: 1px solid var(--line);
    box-shadow: none; flex-wrap: wrap;
  }
  body[data-nav="dock"] .topbar .brand { display: flex; }
  body[data-nav="dock"] .topbar nav { width: auto; margin-left: auto; flex-wrap: wrap; justify-content: flex-end; }
  body[data-nav="dock"] .who { display: block; }
}

/* ---------- 테마 선택기 ---------- */
.theme-grid { display: grid; gap: .7rem; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.theme-opt {
  display: block; position: relative; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: .7rem; background: var(--input); transition: border-color .14s ease, transform .14s ease;
}
.theme-opt:hover { border-color: var(--accent); transform: translateY(-1px); }
.theme-opt input { position: absolute; opacity: 0; pointer-events: none; }
.theme-opt.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--focus-ring); }
.theme-opt .swatches { display: flex; gap: .28rem; margin-bottom: .5rem; }
.theme-opt .sw { width: 26px; height: 26px; border-radius: 7px; border: 1px solid rgba(255,255,255,.14); }
.theme-opt .tname { font-weight: 700; font-size: .9rem; display: flex; align-items: center; gap: .35rem; }
.theme-opt .tblurb { color: var(--muted); font-size: .75rem; margin-top: .18rem; line-height: 1.4; }
.theme-opt .tnav { font-size: .68rem; color: var(--muted); border: 1px solid var(--line); border-radius: 99px; padding: .05rem .4rem; }

/* 라디오 선택 즉시 시각 반영 (서버 왕복 없이) */
.theme-opt:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 2px var(--focus-ring); }
