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

:root {
  --bg:         #080c0e;
  --bg2:        #0d1214;
  --bg3:        #131b1f;
  --sidebar-bg: #060a0c;
  --nav-bg:     #050809;
  --border:     #1e2a30;
  --accent:     #e85a50;
  --accent-dim: #a83a30;
  --accent-bg:  #1a0e0d;
  --dim:        #4a5560;
  --muted:      #6a7a86;
  --text:       #c8dde5;
  --white:      #eaf4f8;
  --danger:     #d04040;
  --success:    #40a060;
  --scanline:   rgba(0,0,0,0.04);
  --overlay:    rgba(0,0,0,0.7);
  --placeholder-bg: rgba(232,90,80,0.08);
  --placeholder-border: rgba(232,90,80,0.25);
  --nav-w:      52px;
  --panel-w:    420px;
}

[data-theme="light"] {
  --bg:         #f8f6f3;
  --bg2:        #efece8;
  --bg3:        #e6e3de;
  --sidebar-bg: #f2f0ec;
  --nav-bg:     #eae7e3;
  --border:     #d8d4ce;
  --accent:     #c84035;
  --accent-dim: #9a3028;
  --accent-bg:  #fde8e6;
  --dim:        #a09890;
  --muted:      #807870;
  --text:       #2a2520;
  --white:      #ffffff;
  --danger:     #c03030;
  --success:    #308050;
  --scanline:   rgba(0,0,0,0.018);
  --overlay:    rgba(0,0,0,0.3);
  --placeholder-bg: rgba(200,64,53,0.06);
  --placeholder-border: rgba(200,64,53,0.2);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  line-height: 1.6;
  overflow: hidden;
}

/* ═══ SIGN-IN SCREEN ═══ */
#signin-screen {
  display: flex; align-items: center; justify-content: center;
  height: 100vh; width: 100%; flex-direction: column; gap: 32px;
}
#signin-screen.hidden { display: none; }
.signin-logo { margin-bottom: 8px; }
#signin-theme-btn {
  position: absolute; top: 16px; right: 16px;
  background: none; border: 1px solid transparent;
  color: var(--dim); cursor: pointer; padding: 6px;
  border-radius: 2px; transition: all 0.15s;
  display: flex; align-items: center; justify-content: center;
}
#signin-theme-btn:hover { color: var(--accent); border-color: var(--border); }
#signin-theme-btn svg { width: 16px; height: 16px; }
.signin-btn {
  background: var(--accent-bg); border: 1px solid var(--accent-dim);
  color: var(--accent); font-family: 'IBM Plex Mono', monospace;
  font-size: 12px; padding: 12px 28px;
  cursor: pointer; border-radius: 2px;
  letter-spacing: 0.08em; transition: all 0.15s;
}
.signin-btn:hover { background: var(--accent-dim); color: var(--white); }

/* ═══ LAYOUT ═══ */
#app { display: none; height: 100vh; }
#app.visible { display: flex; }

/* ═══ NAV RAIL ═══ */
#nav-rail {
  width: var(--nav-w); flex-shrink: 0;
  display: flex; flex-direction: column;
  align-items: center;
  background: var(--nav-bg);
  border-right: 1px solid var(--border);
  padding: 14px 0 12px;
  z-index: 10;
}
.nav-logo { margin-bottom: 20px; cursor: default; }
.nav-icon {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 4px; cursor: pointer;
  color: var(--dim); position: relative;
  transition: all 0.15s; margin-bottom: 4px;
  background: none; border: none;
  font-family: 'IBM Plex Mono', monospace;
}
.nav-icon:hover { color: var(--muted); background: var(--bg2); }
.nav-icon.active { color: var(--accent); background: var(--accent-bg); }
.nav-icon.active::before {
  content: ''; position: absolute; left: -8px; top: 6px; bottom: 6px;
  width: 3px; background: var(--accent); border-radius: 0 2px 2px 0;
}
.nav-icon svg { width: 18px; height: 18px; }
.nav-spacer { flex: 1; }
.nav-icon.bottom { margin-bottom: 4px; }

