/* ─── Variables ─────────────────────────────────────────── */
:root {
  --bg:         #f4f1eb;
  --surface:    #ffffff;
  --surface2:   #f9f7f3;
  --border:     #e2ddd4;
  --border2:    #ccc7bc;
  --text:       #1c1a16;
  --text-muted: #8a8278;
  --accent:     #2563eb;
  --accent-dim: #bfcfef;
  --error:      #dc2626;
  --correct:    #16a34a;
  --sidebar-w:  270px;
}

/* ─── Reset ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  font-family: 'Raleway', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ─── Layout ─────────────────────────────────────────────── */
.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ─── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 28px 20px;
  gap: 24px;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-icon {
  font-size: 24px;
  color: var(--accent);
  line-height: 1;
}
.brand-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 21px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.01em;
}
.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 1px;
}

/* ─── Controls ─────────────────────────────────────────────── */
.controls { display: flex; flex-direction: column; gap: 20px; }

.field-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  padding: 9px 32px 9px 12px;
  font-family: 'Raleway', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238a8278' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  transition: border-color 0.2s;
}
.select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }

/* Radio */
.radio-group { display: flex; flex-direction: column; gap: 8px; }
.radio-item {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}
.radio-item input[type=radio] { display: none; }
.radio-box {
  width: 17px; height: 17px;
  border-radius: 50%;
  border: 2px solid var(--border2);
  flex-shrink: 0;
  position: relative;
  transition: border-color 0.2s;
  background: var(--surface2);
}
.radio-item input:checked + .radio-box { border-color: var(--accent); }
.radio-item input:checked + .radio-box::after {
  content: '';
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  background: var(--accent);
}

/* Checkboxes */
.check-group { display: flex; flex-direction: column; gap: 9px; }
.check-item {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}
.check-item input[type=checkbox] { display: none; }
.check-box {
  width: 17px; height: 17px;
  border-radius: 4px;
  border: 2px solid var(--border2);
  flex-shrink: 0;
  position: relative;
  transition: all 0.15s;
  background: var(--surface2);
}
.check-item input:checked + .check-box { background: var(--accent); border-color: var(--accent); }
.check-item input:checked + .check-box::after {
  content: '';
  position: absolute;
  left: 3px; top: 1px;
  width: 7px; height: 10px;
  border: 2px solid #fff;
  border-top: none; border-left: none;
  transform: rotate(45deg);
}

/* ─── Sidebar Actions ─────────────────────────────────────── */
.sidebar-actions { display: flex; flex-direction: column; gap: 8px; }

.btn-primary {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 7px;
  font-family: 'Raleway', sans-serif;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  letter-spacing: 0.04em;
  transition: background 0.2s, transform 0.1s;
  box-shadow: 0 2px 8px rgba(37,99,235,0.25);
}
.btn-primary:hover { background: #1d4ed8; }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { background: #93b4f5; box-shadow: none; cursor: not-allowed; }

.btn-ghost {
  width: 100%;
  padding: 10px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 7px;
  font-family: 'Raleway', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.btn-ghost:hover { color: var(--text); border-color: var(--border2); background: var(--surface2); }

/* ─── Stats ─────────────────────────────────────────────── */
.stats {
  margin-top: auto;
  display: flex;
  gap: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}
.stat { display: flex; flex-direction: column; }
.stat-num {
  font-family: 'Cormorant Garamond', serif;
  font-size: 28px;
  font-weight: 600;
  color: var(--accent);
  line-height: 1;
}
.stat-label { font-size: 11px; color: var(--text-muted); margin-top: 3px; }

/* ─── Main ─────────────────────────────────────────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

/* ─── Panels ─────────────────────────────────────────────── */
.panels {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--surface);
}

.panel + .panel { border-left: 1px solid var(--border); }

.panel-divider {
  width: 1px;
  background: var(--border);
  flex-shrink: 0;
}

/* ─── Input mode tabs ────────────────────────────────────────── */
.input-mode-tabs {
  display: flex;
  gap: 2px;
  background: var(--bg);
  border-radius: 6px;
  padding: 3px;
}
.input-tab {
  -webkit-appearance: none;
  appearance: none;
  background: none;
  border: none;
  padding: 4px 12px;
  font-family: 'Raleway', sans-serif;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.input-tab.active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.input-tab:hover:not(.active) { color: var(--text); }

/* ─── File drop zone ─────────────────────────────────────────── */
.file-drop-zone {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  border: 2px dashed var(--border2);
  border-radius: 0;
  background: var(--surface);
  transition: border-color 0.2s, background 0.2s;
  cursor: default;
}
.file-drop-zone.drag-over {
  border-color: var(--accent);
  background: #eff5ff;
}
.file-drop-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  pointer-events: none;
}
.file-drop-inner * { pointer-events: auto; }
.file-drop-icon { font-size: 40px; line-height: 1; margin-bottom: 4px; }
.file-drop-title { font-size: 15px; font-weight: 600; color: var(--text); }
.file-drop-hint { font-size: 13px; color: var(--text-muted); }
.file-drop-formats { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.file-browse-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.file-browse-btn:hover { color: #1d4ed8; }

/* ─── File loaded state ──────────────────────────────────────── */
.file-loaded {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 8px;
  padding: 14px 18px;
  width: 100%;
  max-width: 400px;
}
.file-loaded-icon {
  color: var(--correct);
  font-size: 20px;
  font-weight: 700;
  flex-shrink: 0;
}
.file-loaded-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}
.file-loaded-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-loaded-chars {
  font-size: 11px;
  color: var(--text-muted);
}
.file-remove-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  flex-shrink: 0;
}
.file-remove-btn:hover { color: var(--error); }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
}

