:root {
  --bg: #f4f5ef;
  --surface: #ffffff;
  --surface-2: #eef2ed;
  --surface-3: #fbfcfa;
  --field: #ffffff;
  --ink: #17211d;
  --muted: #667169;
  --line: #d8ded7;
  --teal: #0b746b;
  --teal-soft: #dcefeb;
  --teal-active-ink: #064d48;
  --red: #b83c35;
  --red-soft: #fae8e6;
  --red-line: #ecc6c2;
  --amber: #a96705;
  --amber-soft: #fff0d8;
  --amber-line: #efd2a4;
  --blue: #315d97;
  --blue-soft: #e4edf8;
  --blue-line: #c5d6ed;
  --green: #287444;
  --green-soft: #e4f2e8;
  --green-line: #bfdbc7;
  --shadow: 0 12px 32px rgba(23, 33, 29, 0.08);
  --header-bg: rgba(244, 245, 239, 0.94);
}

:root[data-theme="dark"] {
  --bg: #111614;
  --surface: #19211e;
  --surface-2: #222d29;
  --surface-3: #151c19;
  --field: #121816;
  --ink: #edf2ee;
  --muted: #a7b4ad;
  --line: #33413c;
  --teal: #4fb8ad;
  --teal-soft: #193b37;
  --teal-active-ink: #d9fbf6;
  --red: #ff8a82;
  --red-soft: #482321;
  --red-line: #783a36;
  --amber: #f3ba62;
  --amber-soft: #432f16;
  --amber-line: #755425;
  --blue: #9cbdf0;
  --blue-soft: #1e304a;
  --blue-line: #3b5680;
  --green: #8ed8a5;
  --green-soft: #1f3c2a;
  --green-line: #39664a;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
  --header-bg: rgba(17, 22, 20, 0.94);
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 42px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--header-bg);
  backdrop-filter: blur(12px);
}

h1 {
  margin: 0;
  font-size: 15px;
  letter-spacing: 0;
}

h2, legend {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 760;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

p { margin: 0; }

.app-header p {
  margin-top: 0;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-status {
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.header-status h1,
.header-status p {
  min-width: 0;
}

.header-status h1 {
  flex: 0 0 auto;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: flex-end;
  min-width: 0;
}

#headerSaveButton {
  background: var(--teal);
  border-color: var(--teal);
  color: white;
  font-weight: 760;
}

.icon-button {
  position: relative;
  width: 30px;
  min-width: 30px;
  padding: 0;
}

.sidebar-button span,
.sidebar-button::before,
.sidebar-button::after {
  position: absolute;
  left: 7px;
  width: 14px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
  content: "";
}

.sidebar-button::before { top: 8px; }
.sidebar-button span { top: 14px; }
.sidebar-button::after { top: 20px; }

.user-menu,
.toolbar-menu {
  position: relative;
}

.user-button span,
.user-button span::before {
  position: absolute;
  left: 50%;
  border: 2px solid currentColor;
  border-radius: 999px;
  content: "";
  transform: translateX(-50%);
}

.user-button span {
  top: 6px;
  width: 15px;
  height: 15px;
}

.user-button span::before {
  top: 3px;
  width: 4px;
  height: 4px;
  background: currentColor;
}

.user-button::after {
  position: absolute;
  left: 50%;
  bottom: 6px;
  width: 10px;
  height: 4px;
  border: 2px solid currentColor;
  border-bottom: 0;
  border-radius: 999px 999px 0 0;
  content: "";
  transform: translateX(-50%);
}

.toolbar-menu summary {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--ink);
  padding: 4px 8px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  list-style: none;
}

.toolbar-menu summary::-webkit-details-marker {
  display: none;
}

.toolbar-menu summary:hover {
  border-color: var(--teal);
}

.menu-panel,
.user-panel {
  position: absolute;
  top: calc(100% + 5px);
  right: 0;
  z-index: 20;
  min-width: 170px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.menu-panel {
  display: grid;
  gap: 3px;
}

.menu-panel a {
  min-height: 28px;
  display: flex;
  align-items: center;
  border-radius: 6px;
  color: var(--ink);
  padding: 4px 7px;
  text-decoration: none;
  font-size: 12px;
}

.menu-panel a:hover {
  background: var(--surface-2);
}

.user-panel {
  width: min(280px, calc(100vw - 28px));
  display: none;
}

.user-menu:hover .user-panel,
.user-menu:focus-within .user-panel,
.user-menu.open .user-panel {
  display: block;
}

.user-panel label {
  margin-top: 0;
}

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

.sidebar-collapsed .layout {
  grid-template-columns: minmax(0, 1fr);
}

.sidebar-collapsed .sidebar {
  display: none;
}

.sidebar, .workspace {
  display: grid;
  gap: 9px;
  align-content: start;
  min-width: 0;
}

.sidebar {
  position: sticky;
  top: 52px;
  max-height: calc(100vh - 62px);
}

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

.filters {
  padding: 9px;
}

label {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

input, select, textarea {
  width: 100%;
  min-height: 30px;
  margin-top: 3px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
}

textarea {
  resize: vertical;
}

button, .button-link {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--ink);
  padding: 4px 8px;
  font: inherit;
  font-size: 12px;
  text-decoration: none;
  cursor: pointer;
}

button:hover, .button-link:hover {
  border-color: var(--teal);
}

button.active {
  background: var(--teal-soft);
  border-color: var(--teal);
  color: var(--teal-active-ink);
  font-weight: 730;
}

.queue-panel {
  min-height: 0;
  overflow: hidden;
}

.queue-head, .pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 7px 9px;
  border-bottom: 1px solid var(--line);
}

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

.queue-head span {
  color: var(--muted);
  font-size: 12px;
}

.queue {
  max-height: calc(100vh - 405px);
  min-height: 170px;
  overflow: auto;
}

.queue-item {
  width: 100%;
  min-height: 50px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  padding: 7px 9px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface);
  text-align: left;
}