.icon-sun { display: none; }
.icon-moon { display: block; }
[data-theme="light"] .icon-sun { display: block; }
[data-theme="light"] .icon-moon { display: none; }

/* ═══ CENTER AREA ═══ */
#center { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* ═══ HEADER ═══ */
#header {
  flex: none; padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
#panel-toggle-btn {
  display: none; background: none; border: 1px solid transparent;
  color: var(--dim); cursor: pointer; padding: 6px;
  border-radius: 2px; transition: all 0.15s;
  align-items: center; justify-content: center; flex-shrink: 0;
}
#panel-toggle-btn:hover { color: var(--accent); border-color: var(--border); }
#panel-toggle-btn svg { width: 16px; height: 16px; }

#client-select-wrap { position: relative; user-select: none; }
#client-trigger {
  display: flex; align-items: center; gap: 8px;
  cursor: pointer; padding: 4px 0;
}
#client-trigger-name {
  color: var(--accent); font-size: 15px; font-weight: 600;
  letter-spacing: 0.12em;
}
#client-caret { color: var(--dim); font-size: 8px; transition: transform 0.2s; }
#client-select-wrap.open #client-caret { transform: rotate(180deg); }
#client-dropdown {
  display: none; position: absolute; top: calc(100% + 6px); left: -8px;
  min-width: 280px; background: var(--bg2);
  border: 1px solid var(--border); border-radius: 3px;
  z-index: 500; overflow: hidden;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
#client-select-wrap.open #client-dropdown { display: block; }
.dd-item {
  padding: 10px 14px; cursor: pointer;
  color: var(--muted); transition: all 0.1s;
  display: flex; align-items: flex-start; gap: 10px;
}
.dd-item:hover { background: var(--bg3); color: var(--text); }
.dd-item.active { color: var(--accent); }
.dd-item.active::before { content: '\2713'; font-size: 10px; color: var(--accent); margin-top: 2px; flex-shrink: 0; }
.dd-item:not(.active)::before { content: ''; display: inline-block; width: 10px; margin-top: 2px; flex-shrink: 0; }
.dd-item-text { display: flex; flex-direction: column; gap: 2px; }
.dd-code { font-size: 12px; font-weight: 600; letter-spacing: 0.06em; }
.dd-label { font-size: 10px; color: var(--dim); }

.header-slash { color: var(--dim); font-weight: 400; }
.header-sub {
  color: var(--muted); font-size: 11px;
  letter-spacing: 0.06em; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
#status-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 8px var(--accent);
  flex-shrink: 0; margin-left: auto;
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.35} }
#header-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.hdr-btn {
  background: none; border: 1px solid transparent;
  color: var(--dim); cursor: pointer; padding: 6px;
  border-radius: 2px; transition: all 0.15s;
  display: flex; align-items: center; justify-content: center;
}
.hdr-btn:hover { color: var(--accent); border-color: var(--border); }
.hdr-btn svg { width: 16px; height: 16px; }
.hdr-btn.spinning svg { animation: spin 0.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.hdr-btn.flash-save { color: var(--accent) !important; }
.hdr-link { text-decoration: none; }
.hdr-sep { width: 1px; height: 16px; background: var(--border); margin: 0 2px; flex-shrink: 0; }
#prompt-actions, #chat-actions { display: flex; align-items: center; gap: 4px; }

/* ═══ RIGHT PANEL ═══ */
#right-panel {
  width: var(--panel-w); flex-shrink: 0;
  display: flex; flex-direction: column;
  border-left: 1px solid var(--border);
  background: var(--sidebar-bg);
  transition: width 0.25s ease, min-width 0.25s ease;
  overflow: hidden;
  min-width: var(--panel-w);
}
#right-panel.collapsed { width: 0; min-width: 0; border-left: none; }

