:root {
  --ui-font: 'Malgun Gothic', '맑은 고딕', 'Apple SD Gothic Neo', 'Noto Sans KR', sans-serif;
  --line: #d6d9de;
  --bg: #f3f4f6;
  --ink: #1f2328;
  --muted: #6b7280;
  --accent: #1d4ed8;
  --edit: #f97316;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--ui-font); font-size: 14px; color: var(--ink); background: var(--bg); display: flex; flex-direction: column; }
button { font: inherit; padding: 5px 12px; border: 1px solid var(--line); background: #fff; border-radius: 4px; cursor: pointer; }
button:hover { background: #f0f2f5; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: #1e40af; }
button.primary:disabled { opacity: .5; cursor: default; }
button.danger { color: #b91c1c; }
input { font: inherit; }

.topbar { display: flex; align-items: center; gap: 18px; padding: 8px 16px; background: #0b2a6b; color: #fff; flex-wrap: wrap; }
.topbar a { color: #dbe4ff; text-decoration: none; }
.topbar a:hover { color: #fff; }
.brand { font-weight: 800; letter-spacing: .5px; color: #fff !important; }
.brand span { font-weight: 400; opacity: .8; margin-left: 4px; }
.topbar nav { display: flex; gap: 14px; }
.primary-link { font-weight: 700; }
#doc-title { font-weight: 600; color: #fff; }
#tb-editor { margin-left: auto; display: flex; gap: 8px; align-items: center; }
#tb-editor button { padding: 4px 12px; }
#who { color: #b8c6ea; font-size: 12px; margin-left: auto; }
#tb-editor:not([hidden]) + #who { margin-left: 0; }
.zoom { font-size: 12px; display: flex; align-items: center; gap: 4px; color: #dbe4ff; }
.zoom input { width: 90px; }

#banner { background: #fff7d6; border-bottom: 1px solid #f0d77a; padding: 8px 16px; font-size: 13px; }
#banner button { padding: 2px 8px; margin-left: 6px; }

/* 목록 */
#list { padding: 20px 24px; overflow: auto; flex: 1; }
.list-head { display: flex; align-items: center; gap: 16px; margin-bottom: 12px; }
.list-head h1 { font-size: 20px; margin: 0; }
.search { display: flex; gap: 6px; margin-left: auto; }
.search input { width: 300px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 4px; }
table.list { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--line); }
table.list th, table.list td { padding: 8px 10px; border-bottom: 1px solid #eceef1; text-align: left; vertical-align: top; }
table.list th { background: #f8f9fb; font-weight: 600; font-size: 13px; }
table.list tr:hover td { background: #f7f9ff; }
table.list td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.list .actions { white-space: nowrap; }
table.list .actions button { padding: 2px 8px; font-size: 12px; }
.muted { color: var(--muted); font-size: 12px; }
td.muted { padding: 30px !important; text-align: center !important; font-size: 14px; }
.err { color: #b91c1c; }

/* 편집 화면 */
#editor { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.formula-bar { display: flex; align-items: center; gap: 8px; padding: 6px 12px; background: #fff; border-bottom: 1px solid var(--line); }
#fb-addr { width: 56px; text-align: center; font-weight: 700; color: var(--accent); }
#fb-input { flex: 0 1 420px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 3px; font-family: Consolas, 'D2Coding', monospace; font-size: 13px; }
#fb-info { color: var(--muted); font-size: 12px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; flex: 1; }
#fb-info code { font-size: 11px; background: #f3f4f6; padding: 1px 4px; border-radius: 3px; }
.tag-auto { color: #0f766e; font-weight: 600; margin-right: 6px; }
.tag-edit { color: var(--edit); font-weight: 600; margin-right: 6px; }
#fb-revert { padding: 2px 10px; font-size: 12px; color: var(--edit); border-color: var(--edit); }
.sheet-scroll { flex: 1; overflow: auto; background: #e9ebef; padding: 16px; }
#sheet-host { display: inline-block; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.15); }
#tabs { display: flex; gap: 2px; padding: 4px 8px 0; background: #dfe2e7; border-top: 1px solid var(--line); overflow-x: auto; flex-shrink: 0; }
.tab { border-radius: 4px 4px 0 0; border-bottom: none; padding: 5px 12px; white-space: nowrap; font-size: 13px; background: #eef0f3; }
.tab.active { background: #fff; font-weight: 700; color: var(--accent); }
.tab-hidden { color: #8a8f98; font-style: italic; }

/* 시트 */
.sheet { position: relative; background: #fff; outline: none; user-select: none; }
.sheet .layer { position: absolute; inset: 0; pointer-events: none; }
.sheet .fill, .sheet .bd, .sheet .tx, .sheet .grid { position: absolute; }
.sheet .grid { border-right: 1px solid #e3e5e8; border-bottom: 1px solid #e3e5e8; }
.sheet .tx { display: flex; padding: 0 2px; line-height: 1.15; overflow: hidden; white-space: pre; }
.sheet .tx.spill { overflow: visible; }
.sheet .tx.wrap { white-space: pre-wrap; word-break: break-all; }
.sheet .tx.wrap .tv { width: 100%; }
.sheet .tx .tv { flex-shrink: 0; }
.sheet .tx.wrap .tv { flex-shrink: 1; }
.sheet .tx .dist { width: 100%; text-align: justify; text-align-last: justify; }
.sheet-screen .tx.edited::after { content: ''; position: absolute; right: 0; top: 0; border-style: solid; border-width: 0 7px 7px 0; border-color: transparent var(--edit) transparent transparent; }
.sheet .shape-img, .sheet .shape-svg, .sheet .shape-box { position: absolute; }
.sheet .shape-svg { overflow: visible; }
.sheet .shape-box { display: flex; flex-direction: column; overflow: hidden; line-height: 1.2; }
.sheet .shape-p { white-space: pre-wrap; }
.sheet .ctrl-layer { pointer-events: none; }
.sheet .combo { position: absolute; pointer-events: auto; background: #fff; border: 1px solid #7a7a7a; display: flex; align-items: center; font: 9pt 'Malgun Gothic', sans-serif; cursor: pointer; overflow: hidden; }
.sheet .combo-label { flex: 1; padding: 0 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet .combo-arrow { width: 15px; flex-shrink: 0; align-self: stretch; display: flex; align-items: center; justify-content: center; font-size: 7px; background: #eceef1; border-left: 1px solid #bbb; }
.sheet .combo:hover { border-color: var(--accent); }
.sheet .combo.edited { box-shadow: inset 0 0 0 1px var(--edit); }
.sheet-print .combo-arrow { display: none; }
.sheet-screen .shape-int { pointer-events: auto; cursor: pointer; }
.sheet-screen .shape-int:hover { outline: 2px dashed #f59e0b; outline-offset: 1px; }
.shape-menu { position: fixed; z-index: 120; background: #fff; border: 1px solid #9aa3af; border-radius: 6px; box-shadow: 0 6px 20px rgba(0,0,0,.2); padding: 6px; display: flex; flex-direction: column; gap: 4px; min-width: 180px; }
.shape-menu textarea { width: 280px; height: 80px; font: 13px var(--ui-font); }
.shape-menu .row { display: flex; gap: 6px; justify-content: flex-end; }
#shape-restore { padding: 2px 10px; font-size: 12px; }
.sel-box { position: absolute; border: 2px solid #1a73e8; pointer-events: none; }
.cell-editor { position: absolute; z-index: 5; border: 2px solid #1a73e8; padding: 1px 3px; resize: none; outline: none; background: #fff; white-space: pre; overflow: hidden; line-height: 1.2; }
.cell-editor.idle { opacity: 0; pointer-events: none; z-index: -1; }
.cell-editor.active { pointer-events: auto; box-shadow: 0 2px 8px rgba(0,0,0,.2); }

/* 목록 고르기 */
.picker { position: fixed; z-index: 100; background: #fff; border: 1px solid #9aa3af; box-shadow: 0 6px 20px rgba(0,0,0,.2); border-radius: 4px; max-width: 520px; display: flex; flex-direction: column; }
.picker-search { margin: 6px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 3px; }
.picker-list { max-height: 300px; overflow: auto; }
.picker-item { padding: 4px 10px; cursor: pointer; white-space: nowrap; font-size: 13px; }
.picker-item small { color: #9aa3af; display: inline-block; width: 38px; font-size: 11px; }
.picker-item.empty { color: #aaa; }
.picker-item.current { font-weight: 700; color: var(--accent); }
.picker-item.active, .picker-item:hover { background: #e8f0fe; }
.picker-none { padding: 10px; color: var(--muted); }

#toast { position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%) translateY(20px); background: #1f2937; color: #fff; padding: 10px 18px; border-radius: 6px; opacity: 0; transition: .2s; pointer-events: none; z-index: 200; max-width: 80vw; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { background: #b91c1c; }
.modal-wrap { position: fixed; inset: 0; background: rgba(0,0,0,.3); display: flex; align-items: center; justify-content: center; z-index: 300; }
.modal { background: #fff; padding: 20px 24px; border-radius: 8px; min-width: 320px; box-shadow: 0 10px 30px rgba(0,0,0,.25); }
.modal-btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.fatal { padding: 40px; color: #b91c1c; }

/* 인쇄 */
#print-host { display: none; }
@media print {
  body { background: #fff; display: block; }
  body > *:not(#print-host) { display: none !important; }
  #print-host { display: block; }
  .print-page .sheet { box-shadow: none; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
