*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --color-primary:       #4f46e5;
  --color-primary-light: #eef2ff;
  --color-primary-dark:  #3730a3;
  --color-danger:        #dc2626;
  --color-pass:          #16a34a;
  --color-fail:          #dc2626;
  --color-unknown:       #d97706;
  --color-bg:            #f8fafc;
  --color-panel:         #ffffff;
  --color-border:        #e2e8f0;
  --color-text:          #0f172a;
  --color-muted:         #64748b;
  --radius:              8px;
  --shadow:              0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}

body { font-family: 'Apple SD Gothic Neo', 'Noto Sans KR', sans-serif; background: var(--color-bg); color: var(--color-text); font-size: 14px; line-height: 1.6; }

/* Header */
#app-header { display: flex; align-items: center; gap: 0; padding: 0 24px; background: var(--color-panel); border-bottom: 1px solid var(--color-border); box-shadow: var(--shadow); height: 48px; }
#app-header h1 { font-size: 15px; font-weight: 800; color: var(--color-text); white-space: nowrap; letter-spacing: -0.4px; margin-right: 28px; }
.logo-dot { color: var(--color-primary); }
nav { display: flex; gap: 0; height: 48px; }
.nav-btn { padding: 0 14px; border: none; border-bottom: 2px solid transparent; background: transparent; cursor: pointer; font-size: 13px; color: var(--color-muted); font-weight: 500; height: 48px; border-radius: 0; text-decoration: none; display: inline-flex; align-items: center; }
.nav-btn:hover { color: var(--color-text); }
.nav-btn.active { color: var(--color-primary); border-bottom-color: var(--color-primary); font-weight: 700; }

/* Main layout */
#app-main { height: calc(100vh - 48px); overflow: hidden; }
.view { display: none; height: 100%; }
.view.active { display: flex; }
.hidden { display: none !important; }

/* Request view - 3-column layout */
#view-request { gap: 0; }
#input-panel { width: 360px; min-width: 300px; flex-shrink: 0; border-right: 1px solid var(--color-border); background: #fafbfc; display: flex; flex-direction: column; gap: 0; overflow-y: auto; padding: 20px; }
#preview-panel { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; border-right: 1px solid var(--color-border); overflow-y: auto; }
#preview-placeholder { color: var(--color-muted); text-align: center; font-size: 12px; line-height: 2.2; }
#layout-preview-container { width: 100%; display: flex; justify-content: center; }
#copy-panel { width: 300px; min-width: 260px; flex-shrink: 0; padding: 20px; overflow-y: auto; background: #fafbfc; }
#copy-placeholder { color: var(--color-muted); text-align: center; font-size: 12px; line-height: 2.2; padding-top: 40px; }
#result-loading { display: flex; align-items: center; gap: 10px; color: var(--color-muted); padding: 16px 0; }

/* Sections */
section { margin-bottom: 20px; }
.section-label { display: flex; align-items: center; gap: 8px; font-size: 10px; font-weight: 700; color: var(--color-muted); text-transform: uppercase; letter-spacing: 1.5px; margin-bottom: 8px; }
.section-label::after { content: ''; flex: 1; height: 1px; background: var(--color-border); }
.label-sub { font-weight: 400; text-transform: none; letter-spacing: 0; }

textarea, input[type="text"], select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--color-border); border-radius: var(--radius); font-size: 13px; font-family: inherit; background: white; color: var(--color-text);
}
textarea { resize: vertical; min-height: 120px; }
textarea:focus, input:focus, select:focus { outline: none; border-color: var(--color-primary); }

