:root {
  color-scheme: dark;
  --bg: #090d14;
  --surface: #101722;
  --surface-2: #151e2b;
  --surface-3: #1b2635;
  --surface-hover: #202d3e;
  --border: #273446;
  --border-soft: #1d2938;
  --text: #edf3fb;
  --text-soft: #9cabbe;
  --text-faint: #6f8198;
  --primary: #5b8cff;
  --primary-hover: #78a1ff;
  --primary-soft: rgba(91, 140, 255, .14);
  --accent: #a78bfa;
  --success: #31c48d;
  --danger: #fb7185;
  --warning: #fbbf24;
  --canvas-bg: #070a0f;
  --shadow: 0 18px 50px rgba(0, 0, 0, .28);
  font-family: "Pretendard", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
  font-size: 14px;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #eef2f7;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --surface-3: #eef3f9;
  --surface-hover: #e8eff8;
  --border: #d5deea;
  --border-soft: #e5eaf1;
  --text: #172033;
  --text-soft: #596a80;
  --text-faint: #8290a2;
  --primary-soft: rgba(48, 103, 232, .10);
  --canvas-bg: #293242;
  --shadow: 0 18px 50px rgba(42, 55, 74, .14);
}

* { box-sizing: border-box; }
html, body { min-width: 320px; min-height: 100%; }
body { margin: 0; overflow: hidden; color: var(--text); background: var(--bg); }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
[hidden] { display: none !important; }

.login-shell { display: grid; min-height: 100vh; place-items: center; padding: 24px; background: radial-gradient(circle at 50% 10%, rgba(91,140,255,.16), transparent 34%), var(--bg); }
.login-card { width: min(420px, 100%); padding: 42px; border: 1px solid var(--border); border-radius: 24px; background: color-mix(in srgb, var(--surface) 94%, transparent); box-shadow: var(--shadow); backdrop-filter: blur(18px); }
.brand-mark { display: grid; width: 52px; height: 52px; place-items: center; border-radius: 15px; color: white; font-size: 22px; font-weight: 800; background: linear-gradient(135deg, var(--primary), var(--accent)); box-shadow: 0 10px 28px rgba(91,140,255,.25); }
.brand-mark-small { width: 36px; height: 36px; border-radius: 11px; font-size: 16px; }
.eyebrow, .section-kicker { display: block; margin: 20px 0 6px; color: var(--primary); font-size: 10px; font-weight: 800; letter-spacing: .14em; }
.login-card h1 { margin: 0; font-size: 28px; letter-spacing: -.04em; }
.login-description { margin: 10px 0 28px; color: var(--text-soft); line-height: 1.7; }
.field-label { display: block; margin: 14px 0 7px; color: var(--text-soft); font-size: 12px; font-weight: 700; }
.control { width: 100%; height: 36px; padding: 0 11px; color: var(--text); border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); transition: border-color .15s, background .15s, box-shadow .15s; }
.control:hover { border-color: color-mix(in srgb, var(--border) 55%, var(--text-soft)); }
.control:focus { border-color: var(--primary); background: var(--surface); box-shadow: 0 0 0 3px var(--primary-soft); outline: 0; }
.button { min-height: 34px; padding: 0 13px; color: var(--text); border: 1px solid transparent; border-radius: 8px; background: var(--surface-3); font-weight: 700; white-space: nowrap; transition: transform .12s, border-color .12s, background .12s; }
.button:hover { transform: translateY(-1px); }
.button:active { transform: translateY(0); }
.button-primary { color: white; background: var(--primary); }
.button-primary:hover { background: var(--primary-hover); }
.button-block { width: 100%; margin-top: 18px; }
.button-ghost, .button-tool { border-color: var(--border); background: transparent; }
.button-ghost:hover, .button-tool:hover, .button-tool.is-active { border-color: var(--primary); background: var(--primary-soft); }
.button-accent { color: #fff; background: linear-gradient(135deg, #7958e9, #9b78f0); }
.button-success { color: #061d14; background: var(--success); }
.button-danger-ghost { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); background: transparent; }
.button-danger-ghost:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }
.icon-button { display: inline-grid; width: 34px; height: 34px; flex: 0 0 34px; place-items: center; padding: 0; color: var(--text); border: 1px solid var(--border); border-radius: 8px; background: transparent; font-size: 20px; line-height: 1; }
.icon-button:hover { border-color: var(--primary); background: var(--primary-soft); }
.message { min-height: 1.4em; margin: 12px 0 0; color: var(--danger); font-size: 12px; }