/* Edge tab to reopen collapsed panel */
#panel-edge-tab {
  display: none; position: fixed; right: 0; top: 50%; transform: translateY(-50%);
  width: 20px; height: 48px; z-index: 50;
  background: var(--bg2); border: 1px solid var(--border); border-right: none;
  border-radius: 4px 0 0 4px; cursor: pointer;
  align-items: center; justify-content: center;
  color: var(--dim); transition: all 0.15s;
}
#panel-edge-tab:hover { color: var(--accent); background: var(--bg3); width: 24px; }
#panel-edge-tab svg { width: 12px; height: 12px; }
#right-panel.collapsed ~ #panel-edge-tab { display: flex; }
.panel-head {
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 10px; letter-spacing: 0.14em;
  color: var(--dim); text-transform: uppercase; font-weight: 600;
  display: flex; align-items: center; justify-content: space-between;
  white-space: nowrap;
}
.panel-collapse-btn {
  background: none; border: none; color: var(--dim);
  cursor: pointer; font-size: 16px; padding: 0 2px;
  font-family: 'IBM Plex Mono', monospace;
  transition: color 0.15s; flex-shrink: 0;
}
.panel-collapse-btn:hover { color: var(--accent); }

/* ═══ RIGHT PANEL: PROMPT VARIABLES ═══ */
#prompt-panel { display: none; flex-direction: column; flex: 1; overflow: hidden; }
#prompt-panel.active { display: flex; }
#var-list { flex: 1; overflow-y: auto; padding: 12px 16px; }
#var-list::-webkit-scrollbar { width: 3px; }
#var-list::-webkit-scrollbar-track { background: transparent; }
#var-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.section-group { margin-bottom: 20px; }
.section-label {
  font-size: 9px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--accent-dim); font-weight: 600; margin-bottom: 10px;
  padding-bottom: 6px; border-bottom: 1px solid var(--border);
}
.var-field { margin-bottom: 14px; }
.var-name {
  font-size: 10px; letter-spacing: 0.08em; color: var(--dim);
  text-transform: lowercase; margin-bottom: 4px;
  display: flex; align-items: center; gap: 6px;
}
.var-name .filled-dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--dim); flex-shrink: 0;
}
.var-name .filled-dot.has-value { background: var(--success); }
.var-input {
  width: 100%; background: var(--bg);
  border: 1px solid var(--border); color: var(--text);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px; padding: 8px 10px;
  border-radius: 2px; outline: none;
  transition: border-color 0.15s;
  resize: vertical; min-height: 34px; line-height: 1.5;
}
.var-input:focus { border-color: var(--accent-dim); }
.var-input::placeholder { color: var(--dim); }
.var-ref {
  font-size: 10px; color: var(--dim); margin-top: 3px;
  cursor: pointer; transition: color 0.15s;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.var-ref:hover { color: var(--muted); }
.var-ref-expanded {
  font-size: 10px; color: var(--muted); margin-top: 4px;
  padding: 6px 8px; background: var(--bg2); border-radius: 2px;
  border: 1px solid var(--border); white-space: pre-wrap;
  word-break: break-word; line-height: 1.5;
  max-height: 120px; overflow-y: auto;
}
.var-ref-expanded::-webkit-scrollbar { width: 3px; }
.var-ref-expanded::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
#prompt-panel.compare-off .var-ref,
#prompt-panel.compare-off .var-ref-expanded { display: none; }

/* ═══ RIGHT PANEL: CHAT SAVED ═══ */
#chat-panel { display: none; flex-direction: column; flex: 1; overflow: hidden; }
#chat-panel.active { display: flex; }
#saved-list { flex: 1; overflow-y: auto; padding: 8px 0; }
#saved-list::-webkit-scrollbar { width: 3px; }
#saved-list::-webkit-scrollbar-track { background: transparent; }
#saved-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.saved-item {
  padding: 10px 16px; cursor: pointer;
  border-left: 2px solid transparent;
  transition: all 0.15s; position: relative;
}
.saved-item:hover { background: var(--bg2); }
.saved-item.active { background: var(--bg2); border-left-color: var(--accent); }
.saved-date {
  font-size: 12px; color: var(--text);
  white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; padding-right: 24px;
}
.saved-preview {
  font-size: 10px; color: var(--dim); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  padding-right: 24px;
}
.saved-delete {
  position: absolute; right: 12px; top: 10px;
  background: none; border: none; color: var(--dim);
  cursor: pointer; font-size: 14px; opacity: 0;
  transition: opacity 0.15s, color 0.15s;
  font-family: 'IBM Plex Mono', monospace;
}
.saved-item:hover .saved-delete { opacity: 1; }
.saved-delete:hover { color: var(--danger) !important; }
.saved-empty {
  padding: 20px 16px; color: var(--dim);
  font-size: 11px; font-style: italic;
}
.panel-foot { padding: 12px 16px; border-top: 1px solid var(--border); }
#export-btn, #clear-saved-btn {
  background: var(--bg2);
  border: 1px solid var(--border); color: var(--muted);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px; padding: 8px 12px;
  cursor: pointer; border-radius: 2px;
  transition: all 0.15s; letter-spacing: 0.05em;
}
#export-btn:hover, #clear-saved-btn:hover { color: var(--accent); border-color: var(--accent-dim); }
#export-btn:disabled, #clear-saved-btn:disabled { opacity: 0.3; cursor: default; }
#export-btn:disabled:hover, #clear-saved-btn:disabled:hover { color: var(--muted); border-color: var(--border); }

