:root {
  --bg: #f6f8fc;
  --surface: #ffffff;
  --surface-hover: #eef2f9;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --muted: #64748b;
  --text: #0f172a;
  --text-secondary: #475569;
  --border: #e2e8f0;
  --cyan: #06b6d4;
  --grid-line: rgba(79, 70, 229, .07);
  --font: system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
}
[data-theme="dark"] {
  --bg: #0a0a0f;
  --surface: #12121a;
  --surface-hover: #1a1a2e;
  --accent: #818cf8;
  --accent-soft: #1e1b4b;
  --muted: #6b7280;
  --text: #f1f5f9;
  --text-secondary: #94a3b8;
  --border: #1e293b;
  --cyan: #22d3ee;
  --grid-line: rgba(99, 102, 241, .04);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.6;
  display: flex;
  flex-direction: column;
}
.bg-grid {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 60px 60px;
}

/* Header */
header.top {
  position: relative; z-index: 2;
  padding: 18px 24px;
  border-bottom: none;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface);
  box-shadow: 0 1px 0 var(--border), 0 4px 24px rgba(79, 70, 229, .08);
}
header.top::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--cyan), var(--accent));
  background-size: 200% 100%;
  animation: gradientSlide 4s linear infinite;
}
.brand {
  display: flex; align-items: center; gap: 12px;
}
.brand-mark {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--cyan));
  display: grid; place-items: center;
  font-weight: 800; font-size: 16px; color: #fff;
  box-shadow: 0 0 20px rgba(79, 70, 229, .4), 0 0 40px rgba(6, 182, 212, .2);
  animation: brandPulse 3s ease-in-out infinite;
}
@keyframes brandPulse {
  0%,100% { box-shadow: 0 0 20px rgba(79, 70, 229, .4), 0 0 40px rgba(6, 182, 212, .2); }
  50% { box-shadow: 0 0 30px rgba(79, 70, 229, .6), 0 0 60px rgba(6, 182, 212, .3); }
}
.brand-name {
  font-size: 18px; font-weight: 800; letter-spacing: 2px;
  background: linear-gradient(135deg, var(--accent), var(--cyan));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.brand-sub { color: var(--text-secondary); font-family: var(--mono); font-size: 11px; }
.user-pill { color: var(--text-secondary); font-size: 13px; font-family: var(--mono); display: flex; align-items: center; gap: 8px; }
.user-pill button, .user-pill .link-btn, .theme-toggle {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 7px 14px; border-radius: 8px; cursor: pointer;
  font-family: var(--mono); font-size: 13px; text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px;
  transition: all .2s ease;
}
.user-pill button:hover, .user-pill .link-btn:hover, .theme-toggle:hover {
  color: #fff;
  border-color: var(--accent);
  background: linear-gradient(135deg, var(--accent), var(--cyan));
  box-shadow: 0 4px 16px rgba(79, 70, 229, .3);
  transform: translateY(-1px);
}

/* Auth view */
.auth-wrap {
  flex: 1; display: grid; place-items: center; padding: 32px; position: relative; z-index: 1;
}
.auth-card {
  width: 100%; max-width: 400px;
  background: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(79, 70, 229, 0.2);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 8px 32px rgba(79, 70, 229, 0.1), inset 0 1px 1px rgba(255, 255, 255, 0.1);
}
.auth-card h2 { font-size: 18px; margin-bottom: 6px; }
.auth-card p { color: var(--text-secondary); font-size: 13px; margin-bottom: 20px; }
.auth-card input {
  width: 100%; padding: 12px 14px; background: var(--bg); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; font-family: var(--font); font-size: 14px;
}
.auth-card input:focus { outline: none; border-color: var(--accent); }
.auth-card button {
  width: 100%; margin-top: 12px; padding: 12px;
  background: var(--accent); color: white; border: none; border-radius: 8px;
  font-weight: 600; cursor: pointer; font-size: 14px;
}
.auth-card button:disabled { opacity: .6; cursor: progress; }
.auth-msg { margin-top: 12px; font-size: 13px; color: var(--text-secondary); }
.auth-msg.error { color: var(--danger); }
.auth-msg.success { color: var(--success); }

/* Chat view */
.chat-wrap {
  flex: 1; display: flex; flex-direction: column;
  max-width: 880px; width: 100%; margin: 0 auto;
  padding: 24px; position: relative; z-index: 1;
  min-height: 0;
}
.messages {
  flex: 1; overflow-y: auto; padding: 8px 4px 16px;
  display: flex; flex-direction: column; gap: 16px;
}
.msg { display: flex; gap: 12px; animation: fadeIn .3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.msg .avatar {
  flex-shrink: 0; width: 28px; height: 28px; border-radius: 8px;
  display: grid; place-items: center; font-size: 12px; font-weight: 700;
}
.msg.user .avatar { background: var(--surface); color: var(--text-secondary); border: 1px solid var(--border); }
.msg.assistant .avatar { background: linear-gradient(135deg, var(--accent), var(--cyan)); color: var(--bg); }
.msg .body {
  flex: 1; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px; font-size: 14px;
  white-space: pre-wrap; word-wrap: break-word;
}
.msg.user .body { background: transparent; border-color: transparent; padding: 6px 0; }
.msg .body .cursor { display: inline-block; width: 7px; height: 14px; background: var(--accent); margin-left: 2px; vertical-align: middle; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* Composer */
.composer {
  display: flex; gap: 8px; align-items: flex-end;
  padding-top: 12px; border-top: 1px solid var(--border);
}
.composer textarea {
  flex: 1; resize: none; min-height: 44px; max-height: 200px;
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  padding: 12px 14px; border-radius: 10px; font-family: var(--font); font-size: 14px;
  line-height: 1.5;
}
.composer textarea:focus { outline: none; border-color: var(--accent); }
.composer button {
  background: var(--accent); color: white; border: none; border-radius: 10px;
  padding: 0 18px; height: 44px; cursor: pointer; font-weight: 600;
}
.composer button:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn {
  background: var(--surface) !important; color: var(--text-secondary) !important;
  border: 1px solid var(--border) !important; padding: 0 12px !important;
  font-size: 18px;
}
.icon-btn:hover { color: var(--text) !important; border-color: var(--accent) !important; }
.icon-btn.active { color: var(--accent) !important; border-color: var(--accent) !important; }
.icon-btn.recording { color: var(--danger) !important; border-color: var(--danger) !important; animation: pulse 1.2s ease-in-out infinite; }
.attach-preview {
  display: flex; gap: 8px; padding: 8px 12px; flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
}
.attach-preview.hidden { display: none; }
.attach-item {
  position: relative; border-radius: 8px; overflow: hidden;
  border: 1px solid var(--border); background: var(--surface);
}
.attach-item img, .attach-item video { height: 64px; max-width: 120px; object-fit: cover; display: block; }
.attach-item .file-tag { padding: 8px 12px; font-size: 12px; color: var(--text-secondary); }
.attach-item .remove-attach {
  position: absolute; top: 2px; right: 2px; background: var(--danger); color: white;
  border: none; border-radius: 50%; width: 18px; height: 18px; font-size: 11px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.hint { font-size: 11px; color: var(--muted); padding: 6px 4px 0; font-family: var(--mono); }

.error-banner {
  background: rgba(239,68,68,.1); border: 1px solid rgba(239,68,68,.3);
  color: var(--danger); padding: 10px 14px; border-radius: 8px; font-size: 13px;
}

.hidden { display: none !important; }

/* ─── Settings Panel ─── */
.settings-overlay {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(0, 0, 0, .5);
  backdrop-filter: blur(4px);
}
.settings-panel {
  position: fixed; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 100;
  width: 90%; max-width: 520px; max-height: 80vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .3);
  overflow-y: auto;
}
.settings-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.settings-header h3 {
  font-size: 16px; font-weight: 700; color: var(--text);
}
.settings-close-btn {
  background: none; border: none; color: var(--muted);
  font-size: 20px; cursor: pointer; padding: 4px 8px; border-radius: 6px;
}
.settings-close-btn:hover { color: var(--danger); background: rgba(239,68,68,.1); }
.settings-desc {
  font-size: 13px; color: var(--text-secondary); margin-bottom: 20px;
}
.settings-list { display: flex; flex-direction: column; gap: 12px; }
.setting-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px;
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: 10px;
  flex-wrap: wrap;
}
.setting-info { flex: 1; min-width: 0; }
.setting-label {
  font-size: 14px; font-weight: 600; color: var(--text);
  display: flex; align-items: center; gap: 8px;
}
.setting-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted); flex-shrink: 0;
}
.setting-dot.active { background: var(--success); box-shadow: 0 0 8px var(--success); }
.setting-desc a { color: var(--accent); text-decoration: none; }
.setting-desc a:hover { text-decoration: underline; }
.setting-actions { display: flex; align-items: center; gap: 8px; }
.setting-input {
  width: 160px; padding: 8px 10px;
  background: var(--bg); border: 1px solid var(--border);
  color: var(--text); border-radius: 6px;
  font-family: var(--mono); font-size: 12px;
}
.setting-input:focus { outline: none; border-color: var(--accent); }
.setting-save {
  background: var(--accent); color: #fff; border: none;
  padding: 8px 12px; border-radius: 6px; font-size: 12px;
  font-weight: 600; cursor: pointer;
}
.setting-save:disabled { opacity: .6; cursor: progress; }
.setting-del {
  background: none; border: 1px solid var(--border); color: var(--muted);
  width: 28px; height: 28px; border-radius: 6px; cursor: pointer;
  display: grid; place-items: center; font-size: 12px;
}
.setting-del:hover { color: var(--danger); border-color: var(--danger); }
.setting-masked {
  font-family: var(--mono); font-size: 11px; color: var(--success); font-weight: 600;
}
.settings-error { color: var(--danger); font-size: 13px; padding: 8px; }
.settings-section-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  color: var(--muted); letter-spacing: .5px;
  padding: 12px 0 4px; margin-top: 4px;
}
.setting-add-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.setting-add-row .setting-key-name { width: 160px; text-transform: uppercase; }
.setting-add-row .setting-key-value { flex: 1; min-width: 140px; }
.setting-suggestion { opacity: .7; }
.setting-suggestion:hover { opacity: 1; }
.setting-quick-add {
  background: none; border: 1px dashed var(--border); color: var(--accent);
  padding: 4px 10px; border-radius: 6px; font-size: 11px;
  cursor: pointer; font-weight: 600;
}
.setting-quick-add:hover { background: var(--accent-soft); }
.cap-instructions {
  font-size: 11px; color: var(--text-secondary); margin: 4px 0 8px;
  line-height: 1.5; font-family: var(--mono);
  background: var(--bg); padding: 8px; border-radius: 6px;
}
.cap-configure-btn {
  background: var(--accent); color: #fff; border: none;
  padding: 6px 12px; border-radius: 6px; font-size: 12px;
  cursor: pointer; font-weight: 600; margin-top: 4px;
}
.config-request-card a {
  color: var(--accent); font-size: 12px; text-decoration: none; margin-right: 12px;
}
.config-request-card a:hover { text-decoration: underline; }

