:root {
  --bg: #f4f4f4;
  --surface: #ffffff;
  --surface-2: #ebebeb;
  --surface-3: #e2e2e2;
  --border: #d4d4d4;
  --border-strong: #111111;
  --text: #111111;
  --muted: #666666;
  --muted-light: #999999;
  --accent: #111111;
  --accent-hover: #333333;
  --inverse: #ffffff;
  --radius: 6px;
  --radius-sm: 4px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  --topbar-h: 52px;
  font-family: "Segoe UI", Inter, system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { min-height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }

/* ——— Login ——— */

.screen { min-height: 100%; }

#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-shell { width: 100%; max-width: 360px; }

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px 24px;
  box-shadow: var(--shadow);
}

.brand {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.04em;
  color: var(--text);
}

.brand-sub {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 4px 0 20px;
}

.login-hint { margin-bottom: 16px; }

.muted { color: var(--muted); }

/* ——— Forms ——— */

input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  margin-bottom: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  transition: border-color 0.12s ease;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--border-strong);
}

textarea { min-height: 100px; resize: vertical; }

input[type="file"] {
  padding: 6px 8px;
  font-size: 13px;
}

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

/* ——— Buttons ——— */

.btn {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  min-height: 32px;
  font-weight: 500;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  line-height: 1.2;
  white-space: nowrap;
  background: var(--surface);
  color: var(--text);
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.btn:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--muted-light);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--inverse);
}

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

.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}

.btn.ghost:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}

.btn.block { width: 100%; }

.btn.small {
  min-height: 28px;
  padding: 0 10px;
  font-size: 12px;
}

.btn.icon { min-width: 28px; padding-inline: 8px; }

.btn.warn,
.btn.success,
.btn.danger {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn.warn:hover:not(:disabled),
.btn.success:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--text);
}

.btn.danger {
  color: var(--text);
}

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

.error {
  color: var(--text);
  margin-top: 8px;
  font-size: 12px;
  font-weight: 500;
}

/* ——— Top bar ——— */

#main-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 20px;
  min-height: var(--topbar-h);
  padding: 0 24px;
  max-width: 1440px;
  margin: 0 auto;
  width: 100%;
}

.topbar-brand {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.04em;
  color: var(--text);
  flex-shrink: 0;
  line-height: 1;
}