.queue-item.active {
  background: var(--teal-soft);
}

.queue-item strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.queue-item span {
  color: var(--muted);
  font-size: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.badge.accepted, .badge.accept { color: var(--green); background: var(--green-soft); border-color: var(--green-line); }
.badge.rejected, .badge.reject { color: var(--red); background: var(--red-soft); border-color: var(--red-line); }
.badge.duplicate, .badge.minor_fix { color: var(--amber); background: var(--amber-soft); border-color: var(--amber-line); }
.badge.warned, .badge.unsure { color: var(--blue); background: var(--blue-soft); border-color: var(--blue-line); }

.pair-panel {
  padding: 10px;
}

.pair-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.pair-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  min-width: 0;
}

#initialToggle {
  flex: 0 0 auto;
}

.pair-actions {
  display: flex;
  gap: 6px;
  flex: 0 0 auto;
}

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

.sentence-grid article {
  min-width: 0;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-3);
}

.sentence-grid textarea {
  min-height: 96px;
  margin-top: 5px;
  font-size: 17px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.initial-text {
  display: none;
  margin-top: 7px;
  padding-top: 7px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.show-initial .initial-text {
  display: block;
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(0, 0, 0, 0.28);
}

.side-sheet {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 40;
  width: min(560px, 100vw);
  height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border-left: 1px solid var(--line);
  background: var(--surface);
  box-shadow: -20px 0 44px rgba(0, 0, 0, 0.22);
  transform: translateX(100%);
  transition: transform 160ms ease;
}

.sheet-open .side-sheet {
  transform: translateX(0);
}

.sheet-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.sheet-head p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.close-button {
  font-size: 18px;
  line-height: 1;
}

.sheet-body {
  min-height: 0;
  overflow: auto;
  padding: 11px;
}

.sheet-body section + section {
  margin-top: 12px;
}

.sheet-body h3 {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.detail-list {
  display: grid;
  grid-template-columns: minmax(120px, auto) minmax(0, 1fr);
  gap: 5px 9px;
  margin: 0;
  font-size: 12px;
}

.detail-list dt {
  color: var(--muted);
  font-weight: 700;
}

.detail-list dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

.sheet-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

#generationPrompt {
  max-height: 48vh;
  margin: 0;
  overflow: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  color: var(--ink);
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  white-space: pre-wrap;
}

.target-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
}

code {
  padding: 1px 4px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
}

.annotation-panel {
  padding: 10px;
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

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

.choice-row, .score-row, .checks {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 5px;
}

.score-row button {
  width: 30px;
  padding: 0;
}

.checks label, .checkbox-line {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 24px;
  margin: 0;
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 12px;
  font-weight: 500;
}

.checks input, .checkbox-line input {
  width: 14px;
  min-height: 14px;
  margin: 0;
}

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

.form-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 9px;
}

#saveButton {
  min-width: 108px;
  background: var(--teal);
  border-color: var(--teal);
  color: white;
  font-weight: 760;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 10px;
}

.login-panel {
  width: min(420px, 100%);
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-panel button {
  width: 100%;
  margin-top: 10px;
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
  font-weight: 760;
}

.form-error {
  min-height: 16px;
  margin-top: 7px;
  color: var(--red);
  font-size: 13px;
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: static;
    max-height: none;
  }
  .queue {
    max-height: 280px;
  }
}

@media (max-width: 760px) {
  .form-footer {
    align-items: stretch;
    flex-direction: column;
  }
  .app-header {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 6px;
    padding: 5px 8px;
  }
  .header-status p {
    display: none;
  }
  .header-actions {
    gap: 6px;
  }
  #themeToggle {
    width: 30px;
    min-width: 30px;
    overflow: hidden;
    color: transparent;
    padding: 0;
  }
  #themeToggle::before {
    color: var(--ink);
    content: "☾";
  }
  :root[data-theme="dark"] #themeToggle::before {
    content: "☼";
  }
  .layout {
    padding: 7px;
  }
  .sentence-grid, .form-grid, .correction-grid {
    grid-template-columns: 1fr;
  }
}