/* ─── Tool Indicators ─── */
.tool-indicator {
  font-family: var(--mono); font-size: 11px;
  padding: 6px 10px; margin: 6px 0;
  border-radius: 6px; border-left: 3px solid var(--accent);
  background: var(--accent-soft); color: var(--accent);
  animation: fadeIn .2s ease;
}
.tool-indicator.tool-done {
  border-left-color: var(--success); color: var(--success);
  background: rgba(16, 185, 129, .08);
}
.tool-indicator.tool-error {
  border-left-color: var(--danger); color: var(--danger);
  background: rgba(239, 68, 68, .08);
}
.tool-detail {
  font-size: 10px; color: var(--text-secondary);
  margin-top: 4px; line-height: 1.4;
  max-height: 60px; overflow: hidden;
}

/* ──�� Config Request Card ─── */
.config-request-card {
  background: var(--surface-hover); border: 1px solid var(--warning);
  border-radius: 10px; padding: 12px 14px; margin: 8px 0;
}
.config-request-card .cap-title {
  font-weight: 600; font-size: 13px; color: var(--warning); margin-bottom: 4px;
}
.config-request-card .cap-reason { font-size: 12px; color: var(--text-secondary); margin-bottom: 8px; }
.config-request-card button {
  background: var(--accent); color: #fff; border: none;
  padding: 6px 12px; border-radius: 6px; font-size: 12px;
  cursor: pointer; font-weight: 600;
}