/* ═══ PROMPT VIEW ═══ */
#prompt-view { display: none; flex: 1; flex-direction: column; min-height: 0; }
#prompt-view.active { display: flex; }

#tab-bar {
  display: flex; border-bottom: 1px solid var(--border);
  padding: 0 24px; gap: 0; flex-shrink: 0;
}
.tab-btn {
  background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--dim); font-family: 'IBM Plex Mono', monospace;
  font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase;
  font-weight: 600; padding: 10px 16px 8px;
  cursor: pointer; transition: all 0.15s;
}
.tab-btn:hover { color: var(--muted); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

#preview-panel { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; }
#preview-panel::-webkit-scrollbar { width: 4px; }
#preview-panel::-webkit-scrollbar-track { background: transparent; }
#preview-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
#prompt-preview, #template-view-content {
  white-space: pre-wrap; word-break: break-word;
  line-height: 1.7; font-size: 12px;
}
#prompt-preview { color: var(--text); flex: 1; }
#template-view { display: none; flex: 1; flex-direction: column; }
#template-editor {
  width: 100%; flex: 1; background: transparent;
  border: none; color: var(--text);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px; line-height: 1.7;
  resize: none; outline: none;
  white-space: pre-wrap; word-break: break-word;
}
#template-editor::placeholder { color: var(--dim); }
#variables-view { display: none; flex: 1; overflow: hidden; min-height: 0; }
.ph-empty {
  color: var(--accent-dim); background: var(--placeholder-bg);
  border: 1px solid var(--placeholder-border);
  border-radius: 2px; padding: 1px 5px;
  font-size: 11px; letter-spacing: 0.04em;
}
.var-filled { transition: background 0.2s, outline 0.2s; border-radius: 2px; padding: 0 1px; }
.var-filled.var-highlight {
  background: var(--accent-bg); outline: 1.5px solid var(--accent);
  outline-offset: 1px;
}
.section-heading { color: var(--accent-dim); font-weight: 600; }

/* Template syntax highlighting overlay */
#template-wrap { position: relative; flex: 1; display: flex; flex-direction: column; overflow: hidden; }
#template-backdrop {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px; line-height: 1.7;
  white-space: pre-wrap; word-break: break-word;
  color: var(--text); pointer-events: none;
  overflow-y: auto;
}
#template-backdrop .tpl-var { color: var(--accent); font-weight: 500; }
#template-backdrop .tpl-section { color: var(--accent-dim); font-weight: 600; }
#template-editor { color: transparent; background: transparent; position: relative; z-index: 1; caret-color: var(--text); }
#template-editor::selection { background: rgba(232,90,80,0.25); }

