/* ─── Reset & Tokens ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #f4f0e8;
  --card:         #ffffff;
  --border:       #cfc9bc;
  --border-light: #e5dfd4;

  --green:        #1b5e38;
  --green-hover:  #154d2e;
  --green-light:  #eaf4ee;

  --text:         #1a1a1a;
  --text-muted:   #6b6560;

  --blue:         #1565c0;
  --orange:       #d84315;

  --ok:           #2e7d32;
  --warn:         #e65100;
  --err:          #c62828;
  --idle:         #9e9e9e;

  --radius:       6px;
  --shadow:       0 1px 3px rgba(0,0,0,.10), 0 1px 2px rgba(0,0,0,.06);
}

/* ─── Base ───────────────────────────────────────────────── */
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  min-height: 100vh;
}

/* ─── App Shell ──────────────────────────────────────────── */
.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 24px 32px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 100vh;
}

/* ─── Header ─────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding-bottom: 4px;
}

.app-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  color: var(--text-muted);
  margin-bottom: 3px;
}

.app-title {
  font-size: 42px;
  font-weight: 700;
  line-height: 1;
  color: var(--text);
}

/* Connection badge */
.status-badge {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--idle);
  flex-shrink: 0;
  transition: background .3s;
}
.status-dot.connected  { background: var(--ok); }
.status-dot.connecting { background: var(--warn); animation: blink 1s ease-in-out infinite; }
.status-dot.error      { background: var(--err); }

@keyframes blink {
  0%,100% { opacity: 1; }
  50%      { opacity: .35; }
}

/* ─── Controls Card ──────────────────────────────────────── */
.controls-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow);
}

.controls-row {
  display: flex;
  align-items: flex-end;
  gap: 20px;
  flex-wrap: wrap;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.control-group.grow { flex: 1; min-width: 120px; }

.control-group.action-buttons {
  flex-direction: row;
  align-items: flex-end;
  gap: 6px;
}

.control-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  user-select: none;
}

/* ─── Select ─────────────────────────────────────────────── */
.select {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 26px 6px 10px;
  font-size: 13px;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23888'/%3E%3C/svg%3E") no-repeat right 9px center;
  -webkit-appearance: none;
  appearance: none;
  color: var(--text);
  cursor: pointer;
  min-width: 140px;
}
.select:focus { outline: none; border-color: var(--green); }
.select-wide  { min-width: 210px; }

/* ─── Tab Button Group ───────────────────────────────────── */
.btn-group {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.btn-tab {
  padding: 6px 13px;
  font-size: 13px;
  font-weight: 500;
  background: #fff;
  color: var(--text);
  border: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.btn-tab + .btn-tab { border-left: 1px solid var(--border); }
.btn-tab:hover:not(.active) { background: #f5f2ee; }
.btn-tab.active {
  background: var(--green);
  color: #fff;
}

/* ─── Action Buttons ─────────────────────────────────────── */
.btn-primary, .btn-secondary {
  padding: 7px 22px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}

.btn-primary {
  background: var(--green);
  color: #fff;
  border: none;
}
.btn-primary:hover:not(:disabled) { background: var(--green-hover); }
.btn-primary:disabled  { opacity: .4; cursor: not-allowed; }

.btn-secondary {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { background: #f5f2ee; }
.btn-secondary:disabled { opacity: .4; cursor: not-allowed; }

/* ─── Range Slider ───────────────────────────────────────── */
.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  outline: none;
  cursor: pointer;
  /* track color set dynamically via JS */
  background: #d0cbc2;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #bbb;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
  cursor: pointer;
  transition: border-color .15s;
}
.slider[data-color="blue"]::-webkit-slider-thumb  { border-color: var(--blue); }
.slider[data-color="orange"]::-webkit-slider-thumb { border-color: var(--orange); }

.slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #bbb;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
  cursor: pointer;
}
.slider[data-color="blue"]::-moz-range-thumb  { border-color: var(--blue); }
.slider[data-color="orange"]::-moz-range-thumb { border-color: var(--orange); }

/* ─── Disabled group ─────────────────────────────────────── */
.group-disabled {
  opacity: .45;
  pointer-events: none;
}

/* ─── Status Bar ─────────────────────────────────────────── */
.status-bar {
  display: flex;
  align-items: center;
  gap: 32px;
  padding: 8px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 12px;
  flex-wrap: wrap;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 9px;
}

.status-key {
  color: var(--text-muted);
  font-weight: 500;
  min-width: 44px;
}

.status-val {
  color: var(--idle);
  font-weight: 400;
}
.status-val.ok       { color: var(--ok);   font-weight: 500; }
.status-val.warn     { color: var(--warn); font-weight: 500; }
.status-val.err      { color: var(--err);  font-weight: 500; }

/* ─── Caption Panels ─────────────────────────────────────── */
.panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  flex: 1;
}

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 280px;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}

.panel-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.btn-clear {
  font-size: 12px;
  color: var(--text-muted);
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 9px;
  cursor: pointer;
  transition: background .15s;
}
.btn-clear:hover { background: #f5f2ee; }

.panel-body {
  flex: 1;
  padding: 14px 16px;
  overflow-y: auto;
  font-size: 15px;
  line-height: 1.75;
  color: var(--text);
}

/* Caption text segments */
.seg-input {
  margin-bottom: 6px;
}

.seg-translation {
  margin-bottom: 10px;
}

.seg-translation.streaming {
  color: var(--text-muted);
}

/* Subtle scrollbar */
.panel-body::-webkit-scrollbar { width: 6px; }
.panel-body::-webkit-scrollbar-track { background: transparent; }
.panel-body::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }

/* ─── Toast notifications ────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  max-width: 380px;
  background: #323232;
  color: #fff;
  padding: 11px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  line-height: 1.5;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
  z-index: 9999;
  animation: toastIn .2s ease;
}
.toast.error { background: var(--err); }

@keyframes toastIn {
  from { transform: translateY(16px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* ─── Responsive ─────────────────────────────────────────── */
@media (max-width: 720px) {
  .app-title { font-size: 30px; }
  .panels    { grid-template-columns: 1fr; }
  .controls-row { gap: 14px; }
}