/* Buttons */
.btn-primary, .btn-secondary, .btn-ghost { display: block; width: 100%; padding: 9px; border-radius: var(--radius); font-size: 13px; font-weight: 600; cursor: pointer; margin-top: 8px; }
.btn-primary  { background: var(--color-primary); color: white; border: none; box-shadow: 0 1px 3px rgba(79,70,229,.3); }
.btn-primary:hover  { background: var(--color-primary-dark); }
.btn-secondary { background: white; color: var(--color-primary); border: 1.5px solid #c7d2fe; }
.btn-secondary:hover { background: var(--color-primary-light); }
.btn-ghost { background: transparent; color: var(--color-muted); border: 1.5px solid var(--color-border); }
.btn-ghost:hover { background: var(--color-bg); }
.btn-primary:disabled, .btn-secondary:disabled, .btn-ghost:disabled { opacity: .5; cursor: default; }
.btn-danger { padding: 8px 16px; background: var(--color-danger); color: white; border: none; border-radius: var(--radius); cursor: pointer; font-size: 13px; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-xs { padding: 2px 7px; font-size: 12px; line-height: 1.4; }

/* Hospital candidates */
#hospital-candidates { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.candidate-chip { padding: 4px 10px; border: 1px solid var(--color-primary); border-radius: 20px; background: #ebf4ff; color: var(--color-primary); font-size: 12px; cursor: pointer; }
.candidate-chip.selected { background: var(--color-primary); color: white; }

/* Image drop zone */
#image-drop-zone { border: 2px dashed var(--color-border); border-radius: var(--radius); padding: 16px; text-align: center; color: var(--color-muted); font-size: 12px; cursor: pointer; position: relative; }
#image-drop-zone.drag-over { border-color: var(--color-primary); background: #ebf4ff; }
#image-input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
#image-preview { position: relative; margin-top: 8px; }
#image-preview-img { width: 100%; border-radius: var(--radius); border: 1px solid var(--color-border); }
#btn-remove-image { position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,.5); color: white; border: none; border-radius: 50%; width: 20px; height: 20px; cursor: pointer; font-size: 12px; }

/* Result panel (work plan in input-panel) */
#result-content { margin-top: 8px; }
.spinner { width: 20px; height: 20px; border: 2px solid var(--color-border); border-top-color: var(--color-primary); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.result-section-title { font-size: 14px; font-weight: 700; margin-bottom: 12px; padding-bottom: 8px; border-bottom: 1px solid var(--color-border); }
#result-copy { margin-bottom: 24px; }
#result-medical-check { margin-bottom: 24px; }

/* Layout preview */
.preview-wrapper {
  position: relative;
  width: 100%;
}
.layout-preview {
  position: absolute;
  inset: 0;
  background: white;
  border-radius: 8px;
  padding: 24px 20px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  overflow: hidden;
}
.preview-hospital { font-size: 9px; font-weight: 600; letter-spacing: 0.08em; color: #999; text-transform: uppercase; margin-bottom: 4px; z-index: 1; }
.preview-slot { text-align: center; z-index: 1; width: 100%; }
.preview-headline { font-size: 20px; font-weight: 700; color: #222; line-height: 1.3; margin: 6px 0; word-break: keep-all; }
.preview-sub { font-size: 13px; font-weight: 500; color: #555; }
.preview-body { font-size: 11px; color: #777; line-height: 1.6; }
.preview-date { font-size: 10px; color: #999; font-weight: 600; }
.preview-cta {
  background: #333; color: #fff;
  font-size: 11px; font-weight: 700;
  padding: 7px 18px; border-radius: 20px;
  margin-top: 8px; display: inline-block;
}
.preview-tag { font-size: 10px; color: #aaa; margin-top: 4px; }

/* Copy slots */
.copy-cards { width: 100%; }
.copy-slot { margin-bottom: 20px; }
.copy-slot-label { font-size: 10px; font-weight: 700; color: var(--color-muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 6px; }
.copy-option {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: 8px; cursor: pointer;
  border: 1.5px solid var(--color-border); margin-bottom: 4px;
  background: #fafafa;
  transition: border-color 0.12s, background 0.12s;
}
.copy-option:hover { border-color: #a5b4fc; background: white; }
.copy-option.selected { border-color: var(--color-primary); background: var(--color-primary-light); }
.copy-option.selected .copy-idx { color: var(--color-primary); background: white; }
.copy-idx { font-size: 9px; font-weight: 700; color: #a5b4fc; background: var(--color-primary-light); border-radius: 3px; padding: 1px 4px; min-width: 18px; text-align: center; }
.copy-text-wrap { flex: 1; min-width: 0; }
.copy-text { font-size: 14px; font-weight: 500; color: var(--color-text); line-height: 1.5; display: block; }
.copy-text[contenteditable="true"] { outline: none; cursor: text; }
.copy-corrected {
  color: var(--color-primary);
  position: relative;
  cursor: help;
}
.copy-corrected::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #f8fafc;
  font-size: 11px;
  font-weight: 400;
  padding: 6px 10px;
  border-radius: 6px;
  white-space: pre-line;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 50;
  min-width: 160px;
  max-width: 240px;
  text-align: left;
  word-break: keep-all;
}
.copy-corrected:hover::after { opacity: 1; }
.copy-option.editing { border-color: var(--color-primary); background: white; cursor: text; }
.copy-original { font-size: 11px; color: var(--color-muted); margin-top: 3px; }
.copy-original::before { content: '✎ '; }

/* 의료법 위반 단어 하이라이팅 */
.copy-flagged {
  color: var(--color-fail);
  text-decoration: underline;
  text-decoration-style: wavy;
  text-underline-offset: 2px;
  cursor: help;
  position: relative;
}
.copy-flagged--alt { cursor: pointer; }
.copy-flagged::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #f8fafc;
  font-size: 11px;
  font-weight: 400;
  padding: 6px 10px;
  border-radius: 6px;
  white-space: pre-line;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 50;
  min-width: 160px;
  max-width: 240px;
  text-align: left;
  word-break: keep-all;
}
.copy-flagged:hover::after { opacity: 1; }

.copy-combine-bar { padding-top: 12px; border-top: 1px solid var(--color-border); margin-top: 4px; }
.btn-copy-combine { background: #1e293b; color: #fff; border: none; border-radius: 6px; padding: 7px 16px; font-size: 13px; font-weight: 600; cursor: pointer; }
.btn-copy-combine:hover { background: #334155; }

/* Medical check items */
.medical-item { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border-radius: var(--radius); margin-bottom: 6px; font-size: 13px; }
.medical-item.pass    { background: #f0fdf4; border: 1px solid #bbf7d0; }
.medical-item.fail    { background: #fef2f2; border: 1px solid #fecaca; }
.medical-item.unknown { background: #fffbeb; border: 1px solid #fde68a; }
.medical-badge { font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 4px; white-space: nowrap; }
.pass .medical-badge { background: var(--color-pass); color: white; }
.fail .medical-badge { background: var(--color-fail); color: white; }
.unknown .medical-badge { background: var(--color-unknown); color: white; }
.medical-item-content { flex: 1; }
.medical-item-name { font-weight: 600; }
.medical-item-note { color: var(--color-muted); font-size: 12px; }

#result-actions { padding-top: 16px; border-top: 1px solid var(--color-border); }
#btn-save { max-width: 200px; }

/* Hospital view */
#view-hospitals { gap: 0; }
#hospital-list-panel { width: 260px; border-right: 1px solid var(--color-border); background: #fafbfc; display: flex; flex-direction: column; overflow: hidden; }
#hospital-list-header { display: flex; align-items: center; justify-content: space-between; padding: 16px; border-bottom: 1px solid var(--color-border); }
#hospital-list-header h2 { font-size: 14px; }
#btn-add-hospital { width: auto; margin: 0; padding: 5px 10px; font-size: 12px; }
#hospital-list { list-style: none; overflow-y: auto; flex: 1; }
#hospital-list li { padding: 10px 16px; cursor: pointer; border-bottom: 1px solid var(--color-border); font-size: 13px; }
#hospital-list li:hover, #hospital-list li.active { background: #ebf4ff; color: var(--color-primary); }
#hospital-list li .specialty { font-size: 11px; color: var(--color-muted); }

#hospital-editor-panel { flex: 1; padding: 24px; overflow-y: auto; }
#hospital-editor-placeholder { color: var(--color-muted); margin-top: 40px; text-align: center; }
#hospital-form { display: flex; flex-direction: column; gap: 10px; max-width: 560px; }
#hospital-form input, #hospital-form textarea, #hospital-form select { width: 100%; }
#hospital-form textarea { min-height: 70px; }
.form-actions { display: flex; justify-content: space-between; padding-top: 8px; }

/* History view */
#view-history { flex-direction: column; padding: 24px; overflow-y: auto; }
#view-history h2 { margin-bottom: 16px; font-size: 16px; }
#history-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
#history-list li { padding: 12px 16px; background: var(--color-panel); border: 1px solid var(--color-border); border-radius: var(--radius); cursor: pointer; display: flex; justify-content: space-between; align-items: center; }
#history-list li:hover { border-color: var(--color-primary); }
.history-meta { font-size: 12px; color: var(--color-muted); }
#btn-history-back { margin-top: 0; margin-bottom: 16px; width: auto; padding: 6px 14px; }

/* Cost badge */
.cost-badge { opacity: 0.75; font-weight: 500; margin-left: 6px; white-space: nowrap; font-size: inherit; }
.cost-info { cursor: pointer; position: relative; margin-left: 2px; font-style: normal; }
.cost-info::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #f8fafc;
  font-size: 11px;
  font-weight: 400;
  padding: 6px 10px;
  border-radius: 8px;
  white-space: pre-line;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 50;
  min-width: max-content;
}
.cost-info:hover::after { opacity: 1; }

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(12px);
  padding: 10px 18px; border-radius: 8px; font-size: 13px; font-weight: 500;
  color: white; pointer-events: none; opacity: 0; transition: opacity 0.2s, transform 0.2s;
  z-index: 1000; white-space: nowrap; box-shadow: 0 4px 12px rgba(0,0,0,.15);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-info    { background: #1e293b; }
.toast-success { background: var(--color-pass); }
.toast-error   { background: var(--color-danger); }

/* Draggable preview image layers */
.preview-layer {
  position: absolute;
  cursor: grab;
  user-select: none;
  box-sizing: border-box;
}
.preview-layer:hover { outline: 2px solid rgba(59,130,246,0.5); }
.preview-layer.selected { outline: 2px solid #3b82f6; }
.preview-layer img { width: 100%; height: 100%; object-fit: contain; display: block; pointer-events: none; }
.resize-handle {
  position: absolute; width: 10px; height: 10px;
  background: #3b82f6; border-radius: 50%;
  z-index: 10;
}
.resize-handle.tl { top:-5px; left:-5px; cursor: nwse-resize; }
.resize-handle.tr { top:-5px; right:-5px; cursor: nesw-resize; }
.resize-handle.bl { bottom:-5px; left:-5px; cursor: nesw-resize; }
.resize-handle.br { bottom:-5px; right:-5px; cursor: nwse-resize; }

/* Markdown rendered content */
#work-plan-body { font-size: 13px; line-height: 1.8; margin-bottom: 24px; }
#work-plan-body h1, #work-plan-body h2, #work-plan-body h3 { font-size: 13px; font-weight: 700; margin: 14px 0 6px; }
#work-plan-body h3 { color: var(--color-primary); }
#work-plan-body ul, #work-plan-body ol { padding-left: 18px; margin: 4px 0; }
#work-plan-body li { margin: 2px 0; }
#work-plan-body strong { font-weight: 700; }
#work-plan-body p { margin: 4px 0; }
#work-plan-body hr { border: none; border-top: 1px solid var(--color-border); margin: 12px 0; }

/* Preview canvas size badge */
.preview-size-badge {
  position: absolute; top: 8px; right: 8px;
  font-size: 9px; font-weight: 600; color: #64748b;
  background: rgba(255,255,255,.92); border: 1px solid var(--color-border);
  border-radius: 4px; padding: 2px 8px; z-index: 2;
  pointer-events: none;
}