.app-shell { display: grid; grid-template-rows: 56px auto minmax(0, 1fr); height: 100vh; min-height: 620px; }
.app-header { display: flex; align-items: center; justify-content: space-between; padding: 0 18px; border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--surface) 94%, transparent); }
.brand, .header-actions { display: flex; align-items: center; gap: 11px; }
.brand strong { display: block; font-size: 15px; }
.brand span { display: block; margin-top: 1px; color: var(--text-faint); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; }
.user-chip { padding: 7px 11px; color: var(--text-soft); border: 1px solid var(--border); border-radius: 999px; background: var(--surface-2); font-size: 12px; }

.search-section { display: grid; grid-template-columns: 150px 1fr; align-items: center; gap: 14px; padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--surface); }
.section-title strong, .panel-heading strong, .viewer-heading strong { display: block; }
.section-title .section-kicker, .panel-heading .section-kicker, .viewer-heading .section-kicker, .modal-header .section-kicker { margin: 0 0 2px; }
.search-hint { color: var(--text-faint); font-size: 11px; }
.search-bar { display: grid; grid-template-columns: repeat(2, minmax(125px, 1fr)) repeat(2, minmax(92px, .7fr)) repeat(4, minmax(92px, .8fr)) auto; align-items: end; gap: 8px; min-width: 0; }
.search-bar label { display: flex; min-width: 0; flex-direction: column; gap: 4px; color: var(--text-soft); font-size: 10px; font-weight: 700; }
.search-bar .control { min-width: 0; }
.search-button { display: flex; align-items: center; justify-content: center; gap: 12px; height: 36px; }
kbd { padding: 2px 5px; color: rgba(255,255,255,.75); border: 1px solid rgba(255,255,255,.25); border-radius: 4px; font-family: inherit; font-size: 9px; }

.workspace { display: grid; grid-template-columns: minmax(300px, 22vw) minmax(480px, 1fr) minmax(300px, 21vw); gap: 8px; min-height: 0; padding: 8px; overflow: hidden; }
.panel { min-width: 0; min-height: 0; overflow: hidden; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); box-shadow: 0 8px 22px rgba(0,0,0,.08); }
.panel-heading { display: flex; height: 54px; align-items: center; justify-content: space-between; padding: 0 13px; border-bottom: 1px solid var(--border); }
.count-badge { padding: 4px 8px; color: var(--primary); border-radius: 999px; background: var(--primary-soft); font-size: 11px; font-weight: 800; }
.list-panel { display: grid; grid-template-rows: auto minmax(0,1fr); }
.table-wrap { position: relative; overflow: auto; scrollbar-color: var(--border) transparent; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 11px; }
th { position: sticky; z-index: 2; top: 0; padding: 9px 8px; color: var(--text-soft); border-bottom: 1px solid var(--border); background: var(--surface-2); text-align: left; }
td { max-width: 180px; padding: 8px; overflow: hidden; border-bottom: 1px solid var(--border-soft); color: var(--text-soft); text-overflow: ellipsis; white-space: nowrap; }
tbody tr { transition: background .1s; }
tbody tr:hover { cursor: pointer; background: var(--surface-hover); }
tbody tr.selected { background: var(--primary-soft); box-shadow: inset 3px 0 var(--primary); }
tbody tr.selected td { color: var(--text); }
.result-empty { position: absolute; inset: 45% 20px auto; color: var(--text-faint); text-align: center; line-height: 1.6; }
table:not(:has(tbody:empty)) + .result-empty { display: none; }

