:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-subtle: #f8faf9;
  --ink: #18201d;
  --muted: #68736f;
  --line: #d9dfdc;
  --line-strong: #bcc6c1;
  --brand: #176b52;
  --brand-dark: #0d503d;
  --blue: #245e91;
  --amber: #9a650c;
  --red: #a63a36;
  --green-soft: #e6f3ed;
  --blue-soft: #e8f0f8;
  --amber-soft: #fff4d9;
  --red-soft: #fbe9e7;
  --shadow: 0 1px 2px rgba(19, 31, 26, 0.07);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
}

button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.app-header {
  min-height: 72px;
  padding: 12px clamp(16px, 3vw, 40px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  color: #fff;
  background: #172a24;
  border-bottom: 3px solid var(--brand);
}

.brand-block { display: flex; align-items: center; gap: 12px; min-width: 260px; }
.brand-mark {
  width: 40px; height: 40px; display: grid; place-items: center;
  border: 1px solid rgba(255,255,255,.34); border-radius: 6px;
  font-weight: 800; font-size: 14px; letter-spacing: 0;
}
.brand-block h1 { margin: 0; font-size: 18px; line-height: 1.25; letter-spacing: 0; }
.brand-block p { margin: 3px 0 0; color: #b8c9c2; font-size: 12px; }

.connection-bar { display: flex; align-items: center; gap: 8px; min-width: 0; }
.connection-bar label { color: #c4d0cb; font-size: 12px; }
.connection-bar input {
  width: min(310px, 30vw); height: 36px; border: 1px solid #50635b;
  border-radius: 4px; padding: 0 10px; color: #fff; background: #213a31; outline: none;
}
.connection-bar input:focus { border-color: #76b9a1; box-shadow: 0 0 0 2px rgba(118,185,161,.18); }
.connection-state { font-size: 12px; padding: 4px 8px; border-radius: 999px; white-space: nowrap; }
.connection-state.is-online { color: #c8f0df; background: #255f4b; }
.connection-state.is-offline { color: #ffd6d2; background: #713934; }

.workspace { width: min(1560px, 100%); margin: 0 auto; padding: 20px clamp(12px, 2.5vw, 32px) 44px; }
.view-tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line-strong); margin-bottom: 18px; }
.view-tab {
  height: 42px; padding: 0 18px; display: inline-flex; align-items: center; gap: 8px;
  border: 0; border-bottom: 3px solid transparent; color: var(--muted); background: transparent;
  cursor: pointer; font-weight: 650;
}
.view-tab:hover { color: var(--ink); background: #edf1ef; }
.view-tab.is-active { color: var(--brand-dark); border-bottom-color: var(--brand); }
.view-tab svg, .button svg, .icon-button svg, .drop-zone svg, .input-with-icon svg { width: 17px; height: 17px; }
.view-panel { display: none; }
.view-panel.is-active { display: block; }

.upload-band {
  display: grid; grid-template-columns: minmax(210px, 1fr) minmax(300px, 1.7fr) auto;
  align-items: center; gap: 20px; padding: 18px 20px; background: var(--surface);
  border: 1px solid var(--line); border-left: 4px solid var(--brand); box-shadow: var(--shadow);
}
.section-kicker { margin: 0 0 4px; color: var(--brand); font-size: 10px; font-weight: 800; letter-spacing: 0; }
.upload-band h2, .section-heading h2, .textbook-toolbar h2 { margin: 0; font-size: 18px; letter-spacing: 0; }
.section-heading h3 { margin: 0; font-size: 15px; letter-spacing: 0; }

.drop-zone {
  min-height: 58px; padding: 10px 14px; display: grid; grid-template-columns: 26px 1fr;
  align-items: center; column-gap: 10px; border: 1px dashed var(--line-strong); border-radius: 4px;
  background: var(--surface-subtle); cursor: pointer;
}
.drop-zone:hover, .drop-zone.is-dragging { border-color: var(--brand); background: var(--green-soft); }
.drop-zone svg { grid-row: 1 / 3; color: var(--brand); }
.drop-zone span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 650; }
.drop-zone small { color: var(--muted); }
.drop-zone input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.button {
  min-height: 36px; padding: 0 13px; display: inline-flex; align-items: center; justify-content: center;
  gap: 7px; border: 1px solid transparent; border-radius: 4px; text-decoration: none;
  cursor: pointer; white-space: nowrap; font-weight: 650; font-size: 13px;
}
.button:disabled, .button.is-disabled { opacity: .42; cursor: not-allowed; pointer-events: none; }
.button-primary { color: #fff; background: var(--brand); border-color: var(--brand); }
.button-primary:hover { background: var(--brand-dark); }
.button-secondary { color: var(--ink); background: #fff; border-color: var(--line-strong); }
.app-header .button-secondary { color: #fff; background: #2b483d; border-color: #5f766d; }
.button-secondary:hover { border-color: #81918a; background: #f3f6f4; }
.app-header .button-secondary:hover { background: #37584b; }
.button-warning { color: #714800; background: var(--amber-soft); border-color: #e0be75; }
.button-success { color: #fff; background: #24704f; border-color: #24704f; }
.button-danger { color: #fff; background: var(--red); border-color: var(--red); }
.button-danger:hover { background: #842f2b; border-color: #842f2b; }
.button-danger-quiet { color: var(--red); background: #fff; border-color: #dfb4b0; }

.import-layout { display: grid; grid-template-columns: 284px minmax(0, 1fr); gap: 16px; margin-top: 16px; align-items: start; }
.task-sidebar { position: sticky; top: 12px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.compact-heading { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.icon-button {
  width: 34px; height: 34px; flex: 0 0 34px; display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 4px; color: var(--muted); background: #fff; cursor: pointer;
}
.icon-button:hover { color: var(--brand); border-color: #94b8aa; background: var(--green-soft); }
.icon-button:disabled { opacity: .4; cursor: not-allowed; }
.task-list { max-height: calc(100vh - 210px); min-height: 230px; overflow: auto; }
.task-item {
  width: 100%; padding: 13px 14px; display: block; text-align: left; border: 0;
  border-bottom: 1px solid #e7ebe9; background: #fff; cursor: pointer;
}
.task-item:hover { background: #f6f8f7; }
.task-item.is-active { background: var(--green-soft); box-shadow: inset 3px 0 var(--brand); }
.task-item-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.task-item strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.task-item p { margin: 7px 0 0; color: var(--muted); font-size: 11px; }
.mini-status { font-size: 10px; color: var(--muted); white-space: nowrap; }
.sidebar-empty { padding: 32px 16px; color: var(--muted); text-align: center; font-size: 13px; }

.task-workspace { min-width: 0; }
.empty-state {
  min-height: 330px; display: grid; place-content: center; justify-items: center; gap: 10px;
  color: var(--muted); background: var(--surface); border: 1px solid var(--line);
}
.empty-state svg { width: 32px; height: 32px; }
.task-detail { display: grid; gap: 14px; }
.task-summary, .action-band, .preview-section, .import-words-section, .issues-section, .textbook-toolbar, .word-table-section {
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.task-summary { padding: 18px; }
.task-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.task-title-row h2 { margin: 0; font-size: 18px; overflow-wrap: anywhere; letter-spacing: 0; }
.status-badge { padding: 5px 9px; border-radius: 999px; font-size: 11px; font-weight: 750; white-space: nowrap; }
.status-neutral { color: #4f5c57; background: #edf0ef; }
.status-running { color: #1c5681; background: var(--blue-soft); }
.status-good { color: #17593e; background: var(--green-soft); }
.status-warning { color: #7b5006; background: var(--amber-soft); }
.status-error { color: #8e2f2b; background: var(--red-soft); }

.progress-block { margin-top: 17px; }
.progress-copy { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; color: var(--muted); }
.progress-copy strong { color: var(--ink); }
.progress-track { height: 7px; margin-top: 7px; overflow: hidden; background: #e5eae7; border-radius: 999px; }
.progress-track span { display: block; width: 0; height: 100%; background: var(--brand); transition: width .25s ease; }
.current-term { min-height: 18px; margin: 8px 0 0; color: var(--muted); font-size: 12px; }
.metric-grid { display: grid; grid-template-columns: repeat(6, minmax(90px, 1fr)); margin-top: 15px; border: 1px solid var(--line); }
.metric-grid div { padding: 10px 12px; border-right: 1px solid var(--line); background: var(--surface-subtle); }
.metric-grid div:last-child { border-right: 0; }
.metric-grid span { display: block; color: var(--muted); font-size: 11px; }
.metric-grid strong { display: block; margin-top: 3px; font-size: 20px; }
.metric-error strong { color: var(--red); }

.sample-controls { display: flex; align-items: flex-end; gap: 16px; padding: 14px 16px 4px; }
.sheet-checks { flex: 1; display: flex; flex-wrap: wrap; gap: 6px; }
.sheet-check {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 9px;
  border: 1px solid var(--line); border-radius: 4px; background: var(--surface-subtle); font-size: 12px;
}
.sheet-check input { accent-color: var(--brand); }
.field-control { display: grid; gap: 5px; min-width: 110px; }
.field-control > span:first-child { color: var(--muted); font-size: 11px; font-weight: 650; }
.field-control input, .field-control select {
  height: 36px; min-width: 0; border: 1px solid var(--line-strong); border-radius: 4px;
  padding: 0 9px; color: var(--ink); background: #fff; outline: none;
}
.field-control textarea {
  width: 100%; min-width: 0; resize: vertical; border: 1px solid var(--line-strong);
  border-radius: 4px; padding: 8px 9px; color: var(--ink); background: #fff; outline: none;
}
.field-control input:focus, .field-control select:focus, .field-control textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(23,107,82,.12); }
.action-buttons { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 16px 16px; }

.table-scroll { width: 100%; overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { padding: 9px 11px; text-align: left; color: #5d6964; background: #f2f5f3; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px 11px; border-bottom: 1px solid #e8ecea; vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fafcfb; }
.dictionary-status { width: 22px; height: 22px; display: inline-grid; place-items: center; }
.dictionary-status svg { width: 18px; height: 18px; stroke-width: 2.3; }
.dictionary-status.is-found { color: var(--brand); }
.dictionary-status.is-missing { color: var(--red); }
.cell-positive { color: var(--brand); font-weight: 700; }
.cell-negative { color: var(--red); font-weight: 700; }
.empty-row { padding: 28px 12px; color: var(--muted); text-align: center; }
.issues-empty-row { font-size: 14px; }

.segmented-control { display: flex; gap: 0; padding: 12px 16px; }
.segmented-control button {
  min-height: 32px; padding: 0 12px; border: 1px solid var(--line-strong); border-right: 0;
  color: var(--muted); background: #fff; cursor: pointer;
}
.segmented-control button:first-child { border-radius: 4px 0 0 4px; }
.segmented-control button:last-child { border-right: 1px solid var(--line-strong); border-radius: 0 4px 4px 0; }
.segmented-control button.is-active { color: #fff; background: var(--brand); border-color: var(--brand); }
.issue-resolved { color: var(--brand); }
.issue-open { color: var(--red); font-weight: 650; }
.inline-filters { display: flex; align-items: center; gap: 8px; }
.inline-filters select, .inline-filters input {
  height: 34px; min-width: 150px; border: 1px solid var(--line-strong); border-radius: 4px;
  padding: 0 9px; color: var(--ink); background: #fff; outline: none;
}
.inline-filters .input-with-icon input { padding-left: 34px; }
.table-edit-button { color: var(--blue); }

.textbook-toolbar {
  display: grid; grid-template-columns: minmax(180px, 1fr) minmax(220px, 1.2fr) 140px minmax(180px, .8fr) 34px;
  align-items: end; gap: 14px; padding: 16px;
}
.wide-control { min-width: 220px; }
.input-with-icon { position: relative; display: block; }
.input-with-icon svg { position: absolute; left: 9px; top: 10px; color: var(--muted); }
.input-with-icon input { width: 100%; padding-left: 34px; }
.word-table-section { margin-top: 14px; }
.word-count-row { display: flex; justify-content: space-between; gap: 12px; padding: 11px 14px; color: var(--muted); border-bottom: 1px solid var(--line); font-size: 12px; }
.word-table-scroll { max-height: calc(100vh - 235px); }
.word-table thead { position: sticky; top: 0; z-index: 2; }
.word-table td:nth-child(2) strong { display: block; font-size: 14px; }
.word-table td:nth-child(3), .word-table td:nth-child(4) { min-width: 180px; max-width: 310px; }
.audio-buttons { display: flex; gap: 5px; }
.audio-button {
  width: 30px; height: 30px; display: grid; place-items: center; border: 1px solid var(--line);
  border-radius: 4px; color: var(--brand); background: #fff; cursor: pointer;
}
.audio-button:hover { background: var(--green-soft); }
.audio-button:disabled { color: #aeb7b3; background: #f3f5f4; cursor: not-allowed; }
.audio-button svg { width: 15px; height: 15px; }

.modal-backdrop {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 20px;
  background: rgba(18, 31, 26, .64); backdrop-filter: blur(2px);
}
.editor-dialog {
  width: min(1080px, 100%); max-height: calc(100vh - 40px); overflow: hidden;
  display: grid; grid-template-rows: auto minmax(0, 1fr); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 6px; box-shadow: 0 18px 48px rgba(0,0,0,.22);
}
.editor-header {
  min-height: 66px; padding: 13px 16px; display: flex; align-items: center;
  justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line);
}
.editor-header h2 { margin: 0; font-size: 18px; letter-spacing: 0; }
.editor-form { overflow: auto; }
.editor-section { padding: 16px; border-bottom: 1px solid var(--line); }
.editor-section > h3, .editor-section-heading h3 { margin: 0 0 12px; font-size: 14px; letter-spacing: 0; }
.editor-section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.editor-section-heading h3 { margin-bottom: 0; }
.editor-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.editor-basic-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; align-items: end; }
.editor-autofill { height: 36px; white-space: nowrap; }
.editor-autofill-area { display: grid; grid-template-rows: 19px 36px; gap: 4px; }
.editor-autofill-area .editor-autofill-hint { grid-row: 1; }
.editor-autofill-area .editor-autofill { grid-row: 2; }
.editor-autofill-hint { color: var(--muted); font-size: 11px; white-space: nowrap; }
.editor-autofill-hint strong { color: var(--ink); font-weight: 600; }
.editor-wide { grid-column: 1 / -1; }
.audio-editor-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.audio-editor-row {
  min-height: 48px; display: grid; grid-template-columns: 48px 34px auto minmax(90px, 1fr);
  align-items: center; gap: 8px; padding: 6px 0;
}
.audio-editor-row strong { font-size: 12px; }
.audio-editor-row small { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.file-button {
  min-height: 34px; padding: 0 10px; display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; border: 1px solid var(--line-strong); border-radius: 4px; cursor: pointer; font-size: 12px;
}
.file-button:hover { border-color: #94b8aa; background: var(--green-soft); }
.file-button svg { width: 15px; height: 15px; }
.file-button input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.repeat-list { display: grid; }
.repeat-item {
  display: grid; grid-template-columns: minmax(120px, .55fr) minmax(220px, 1.45fr) 34px;
  align-items: end; gap: 10px; padding: 10px 0; border-bottom: 1px solid #e8ecea;
}
.repeat-item:last-child { border-bottom: 0; }
.repeat-item.is-definition, .repeat-item.is-synonym { grid-template-columns: minmax(0, 1fr) 34px; }
.repeat-item.is-example { grid-template-columns: minmax(260px, 1.2fr) minmax(220px, 1fr) 34px 34px 34px; }
.repeat-item .field-control { min-width: 0; }
.repeat-empty { padding: 12px 0; color: var(--muted); font-size: 12px; }
.editor-footer {
  position: sticky; bottom: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 16px; background: #f7f9f8; border-top: 1px solid var(--line);
}
.editor-footer-actions { display: flex; gap: 8px; }
.publish-warning-dialog {
  width: min(460px, 100%); padding: 22px; background: #fff; border: 1px solid #d69a95;
  border-radius: 6px; box-shadow: 0 18px 48px rgba(0,0,0,.22);
}
.publish-warning-header { display: flex; align-items: flex-start; gap: 12px; color: var(--red); }
.publish-warning-header > svg { width: 25px; height: 25px; flex: none; }
.publish-warning-header h2 { margin: 0; font-size: 18px; letter-spacing: 0; }
.publish-warning-header p { margin: 4px 0 0; color: #8e2f2b; font-size: 13px; }
.publish-warning-message { margin: 18px 0 10px; color: var(--ink); line-height: 1.6; }
.publish-warning-issues { margin: 0; padding: 10px 12px; list-style: none; border: 1px solid #e8c2be; background: var(--red-soft); }
.publish-warning-issues li { padding: 4px 0; color: #7f2b27; }
.publish-warning-issues strong { font-size: 16px; }
.publish-warning-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

.toast {
  position: fixed; right: 20px; bottom: 20px; z-index: 70; max-width: min(420px, calc(100vw - 40px));
  padding: 11px 14px; color: #fff; background: #24352f; border-radius: 5px; box-shadow: 0 8px 28px rgba(0,0,0,.18);
  opacity: 0; transform: translateY(8px); pointer-events: none; transition: .18s ease;
}
.toast.is-visible { opacity: 1; transform: translateY(0); }
.toast.is-error { background: #842f2b; }
.busy-overlay {
  position: fixed; inset: 0; z-index: 60; display: grid; place-content: center; justify-items: center; gap: 12px;
  color: #fff; background: rgba(18, 31, 26, .62); backdrop-filter: blur(2px);
}
.busy-overlay[hidden] { display: none; }
.spinner { width: 30px; height: 30px; border: 3px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1020px) {
  .app-header { align-items: flex-start; flex-direction: column; gap: 10px; }
  .connection-bar { width: 100%; }
  .connection-bar input { flex: 1; width: auto; }
  .upload-band { grid-template-columns: 1fr auto; }
  .upload-band > div:first-child { grid-column: 1 / -1; }
  .import-layout { grid-template-columns: 230px minmax(0, 1fr); }
  .metric-grid { grid-template-columns: repeat(3, 1fr); }
  .metric-grid div:nth-child(3) { border-right: 0; }
  .metric-grid div:nth-child(-n+3) { border-bottom: 1px solid var(--line); }
  .textbook-toolbar { grid-template-columns: 1fr 1fr; }
  .textbook-toolbar > div:first-child { grid-column: 1 / -1; }
  .audio-editor-grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .app-header { padding: 12px; }
  .connection-bar { display: grid; grid-template-columns: auto 1fr auto; }
  .connection-bar label { display: none; }
  .workspace { padding: 12px 8px 28px; }
  .view-tab { flex: 1; padding: 0 8px; }
  .upload-band { grid-template-columns: 1fr; padding: 14px; }
  .upload-band > div:first-child { grid-column: auto; }
  .import-layout { grid-template-columns: 1fr; }
  .task-sidebar { position: static; }
  .task-list { max-height: 240px; min-height: 0; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .metric-grid div { border-bottom: 1px solid var(--line); }
  .metric-grid div:nth-child(2n) { border-right: 0; }
  .metric-grid div:nth-last-child(-n+2) { border-bottom: 0; }
  .sample-controls { align-items: stretch; flex-direction: column; }
  .action-buttons .button { flex: 1 1 calc(50% - 8px); }
  .textbook-toolbar { grid-template-columns: 1fr; }
  .textbook-toolbar > div:first-child { grid-column: auto; }
  .wide-control { min-width: 0; }
  .word-table-scroll { max-height: none; }
  .modal-backdrop { padding: 0; }
  .editor-dialog { width: 100%; max-height: 100vh; min-height: 100vh; border: 0; border-radius: 0; }
  .editor-grid { grid-template-columns: 1fr; }
  .editor-basic-grid { grid-template-columns: 1fr; }
  .editor-autofill { width: 100%; }
  .editor-autofill-area { width: 100%; }
  .editor-autofill-hint { white-space: normal; }
  .editor-wide { grid-column: auto; }
  .inline-filters { width: 100%; flex-direction: column; align-items: stretch; }
  .inline-filters select, .inline-filters input { width: 100%; }
  .repeat-item, .repeat-item.is-example { grid-template-columns: 1fr 34px; }
  .repeat-item .field-control { grid-column: 1; }
  .repeat-item > .icon-button { grid-column: 2; grid-row: 1; }
  .repeat-item.is-example > .audio-button { grid-column: 2; grid-row: 2; }
  .repeat-item.is-example > [data-regenerate-example] { grid-column: 2; grid-row: 3; }
  .repeat-item.is-example > [data-remove-editor] { grid-column: 2; grid-row: 4; }
  .audio-editor-row { grid-template-columns: 42px 34px 1fr; }
  .audio-editor-row small { grid-column: 1 / -1; }
}
