/* ── Theme Variables ── */
:root {
  --bg-start: #F8FAFC;
  --bg-end: #F1F5F9;
  --card-bg: #ffffff;
  --card-header-bg: #F1F5F9;
  --card-header-color: #64748B;
  --border: #E2E8F0;
  --text: #0F172A;
  --text-muted: #64748B;
  --chat-bg: #ffffff;
  --bubble-in-bg: #F1F5F9;
  --bubble-in-text: #0F172A;
  --doc-bg: #ffffff;
  --doc-h1: #0F172A;
  --doc-h2: #0071E3;
  --doc-text: #1E293B;
  --placeholder: #CBD5E1;
  --header-bg: rgba(248,250,252,0.85);
  --upload-border: #CBD5E1;
  --upload-bg: #ffffff;
  --upload-text: #0071E3;
  --upload-hover: #F1F5F9;
  --status-bg: rgba(15,23,42,0.05);
  --progress-bg: rgba(15,23,42,0.06);
  --progress-fill: #0071E3;
  --accent: #0071E3;
}

[data-theme="dark"] {
  --bg-start: #0F172A;
  --bg-end: #1A202C;
  --card-bg: #1E293B;
  --card-header-bg: #334155;
  --card-header-color: #94A3B8;
  --border: #475569;
  --text: #F1F5F9;
  --text-muted: #94A3B8;
  --chat-bg: #1E293B;
  --bubble-in-bg: #334155;
  --bubble-in-text: #F1F5F9;
  --doc-bg: #1E293B;
  --doc-h1: #F1F5F9;
  --doc-h2: #60A5FA;
  --doc-text: #E2E8F0;
  --placeholder: #64748B;
  --header-bg: rgba(15,23,42,0.82);
  --upload-border: #64748B;
  --upload-bg: #1E293B;
  --upload-text: #60A5FA;
  --upload-hover: #334155;
  --status-bg: rgba(241,245,249,0.06);
  --progress-bg: rgba(241,245,249,0.06);
  --progress-fill: #60A5FA;
  --accent: #60A5FA;
}

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

body {
  font-family: 'Inter', 'Hind Siliguri', sans-serif;
  background: linear-gradient(135deg, var(--bg-start) 0%, var(--bg-end) 100%);
  color: var(--text);
  display: flex;
  flex-direction: column;
  transition: background 0.3s;
}

/* ── Header ── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 18px;
  background: var(--header-bg);
  backdrop-filter: blur(10px);
  color: white;
  flex-shrink: 0;
  z-index: 10;
}
.app-title { font-size: 0.95rem; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.app-icon { width: 22px; height: 22px; border-radius: 5px; flex-shrink: 0; }
.header-right { display: flex; align-items: center; gap: 10px; }
.header-status {
  font-size: 0.78rem;
  background: var(--status-bg);
  padding: 3px 11px;
  border-radius: 20px;
  color: rgba(255,255,255,0.85);
}
.btn-theme {
  background: var(--status-bg);
  border: none;
  border-radius: 50%;
  width: 30px; height: 30px;
  cursor: pointer;
  font-size: 0.95rem;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
}
.btn-theme:hover { background: rgba(255,255,255,0.2); }

/* ── Progress Bar ── */
.progress-bar-wrap {
  height: 3px;
  background: var(--progress-bg);
  flex-shrink: 0;
  display: none;
  overflow: hidden;
}
body[data-state="processing"] .progress-bar-wrap { display: block; }

.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
  transition: width 0.6s ease;
  width: 0%;
}

/* ── Grid ── */
.app-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 5fr 7fr;
  grid-template-rows: 2fr 2.8fr;
  grid-template-areas:
    "recorder canvas"
    "raw      canvas";
  gap: 10px;
  padding: 10px;
  min-height: 0;
}

