/* index.css — 3-panel layout: WhatsApp | Logs | Filesystem+Fiche */

:root {
  --wa-bg-app: #111b21;
  --wa-bg-header: #202c33;
  --wa-bg-chat: #0b141a;
  --wa-bg-input: #202c33;
  --wa-bg-input-field: #2a3942;
  --wa-bubble-out: #005c4b;
  --wa-bubble-in: #202c33;
  --wa-text: #e9edef;
  --wa-text-secondary: #8696a0;
  --wa-green: #00a884;
  --wa-time: rgba(255,255,255,0.6);
  --wa-check: #53bdeb;
}

body { display: flex; flex-direction: column; overflow: hidden; }

/* === Header === */
.app-header {
  display: flex; align-items: center; gap: 16px;
  padding: 0 20px; height: 44px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.app-header .logo { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.header-controls {
  display: flex; align-items: center; gap: 8px; margin-left: auto;
}
.header-controls label { font-size: 11px; color: var(--text-muted); }
.phone-input {
  font-size: 11px; padding: 3px 6px; width: 130px;
  font-family: var(--font-mono);
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 3px; color: var(--text-secondary);
}
.channel-select {
  font-size: 11px; padding: 3px 6px;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 3px; color: var(--text-secondary);
  font-family: var(--font-mono);
}
.logout-btn {
  font-size: 12px; color: var(--text-muted);
  padding: 4px 8px; border-radius: 3px; margin-left: 8px;
}
.logout-btn:hover { color: var(--red); }

/* === 3-panel layout === */
.app-layout { display: flex; flex: 1; min-height: 0; }

/* Panel title bar */
.panel-title {
  padding: 6px 12px;
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-muted);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

/* === Left: WhatsApp === */
.left-panel {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 12px 16px;
  flex-shrink: 0;
}
.phone-frame {
  width: 360px;
  height: min(680px, calc(100vh - 120px));
  border-radius: 36px;
  border: 5px solid #1e1e1e;
  overflow: hidden;
  box-shadow: 0 0 0 1px #111, 0 12px 40px rgba(0,0,0,0.5);
  background: var(--wa-bg-app);
  flex-shrink: 0;
}
.phone-statusbar {
  height: 32px; background: var(--wa-bg-header);
  display: flex; align-items: flex-end; justify-content: center;
  padding-bottom: 2px; font-size: 11px; font-weight: 600; color: var(--wa-text);
}
.session-bar {
  display: flex; gap: 6px; align-items: center;
  margin-top: 6px; font-size: 10px;
  font-family: var(--font-mono); color: var(--text-muted);
  min-height: 16px;
}
.session-bar .badge {
  padding: 1px 6px; border-radius: 3px; font-size: 10px;
}
.session-bar .badge.new { background: rgba(240,180,73,0.15); color: var(--amber); }
.session-bar .badge.resume { background: rgba(61,214,140,0.15); color: var(--green); }

/* === WhatsApp internals === */
.wa-app { display: flex; flex-direction: column; height: 100%; }
.wa-header {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; background: var(--wa-bg-header); min-height: 44px;
}
.wa-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--wa-green);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 600; color: #fff; flex-shrink: 0;
}
.wa-header-info { flex: 1; min-width: 0; }
.wa-contact-name {
  font-size: 14px; font-weight: 500; color: var(--wa-text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.wa-status { font-size: 11px; color: var(--wa-text-secondary); }
.wa-status.typing { color: var(--wa-green); }
.wa-chat {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 6px 10px; background: var(--wa-bg-chat);
  display: flex; flex-direction: column; gap: 2px;
}
.wa-date {
  align-self: center; background: #182229;
  color: var(--wa-text-secondary); font-size: 10px;
  padding: 2px 8px; border-radius: 4px; margin: 4px 0;
}
.wa-msg {
  max-width: 85%; padding: 5px 7px 3px;
  border-radius: 7px; position: relative;
  line-height: 1.35; word-wrap: break-word;
}
.wa-msg.in { align-self: flex-start; background: var(--wa-bubble-in); border-top-left-radius: 0; }
.wa-msg.out { align-self: flex-end; background: var(--wa-bubble-out); border-top-right-radius: 0; }
.wa-msg.in.tail::before {
  content: ''; position: absolute; top: 0; left: -7px;
  border-top: 0 solid transparent; border-bottom: 9px solid transparent;
  border-right: 7px solid var(--wa-bubble-in);
}
.wa-msg.out.tail::after {
  content: ''; position: absolute; top: 0; right: -7px;
  border-top: 0 solid transparent; border-bottom: 9px solid transparent;
  border-left: 7px solid var(--wa-bubble-out);
}
.wa-msg-text { font-size: 13px; color: var(--wa-text); white-space: pre-wrap; }
.wa-msg-meta { display: flex; justify-content: flex-end; align-items: center; gap: 3px; margin-top: 1px; }
.wa-msg-time { font-size: 10px; color: var(--wa-time); }
.wa-msg-check { color: var(--wa-check); line-height: 1; }
.wa-msg-check svg { width: 14px; height: 10px; fill: var(--wa-check); }
.wa-typing {
  align-self: flex-start; background: var(--wa-bubble-in);
  border-radius: 7px; border-top-left-radius: 0; padding: 8px 12px;
}
.wa-typing-dots { display: flex; gap: 3px; }
.wa-typing-dots span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--wa-text-secondary);
  animation: wa-pulse 1.4s infinite ease-in-out;
}
.wa-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.wa-typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes wa-pulse {
  0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
  30% { opacity: 1; transform: scale(1); }
}
.wa-attach-bar {
  display: flex; gap: 4px; padding: 4px 8px;
  background: var(--wa-bg-input); border-top: 1px solid #1a2228; flex-wrap: wrap;
}
.wa-file-chip {
  display: flex; align-items: center; gap: 3px;
  padding: 2px 7px; background: var(--wa-bg-input-field);
  border-radius: 8px; font-size: 10px; color: var(--wa-text-secondary);
}
.wa-file-chip .remove { cursor: pointer; font-size: 12px; padding: 0 2px; }
.wa-file-chip .remove:hover { color: var(--wa-text); }
.wa-input-bar {
  display: flex; align-items: flex-end; gap: 4px;
  padding: 4px 6px; background: var(--wa-bg-input);
}
.wa-attach-btn {
  width: 32px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; color: var(--wa-text-secondary);
}
.wa-attach-btn svg { width: 18px; height: 18px; fill: var(--wa-text-secondary); }
.wa-attach-btn:hover svg { fill: var(--wa-text); }
.wa-input-field {
  flex: 1; background: var(--wa-bg-input-field);
  border: none; border-radius: 16px;
  padding: 6px 12px; font-size: 13px; color: var(--wa-text);
  min-height: 34px; max-height: 90px;
  resize: none; outline: none; line-height: 1.35;
}
.wa-input-field::placeholder { color: var(--wa-text-secondary); }
.wa-send-btn {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--wa-green);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: opacity 0.15s;
}
.wa-send-btn:hover { opacity: 0.85; }
.wa-send-btn svg { width: 15px; height: 15px; fill: #fff; }

/* === Center: Logs === */
.center-panel {
  width: 320px;
  display: flex; flex-direction: column;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  flex-shrink: 0;
}
.logs-scroll {
  flex: 1; overflow-y: auto;
  padding: 8px; display: flex;
  flex-direction: column; gap: 6px;
}
/* Live log entry (current request) */
.log-live {
  border: 1px solid var(--border);
  border-radius: 5px; overflow: hidden;
}
.log-live .log-live-header {
  padding: 5px 8px; font-size: 11px;
  background: var(--bg-surface); color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 6px;
}
.log-live .log-live-steps {
  padding: 4px 8px;
  font-family: var(--font-mono); font-size: 11px; line-height: 1.6;
}
.log-step-line {
  padding: 2px 0;
  color: var(--text-secondary);
  display: flex; align-items: baseline; gap: 4px;
}
.log-step-line .step-type {
  font-size: 10px; font-weight: 500;
  padding: 0 4px; border-radius: 2px;
  flex-shrink: 0;
}
.log-step-line .step-type.thinking { background: rgba(108,114,203,0.15); color: var(--accent); }
.log-step-line .step-type.tool_use { background: rgba(240,180,73,0.15); color: var(--amber); }
.log-step-line .step-type.text { background: rgba(61,214,140,0.15); color: var(--green); }
.log-step-line .step-type.result { background: rgba(255,255,255,0.06); color: var(--text-muted); }
.log-step-line .step-type.guardian { background: rgba(108,114,203,0.15); color: var(--accent); }
.log-step-line .step-type.guardian-fail { background: rgba(239,93,93,0.15); color: var(--red); }
.log-step-line .step-detail {
  color: var(--text-muted); font-size: 10px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  min-width: 0;
}
/* Spinner for active log */
.log-spinner {
  display: inline-block; width: 10px; height: 10px;
  border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Past log entries (from logs.jsonl) */
.log-entry {
  border: 1px solid var(--border); border-radius: 5px; overflow: hidden;
}
.log-header {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 8px; background: var(--bg-surface);
  cursor: pointer; font-size: 11px;
}
.log-header:hover { background: var(--bg-hover); }
.log-time { font-family: var(--font-mono); color: var(--text-muted); font-size: 10px; }
.log-mode { padding: 1px 5px; border-radius: 2px; font-size: 9px; font-weight: 500; }
.log-mode.resume { background: rgba(61,214,140,0.15); color: var(--green); }
.log-mode.fresh { background: rgba(108,114,203,0.15); color: var(--accent); }
.log-mode.fallback { background: rgba(240,180,73,0.15); color: var(--amber); }
.log-preview {
  flex: 1; color: var(--text-secondary);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
}
.log-toggle { color: var(--text-muted); font-size: 12px; flex-shrink: 0; transition: transform 0.15s; }
.log-toggle.open { transform: rotate(90deg); }
.log-body {
  display: none; padding: 6px 8px;
  font-family: var(--font-mono); font-size: 10px; line-height: 1.5;
  border-top: 1px solid var(--border);
}
.log-body.open { display: block; }
.log-section { margin-bottom: 6px; }
.log-section-title {
  color: var(--text-muted); font-size: 9px;
  text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 2px;
}
.log-section-content {
  color: var(--text-secondary); white-space: pre-wrap; word-wrap: break-word;
}
.log-guardian-ok { color: var(--green); }
.log-guardian-fail { color: var(--red); }

/* === Right: Filesystem + Fiche === */
.right-panel {
  flex: 1; display: flex; flex-direction: column;
  min-width: 0;
}
.right-top {
  flex: 1; display: flex; flex-direction: column;
  min-height: 0; border-bottom: 1px solid var(--border);
}
.right-bottom {
  height: 220px; display: flex; flex-direction: column;
  flex-shrink: 0;
}

/* Filesystem */
.fs-breadcrumb {
  display: flex; align-items: center; gap: 3px;
  padding: 5px 12px; font-size: 11px;
  font-family: var(--font-mono);
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  flex-wrap: wrap; flex-shrink: 0;
}
.fs-breadcrumb span { color: var(--text-muted); }
.fs-breadcrumb a { color: var(--text-secondary); }
.fs-breadcrumb a:hover { color: var(--text-primary); text-decoration: none; }
.fs-content { flex: 1; overflow-y: auto; }
.fs-entry {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 12px; font-size: 12px;
  cursor: pointer; transition: background 0.1s;
  border-bottom: 1px solid var(--border);
}
.fs-entry:hover { background: var(--bg-hover); }
.fs-entry .fs-icon { color: var(--text-muted); width: 14px; text-align: center; flex-shrink: 0; font-size: 11px; }
.fs-entry .fs-name {
  flex: 1; color: var(--text-primary); min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.fs-entry.dir .fs-name { color: var(--amber); }
.fs-entry .fs-size {
  color: var(--text-muted); font-size: 10px;
  font-family: var(--font-mono); flex-shrink: 0;
}
.fs-file-content {
  padding: 12px; white-space: pre-wrap;
  font-family: var(--font-mono); font-size: 11px;
  line-height: 1.45; overflow-y: auto; flex: 1;
}

/* Fiche */
.fiche-pane {
  flex: 1; display: flex; flex-direction: column;
  padding: 8px 12px;
}
.fiche-pane textarea {
  flex: 1; font-family: var(--font-mono);
  font-size: 11px; line-height: 1.45;
  resize: none; border-radius: 4px; padding: 8px;
}
.fiche-actions {
  display: flex; align-items: center; gap: 8px; margin-top: 6px;
}
.fiche-actions button {
  padding: 4px 12px; background: var(--accent);
  color: #fff; font-size: 11px; font-weight: 500;
  border-radius: 4px; transition: opacity 0.15s;
}
.fiche-actions button:hover { opacity: 0.9; }
.fiche-status { font-size: 10px; color: var(--green); }
.fiche-status.error { color: var(--red); }
