:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --line: #334155;
  --text: #f8fafc;
  --muted: #94a3b8;
  
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #10b981;
  --success-hover: #059669;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --sel: #1e3a8a;
  
  --radius: 8px;
  --gap: 12px;
}

* { box-sizing: border-box; }

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

html, body {
  margin: 0; padding: 0;
  background-color: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  height: 100dvh; overflow: hidden;
}

.mono {
  font-family: 'JetBrains Mono', 'Consolas', monospace;
  font-size: 13px;
}

.grow { flex: 1; }
.w-full { width: 100%; }
.mt-2 { margin-top: 12px; }
.mt-3 { margin-top: 18px; }
.mb-2 { margin-bottom: 12px; }
.mb-3 { margin-bottom: 18px; }
.text-center { text-align: center; }
.flex-center { display: flex; justify-content: center; align-items: center; }
.gap-4 { gap: 16px; }
.wrap { flex-wrap: wrap; }
.desktop-only { display: inline-block; }

.app-shell {
  display: flex; flex-direction: column;
  width: 100vw; height: 100dvh;
  margin: 0; background: var(--bg);
}

@media (min-width: 1024px) {
  .app-shell {
    width: min(1600px, 98vw); 
    height: calc(100vh - 16px);
    margin: 8px auto; 
    border: 1px solid var(--line);
    border-radius: var(--radius); 
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
  }
}

.toolbar {
  display: flex; align-items: center; padding: 8px 12px;
  border-bottom: 1px solid var(--line); background: var(--panel);
}

.toolbar-scroll { 
  display: flex; align-items: center; gap: 8px; 
  overflow-x: auto; scrollbar-width: none; 
}
.toolbar-scroll::-webkit-scrollbar { display: none; } 

.toolbar-sep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; flex-shrink: 0; }
.toolbar-label { color: var(--muted); font-size: 13px; font-weight: 500; }
.hint { color: var(--muted); font-size: 12px; }

.btn {
  border: 1px solid var(--line); background: #273448; color: var(--text);
  border-radius: 6px; padding: 6px 12px; font-size: 13px; font-weight: 500;
  cursor: pointer; white-space: nowrap; transition: all 0.2s ease;
}

.btn:hover:not(:disabled) { background: #334155; }
.btn:disabled { opacity: 0.3; cursor: not-allowed; }

.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: var(--success-hover); }

.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }

.btn-outline { background: transparent; border-color: var(--muted); }
.btn-wide { width: 100%; }

.split-layout { display: grid; grid-template-columns: 1fr; flex: 1; overflow: hidden; }

@media (min-width: 1024px) { 
  .split-layout { grid-template-columns: 1.6fr 1.2fr; } 
}

