/* Zerodha design language — white surface, #387ed1 blue, Inter, clean lines */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --blue:       #387ed1;
  --blue-dark:  #2c67b3;
  --blue-light: #eef4fd;
  --black:      #1a1a1a;
  --text:       #444444;
  --muted:      #999999;
  --line:       #e0e0e0;
  --off:        #f7f7f8;
  --white:      #ffffff;

  --success:    #27ae60;
  --warning:    #d97706;
  --error:      #dc2626;

  --radius:     8px;
  --shadow:     0 1px 4px rgba(0,0,0,0.08);
}

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

html { -webkit-font-smoothing: antialiased; }

html, body { height: 100%; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  background: var(--off);
  color: var(--text);
  line-height: 1.65;
}

/* ── Layout ── */
.page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Header ── */
.header {
  background: rgba(255,255,255,0.97);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  padding: 0 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 14px;
  text-decoration: none;
}

.header-logo img {
  height: 22px;
  width: auto;
  display: block;
}

.header-divider {
  width: 1px;
  height: 18px;
  background: var(--line);
}

.header-product {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 2px;
}

.header-nav a {
  font-size: 0.85rem;
  color: var(--muted);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.header-nav a:hover {
  background: var(--off);
  color: var(--black);
}

/* ── Main ── */
.main {
  flex: 1;
  padding: 20px 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
}

/* ── Controls bar ── */
.controls {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 18px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  box-shadow: var(--shadow);
}

.control-group {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.875rem;
  color: var(--muted);
}

.control-group label {
  white-space: nowrap;
  font-weight: 500;
  color: var(--text);
}

.control-group select {
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 0.875rem;
  font-family: inherit;
  background: var(--off);
  color: var(--black);
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
}

.control-group select:focus {
  border-color: var(--blue);
}

.control-group input[type="checkbox"] {
  accent-color: var(--blue);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

.controls-spacer { flex: 1; }

/* ── Split editor ── */
.split-editor {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  flex: 1;
}

.editor-pane {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow);
  min-height: 540px;
}

.pane-header {
  background: var(--white);
  border-bottom: 1px solid var(--line);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.pane-title {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}

.pane-meta {
  font-size: 0.78rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

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

/* Copy button in cleaned pane header */
.pane-copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--white);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  white-space: nowrap;
}

.pane-copy-btn:hover {
  border-color: var(--blue);
  color: var(--blue);
  background: var(--blue-light);
}

.pane-copy-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.pane-copy-btn.copied {
  border-color: var(--success);
  color: var(--success);
  background: #f0fff4;
}

/* ── Output area ── */
.output-area {
  flex: 1;
  padding: 18px 20px;
  overflow-y: auto;
  font-family: inherit;
  font-size: 14.5px;
  line-height: 1.85;
  word-break: break-word;
  color: var(--text);
  position: relative;
}

.output-placeholder {
  position: absolute;
  top: 18px;
  left: 20px;
  color: #c8c8c8;
  font-style: italic;
  font-size: 0.9rem;
  pointer-events: none;
}

.output-area p {
  margin: 0 0 1.1em 0;
  line-height: 1.85;
  color: var(--text);
}

.output-area p:last-child { margin-bottom: 0; }

/* Production direction chips */
.prod-direction {
  display: block;
  background: #eef4fd;
  border-left: 3px solid var(--blue);
  color: #2c67b3;
  font-size: 0.82rem;
  font-family: "SF Mono", "Fira Code", "Menlo", monospace;
  padding: 4px 10px;
  border-radius: 0 5px 5px 0;
  margin: 0.6em 0;
  white-space: pre-wrap;
}

.prod-direction-inline {
  display: inline-block;
  background: #eef4fd;
  border-left: 2px solid var(--blue);
  color: #2c67b3;
  font-size: 0.82rem;
  font-family: "SF Mono", "Fira Code", "Menlo", monospace;
  padding: 1px 8px;
  border-radius: 0 4px 4px 0;
  margin: 2px 0;
}

/* ── Original textarea ── */
textarea#original-script {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  padding: 18px 20px;
  font-family: inherit;
  font-size: 14.5px;
  line-height: 1.85;
  color: var(--text);
  background: var(--white);
  width: 100%;
}

textarea#original-script::placeholder {
  color: #c8c8c8;
  font-style: italic;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border: none;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
  white-space: nowrap;
  text-decoration: none;
}