.topnav {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.topnav::-webkit-scrollbar { display: none; }

.nav {
  flex-shrink: 0;
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 500;
  font-size: 13px;
  min-height: 32px;
  white-space: nowrap;
  transition: color 0.12s ease, background 0.12s ease;
}

.nav:hover {
  color: var(--text);
  background: var(--surface-2);
}

.nav.active {
  color: var(--text);
  background: var(--surface-2);
  font-weight: 600;
  box-shadow: inset 0 -2px 0 var(--text);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.topbar-actions {
  flex-shrink: 0;
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.lang-picker {
  display: flex;
  align-items: center;
  gap: 2px;
}

.lang-picker-login {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 200;
}

.lang-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}

.lang-btn:hover {
  background: var(--surface-2);
}

.lang-btn.active {
  border-color: var(--text);
  background: var(--surface-2);
}

.lang-flag {
  font-size: 18px;
  line-height: 1;
}

/* ——— Content ——— */

.content {
  flex: 1;
  min-width: 0;
  padding: 24px 24px 48px;
  max-width: 1440px;
  margin: 0 auto;
  width: 100%;
}

.view { max-width: 100%; }

.view-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.view-header h1 {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.3;
  margin: 0;
  letter-spacing: -0.02em;
}

.view-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  min-width: 0;
}

.view-header-title {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* ——— Cards & layout ——— */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.card h3 {
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.card-header h3 { margin: 0; }

.stats-block { margin-bottom: 12px; }

.textarea-lg { min-height: 200px; }
.textarea-md { min-height: 120px; }

.form-grid-action { display: flex; align-items: flex-end; }

/* ——— Badges (monochrome) ——— */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
  text-transform: lowercase;
}

.badge-running {
  background: var(--text);
  color: var(--inverse);
  border-color: var(--text);
}

.badge-paused {
  background: var(--surface);
  color: var(--text);
  border-color: var(--text);
}

.badge-completed {
  background: var(--surface-2);
  color: var(--muted);
}

.badge-pending,
.badge-active {
  background: var(--surface);
  color: var(--muted);
}

/* ——— Stats ——— */

.stats {
  display: flex;
  gap: 8px;
  margin: 0;
  flex-wrap: wrap;
}

.stat {
  flex: 1;
  min-width: 88px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  text-align: left;
}

.stat .val {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.stat .lbl {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 2px;
}

/* ——— Tables ——— */

.table-wrap {
  margin-bottom: 12px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.data-table,
table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
  background: var(--surface);
}

.data-table { border: none; }

th, td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  text-align: left;
  vertical-align: top;
}

tr:last-child td { border-bottom: none; }

th {
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--bg);
  font-weight: 600;
  white-space: nowrap;
}

tbody tr:hover td { background: #fafafa; }

td.cell-actions {
  white-space: nowrap;
  width: 1%;
}

.cell-preview {
  max-width: 420px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

a {
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 2px;
}

a:hover { color: var(--muted); }

/* ——— Tabs ——— */

.tabs {
  display: flex;
  gap: 0;
  margin-bottom: 16px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
}

.tab {
  background: transparent;
  color: var(--muted);
  border: none;
  border-bottom: 2px solid transparent;
  padding: 8px 14px;
  border-radius: 0;
  cursor: pointer;
  font-weight: 500;
  font-size: 13px;
  min-height: 36px;
  margin-bottom: -1px;
  transition: color 0.12s ease, border-color 0.12s ease;
}

.tab:hover { color: var(--text); }

.tab.active {
  color: var(--text);
  border-bottom-color: var(--text);
  font-weight: 600;
}

/* ——— Toast & modal ——— */

.toast-stack {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  animation: toast-in 0.15s ease;
}

.toast.success,
.toast.error,
.toast.warn {
  border-color: var(--border-strong);
}

.toast-title {
  font-weight: 600;
  margin-bottom: 2px;
  font-size: 13px;
}

.toast-body {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
  white-space: pre-wrap;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
}

.modal h3 {
  margin-bottom: 8px;
  font-size: 15px;
  font-weight: 600;
}

.modal p {
  color: var(--muted);
  line-height: 1.5;
  margin-bottom: 16px;
  white-space: pre-wrap;
  font-size: 13px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.modal-wide {
  width: min(520px, 100%);
}

.modal-export {
  width: min(560px, 100%);
  max-height: min(90vh, 720px);
  display: flex;
  flex-direction: column;
}

.modal-export .export-columns-grid {
  flex: 1;
  min-height: 0;
}

.export-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.export-columns-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px 16px;
  max-height: 280px;
  overflow-y: auto;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  background: var(--surface-2);
}

.export-col-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 5px 0;
  font-size: 13px;
  line-height: 1.35;
  cursor: pointer;
  min-width: 0;
}

.export-col-item span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.export-link-hint {
  margin-bottom: 16px !important;
  font-size: 12px !important;
}

.export-columns {
  max-height: 320px;
  overflow-y: auto;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
}

.export-col-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-size: 13px;
  cursor: pointer;
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.clickable-row {
  cursor: pointer;
}

.clickable-row:hover td {
  background: var(--surface-2);
}

.modal-call-detail {
  width: min(720px, 100%);
  max-height: min(90vh, 860px);
  overflow-y: auto;
}

.modal-call-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.modal-call-header h3 {
  margin-bottom: 4px;
}

.modal-call-header .hint {
  margin-bottom: 0;
}

.detail-dl {
  display: grid;
  gap: 0;
  margin-bottom: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.detail-dl-compact {
  grid-template-columns: 1fr;
}

.detail-dl-row {
  display: grid;
  grid-template-columns: minmax(120px, 34%) 1fr;
  gap: 12px;
  padding: 8px 12px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}

.detail-dl-row:last-child {
  border-bottom: none;
}

.detail-dl-row:nth-child(even) {
  background: var(--surface-2);
}

.detail-dl-row dt {
  color: var(--muted);
  font-weight: 500;
}

.detail-dl-row dd {
  margin: 0;
  word-break: break-word;
}

.call-transcript {
  margin: 0 0 8px;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 320px;
  overflow-y: auto;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.live-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--inverse);
  margin-right: 5px;
  animation: pulse 1.4s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ——— Forms & misc ——— */

.schema-row {
  display: grid;
  grid-template-columns: 1fr 2fr auto;
  gap: 8px;
  margin-bottom: 8px;
  align-items: center;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

.section-title {
  font-size: 11px;
  margin: 16px 0 8px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.section-title:first-child { margin-top: 0; }

.hint {
  font-size: 12px;
  color: var(--muted);
  margin: 6px 0 10px;
  line-height: 1.5;
}

.hint code {
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 11px;
  border: 1px solid var(--border);
}

.provider-row {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 8px;
  background: var(--bg);
}

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 6px;
  margin-bottom: 10px;
}

.checkbox-grid label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
  margin-bottom: 0;
  color: var(--text);
}

.checkbox-grid input { width: auto; margin: 0; }

.checkbox-group { margin-bottom: 10px; }

.checkbox-group-title {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

pre.preview {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 12px;
  white-space: pre-wrap;
  margin: 6px 0 12px;
  color: var(--muted);
  line-height: 1.5;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
}

.transcript-cell { max-width: 280px; }

.verdict {
  display: inline-block;
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
}

.verdict-pass {
  background: var(--text);
  color: var(--inverse);
  border-color: var(--text);
}

.verdict-fail {
  background: var(--surface);
  color: var(--text);
  border-color: var(--text);
}

.verdict-needs_review {
  background: var(--surface-2);
  color: var(--muted);
}

.scorecard-row {
  display: grid;
  grid-template-columns: 1fr 1.2fr 72px auto;
  gap: 8px;
  margin-bottom: 8px;
  align-items: center;
}

.qa-feedback {
  white-space: pre-wrap;
  max-width: 420px;
  line-height: 1.45;
  font-size: 13px;
  color: var(--muted);
}

.ok-text { color: var(--text) !important; font-weight: 500; }

.file-columns-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 10px;
}

.file-columns-list {
  margin: 0;
  padding-left: 18px;
  font-size: 13px;
}

.file-columns-list li { margin-bottom: 3px; }

.file-columns-list code {
  background: var(--surface);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12px;
  border: 1px solid var(--border);
}

.campaign-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* ——— Responsive ——— */

@media (max-width: 768px) {
  .topbar-inner {
    flex-wrap: wrap;
    padding: 10px 16px;
    gap: 8px;
    min-height: auto;
  }

  .topnav {
    order: 3;
    width: 100%;
    padding-bottom: 2px;
  }

  .content {
    padding: 16px 16px 40px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .view-header h1 {
    font-size: 16px;
  }
}
