:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --border: #d8dee6;
  --text: #172033;
  --muted: #667085;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --soft: #eef2f6;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Malgun Gothic", "Segoe UI", sans-serif;
  font-size: 14px;
}

body.login-mode {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: #ffffff;
}

.shell {
  width: min(1080px, 100%);
  margin: 0 auto;
  padding: 14px;
}

body.login-mode .shell {
  width: 360px;
  min-height: 360px;
  display: grid;
  place-items: center;
  padding: 0;
}

body.login-mode .topbar,
body.login-mode #statusBar {
  display: none;
}

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

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  margin-bottom: 10px;
}

h1, h2, p { margin: 0; }
h1 { font-size: 24px; letter-spacing: 0; }
h2 { font-size: 17px; margin-bottom: 10px; }
p { color: var(--muted); margin-top: 4px; }

.account { display: flex; gap: 8px; align-items: center; }

.panel { padding: 14px; margin-bottom: 10px; }

.login-panel {
  width: min(320px, calc(100vw - 32px));
  min-height: 320px;
  max-height: 360px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: 14px;
}

.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.login-brand img {
  width: 118px;
  height: 142px;
  object-fit: contain;
  display: block;
}

.login-brand strong {
  font-size: 29px;
  font-weight: 800;
  letter-spacing: 0;
  line-height: 1;
  color: #162033;
}

.login-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.login-grid input,
.login-grid button {
  width: 100%;
  height: 38px;
}

.upload-panel,
.title-panel,
.section-head,
.actions,
.tab-actions,
.pdf-panel,
.pdf-controls,
.pdf-actions,
.cover-row,
.settings-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.upload-panel {
  justify-content: flex-start;
  border-style: dashed;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
  min-height: 78px;
}
.upload-panel.drag-over {
  background: #eef6ff;
  border-color: var(--blue);
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.22);
}
.upload-copy {
  min-width: 0;
  flex: 1;
}
.upload-copy p {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-button-tall {
  width: 54px;
  min-height: 50px;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.2;
  padding: 6px 8px;
}
.pdf-panel {
  justify-content: space-between;
  gap: 12px;
}
.pdf-panel h2 {
  flex: 0 0 auto;
  margin-bottom: 0;
}
.pdf-controls {
  justify-content: flex-end;
  flex: 1;
  min-width: 0;
  flex-wrap: wrap;
}
.cover-row {
  justify-content: flex-end;
  font-weight: 700;
}
.cover-row span { white-space: nowrap; }
.cover-row select { min-width: 220px; }
.pdf-actions { flex-wrap: nowrap; justify-content: flex-end; }
.title-panel label { font-weight: 700; width: 46px; }
.title-panel input { flex: 1; }
.section-head { justify-content: space-between; align-items: flex-start; }
.actions { flex-wrap: wrap; justify-content: flex-end; }
.tab-actions {
  justify-content: flex-start;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

input, select, textarea, button {
  font-family: inherit;
  font-size: 14px;
}

input, select, textarea {
  border: 1px solid #cbd5df;
  border-radius: 6px;
  background: white;
  padding: 8px 9px;
  color: var(--text);
}

button,
.file-button {
  border: 1px solid var(--blue);
  background: var(--blue);
  color: white;
  border-radius: 6px;
  padding: 8px 11px;
  cursor: pointer;
  white-space: nowrap;
}

button:hover,
.file-button:hover { background: var(--blue-dark); }

button.secondary {
  background: var(--soft);
  border-color: #cbd5df;
  color: var(--text);
}

button.ghost {
  background: transparent;
  border-color: #cbd5df;
  color: var(--text);
}

.file-button input { display: none; }

.tabs {
  display: flex;
  gap: 6px;
  margin: 10px 0;
}

.tab {
  background: var(--soft);
  border-color: #cbd5df;
  color: var(--text);
}

.tab.active {
  background: var(--blue);
  border-color: var(--blue);
  color: white;
}

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 10px;
}

.review-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 10px;
}

.table-wrap {
  overflow: auto;
  max-height: 560px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 760px;
  background: white;
}

th, td {
  border-bottom: 1px solid #e1e7ef;
  border-right: 1px solid #e1e7ef;
  padding: 7px;
  text-align: left;
}

th {
  background: #eef2f6;
  font-weight: 700;
  position: sticky;
  top: 0;
}

td[contenteditable="true"] { background: #fff; }
td:focus { outline: 2px solid #93c5fd; outline-offset: -2px; }
tr.selected-row td { background: #eff6ff; }

.select-cell {
  padding: 4px;
}

.cell-select {
  width: 100%;
  min-width: 112px;
  height: 32px;
  padding: 4px 6px;
  border-radius: 4px;
}

.sheet-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.review-result-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.review-results {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 620px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  background: #fbfcfe;
}

.review-results.empty {
  justify-content: center;
  align-items: center;
  color: var(--muted);
  text-align: center;
}

.review-item {
  width: 100%;
  display: grid;
  gap: 5px;
  text-align: left;
  white-space: normal;
  color: var(--text);
  background: #ffffff;
  border-color: var(--border);
  padding: 10px;
}

.review-item:hover {
  background: #f8fbff;
  border-color: #b9d3ff;
}

.review-item .review-meta {
  color: var(--blue);
  font-weight: 700;
  font-size: 12px;
}

.review-item strong {
  font-size: 13px;
  line-height: 1.45;
}

.review-item small {
  color: var(--muted);
  line-height: 1.4;
}

#reviewText {
  width: 100%;
  min-height: 620px;
  resize: vertical;
  line-height: 1.55;
}

.settings-row { margin-bottom: 10px; }
.settings-row input[type="password"] { min-width: 360px; }

.message { min-height: 20px; color: var(--muted); }
.hidden { display: none !important; }

#statusBar {
  color: #475467;
  padding: 4px 2px;
}

@media (max-width: 900px) {
  .grid, .review-grid { grid-template-columns: 1fr; }
  .upload-panel, .section-head { align-items: stretch; flex-direction: column; }
  .pdf-panel, .pdf-controls { align-items: stretch; flex-direction: column; }
  .cover-row, .pdf-actions { justify-content: stretch; }
  .pdf-actions { flex-wrap: wrap; }
  .file-button-tall { width: 100%; flex-direction: row; gap: 4px; }
  .upload-copy p { white-space: normal; }
}