/* ── Cards ── */
.card {
  background: var(--card-bg);
  border-radius: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 4px 16px rgba(0,0,0,0.06);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  transition: background 0.3s;
  position: relative;
}
[data-theme="dark"] .card {
  box-shadow: 0 1px 0 rgba(255,255,255,0.04), 0 4px 20px rgba(0,0,0,0.5);
}
.card-recorder { grid-area: recorder; }
.card-raw      { grid-area: raw; }
.card-canvas   { grid-area: canvas; grid-row: 1 / 3; }

/* ── Loading state ── */
.card.loading .card-header::after {
  content: '';
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent);
  margin-left: 8px;
  animation: pulse-fast 0.9s ease-in-out infinite;
  vertical-align: middle;
}

.loading-hint {
  display: none;
  position: relative;
  overflow: hidden;
  font-size: 0.68rem;
  color: var(--text-muted);
  font-style: italic;
  font-family: 'Inter', sans-serif;
  padding: 6px 14px 6px;
  flex-shrink: 0;
  background: var(--card-header-bg);
  border-bottom: 1px solid var(--border);
  transition: opacity 0.25s ease;
}
.card.loading .loading-hint { display: block; }

/* Shimmer bar inside the hint */
.loading-hint::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent 0%, var(--accent) 40%, var(--accent) 60%, transparent 100%);
  background-size: 300% 100%;
  animation: card-shimmer 1.4s ease-in-out infinite;
}
@keyframes card-shimmer {
  0%   { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

.card-header {
  padding: 10px 14px;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--card-header-color);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  border-bottom: 1px solid var(--border);
  background: var(--card-header-bg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  transition: background 0.3s, border-color 0.3s;
}
.card-body { flex: 1; overflow-y: auto; min-height: 0; }

/* ── Recorder ── */
.recorder-body {
  padding: 20px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.recorder-body > * { width: 100%; }
.status-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 1.4rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-family: 'Inter', monospace;
  color: var(--text);
}
.pulse-ring {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: pulse 2s infinite;
  flex-shrink: 0;
}
body[data-state="recording"] .pulse-ring { background: #FF3B30; animation: pulse-fast 0.6s infinite; }
[data-theme="dark"] body[data-state="recording"] .pulse-ring { background: #FF453A; }
body[data-state="processing"] .pulse-ring { background: #FF9500; animation: pulse-fast 0.4s infinite; }

@keyframes pulse { 0%,100%{opacity:1;transform:scale(1)}50%{opacity:.4;transform:scale(1.3)} }
@keyframes pulse-fast { 0%,100%{opacity:1;transform:scale(1)}50%{opacity:.5;transform:scale(1.4)} }

#visualizer {
  width: 100%; height: 56px;
  border-radius: 8px;
  background: var(--card-header-bg);
  display: none;
}
body[data-state="recording"] #visualizer { display: block; }

.btn-record {
  width: 100%;
  max-width: 280px;
  background: var(--accent);
  color: white;
  border: none;
  padding: 11px 20px;
  font-size: 0.92rem;
  border-radius: 10px;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  font-weight: 600;
  transition: opacity 0.2s, transform 0.1s;
  box-shadow: 0 2px 8px rgba(0,113,227,0.28);
}
.btn-record:hover { opacity: 0.9; transform: translateY(-1px); }
body[data-state="recording"] .btn-record { background: #FF3B30; box-shadow: 0 2px 8px rgba(255,59,48,0.28); }
body[data-state="processing"] .btn-record { background: #3A3A3C; cursor: not-allowed; box-shadow: none; }

.btn-pause {
  width: 100%;
  max-width: 280px;
  background: #FF9500;
  color: white;
  border: none;
  padding: 11px 20px;
  font-size: 0.92rem;
  border-radius: 10px;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  font-weight: 600;
  transition: opacity 0.2s, transform 0.1s;
  box-shadow: 0 2px 8px rgba(255,149,0,0.28);
}
.btn-pause:hover { opacity: 0.9; transform: translateY(-1px); }
body[data-state="processing"] .btn-pause { display: none; }

.divider { width:100%; display:flex; align-items:center; gap:10px; color:var(--text-muted); font-size:0.72rem; }
.divider::before,.divider::after { content:''; flex:1; height:1px; background:var(--border); }

.btn-upload {
  width: 100%;
  max-width: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--upload-bg);
  color: var(--upload-text);
  border: 2px dashed var(--upload-border);
  padding: 10px 20px;
  font-size: 0.88rem;
  border-radius: 9px;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  font-weight: 600;
  transition: all 0.2s;
}
.btn-upload:hover { background: var(--upload-hover); border-color: var(--upload-text); }
body[data-state="processing"] .btn-upload,
body[data-state="recording"] .btn-upload { opacity: 0.35; pointer-events: none; }

.upload-filename { font-size: 0.72rem; color: var(--upload-text); min-height: 1em; text-align: center; }
.current-filename { font-size: 0.7rem; color: var(--text-muted); text-align: center; word-break: break-all; }
.current-filename a { color: var(--accent); text-decoration: none; }

.upload-status {
  width: 100%;
  max-width: 280px;
  background: rgba(0,0,0,0.05);
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 0.78rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: 'Inter', sans-serif;
}
[data-theme="dark"] .upload-status { background: rgba(255,255,255,0.04); border-color: rgba(255,255,255,0.08); }
.upload-status.info { color: var(--accent); background: rgba(0,113,227,0.08); border-color: rgba(0,113,227,0.2); }
[data-theme="dark"] .upload-status.info { background: rgba(10,132,255,0.12); border-color: rgba(10,132,255,0.2); }
.upload-status.warn { color: #FF9500; background: rgba(255,149,0,0.08); border-color: rgba(255,149,0,0.2); }

/* ── Chat Window ── */
.chat-window { padding: 12px; display: flex; flex-direction: column; gap: 9px; background: var(--chat-bg); }
.chat-placeholder { color: var(--placeholder); font-size: 0.85rem; text-align: center; margin: auto; }

.msg-row { display: flex; align-items: flex-end; gap: 7px; }
.msg-row.right { justify-content: flex-end; }

.avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  padding: 5px;
}
.avatar svg { width:100%; height:100%; }
.av1 { background: #0EA5E9; }
.av2 { background: #6366F1; }
.av3 { background: #8B5CF6; }
.av4 { background: #F59E0B; }
[data-theme="dark"] .av1 { background: #22D3EE; }
[data-theme="dark"] .av2 { background: #818CF8; }
[data-theme="dark"] .av3 { background: #A78BFA; }
[data-theme="dark"] .av4 { background: #FBBF24; }

.msg-content { display:flex; flex-direction:column; gap:2px; max-width:76%; }
.msg-row.right .msg-content { align-items: flex-end; }
.msg-label { font-size:0.65rem; color:var(--text-muted); font-weight:600; padding:0 4px; font-family:'Inter',sans-serif; }

.bubble {
  padding: 7px 11px;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.65;
  word-wrap: break-word;
  font-family: 'Hind Siliguri', sans-serif;
}
.bubble.sp1 { background: #0EA5E9; color: white; border-bottom-right-radius: 3px; }
.bubble.sp2 { background: #6366F1; color: white; border-bottom-left-radius: 3px; }
.bubble.sp3 { background: #8B5CF6; color: white; border-bottom-right-radius: 3px; }
.bubble.sp4 { background: #F59E0B; color: white; border-bottom-left-radius: 3px; }
.bubble.sp-solo { background: #0EA5E9; color: white; border-bottom-right-radius: 3px; }
[data-theme="dark"] .bubble.sp1 { background: #22D3EE; color: #0F172A; }
[data-theme="dark"] .bubble.sp2 { background: #818CF8; color: #0F172A; }
[data-theme="dark"] .bubble.sp3 { background: #A78BFA; color: #0F172A; }
[data-theme="dark"] .bubble.sp4 { background: #FBBF24; color: #0F172A; }
[data-theme="dark"] .bubble.sp-solo { background: #22D3EE; color: #0F172A; }

.bubble.left-in {
  background: var(--bubble-in-bg);
  color: var(--bubble-in-text);
}

.card-badge {
  font-size: 0.65rem;
  background: rgba(0,113,227,0.1);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 700;
  letter-spacing: 0.3px;
}
[data-theme="dark"] .card-badge {
  background: rgba(10,132,255,0.12);
}

/* ── Document Canvas ── */
.doc-canvas {
  padding: 40px 52px;
  background: var(--doc-bg);
  overflow-y: auto;
  transition: background 0.3s;
}

.doc-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  height: 100%;
  color: var(--placeholder);
  font-size: 0.88rem;
  text-align: center;
}
.doc-placeholder-icon { font-size: 2.8rem; opacity: 0.35; }

/* ── Document type chooser (shown while transcription runs) ── */
.doc-choice {
  display: flex;
  flex-direction: column;
  height: 100%;
  justify-content: center;
  padding: 8px 4px;
  gap: 6px;
}
.doc-choice-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  text-align: center;
}
.doc-choice-sub {
  font-size: 0.82rem;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 18px;
  min-height: 1.2em;
}
.doc-choice-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
}
.doc-choice-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 18px 18px 18px 48px;
  background: var(--card-header-bg);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.18s ease, transform 0.12s ease, background 0.18s ease;
  font-family: inherit;
}
.doc-choice-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}
.doc-choice-card.selected {
  border-color: var(--accent);
  background: var(--upload-hover);
}
.doc-choice-num {
  position: absolute;
  left: 16px;
  top: 18px;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
}
.doc-choice-name {
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--text);
}
.doc-choice-desc {
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--text-muted);
}

/* exec-doc root */
.exec-doc { font-family: 'Inter', sans-serif; max-width: 860px; }

.doc-title {
  font-size: 1.7rem;
  font-weight: 800;
  color: var(--doc-h1);
  line-height: 1.25;
  border-bottom: 3px solid #667eea;
  padding-bottom: 16px;
  margin-bottom: 24px;
  letter-spacing: -0.3px;
}

/* Callout / Executive Summary */
.callout-box {
  background: rgba(0,113,227,0.06);
  border-left: 4px solid var(--accent);
  border-radius: 0 10px 10px 0;
  padding: 18px 22px;
  margin-bottom: 28px;
}
[data-theme="dark"] .callout-box {
  background: rgba(10,132,255,0.1);
}
.callout-label {
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--accent);
  margin-bottom: 8px;
}

/* Metrics row */
.metrics-row {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 28px;
}
.metric-card {
  flex: 1;
  min-width: 110px;
  background: var(--card-header-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  text-align: center;
}
.metric-value {
  font-size: 1.55rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1.1;
  margin-bottom: 4px;
}
.metric-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-weight: 600;
}

/* Sections */
.doc-section { margin-bottom: 28px; }

.doc-h2 {
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--doc-h2);
  text-transform: uppercase;
  letter-spacing: 1.1px;
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.doc-h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--doc-h1);
  margin: 14px 0 6px;
}
.doc-p {
  font-size: 0.95rem;
  line-height: 1.85;
  color: var(--doc-text);
  margin-bottom: 10px;
}
.doc-ul { list-style: none; padding: 0; margin-bottom: 10px; display: flex; flex-direction: column; gap: 6px; }
.doc-li {
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--doc-text);
  padding-left: 20px;
  position: relative;
}
.doc-li::before { content: '▸'; position: absolute; left: 0; color: var(--accent); font-size: 0.72rem; top: 4px; }

/* Table */
.doc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  margin-bottom: 10px;
}
.doc-table th {
  background: var(--accent);
  color: white;
  padding: 9px 13px;
  text-align: left;
  font-weight: 700;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.doc-table td {
  padding: 8px 13px;
  color: var(--doc-text);
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  line-height: 1.5;
}
.doc-table tr:nth-child(even) td { background: rgba(0,113,227,0.03); }
[data-theme="dark"] .doc-table tr:nth-child(even) td { background: rgba(10,132,255,0.05); }

/* Chart */
.chart-wrap {
  background: var(--card-header-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 10px;
}

/* Two-col layout */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 10px; }
.col {}

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

.btn-copy {
  background: rgba(0,0,0,0.05);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 4px 11px;
  border-radius: 6px;
  font-size: 0.7rem;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  font-weight: 700;
  transition: all 0.2s;
  letter-spacing: 0.3px;
  white-space: nowrap;
}
[data-theme="dark"] .btn-copy {
  background: rgba(255,255,255,0.07);
}
.btn-copy:hover { background: rgba(0,0,0,0.09); color: var(--text); }
[data-theme="dark"] .btn-copy:hover { background: rgba(255,255,255,0.12); }

/* ── Refinement Bar ── */
.refine-bar {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  background: var(--card-header-bg);
  flex-shrink: 0;
}
#refine-input {
  flex: 1;
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  font-family: 'Inter', sans-serif;
  font-size: 0.85rem;
  resize: none;
  min-height: 32px;
  max-height: 80px;
  transition: border 0.2s;
}
#refine-input:focus { outline: none; border-color: var(--accent); }
#btn-refine {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 7px 16px;
  font-family: 'Inter', sans-serif;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: opacity 0.2s;
}
#btn-refine:hover { opacity: 0.9; }
.card.loading #btn-refine { opacity: 0.5; cursor: not-allowed; }

/* ── Print stylesheet ── */
@media print {
  body { background: white !important; overflow: auto; }
  .app-header, .app-grid > .card-recorder, .app-grid > .card-raw,
  .progress-bar-wrap, .toast, .card-header .doc-actions { display: none !important; }
  .app-grid {
    display: block !important;
    padding: 0 !important;
  }
  .card-canvas {
    box-shadow: none !important;
    border-radius: 0 !important;
    height: auto !important;
  }
  .card-canvas .card-header { display: none !important; }
  .doc-canvas {
    padding: 20mm 25mm !important;
    overflow: visible !important;
    height: auto !important;
  }
  .exec-doc { max-width: 100% !important; }
  .doc-title { color: #0F172A !important; }
  .doc-h2 { color: #0071E3 !important; }
  .doc-p, .doc-li, .doc-table td { color: #1E293B !important; }
  .metric-card { border: 1px solid #E2E8F0 !important; background: #F1F5F9 !important; }
  .metric-value { color: #0071E3 !important; }
  .chart-wrap { border: 1px solid #E2E8F0 !important; background: white !important; }
  .doc-table th { background: #0071E3 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .callout-box { border-left: 4px solid #0071E3 !important; background: rgba(0,113,227,0.05) !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%) translateY(120px);
  background: #1C1C1E;
  color: white;
  padding: 10px 20px;
  border-radius: 8px;
  opacity: 0;
  transition: all 0.3s ease;
  pointer-events: none;
  z-index: 1000;
  font-size: 0.85rem;
  font-family: 'Inter', sans-serif;
}
[data-theme="light"] .toast {
  background: #1D1D1F;
}
.toast.show { opacity:1; transform:translateX(-50%) translateY(0); pointer-events:auto; }
.toast.success { background: #30D158; }
.toast.error { background: #FF3B30; }

/* ── Responsive ── */
@media (max-width: 860px) {
  html, body { overflow: auto; }
  .app-grid {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    grid-template-areas: "recorder" "raw" "canvas";
    height: auto;
  }
  .card { min-height: 280px; }
  .doc-canvas { padding: 24px; }
}