/* Variables table */
.var-table-wrap { overflow-x: auto; overflow-y: auto; flex: 1; height: 100%; }
.var-table-wrap::-webkit-scrollbar { width: 4px; height: 4px; }
.var-table-wrap::-webkit-scrollbar-track { background: transparent; }
.var-table-wrap::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.var-table { border-collapse: collapse; table-layout: fixed; }
.var-table th {
  font-size: 9px; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--dim); font-weight: 600; padding: 8px 12px;
  border-bottom: 2px solid var(--border); text-align: left;
  position: sticky; top: 0; background: var(--bg); z-index: 2;
}
.var-table th.col-section { width: 100px; min-width: 100px; }
.var-table th.col-variable { width: 140px; min-width: 140px; }
.var-table th.col-client { width: 280px; min-width: 280px; }
.var-table td {
  padding: 6px 10px; border-bottom: 1px solid var(--border);
  vertical-align: top; font-size: 12px;
}
.var-table td.cell-section {
  font-size: 9px; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--accent-dim); font-weight: 600; white-space: nowrap;
}
.var-table td.cell-varname { font-size: 11px; color: var(--dim); letter-spacing: 0.04em; }
.var-table .cell-value { padding: 0; }
.var-table .cell-textarea {
  width: 100%; background: transparent; border: 1px solid transparent;
  color: var(--text); font-family: 'IBM Plex Mono', monospace;
  font-size: 12px; padding: 6px 10px; line-height: 1.5;
  resize: none; outline: none; overflow: hidden;
  min-height: 32px; border-radius: 2px;
  transition: border-color 0.15s, background 0.15s;
}
.var-table .cell-textarea:hover { border-color: var(--border); }
.var-table .cell-textarea:focus { border-color: var(--accent-dim); background: var(--bg2); }
.var-table tr.section-row td { padding-top: 16px; }

/* Bottom bar */
#bottom-bar {
  flex: none; padding: 12px 24px;
  border-top: 1px solid var(--border); background: var(--bg);
  display: flex; align-items: center; gap: 12px;
}
#unfilled-count { font-size: 10px; letter-spacing: 0.08em; color: var(--dim); }
#unfilled-count.has-unfilled { color: var(--accent-dim); }
#unfilled-count.all-filled { color: var(--success); }
.bottom-spacer { flex: 1; }
.bottom-btn {
  background: var(--bg2); border: 1px solid var(--border);
  color: var(--muted); font-family: 'IBM Plex Mono', monospace;
  font-size: 11px; padding: 8px 16px;
  cursor: pointer; border-radius: 2px;
  transition: all 0.15s; letter-spacing: 0.05em;
}
.bottom-btn:hover { color: var(--accent); border-color: var(--accent-dim); }
.bottom-btn.primary {
  background: var(--accent-bg); border-color: var(--accent-dim); color: var(--accent);
}
.bottom-btn.primary:hover { background: var(--accent-dim); color: var(--white); }
.bottom-btn.flash { color: var(--success) !important; border-color: var(--success) !important; }
.bottom-btn:disabled { opacity: 0.35; cursor: not-allowed; pointer-events: none; }
.bottom-btn .btn-spinner {
  display: inline-block; width: 10px; height: 10px;
  border: 1.5px solid currentColor; border-top-color: transparent;
  border-radius: 50%; animation: spin 0.6s linear infinite;
  vertical-align: middle; margin-right: 6px;
}

/* ═══ CHAT VIEW ═══ */
#chat-view { display: none; flex: 1; flex-direction: column; min-height: 0; }
#chat-view.active { display: flex; }

#view-banner {
  display: none; padding: 10px 24px;
  background: var(--accent-bg);
  border-bottom: 1px solid var(--accent-dim);
  font-size: 11px; color: var(--accent);
  align-items: center; gap: 10px; letter-spacing: 0.05em;
  flex-shrink: 0;
}
#view-banner.visible { display: flex; }
.view-title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.view-close {
  background: none; border: none; color: var(--accent);
  cursor: pointer; font-family: 'IBM Plex Mono', monospace;
  font-size: 12px; padding: 2px 8px; border-radius: 2px;
  transition: background 0.15s;
}
.view-close:hover { background: var(--accent-dim); color: var(--white); }

