/* ── Variables ─────────────────────────────────────────────────────────── */
:root {
  --color-bg:        #fff;
  --color-surface:   #efefef;
  --color-surface-2: #f7f7f7;
  --color-border:    #dbdbdb;
  --color-primary:   #F2A900;
  --color-primary-h: #d4940a;
  --color-text:      #363636;
  --color-text-muted:#70777f;
  --color-error:     #ef4444;
  --color-success:   #22c55e;
  --radius:          6px;
  --shadow-sm:       0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow:          0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --transition:      all 0.1s linear;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg:        #141b23;
    --color-surface:   #222f3a;
    --color-surface-2: #1a242f;
    --color-border:    #526980;
    --color-primary:   #F2A900;
    --color-primary-h: #ffd04a;
    --color-text:      #dbdbdb;
    --color-text-muted:#a9b1ba;
    color-scheme:      dark;
  }
}


.lang-select option, .select-compact option {
  background-color: var(--color-surface);
  color: var(--color-text);
}

/* ── Reset & Base ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body, input, textarea, select, button {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
body {
  background: var(--color-bg);
  color: var(--color-text);
  display: flex;
  flex-direction: column;
  line-height: 1.4;
  text-rendering: optimizeLegibility;
}

/* ── Header ────────────────────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  z-index: 50;
}
.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.app-logo {
  display: block;
  flex-shrink: 0;
}
.app-title {
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: -0.025em;
  color: var(--color-text);
  transition: opacity 0.35s ease;
}
.header-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}
.select-group {
  display: flex;
  align-items: center;
  gap: 6px;
}
.select-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--color-text-muted);
  letter-spacing: 0.05em;
}
.select-compact {
  font-size: 0.85rem;
  padding: 6px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  outline: none;
  transition: var(--transition);
}
.select-compact:hover { border-color: var(--color-text-muted); }

.settings-btn {
  width: 34px;
  height: 34px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}
.settings-btn:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
  border-color: var(--color-text-muted);
}

/* ── Main Layout ───────────────────────────────────────────────────────── */
.panels {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  min-height: 0;
  padding: 24px;
  gap: 12px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

.panel {
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  position: relative;
  transition: var(--transition);
}
.panel:focus-within {
  box-shadow: var(--shadow);
  border-color: var(--color-primary);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface-2);
  min-height: 8px;
}

.lang-select {
  font-size: 0.9rem;
  font-weight: 500;
  padding: 4px 8px;
  border: none;
  background: transparent;
  color: var(--color-text);
  cursor: pointer;
  outline: none;
}

.detected-badge {
  font-size: 0.75rem;
  background: var(--color-primary);
  color: #000;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 500;
}
.detected-badge.detecting {
  background: var(--color-surface-2);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
  font-style: italic;
  font-weight: 400;
}

/* ── Text Areas ────────────────────────────────────────────────────────── */
.textarea-container {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
}

.panel-textarea {
  flex: 1;
  width: 100%;
  padding: 20px;
  font-size: 1.1rem;
  line-height: 1.6;
  color: var(--color-text);
  border: none;
  resize: none;
  outline: none;
  background: transparent;
}

.panel-output-content {
  flex: 1;
  padding: 20px;
  font-size: 1.1rem;
  line-height: 1.6;
  color: var(--color-text);
  white-space: pre-wrap;
  word-break: break-word;
  overflow-y: auto;
  min-height: 0;
}
.panel-output-content .placeholder {
  color: var(--color-text-muted);
  font-style: italic;
}

/* ── Swap Button ───────────────────────────────────────────────────────── */
.swap-btn {
  align-self: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--color-border);
  border-radius: 50%;
  background: var(--color-surface);
  color: var(--color-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  z-index: 10;
}
.swap-btn:hover {
  transform: rotate(180deg);
  background: var(--color-primary);
  color: #000;
  border-color: var(--color-primary);
}
.swap-btn.inert {
  visibility: hidden;
  pointer-events: none;
}

/* ── Drop Overlay ──────────────────────────────────────────────────────── */
.drop-overlay {
  position: absolute;
  inset: 0;
  background: rgba(242, 169, 0, 0.1);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  pointer-events: none;
  border: 2px dashed var(--color-primary);
  margin: 8px;
  border-radius: var(--radius);
}
.drop-msg {
  background: var(--color-surface);
  padding: 12px 24px;
  border-radius: 999px;
  font-weight: 500;
  box-shadow: var(--shadow);
}