.viewer-panel { display: grid; grid-template-rows: auto auto minmax(0,1fr); }
.viewer-heading { display: flex; min-height: 62px; align-items: center; justify-content: space-between; gap: 14px; padding: 9px 13px; border-bottom: 1px solid var(--border); }
.document-summary { display: block; max-width: 55ch; margin-top: 3px; overflow: hidden; color: var(--text-faint); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.page-controls, .tool-group { display: flex; align-items: center; gap: 6px; }
.page-status { min-width: 58px; color: var(--text-soft); font-size: 12px; font-variant-numeric: tabular-nums; text-align: center; }
.viewer-toolbar { display: flex; min-height: 49px; align-items: center; gap: 8px; padding: 7px 9px; overflow-x: auto; border-bottom: 1px solid var(--border); background: var(--surface-2); scrollbar-width: thin; }
.tool-divider { width: 1px; height: 24px; flex: 0 0 1px; background: var(--border); }
.toolbar-spacer { flex: 1 0 8px; }
.zoom-status { min-width: 44px; color: var(--text-soft); font-size: 11px; text-align: center; }
.compact-select { width: 112px; height: 34px; }
#image-viewport { position: relative; min-height: 0; overflow: auto; background-color: var(--canvas-bg); background-image: linear-gradient(45deg, rgba(255,255,255,.018) 25%, transparent 25%), linear-gradient(-45deg, rgba(255,255,255,.018) 25%, transparent 25%); background-size: 24px 24px; scrollbar-color: #39485d transparent; }
#document-canvas { display: none; margin: 18px auto 54px; background: white; box-shadow: 0 8px 28px rgba(0,0,0,.5); }
#image-viewport.has-document #document-canvas { display: block; }
.viewer-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 7px; color: var(--text-faint); }
.viewer-empty strong { color: var(--text-soft); font-size: 15px; }
.empty-icon { display: grid; width: 54px; height: 54px; place-items: center; margin-bottom: 5px; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); font-size: 25px; }
#image-viewport.has-document .viewer-empty { display: none; }
.viewer-tip { position: sticky; z-index: 3; bottom: 10px; display: none; width: max-content; max-width: calc(100% - 24px); margin: 0 auto 10px; padding: 7px 11px; color: #dbe7f7; border: 1px solid rgba(255,255,255,.09); border-radius: 999px; background: rgba(8,13,20,.82); font-size: 10px; backdrop-filter: blur(8px); pointer-events: none; }
#image-viewport.has-document .viewer-tip { display: block; }

.details { overflow-y: auto; scrollbar-color: var(--border) transparent; }
.sticky-heading { position: sticky; z-index: 3; top: 0; background: var(--surface); }
.line-info { margin: 0 12px 8px; padding: 10px 12px; color: var(--text); border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); font-size: 12px; font-weight: 700; line-height: 1.45; }
.line-info.is-active { border-color: color-mix(in srgb, #ff2638 45%, var(--border)); background: color-mix(in srgb, #ff2638 10%, var(--surface-2)); }
.line-info small { display: block; margin-top: 4px; color: var(--text-soft); font-weight: 500; }
.detail-section { border-bottom: 1px solid var(--border); }
#document-canvas { cursor: crosshair; }
#document-canvas.has-line { cursor: pointer; }
.detail-section summary { display: flex; min-height: 44px; align-items: center; justify-content: space-between; padding: 0 13px; color: var(--text-soft); font-size: 12px; font-weight: 800; list-style: none; }
.detail-section summary::-webkit-details-marker { display: none; }
.detail-section summary:hover { color: var(--text); background: var(--surface-2); }
.summary-icon { color: var(--text-faint); font-size: 17px; transition: transform .18s; }
.detail-section[open] .summary-icon { transform: rotate(45deg); }
.detail-body { padding: 0 12px 13px; }
.memo-input { height: auto; min-height: 72px; padding: 9px 10px; resize: vertical; }
.detail-list { color: var(--text-soft); font-size: 11px; line-height: 1.7; overflow-wrap: anywhere; }
.detail-list hr, .attachment-grid hr { border: 0; border-top: 1px solid var(--border-soft); }
.empty-copy { color: var(--text-faint); }
.attachment-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; }
.picture-entry { min-width: 0; padding: 8px; overflow: hidden; border: 1px solid var(--border-soft); border-radius: 9px; background: var(--surface-2); color: var(--text-faint); font-size: 9px; overflow-wrap: anywhere; }
.picture-entry br:first-of-type { display: none; }
.picture-thumb { display: block; width: 100%; height: 86px; margin: 6px 0; object-fit: cover; border-radius: 6px; background: var(--surface-3); }
.picture-entry button, .voice-delete, .voice-share { min-height: 26px; margin: 2px 3px 0 0; padding: 0 7px; color: var(--text-soft); border: 1px solid var(--border); border-radius: 6px; background: transparent; font-size: 10px; }
.upload-box { display: grid; grid-template-columns: 1fr auto; gap: 7px; margin-top: 10px; padding: 10px; border: 1px dashed var(--border); border-radius: 9px; background: var(--surface-2); }
.file-input { grid-column: 1 / -1; width: 100%; color: var(--text-soft); font-size: 10px; }
.file-input::file-selector-button { margin-right: 7px; padding: 5px 8px; color: var(--text); border: 1px solid var(--border); border-radius: 6px; background: var(--surface-3); }
.upload-box .button-block, .upload-box #print-pictures { margin: 0; }
#print-pictures { grid-column: 1 / -1; min-height: 30px; color: var(--text-soft); border: 1px solid var(--border); border-radius: 7px; background: transparent; font-size: 11px; }
audio { width: 100%; height: 34px; margin: 5px 0; }

.modal { width: min(760px, calc(100vw - 32px)); max-height: min(760px, calc(100vh - 40px)); padding: 0; overflow: hidden; color: var(--text); border: 1px solid var(--border); border-radius: 15px; background: var(--surface); box-shadow: var(--shadow); }
.modal::backdrop { background: rgba(3,7,12,.72); backdrop-filter: blur(4px); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.modal-header h3 { margin: 0; }
.modal-content { max-height: 65vh; padding: 15px; overflow: auto; color: var(--text-soft); font-size: 12px; line-height: 1.7; }
.share-dialog { width: min(960px, calc(100vw - 32px)); }
.share-source { margin: 0; padding: 12px 16px; color: var(--text-soft); border-bottom: 1px solid var(--border); background: var(--surface-2); font-size: 11px; }
.share-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 15px; }
.share-columns h4 { margin: 0 0 8px; }
.share-choice { width: 100%; margin: 3px 0; padding: 8px; color: var(--text-soft); border: 1px solid var(--border); border-radius: 7px; background: var(--surface-2); font-size: 11px; text-align: left; }
.share-choice:hover { color: var(--text); border-color: var(--primary); background: var(--primary-soft); }

.line-blink { animation: blink .72s steps(2, start) infinite; }
@keyframes blink { 50% { opacity: .3; } }

@media (max-width: 1450px) {
  .workspace { grid-template-columns: minmax(280px, 24vw) minmax(460px, 1fr) minmax(280px, 23vw); }
  .viewer-toolbar { align-items: flex-start; flex-wrap: wrap; }
  .toolbar-spacer { display: none; }
  .search-section { grid-template-columns: 120px 1fr; }
  .search-bar { grid-template-columns: repeat(4, minmax(90px,1fr)) auto; }
}

@media (max-width: 1080px) {
  body { overflow: auto; }
  .app-shell { height: auto; min-height: 100vh; grid-template-rows: 56px auto auto; }
  .search-section { grid-template-columns: 1fr; }
  .search-hint { display: none; }
  .workspace { grid-template-columns: minmax(270px, 34vw) minmax(0,1fr); grid-template-rows: minmax(680px, calc(100vh - 220px)) auto; overflow: visible; }
  .details { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(2,1fr); overflow: visible; }
  .details > .panel-heading { grid-column: 1 / -1; }
  .detail-section { border-right: 1px solid var(--border); }
}

@media (max-width: 720px) {
  .app-header { padding: 0 10px; }
  .brand span, .user-chip { display: none; }
  .search-bar { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .search-button { grid-column: 1 / -1; }
  .workspace { display: flex; flex-direction: column; padding: 6px; }
  .list-panel { height: 300px; flex: none; }
  .viewer-panel { height: 720px; flex: none; }
  .details { display: block; }
  .viewer-heading { min-height: 58px; }
  .document-summary { max-width: 36vw; }
  .viewer-toolbar { max-height: 104px; }
  .tool-divider { display: none; }
  .attachment-grid, .share-columns { grid-template-columns: 1fr; }
  .login-card { padding: 30px 24px; }
}

/* 동화/통합 목록 상태색 (EnWonView CellFormatting 규칙) */
#won-list td.cell-pending { background: #fee2e2; color: #991b1b; font-weight: 600; }
#won-list td.cell-done { background: #a7f3d0; color: #064e3b; font-weight: 600; }
#won-list td.cell-memo { background: #fde68a; color: #78350f; }
#won-list td.cell-sago { background: #fb7185; color: #fff; font-weight: 600; }
#won-list tr.status-pending td:first-child { box-shadow: inset 3px 0 0 #ef4444; }
#won-list tr.status-done td:first-child { box-shadow: inset 3px 0 0 #10b981; }