#feed {
  flex: 1; overflow-y: auto; padding: 24px 24px 0;
  display: flex; flex-direction: column; gap: 0; scroll-behavior: smooth;
}
#feed::-webkit-scrollbar { width: 4px; }
#feed::-webkit-scrollbar-track { background: transparent; }
#feed::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.msg {
  display: flex; flex-direction: column;
  margin-bottom: 20px; opacity: 0; transform: translateY(6px);
  animation: fadeIn 0.22s ease forwards;
}
@keyframes fadeIn { to { opacity:1; transform:translateY(0); } }
.msg-meta { font-size: 10px; letter-spacing: 0.1em; margin-bottom: 5px; color: var(--dim); }
.msg.user .msg-meta { text-align: right; color: var(--accent-dim); }
.bubble {
  padding: 11px 16px; border-radius: 2px; max-width: 78%;
  white-space: pre-wrap; word-break: break-word; line-height: 1.65;
  position: relative;
}
.msg.agent .bubble {
  background: var(--bg2); border: 1px solid var(--border);
  border-left: 2px solid var(--accent-dim);
  color: var(--text); align-self: flex-start;
}
.msg.agent .bubble::before { content: '> '; color: var(--accent-dim); }
.msg.user { align-items: flex-end; }
.msg.user .bubble {
  background: var(--accent-bg); border: 1px solid var(--accent-dim);
  color: var(--accent); align-self: flex-end; text-align: right;
}
.bubble a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.tool-tag { font-size: 11px; letter-spacing: 0.06em; color: var(--dim); margin-top: 5px; }

/* Comments */
.comment {
  display: flex; flex-direction: column;
  margin-bottom: 16px; opacity: 0; transform: translateY(6px);
  animation: fadeIn 0.22s ease forwards;
}
.comment-meta {
  font-size: 10px; letter-spacing: 0.1em; margin-bottom: 4px;
  color: var(--muted); font-style: italic;
}
.comment-text {
  color: var(--muted); font-size: 12px; line-height: 1.6;
  font-style: italic; padding-left: 12px;
  border-left: 1px solid var(--dim);
  white-space: pre-wrap; word-break: break-word;
}
.comment-delete {
  background: none; border: none; color: var(--dim);
  cursor: pointer; font-size: 11px; padding: 0;
  font-family: 'IBM Plex Mono', monospace;
  transition: color 0.15s; margin-left: 10px;
  opacity: 0; transition: opacity 0.15s, color 0.15s;
}
.comment:hover .comment-delete { opacity: 1; }
.comment-delete:hover { color: var(--danger); }
.comments-divider {
  display: flex; align-items: center; gap: 12px;
  margin: 24px 0 16px; opacity: 0; transform: translateY(6px);
  animation: fadeIn 0.22s ease forwards;
}
.comments-divider::before, .comments-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}
.comments-divider-label {
  font-size: 9px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--dim); font-weight: 600; white-space: nowrap;
}

/* Typing indicator */
#typing {
  display: none; align-items: center; gap: 5px;
  padding: 0 0 20px 0; color: var(--dim); font-size: 11px;
}
#typing.visible { display: flex; }
.dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--accent-dim);
  animation: blink 1.2s ease-in-out infinite;
}
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%,80%,100%{opacity:0.2} 40%{opacity:1} }

/* Input bar */
#input-zone {
  flex: none; padding: 16px 24px 20px;
  border-top: 1px solid var(--border); background: var(--bg);
}
#input-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 2px; padding: 10px 14px; transition: border-color 0.15s;
}
#input-row:focus-within { border-color: var(--accent-dim); }
#prompt-sym { color: var(--accent); font-weight: 600; flex: none; user-select: none; }
#msg-input {
  flex: 1; background: transparent; border: none; outline: none;
  color: var(--text); font-family: 'IBM Plex Mono', monospace;
  font-size: 13px; caret-color: var(--accent); resize: none;
  height: 22px; max-height: 120px; overflow-y: hidden; line-height: 1.6;
}
#msg-input::placeholder { color: var(--dim); }
#send-btn {
  flex: none; background: none; border: none; cursor: pointer;
  color: var(--dim); padding: 2px 4px; transition: color 0.15s;
  display: flex; align-items: center;
}
#send-btn:hover { color: var(--accent); }
#send-btn svg { width: 16px; height: 16px; }
#chat-hint { margin-top: 8px; font-size: 10px; color: var(--dim); letter-spacing: 0.06em; }