/* ── Footer ────────────────────────────────────────────────────────────── */
.panel-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-top: 1px solid var(--color-border);
}
.footer-left, .footer-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  color: var(--color-text-muted);
  cursor: pointer;
  border-radius: var(--radius);
  border: none;
  background: transparent;
  transition: var(--transition);
}
.icon-btn:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}
.icon-btn[aria-disabled="true"] {
  opacity: 0.35;
  cursor: not-allowed;
}
.icon-btn[aria-disabled="true"]:hover {
  background: transparent;
  color: var(--color-text-muted);
}

.lang-label {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--color-text-muted);
  font-style: italic;
}

.char-count {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

.chunk-progress {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  font-style: italic;
}

.incomplete-badge {
  font-size: 0.75rem;
  color: #d97706;
  font-style: italic;
}
.incomplete-badge::before {
  content: '\26A0\FE0F\00A0';
}

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn-primary {
  padding: 8px 20px;
  background: var(--color-primary);
  color: #000;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}
.btn-primary:hover { background: var(--color-primary-h); }
.btn-primary:active { background: var(--color-primary-h); }

.btn-ghost {
  padding: 6px 12px;
  background: transparent;
  color: var(--color-text-muted);
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 0.85rem;
  cursor: pointer;
  transition: var(--transition);
}
.btn-ghost:hover { background: var(--color-surface-2); color: var(--color-text); }

/* ── Config Panel ────────────────────────────────────────────────────────── */
.config-panel {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 16px 24px;
  box-shadow: var(--shadow-sm);
  animation: slideDown 0.1s ease-out;
}
@keyframes slideDown {
  from { transform: translateY(-20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.config-inner {
  max-width: 800px;
  margin: 0 auto;
}
.config-title { font-size: 0.8rem; font-weight: 700; color: var(--color-text-muted); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.05em; }
.config-row { display: flex; gap: 12px; align-items: center; }
.config-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface-2);
  color: var(--color-text);
  outline: none;
}
.config-input:focus { border-color: var(--color-primary); }
.config-row + .config-row { margin-top: 8px; }
.config-separator {
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.8rem;
  padding: 6px 0;
}

/* ── Notifications ───────────────────────────────────────────────────────── */
.notification {
  position: fixed;
  bottom: 56px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 24px;
  border-radius: 999px;
  background: var(--color-text);
  color: var(--color-bg);
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  z-index: 1000;
  animation: popUp 0.1s linear;
}
@keyframes popUp {
  from { transform: translate(-50%, 20px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}
.notification.error { background: var(--color-error); color: #fff; }
.notification.success { background: var(--color-success); color: #fff; }

/* ── Loading Animation ─────────────────────────────────────────────────── */
.loading {
  position: relative;
  overflow: hidden;
}
.loading::after {
  content: "";
  position: absolute;
  top: 0; left: -100%;
  width: 100%; height: 2px;
  background: linear-gradient(90deg, transparent, var(--color-primary), transparent);
  animation: loading-bar 1.5s infinite;
}
@keyframes loading-bar {
  to { left: 100%; }
}

/* ── Document List & Status ──────────────────────────────────────────────── */
.doc-list {
  padding: 16px 20px;
  background: var(--color-surface-2);
  border-top: 1px solid var(--color-border);
}
.doc-list-title {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--color-text-muted);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.doc-file-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.doc-file-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  color: var(--color-text);
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}
.doc-file-list li:hover {
  border-color: var(--color-text-muted);
}
.doc-dl-btn {
  margin-left: 12px;
}

.status-bar {
  padding: 10px 16px;
  background: var(--color-surface-2);
  border-top: 1px solid var(--color-border);
  font-size: 0.85rem;
  color: var(--color-text-muted);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.pending-file {
  display: flex;
  align-items: center;
  gap: 10px;
}
.pending-file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Voice recording ────────────────────────────────────────────────────── */
.icon-btn.recording {
  color: var(--color-error);
  animation: pulse-record 1s ease-in-out infinite;
}
@keyframes pulse-record {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

.icon-btn.transcribing {
  pointer-events: none;
  color: var(--color-primary);
}
.icon-btn.transcribing svg { display: none; }
.icon-btn.transcribing::before {
  content: '';
  display: block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

/* ── App Footer ─────────────────────────────────────────────────────────── */
.app-footer {
  flex-shrink: 0;
  text-align: center;
  padding: 6px 16px;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
}
.app-footer a {
  color: var(--color-text-muted);
  text-decoration: none;
}
.app-footer a:hover { color: var(--color-primary); }

/* ── Utilities ──────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .panels {
    grid-template-columns: 1fr;
    padding: 12px;
    gap: 0;
    overflow-y: auto;
  }
  /* Scale the button down so -½height margins cancel it out, leaving no dead space */
  .swap-btn {
    width: 32px;
    height: 32px;
    transform: rotate(90deg);
    margin: -16px auto;
  }
  .swap-btn:hover { transform: rotate(270deg); }
  body { overflow: auto; }
}

/* ── Mode Tabs ───────────────────────────────────────────────────────────── */
.source-header {
  gap: 8px;
  flex-wrap: wrap;
}
.source-lang-info {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}
.mode-tabs {
  display: flex;
  gap: 3px;
}
.mode-tab {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--color-text-muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}
.mode-tab:hover { background: var(--color-surface-2); color: var(--color-text); }
.mode-tab.active {
  background: var(--color-primary);
  color: #000;
  border-color: var(--color-primary);
}

/* ── Document Upload Area ────────────────────────────────────────────────── */
.doc-upload-area {
  flex: 1;
  display: flex;
  align-items: stretch;
  padding: 16px;
  min-height: 0;
}
.doc-upload-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  border: 2px dashed var(--color-border);
  border-radius: var(--radius);
  padding: 32px 20px;
  cursor: pointer;
  transition: var(--transition);
  color: var(--color-text-muted);
  text-align: center;
}
.doc-upload-zone:hover,
.doc-upload-area.drag-over .doc-upload-zone {
  border-color: var(--color-primary);
  background: rgba(242, 169, 0, 0.05);
  color: var(--color-text);
}
.doc-upload-text { font-size: 0.9rem; font-weight: 500; }
.doc-upload-link { color: var(--color-primary); text-decoration: underline; }
.doc-upload-hint { font-size: 0.78rem; color: var(--color-text-muted); }

/* ── Document mode: output panel layout ──────────────────────────────────── */
.panel-output.doc-mode .panel-output-content { display: none; }
.panel-output.doc-mode #results-doc-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  border-top: none;
  background: transparent;
  display: flex !important;
  flex-direction: column;
}
.doc-list-placeholder {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  font-style: italic;
  font-size: 1rem;
  padding: 20px;
  text-align: center;
}

/* ── Language Picker ─────────────────────────────────────────────────────── */
.lang-picker { position: relative; }
.lang-picker-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--color-text);
  background: transparent;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition);
}
.lang-picker-btn:hover { background: var(--color-surface-2); }
.lang-picker-chevron { color: var(--color-text-muted); flex-shrink: 0; transition: var(--transition); }
.lang-picker-btn[aria-expanded="true"] .lang-picker-chevron { transform: rotate(180deg); }
.lang-picker-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  width: 280px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 200;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.lang-search-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text-muted);
  flex-shrink: 0;
}
.lang-search-input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-size: 0.875rem;
  color: var(--color-text);
}
.lang-search-input::placeholder { color: var(--color-text-muted); }
.lang-list {
  list-style: none;
  overflow-y: auto;
  max-height: 260px;
  padding: 4px 0;
}
.lang-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 12px;
  font-size: 0.875rem;
  cursor: pointer;
  color: var(--color-text);
  transition: background 0.08s;
}
.lang-list-item:hover { background: var(--color-surface-2); }
.lang-list-item.selected { color: var(--color-primary); font-weight: 600; }
.lang-tts-icon { font-size: 0.7rem; opacity: 0.55; }
.lang-no-results {
  padding: 16px 12px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--color-text-muted);
  font-style: italic;
}

@media (max-width: 640px) {
  /* Header: wrap model selects below logo row */
  .app-header {
    flex-wrap: wrap;
    padding: 10px 16px;
    gap: 8px;
  }
  .header-left {
    flex: 1;
  }
  .settings-btn {
    flex-shrink: 0;
  }
  .header-controls {
    width: 100%;
    gap: 8px;
  }
  .select-group {
    flex: 1;
    min-width: 0;
  }
  .select-label {
    display: none;
  }
  .select-compact {
    width: 100%;
    min-width: 0;
    font-size: 0.8rem;
    padding: 6px 8px;
  }

  /* Config panel: stack inputs vertically */
  .config-panel {
    padding: 12px 16px;
  }
  .config-row {
    flex-wrap: wrap;
  }
  .config-input {
    flex: 1 1 100%;
  }

  /* Notification: prevent overflow */
  .notification {
    max-width: calc(100vw - 32px);
    text-align: center;
    white-space: normal;
    border-radius: var(--radius);
  }

  /* Panels: tighter padding on very small screens.
     gap intentionally omitted — the 900px rule sets gap:0 for the swap-btn fix. */
  .panels {
    padding: 8px;
  }
}
