:root {
  --bg: #f5f7f8;
  --panel: #ffffff;
  --ink: #1d252c;
  --muted: #687581;
  --line: #d8e0e6;
  --accent: #146c63;
  --accent-strong: #0f514b;
  --warn: #986400;
  --error: #a23b3b;
}

* {
  box-sizing: border-box;
}

/* hidden 속성이 display: grid/flex 등 CSS 규칙에 덮어씌워지지 않도록 보장 */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
select,
input {
  font: inherit;
}

.shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  min-height: 100vh;
}

.workspace {
  padding: 28px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: start;
  margin-bottom: 18px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.2;
}

h2 {
  font-size: 16px;
}

.topbar p,
.action-panel p {
  color: var(--muted);
  margin-top: 6px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.upload-panel {
  padding: 18px;
}

.file-drop {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 108px;
  border: 1px dashed #9aabb8;
  border-radius: 8px;
  background: #fbfcfd;
  color: var(--muted);
  cursor: pointer;
  text-align: center;
  padding: 16px;
}

.file-drop input {
  display: none;
}

.controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 1fr)) auto;
  gap: 12px;
  align-items: end;
  margin-top: 14px;
}

label {
  color: var(--muted);
  display: grid;
  gap: 6px;
  font-size: 13px;
}

select,
button,
.download-link {
  border: 1px solid var(--line);
  border-radius: 6px;
  min-height: 44px;
}

select {
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
}

button,
.download-link {
  background: var(--accent);
  color: #fff;
  padding: 0 14px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

button:hover,
.download-link:hover {
  background: var(--accent-strong);
}

button:disabled,
.download-link.disabled {
  background: #c8d2d8;
  cursor: not-allowed;
  pointer-events: none;
}

.icon-button {
  width: 40px;
  padding: 0;
}

.status-row {
  min-height: 36px;
  display: flex;
  align-items: center;
  color: var(--muted);
  font-size: 14px;
}

.status-row.error {
  color: var(--error);
}

/* ── 뷰 모드 탭 ── */
.view-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}

.tab-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 20px;
  min-height: 44px;
  padding: 0 16px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.tab-btn:hover {
  background: #edf3f5;
  color: var(--ink);
}

.tab-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.tab-icon {
  margin-right: 4px;
}

/* ── 프리뷰 그리드 (텍스트 뷰 / 문서 뷰 공통) ── */
.preview-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.preview-panel {
  min-height: 420px;
  overflow: hidden;
}

.doc-preview-panel {
  min-height: 560px;
}

.panel-header {
  min-height: 52px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.panel-header span {
  color: var(--muted);
  font-size: 13px;
}

.panel-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ── 편집 버튼 ── */
.edit-btn {
  min-height: 28px;
  padding: 0 10px;
  font-size: 12px;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 5px;
}
.edit-btn:hover { background: var(--accent); color: #fff; }
.edit-btn.active { background: var(--accent); color: #fff; }

/* ── 편집 툴바 ── */
.edit-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 14px;
  background: #fffbeb;
  border-bottom: 1px solid #f0d97a;
  font-size: 13px;
  color: var(--warn);
}
.edit-bar-actions { display: flex; gap: 8px; }

.btn-save {
  min-height: 30px;
  padding: 0 12px;
  font-size: 13px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 5px;
}
.btn-save:hover { background: var(--accent-strong); }

.btn-cancel {
  min-height: 30px;
  padding: 0 12px;
  font-size: 13px;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 5px;
}
.btn-cancel:hover { background: var(--line); color: var(--ink); }

/* ── 편집 textarea ── */
.block-edit {
  display: block;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 10px 8px;
  font: inherit;
  font-size: 14px;
  line-height: 1.55;
  resize: vertical;
  min-height: 56px;
  background: #fffef5;
  color: var(--ink);
  margin-bottom: 2px;
  transition: border-color 0.15s;
}
.block-edit:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
}

/* ── 수정된 블록 표시 ── */
.block.edited {
  border-left: 3px solid var(--accent);
  padding-left: 9px;
  background: #f2faf8;
}

/* ── 텍스트 뷰 블록 리스트 ── */
.preview-list {
  max-height: 560px;
  overflow: auto;
  padding: 12px;
  scroll-behavior: smooth;
}

.preview-list.empty {
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 320px;
}

.block {
  border-bottom: 1px solid #edf1f4;
  padding: 12px 4px;
  white-space: pre-wrap;
  line-height: 1.55;
  cursor: default;
  transition: background 0.12s;
}

/* 원문 블록 - 클릭 가능 표시 */
#sourcePreview .block {
  cursor: pointer;
  border-radius: 4px;
}