#input-zone.comment-mode #input-row { border-color: var(--dim); background: transparent; }
#input-zone.comment-mode #input-row:focus-within { border-color: var(--muted); }
#input-zone.comment-mode #prompt-sym { color: var(--muted); }
#input-zone.comment-mode #msg-input { color: var(--muted); font-style: italic; }

/* ═══ MODALS ═══ */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: var(--overlay); z-index: 1000;
  align-items: center; justify-content: center;
}
.modal-overlay.visible { display: flex; }
.modal-box {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 4px; width: 560px; max-width: 90vw;
  max-height: 80vh; overflow-y: auto; padding: 24px;
}
.modal-box::-webkit-scrollbar { width: 4px; }
.modal-box::-webkit-scrollbar-track { background: transparent; }
.modal-box::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.modal-head {
  display: flex; align-items: center;
  justify-content: space-between; margin-bottom: 20px;
}
.modal-title {
  font-size: 12px; letter-spacing: 0.14em;
  color: var(--accent); font-weight: 600; text-transform: uppercase;
}
.modal-close {
  background: none; border: none; color: var(--dim);
  cursor: pointer; font-size: 18px;
  font-family: 'IBM Plex Mono', monospace; transition: color 0.15s;
}
.modal-close:hover { color: var(--danger); }
.modal-divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.form-label {
  font-size: 10px; letter-spacing: 0.1em; color: var(--dim);
  text-transform: uppercase; margin-bottom: 6px; display: block;
}
.form-label:not(:first-of-type) { margin-top: 12px; }
.form-input, .form-textarea {
  width: 100%; background: var(--bg);
  border: 1px solid var(--border); color: var(--text);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px; padding: 8px 10px;
  border-radius: 2px; outline: none; transition: border-color 0.15s;
}
.form-input:focus, .form-textarea:focus { border-color: var(--accent-dim); }
.form-input::placeholder, .form-textarea::placeholder { color: var(--dim); }
.form-textarea { height: 70px; resize: vertical; line-height: 1.5; }
.modal-actions { margin-top: 20px; display: flex; gap: 8px; justify-content: flex-end; }
.modal-btn {
  background: var(--bg); border: 1px solid var(--border);
  color: var(--muted); font-family: 'IBM Plex Mono', monospace;
  font-size: 11px; padding: 8px 16px;
  cursor: pointer; border-radius: 2px;
  transition: all 0.15s; letter-spacing: 0.05em;
}
.modal-btn:hover { color: var(--text); border-color: var(--muted); }
.modal-btn.primary {
  background: var(--accent-bg); border-color: var(--accent-dim); color: var(--accent);
}
.modal-btn.primary:hover { background: var(--accent-dim); color: var(--white); }

/* Settings modal client cards */
.client-card {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 2px; padding: 14px 14px;
  margin-bottom: 8px;
}
.client-card-head {
  display: flex; align-items: center; gap: 10px; margin-bottom: 4px;
}
.client-card-name { font-size: 13px; font-weight: 600; color: var(--accent); letter-spacing: 0.08em; }
.client-card-label { font-size: 11px; color: var(--muted); }
.client-card-detail { font-size: 10px; color: var(--dim); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.client-card-actions { display: flex; gap: 6px; margin-left: auto; }
.client-card-btn {
  background: none; border: none; color: var(--dim);
  cursor: pointer; font-size: 10px; padding: 2px 6px;
  font-family: 'IBM Plex Mono', monospace;
  letter-spacing: 0.06em; transition: color 0.15s;
}
.client-card-btn:hover { color: var(--accent); }
.client-card-btn.danger:hover { color: var(--danger); }

/* Edit client form inside card */
.client-edit-form { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }
.client-edit-form .form-label { margin-top: 8px; }
.client-edit-form .form-label:first-child { margin-top: 0; }
.client-edit-actions { margin-top: 10px; display: flex; gap: 6px; justify-content: flex-end; }

#add-client-section { margin-top: 16px; }
#add-client-toggle {
  background: var(--accent-bg); border: 1px solid var(--accent-dim); color: var(--accent);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px; padding: 8px 16px;
  cursor: pointer; border-radius: 2px;
  letter-spacing: 0.05em; transition: all 0.15s;
}
#add-client-toggle:hover { background: var(--accent-dim); color: var(--white); }