.panel-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.char-count {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--text-muted);
}

/* ─── Editor ─────────────────────────────────────────────── */
.editor {
  flex: 1;
  width: 100%;
  background: var(--surface);
  border: none;
  resize: none;
  padding: 20px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 14px;
  line-height: 1.8;
  color: var(--text);
  outline: none;
}
.editor::placeholder { color: #bbb5ac; }

.result-display {
  overflow-y: auto;
  cursor: default;
  user-select: text;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.editor-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: #ccc5bb;
  font-size: 13px;
  background: var(--surface);
}
.placeholder-icon { font-size: 40px; opacity: 0.35; }

/* ─── Small button ─────────────────────────────────────────── */
.btn-small {
  padding: 4px 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text-muted);
  font-family: 'Raleway', sans-serif;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}
.btn-small:hover { color: var(--accent); border-color: var(--accent-dim); }

/* ─── Loading ─────────────────────────────────────────────── */
.loading {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: #eff6ff;
}
.loading-bar {
  height: 3px;
  background: var(--accent-dim);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 10px;
}
.loading-bar::after {
  content: '';
  display: block;
  height: 100%;
  width: 40%;
  background: var(--accent);
  border-radius: 3px;
  animation: slide 1.4s ease-in-out infinite;
}
@keyframes slide {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}
.loading-text { font-size: 13px; font-weight: 600; color: var(--accent); }
.loading-hint { font-size: 11px; color: var(--text-muted); margin-top: 3px; }
.dots::after {
  content: '';
  animation: dots 1.5s steps(4, end) infinite;
}
@keyframes dots {
  0%   { content: ''; }
  25%  { content: '.'; }
  50%  { content: '..'; }
  75%  { content: '...'; }
  100% { content: ''; }
}

/* ─── Error ─────────────────────────────────────────────── */
.error-box {
  margin: 12px 20px;
  padding: 12px 16px;
  background: #fef2f2;
  border: 1px solid #fca5a5;
  border-radius: 7px;
  color: var(--error);
  font-size: 13px;
  font-weight: 500;
}

/* ─── Tabs ─────────────────────────────────────────────── */
.tabs-section {
  border-top: 2px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  max-height: 260px;
  display: flex;
  flex-direction: column;
}