.btn:active { transform: scale(0.97); }

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  background: var(--blue);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--blue-dark);
}

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

.btn-ghost:hover:not(:disabled) {
  background: var(--off);
  color: var(--black);
  border-color: #c0c0c0;
}

.btn-sm {
  padding: 5px 12px;
  font-size: 0.8rem;
}

/* ── Status bar ── */
.status-bar {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  box-shadow: var(--shadow);
}

#status-text { color: var(--muted); }
#status-text.status-success { color: var(--success); }
#status-text.status-error   { color: var(--error); }
#status-text.status-warning { color: var(--warning); }
#status-text.status-working { color: var(--blue); }

.loader {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--blue);
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--line);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
  flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Change stats bar ── */
.change-stats {
  background: var(--blue-light);
  border-bottom: 1px solid #c8ddf5;
  padding: 8px 18px;
  font-size: 0.82rem;
  color: var(--blue-dark);
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.change-stat-item {
  display: flex;
  align-items: center;
  gap: 5px;
}

.change-stat-item strong { font-weight: 700; }

/* "Already close to style" notice */
.clean-notice {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 4px;
  padding: 2px 9px;
  font-size: 0.79rem;
  color: var(--success);
  font-weight: 500;
  margin-left: 4px;
}

/* ── Fact check bar ── */
.fact-bar {
  border-bottom: 1px solid var(--line);
  padding: 8px 18px;
  font-size: 0.82rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.fact-bar.fact-ok {
  background: #f0fdf4;
  border-bottom-color: #bbf7d0;
  color: var(--success);
}

.fact-bar.fact-issues {
  background: #fffbeb;
  border-bottom-color: #fde68a;
  color: #92400e;
}

.fact-bar.fact-no-kb {
  background: var(--off);
  color: var(--muted);
}

.fact-bar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}

.fact-bar-toggle {
  background: none;
  border: 1px solid currentColor;
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 0.78rem;
  font-family: inherit;
  cursor: pointer;
  color: inherit;
  opacity: 0.8;
  white-space: nowrap;
  transition: opacity 0.15s;
}

.fact-bar-toggle:hover { opacity: 1; }

/* ── Issues list ── */
.issues-list {
  background: var(--white);
  border-bottom: 1px solid var(--line);
  padding: 12px 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
  max-height: 260px;
  overflow-y: auto;
}

.inline-issue {
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 0.85rem;
  border-left: 3px solid transparent;
  line-height: 1.5;
}

.inline-issue.issue-incorrect  { background: #fff5f5; border-left-color: var(--error); }
.inline-issue.issue-unverified { background: #fffbeb; border-left-color: var(--warning); }
.inline-issue.issue-outdated   { background: #fff8f0; border-left-color: #ea580c; }

.inline-issue-type {
  font-weight: 700;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 2px;
}

.inline-issue.issue-incorrect .inline-issue-type  { color: var(--error); }
.inline-issue.issue-unverified .inline-issue-type { color: var(--warning); }
.inline-issue.issue-outdated .inline-issue-type   { color: #ea580c; }

.inline-issue-claim { font-style: italic; color: var(--black); margin-bottom: 2px; }
.inline-issue-details { color: var(--muted); font-size: 0.82rem; }

.inline-issue-source {
  margin-top: 3px;
  font-size: 0.78rem;
  color: var(--blue);
}

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
  backdrop-filter: blur(3px);
}

.modal {
  background: var(--white);
  border-radius: var(--radius);
  width: 100%;
  max-width: 860px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 40px rgba(0,0,0,0.15);
  overflow: hidden;
}

.modal-header {
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h2 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--black);
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
  padding: 2px 8px;
  border-radius: 4px;
  transition: background 0.15s;
  font-family: inherit;
}

.modal-close:hover { background: var(--off); color: var(--black); }

.modal-body {
  overflow-y: auto;
  padding: 20px 22px;
  flex: 1;
}

.stats-row {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.stat-chip {
  background: var(--off);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 0.85rem;
}

.stat-chip strong { color: var(--blue); }

/* ── Diff display ── */
.diff-block {
  font-family: "SF Mono", "Fira Code", "Menlo", monospace;
  font-size: 12.5px;
  line-height: 1.65;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.diff-line {
  padding: 2px 14px;
  white-space: pre-wrap;
  word-break: break-word;
}

.diff-line.removed { background: #fff5f5; color: #b91c1c; }
.diff-line.added   { background: #f0fdf4; color: #15803d; }
.diff-line.context { color: var(--muted); }

.diff-line.header {
  background: var(--off);
  color: var(--muted);
  font-weight: 600;
  padding: 6px 14px;
  border-bottom: 1px solid var(--line);
}

/* ── btn-icon ── */
.btn-icon {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
  padding: 2px 6px;
}

.btn-icon:hover { color: var(--black); }

/* ── Admin / KB pages ── */
.admin-main { max-width: 820px; }

.admin-header { padding-bottom: 8px; }

.admin-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--black);
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}

.admin-subtitle {
  color: var(--muted);
  font-size: 0.93rem;
  line-height: 1.6;
}

.admin-section {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.admin-section h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--black);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-hint {
  color: var(--muted);
  font-size: 0.88rem;
  margin-bottom: 16px;
  line-height: 1.5;
}

.section-hint code {
  background: var(--off);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 0.83rem;
}

.badge {
  background: var(--blue);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 20px;
}

.kb-upload-tabs {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  width: fit-content;
  margin-bottom: 18px;
}

.kb-tab {
  padding: 6px 16px;
  font-size: 0.88rem;
  font-family: inherit;
  border: none;
  background: var(--off);
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s;
}

.kb-tab.active {
  background: var(--blue);
  color: #fff;
  font-weight: 500;
}

.kb-tab-content {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-row { display: flex; flex-direction: column; gap: 5px; }

.form-row label {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--black);
}

.form-row .hint { font-weight: 400; color: var(--muted); }

.text-input {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--off);
  color: var(--black);
  outline: none;
  transition: border-color 0.15s;
}

.text-input:focus { border-color: var(--blue); }

.kb-textarea {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 0.88rem;
  font-family: "SF Mono", "Fira Code", "Menlo", monospace;
  line-height: 1.65;
  background: var(--off);
  color: var(--black);
  resize: vertical;
  min-height: 180px;
  outline: none;
  transition: border-color 0.15s;
}

.kb-textarea:focus { border-color: var(--blue); }

.drop-zone {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  cursor: pointer;
  background: var(--off);
  transition: border-color 0.15s, background 0.15s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.drop-zone:hover, .drop-zone-active {
  border-color: var(--blue);
  background: var(--blue-light);
}

.drop-zone p { font-size: 0.9rem; color: var(--muted); }
.drop-zone svg { color: var(--muted); margin-bottom: 4px; }

.status-message {
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 0.88rem;
  margin-top: 4px;
}

.status-success { background: #f0fdf4; color: var(--success); }
.status-error   { background: #fff5f5; color: var(--error); }
.status-working { background: var(--blue-light); color: var(--blue); }

.doc-list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }

.doc-item {
  background: var(--off);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.doc-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.doc-name { font-weight: 600; font-size: 0.9rem; color: var(--black); }
.doc-desc { font-size: 0.83rem; color: var(--muted); }
.doc-meta { font-size: 0.78rem; color: #c0c0c0; }

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

/* ── KB stats ── */
.kb-stats-grid { display: flex; gap: 16px; flex-wrap: wrap; }

.kb-stat {
  background: var(--off);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px 20px;
  min-width: 160px;
}

.kb-stat-value { font-size: 1.25rem; font-weight: 700; color: var(--blue); word-break: break-all; }
.kb-stat-label { font-size: 0.78rem; color: var(--muted); margin-top: 2px; }

.kb-empty-state {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

/* ── Progress bar ── */
.progress-bar-track { height: 4px; background: var(--line); border-radius: 99px; overflow: hidden; }

.progress-bar-fill {
  height: 100%;
  background: var(--blue);
  border-radius: 99px;
  transition: width 0.3s ease;
  width: 0%;
}

/* ── KB staleness banner ── */
.kb-stale-banner {
  border-radius: var(--radius);
  padding: 9px 18px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.kb-stale-banner.kb-stale-warning {
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
}

.kb-stale-banner a { color: var(--blue); font-weight: 600; text-decoration: none; }
.kb-stale-banner a:hover { text-decoration: underline; }

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

/* ── Responsive ── */
@media (max-width: 900px) {
  .split-editor { grid-template-columns: 1fr; }
  .main { padding: 14px 16px 20px; }
  .header { padding: 0 16px; }
}