/* ═══ MOBILE PANEL OVERLAY ═══ */
#panel-overlay {
  display: none; position: fixed; inset: 0;
  background: var(--overlay); z-index: 600;
}
#panel-overlay.visible { display: block; }

/* ═══ TOAST ═══ */
#toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--bg2); border: 1px solid var(--border);
  color: var(--text); font-family: 'IBM Plex Mono', monospace;
  font-size: 11px; padding: 10px 16px; border-radius: 2px;
  z-index: 2000; opacity: 0; transform: translateY(8px);
  transition: all 0.2s ease; pointer-events: none;
  letter-spacing: 0.04em;
}
#toast.visible { opacity: 1; transform: translateY(0); }
#toast.success { border-color: var(--success); color: var(--success); }
#toast.error { border-color: var(--danger); color: var(--danger); }

/* scanline */
body::after {
  content: ''; pointer-events: none; position: fixed; inset: 0;
  background: repeating-linear-gradient(0deg, transparent, transparent 2px, var(--scanline) 2px, var(--scanline) 4px);
  z-index: 9999;
}

/* ═══ SCROLLBAR GLOBAL ═══ */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ═══ CSV MODAL ═══ */
.csv-panel-btn {
  background: none; border: none; color: var(--dim);
  cursor: pointer; padding: 2px; display: flex;
  align-items: center; justify-content: center;
  transition: color 0.15s; flex-shrink: 0;
}
.csv-panel-btn:hover { color: var(--accent); }
.csv-panel-btn svg { width: 14px; height: 14px; }

.csv-diff-row {
  padding: 8px 0; border-bottom: 1px solid var(--border);
  font-size: 11px; line-height: 1.5;
}
.csv-diff-row:last-child { border-bottom: none; }
.csv-diff-var { color: var(--accent); font-weight: 600; letter-spacing: 0.06em; margin-bottom: 4px; }
.csv-diff-old { color: var(--dim); }
.csv-diff-new { color: var(--success); }
.csv-diff-arrow { color: var(--muted); margin: 0 6px; }
.csv-diff-unchanged { color: var(--dim); opacity: 0.5; }
.csv-error-list { color: var(--danger); font-size: 11px; line-height: 1.6; padding: 8px 0; }
.csv-error-list li { margin-bottom: 4px; }

/* ═══ MOBILE ═══ */
@media (max-width: 700px) {
  :root { --nav-w: 44px; }
  .nav-icon { width: 32px; height: 32px; }
  .nav-icon svg { width: 16px; height: 16px; }
  .nav-icon.active::before { left: -6px; }

  #right-panel {
    position: fixed; top: 0; right: 0; bottom: 0;
    z-index: 700; width: 300px; min-width: 300px;
    transform: translateX(100%);
    transition: transform 0.25s ease;
  }
  #right-panel.mobile-open { transform: translateX(0); }
  #right-panel.collapsed { width: 300px; min-width: 300px; border-left: 1px solid var(--border); }
  #panel-toggle-btn { display: flex !important; }
  #panel-edge-tab { display: none !important; }

  .header-slash, .header-sub { display: none; }
  #header { padding: 12px 16px; gap: 8px; }
  #feed { padding: 16px 16px 0; }
  #input-zone { padding: 12px 16px 16px; }
  #view-banner { padding: 10px 16px; }
  .bubble { max-width: 90%; }
  #preview-panel { padding: 16px; }
  #tab-bar { padding: 0 16px; }
  #bottom-bar { padding: 12px 16px; }
}