.panel { display: flex; flex-direction: column; padding: var(--gap); overflow-y: auto; }
.panel-left { border-bottom: 1px solid var(--line); background: #0b1120; }
@media (min-width: 1024px) { 
  .panel-left { border-bottom: none; border-right: 1px solid var(--line); } 
}

.panel-header { display: flex; justify-content: space-between; align-items: center; }
.panel-title { margin: 0 0 16px 0; font-size: 16px; font-weight: 600; color: var(--text); }

.preview-viewport {
  flex: 1; position: relative;
  border: 1px solid var(--line); border-radius: 6px;
  overflow: auto; background: #0f172a;
}
.preview-container { display: flex; flex-direction: column; gap: 8px; padding: 8px; }
.preview-row {
  display: flex; flex-direction: column;
  background: rgba(30, 41, 59, 0.3); border: 1px solid var(--line); 
  border-radius: 6px; padding: 10px; transition: all 0.2s;
}
.preview-row:hover { background: rgba(255, 255, 255, 0.05); }
.preview-row.row-selected { background: rgba(59, 130, 246, 0.1) !important; border-color: var(--primary); }
.preview-row.row-translated { border-left: 3px solid var(--success); }

.preview-row.separator {
  flex-direction: row; align-items: center; background: transparent;
  border: none; border-bottom: 2px solid var(--line); border-radius: 0;
  padding: 16px 8px 8px 8px; gap: 12px;
}

.checkbox-cell { display: flex; align-items: flex-start; gap: 12px; }
.checkbox-cell input[type="checkbox"] { margin-top: 4px; width: 16px; height: 16px; cursor: pointer; accent-color: var(--primary); }
.checkbox-cell input[type="checkbox"]:disabled { cursor: not-allowed; opacity: 0.4; }

.text-content {
  flex: 1; display: flex; flex-direction: column; gap: 6px;
  font-family: 'JetBrains Mono', monospace; font-size: 13px; cursor: pointer;
}
.text-content .file-meta { color: var(--primary); font-size: 11px; font-weight: 700; margin-bottom: 2px; }
.text-content .original { color: var(--muted); border-bottom: 1px dashed rgba(51, 65, 85, 0.5); padding-bottom: 6px; white-space: pre-wrap; word-break: break-word; }
.text-content .translated { color: var(--text); white-space: pre-wrap; word-break: break-word; }
.cell-muted { color: var(--muted) !important; font-style: italic; }

.highlight {
  background-color: rgba(253, 224, 71, 0.85);
  color: #000;
  border-radius: 2px;
  padding: 0 2px;
}

.progress-wrap { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.progress-track { width: 100px; height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: var(--success); transition: width 0.3s ease; }

.card-box { background: rgba(30, 41, 59, 0.4); border: 1px solid var(--line); border-radius: 6px; padding: 12px; }
.input-group { display: flex; align-items: center; gap: 8px; }

.text-input, input[type="number"] {
  height: 32px; border-radius: 6px; border: 1px solid var(--line);
  background: #0f172a; color: var(--text); padding: 4px 8px; transition: border-color 0.2s;
}
.text-input:focus, input[type="number"]:focus, .input-area:focus { outline: none; border-color: var(--primary); }

.input-area {
  width: 100%; min-height: 180px; border-radius: 6px; border: 1px solid var(--line);
  background: #0f172a; color: var(--text); padding: 10px; resize: vertical; line-height: 1.5;
}
.input-area.small { min-height: 80px; }

.text-input:disabled, input[type="number"]:disabled, .input-area:disabled {
  background: rgba(30, 41, 59, 0.4);
  border-color: rgba(51, 65, 85, 0.5);
  color: var(--muted);
  cursor: not-allowed;
}

.section-label { display: block; font-size: 13px; font-weight: 500; color: var(--muted); margin-bottom: 6px; }
.inline-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.status-toast { font-size: 12px; color: var(--success); min-height: 18px; margin-bottom: 8px; transition: opacity 0.2s ease; }
.status-toast.empty { opacity: 0; min-height: 0; height: 0; margin: 0; overflow: hidden; }

.name-table-wrap, .proofread-results-wrap {
  border: 1px solid var(--line); border-radius: 6px; overflow: auto; background: #0f172a;
}
.name-table-wrap { max-height: 400px; min-height: 150px; }
.proofread-results-wrap { max-height: 50vh; padding: 4px; }

.name-table { width: 100%; border-collapse: collapse; }
.name-table th, .name-table td { 
  border-bottom: 1px solid var(--line); padding: 6px 8px; font-size: 12px; 
  vertical-align: middle; text-align: center;
}
.name-table th { background: var(--panel); position: sticky; top: 0; z-index: 1; font-weight: 600; color: var(--muted); }
.name-table td.mono { font-family: 'JetBrains Mono', monospace; }
.name-table th:nth-child(1) { width: 30%; }
.name-table th:nth-child(2) { width: 45%; }
.name-table th:nth-child(3) { width: 25%; }
.name-table .text-input { height: 26px; font-size: 12px; padding: 2px 6px; text-align: center; }
.name-table .btn { padding: 4px 8px; font-size: 11px; }

.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.action-grid .btn-danger { grid-column: 1 / -1; }

.status-bar { border-top: 1px solid var(--line); padding: 6px 12px; font-size: 12px; background: var(--panel); color: var(--muted); }

.modal-backdrop {
  position: fixed; inset: 0; display: none; align-items: center; justify-content: center;
  background: rgba(15, 23, 42, 0.85); backdrop-filter: blur(2px);
}
.modal-backdrop.open { display: flex; }

#settingsModal { z-index: 60; }
#proofreadModal { z-index: 65; }
#lineEditorModal { z-index: 70; }
#startupModal { z-index: 80; }

.modal {
  width: min(500px, 92vw); max-height: 90vh; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 18px; box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
}
.modal-wide { width: min(700px, 94vw); }
.modal-xl { width: min(1100px, 96vw); }

.modal h3 { margin: 0 0 12px 0; font-size: 18px; }
.modal-actions { display: flex; align-items: center; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.checkbox-line { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }

@media (max-width: 768px) {
  .desktop-only { display: none; }
  .modal { padding: 14px; }
  .split-layout { grid-template-rows: 1fr 1fr; }
  .panel-left { flex: none; height: 45vh; }
  .panel-right { flex: 1; min-height: 0; display: flex; flex-direction: column; }
  
  .name-table-wrap { 
    max-height: 400px; min-height: 150px; display: block !important; 
    overflow-x: auto; -webkit-overflow-scrolling: touch; 
  }
  .name-table-wrap table { display: table !important; width: 100%; min-width: 320px; }
  .name-table-wrap thead { display: table-header-group !important; }
  .name-table-wrap tbody { display: table-row-group !important; }
  .name-table-wrap th, .name-table-wrap td { font-size: 12px; padding: 6px 4px; }
  .name-table-wrap input { font-size: 12px; padding: 4px; }
  .name-table-wrap .btn { font-size: 11px; padding: 4px 6px; }
}