#sourcePreview .block:hover {
  background: #f0f8f7;
}

/* 원문 클릭 시 활성 상태 */
.block.active-src {
  background: #e0f4f2 !important;
  border-left: 3px solid var(--accent);
  padding-left: 9px;
}

/* 번역 블록 포커싱 하이라이트 */
.block.focused {
  background: #fff8e0;
  border-left: 3px solid #e6a800;
  padding-left: 9px;
  border-radius: 4px;
  animation: focusPulse 0.4s ease;
}

@keyframes focusPulse {
  0%   { box-shadow: 0 0 0 0 rgba(230, 168, 0, 0.4); }
  70%  { box-shadow: 0 0 0 6px rgba(230, 168, 0, 0); }
  100% { box-shadow: 0 0 0 0 rgba(230, 168, 0, 0); }
}

.block:last-child {
  border-bottom: 0;
}

/* ── 문서 미리보기 컨테이너 ── */
.doc-embed-container {
  height: 520px;
  overflow: auto;
  display: flex;
  flex-direction: column;
}

.doc-iframe {
  flex: 1;
  width: 100%;
  height: 100%;
  min-height: 480px;
  border: none;
  display: block;
}

.doc-placeholder {
  color: var(--muted);
  text-align: center;
  padding: 60px 20px;
  font-size: 14px;
}

.doc-text-preview {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 13px;
  line-height: 1.65;
  white-space: pre-wrap;
  padding: 20px;
  color: var(--ink);
  overflow: auto;
}

.doc-unsupported {
  text-align: center;
  padding: 24px 20px 12px;
  color: var(--muted);
}

.doc-unsupported-icon {
  font-size: 32px;
  display: block;
  margin-bottom: 10px;
}

.doc-unsupported p {
  margin-bottom: 4px;
  font-size: 13px;
}

.doc-unsupported-sub {
  font-size: 12px;
  color: #a0b0b8;
}

/* ── 액션 패널 ── */
.action-panel {
  margin-top: 16px;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.download-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* ── 사이드바 이력 ── */
.history {
  border-left: 1px solid var(--line);
  background: #eef3f5;
  padding: 24px 18px;
}

.history header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-item {
  display: block;
  width: 100%;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  text-align: left;
  color: var(--ink);
  cursor: pointer;
}

.history-item:hover {
  border-color: #8fa5b1;
}

.history-title {
  font-weight: 700;
  overflow-wrap: anywhere;
}

.history-meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 6px;
}

.badge {
  display: inline-flex;
  border-radius: 4px;
  background: #e2ecea;
  color: var(--accent-strong);
  padding: 2px 6px;
  margin-top: 8px;
  font-size: 12px;
}

/* ── iOS Safe Area (노치/홈 바 대응) ── */
.shell {
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

/* ── 반응형 ── */
@media (max-width: 980px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .history {
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 760px) {
  .workspace {
    padding: 18px;
  }

  .controls,
  .preview-grid,
  .action-panel {
    grid-template-columns: 1fr;
    display: grid;
  }

  .preview-list,
  .doc-embed-container {
    max-height: 380px;
    height: 380px;
  }
}

@media (max-width: 480px) {
  h1 {
    font-size: 20px;
  }

  .workspace {
    padding: 12px;
  }

  .controls {
    grid-template-columns: 1fr;
  }

  .preview-list,
  .doc-embed-container {
    max-height: 300px;
    height: 300px;
  }

  .action-panel {
    flex-direction: column;
    align-items: stretch;
  }

  .download-actions {
    justify-content: stretch;
  }

  .download-actions button,
  .download-actions .download-link {
    flex: 1;
  }
}