/* App grid: dashboard (sol) + Ülgen chat (sağ) */
.app-grid {
  display: grid;
  grid-template-columns: 1fr 400px;
  gap: 24px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: 24px;
  position: relative; z-index: 1;
  min-height: calc(100vh - 80px);
}
.dashboard-pane { min-width: 0; }
.chat-pane {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  display: flex; flex-direction: column;
  position: sticky; top: 24px;
  height: calc(100vh - 110px);
  box-shadow: 0 1px 3px rgba(15, 23, 42, .04);
  overflow: hidden;
}
.chat-pane-header {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  font-family: var(--mono); font-size: 13px; font-weight: 600;
  color: var(--text);
}
.chat-pane-header .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--success); box-shadow: 0 0 8px var(--success);
  animation: pulse 2s ease-in-out infinite;
}
.chat-pane-header .route-pill {
  margin-left: auto; font-size: 10px; color: var(--text-secondary);
  background: var(--surface-hover); padding: 4px 8px; border-radius: 5px;
  border: 1px solid var(--border); font-weight: 500; max-width: 200px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-pane .messages { padding: 14px; gap: 12px; }
.chat-pane .composer {
  padding: 12px; border-top: 1px solid var(--border);
  background: var(--surface);
  flex-wrap: wrap;
}
.chat-pane .composer textarea { font-size: 13px; min-height: 40px; }
.chat-pane .composer button { height: 40px; padding: 0 14px; }
.chat-pane .icon-btn { padding: 0 10px !important; font-size: 16px; }

@media (max-width: 980px) {
  .app-grid { grid-template-columns: 1fr; }
  .chat-pane { position: static; height: 70vh; }
}

/* Voice waveform animation */
.wave {
  width: 100%; height: 0;
  display: flex; align-items: center; justify-content: center;
  gap: 3px; overflow: hidden;
  transition: height .25s ease, margin .25s ease;
}
.wave.active {
  height: 26px;
  margin-bottom: 6px;
}
.wave span {
  display: block; width: 3px; height: 4px;
  background: linear-gradient(180deg, var(--accent), var(--cyan));
  border-radius: 2px;
  animation: waveBar 1s ease-in-out infinite;
}
.wave span:nth-child(1) { animation-delay: -.9s; }
.wave span:nth-child(2) { animation-delay: -.7s; }
.wave span:nth-child(3) { animation-delay: -.5s; }
.wave span:nth-child(4) { animation-delay: -.3s; }
.wave span:nth-child(5) { animation-delay: -.5s; }
.wave span:nth-child(6) { animation-delay: -.7s; }
.wave span:nth-child(7) { animation-delay: -.9s; }
@keyframes waveBar {
  0%, 100% { height: 4px; opacity: .5; }
  50% { height: 22px; opacity: 1; }
}

/* Header refresh button uses same theme-toggle look */
#refreshBtn {
  background: var(--surface); border: 1px solid var(--border); color: var(--text-secondary);
  padding: 7px 12px; border-radius: 8px; cursor: pointer;
  font-family: var(--mono); font-size: 14px; transition: all .15s ease;
}
#refreshBtn:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