.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  background: var(--surface2);
}
.tab {
  padding: 10px 18px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-family: 'Raleway', sans-serif;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-content { display: none; flex: 1; overflow-y: auto; }
.tab-content.active { display: block; }

/* ─── Diff ─────────────────────────────────────────────── */
.diff-view {
  padding: 16px 20px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  line-height: 1.9;
  white-space: pre-wrap;
  word-wrap: break-word;
  color: var(--text);
}
.diff-view .removed {
  background: #fee2e2;
  color: #b91c1c;
  text-decoration: line-through;
  border-radius: 3px;
  padding: 1px 3px;
}
.diff-view .added {
  background: #dcfce7;
  color: #15803d;
  border-radius: 3px;
  padding: 1px 3px;
  font-weight: 600;
}

/* ─── Changes List ─────────────────────────────────────────── */
.changes-list {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.change-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 14px;
  background: var(--surface2);
  border-radius: 7px;
  border-left: 3px solid var(--border2);
}
.change-card.spelling    { border-left-color: #dc2626; }
.change-card.grammar     { border-left-color: #ea580c; }
.change-card.punctuation { border-left-color: #ca8a04; }
.change-card.style       { border-left-color: #7c3aed; }

.change-badge {
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 3px 8px;
  border-radius: 4px;
  background: var(--border);
  color: var(--text-muted);
}
.change-card.spelling    .change-badge { background: #fee2e2; color: #dc2626; }
.change-card.grammar     .change-badge { background: #ffedd5; color: #ea580c; }
.change-card.punctuation .change-badge { background: #fef9c3; color: #a16207; }
.change-card.style       .change-badge { background: #ede9fe; color: #7c3aed; }

.change-body { flex: 1; min-width: 0; }
.change-msg  { font-size: 12px; color: var(--text); margin-bottom: 4px; font-weight: 500; }
.change-orig { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: #b91c1c; text-decoration: line-through; }
.change-suggestions { margin-top: 5px; display: flex; flex-wrap: wrap; gap: 4px; }
.suggestion-tag {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  padding: 2px 8px;
  background: #dcfce7;
  color: #15803d;
  border-radius: 4px;
  font-weight: 600;
}

/* ─── Download area ─────────────────────────────────────────── */
.download-area {
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  text-align: center;
}
.download-hint { font-size: 13px; color: var(--text-muted); }

.download-formats {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.download-format-btn {
  -webkit-appearance: none;
  appearance: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 18px 24px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
  min-width: 90px;
  font-family: 'Raleway', sans-serif;
}
.download-format-btn:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 10px rgba(37,99,235,0.12);
  transform: translateY(-1px);
}
.download-format-btn:active { transform: scale(0.97); }

.dfmt-icon { font-size: 24px; line-height: 1; }
.dfmt-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.05em;
}
.dfmt-desc { font-size: 11px; color: var(--text-muted); }

/* ─── Responsive ─────────────────────────────────────────────── */
@media (max-width: 700px) {
  .app { flex-direction: column; height: auto; min-height: 100vh; overflow: visible; }
  .sidebar { width: 100%; height: auto; padding: 16px; }
  .main { overflow: visible; }
  .panels { flex-direction: column; height: auto; }
  .panel { min-height: 200px; }
  .tabs-section { max-height: none; }
}

/* ─── Page Navigation ───────────────────────────────────── */
.page-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--accent-dim); color: var(--accent); font-weight: 600; }
.nav-icon { font-size: 15px; width: 18px; text-align: center; }

/* ─── Morph: token flow ─────────────────────────────────── */
.token-flow {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-bottom: 20px;
}
.token-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  padding: 6px 4px 4px;
  border-radius: 6px;
  transition: background .15s;
}
.token-chip:hover, .token-chip.active { background: var(--surface2); }
.token-word {
  font-family: 'JetBrains Mono', monospace;
  font-size: 15px;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  padding-bottom: 2px;
}
.token-pos {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

/* ─── Morph: detail panel ───────────────────────────────── */
.token-detail {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 20px;
  margin-bottom: 20px;
}
.detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.detail-word {
  font-family: 'JetBrains Mono', monospace;
  font-size: 18px;
  font-weight: 600;
}
.detail-lemma { font-size: 13px; color: var(--text-muted); }
.detail-pos { font-size: 12px; font-weight: 600; text-transform: uppercase; }
.detail-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 8px; }
.detail-table td { padding: 4px 8px; border-bottom: 1px solid var(--border); }
.detail-table td:first-child { color: var(--text-muted); width: 140px; }
.detail-gloss { font-size: 13px; color: var(--text-muted); font-style: italic; margin-top: 8px; }

/* ─── Morph: full table ─────────────────────────────────── */
.morph-table-wrap { overflow-x: auto; margin-top: 8px; }
.morph-table-title { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); margin-bottom: 8px; }
.morph-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.morph-table th {
  text-align: left; padding: 8px 10px;
  background: var(--surface2); font-size: 11px;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-muted); border-bottom: 1px solid var(--border);
}
.morph-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.morph-table tr:last-child td { border-bottom: none; }
.pos-badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.features-cell { color: var(--text-muted); font-size: 12px; }
.gloss-cell { color: var(--text-muted); font-style: italic; font-size: 12px; }

/* ─── Lang: result card ─────────────────────────────────── */
.lang-result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 20px;
}
.lang-detected { display: flex; align-items: center; gap: 20px; }
.lang-flag { font-size: 48px; line-height: 1; }
.lang-name { font-family: 'Cormorant Garamond', serif; font-size: 28px; font-weight: 600; }
.lang-confidence { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

.lang-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 20px;
  margin-bottom: 12px;
}
.lang-section-title {
  font-size: 11px; text-transform: uppercase;
  letter-spacing: .08em; color: var(--text-muted);
  margin-bottom: 12px; font-weight: 600;
}

/* ─── Lang: probability bars ────────────────────────────── */
.prob-row {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 10px; font-size: 13px;
}
.prob-row--main .prob-bar { background: var(--accent); }
.prob-flag { font-size: 18px; width: 24px; }
.prob-name { width: 90px; font-weight: 500; }
.prob-bar-wrap { flex: 1; height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
.prob-bar { height: 100%; background: var(--border2); border-radius: 4px; transition: width .4s ease; }
.prob-pct { width: 36px; text-align: right; color: var(--text-muted); }

/* ─── Lang: indicators ──────────────────────────────────── */
.lang-indicators-list { display: flex; flex-wrap: wrap; gap: 8px; }
.indicator-tag {
  background: var(--surface2); border: 1px solid var(--border);
  padding: 4px 12px; border-radius: 20px; font-size: 13px;
  font-family: 'JetBrains Mono', monospace;
}
.lang-explanation-text { font-size: 14px; line-height: 1.7; color: var(--text); }
