/* Cockpit Jarvis v1.2 — mobile-first dark mode + tabs + Kanban */

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

:root {
  --bg: #0a0e1a;
  --bg-elev: #131826;
  --bg-elev2: #1a2138;
  --bg-elev3: #232a44;
  --border: #232a44;
  --text: #e6edf7;
  --text-dim: #8a93a8;
  --accent: #4f8eff;
  --green: #2dd47f;
  --yellow: #f5c542;
  --red: #ff5e5e;
  --orange: #ff924d;
  --gray: #6b7388;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  min-height: 100vh; min-height: 100dvh;
  overflow-x: hidden;
}
body { display: flex; flex-direction: column; padding-bottom: env(safe-area-inset-bottom); }

/* ==== TOPBAR ==== */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--bg-elev); border-bottom: 1px solid var(--border);
  backdrop-filter: saturate(180%) blur(20px);
}
.topbar-left { display: flex; flex-direction: column; gap: 2px; }
.brand { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }
.subtitle { font-size: 11px; color: var(--text-dim); }
.topbar-right { display: flex; align-items: center; gap: 8px; }

.badge { font-size: 18px; color: var(--green); transition: color 0.3s; }
.badge.stale { color: var(--yellow); animation: pulse 2s infinite; }
.badge.offline { color: var(--red); }
.badge.fresh { color: var(--green); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

.icon-btn {
  background: transparent; border: 1px solid var(--border); color: var(--text);
  width: 38px; height: 38px; border-radius: 10px; font-size: 18px;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  transition: background 0.15s, transform 0.1s;
}
.icon-btn:active { transform: scale(0.92); background: var(--bg-elev2); }

/* ==== TABS ==== */
.tabs {
  position: sticky; top: 65px; z-index: 40;
  display: flex; gap: 4px; padding: 8px 12px;
  background: var(--bg); border-bottom: 1px solid var(--border);
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  background: var(--bg-elev2); color: var(--text-dim);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 14px; font-size: 13px; font-weight: 600;
  cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.1s;
}
.tab:active { transform: scale(0.96); }
.tab.active { background: var(--accent); color: white; border-color: var(--accent); }

.tab-count {
  font-size: 11px; padding: 2px 7px; border-radius: 10px;
  background: rgba(255,255,255,0.18); color: white; font-weight: 700;
}
.tab:not(.active) .tab-count { background: var(--border); color: var(--text-dim); }

/* ==== TAB PANES ==== */
#cockpit-grid { flex: 1; padding: 14px; max-width: 1400px; margin: 0 auto; width: 100%; }
.tab-pane { display: flex; flex-direction: column; gap: 14px; }
.tab-pane[hidden] { display: none !important; }

.section-intro {
  font-size: 12px; color: var(--text-dim); padding: 8px 12px;
  background: var(--bg-elev2); border-radius: 8px; border: 1px solid var(--border);
}
.section-title { font-size: 14px; font-weight: 600; color: var(--text-dim); margin-top: 4px; }

/* ==== KPI ROW ==== */
.kpi-row {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px;
}
@media (min-width: 600px) { .kpi-row { grid-template-columns: repeat(4, 1fr); } }
.kpi {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px; text-align: center;
}
.kpi-num { font-size: 28px; font-weight: 700; line-height: 1; }
.kpi-label { font-size: 11px; color: var(--text-dim); margin-top: 6px; text-transform: uppercase; letter-spacing: 0.04em; }

/* ==== CARDS LIST / GRID ==== */
.cards-list { display: flex; flex-direction: column; gap: 10px; }
.cards-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 600px) { .cards-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1024px) { .cards-grid { grid-template-columns: repeat(3, 1fr); } }

/* ==== ACTION CARD V2 (clearer + Jarvis suggestion) ==== */
.action-card {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-left: 4px solid var(--gray); border-radius: 12px;
  padding: 14px; display: flex; flex-direction: column; gap: 10px;
}
.action-card.tier-1 { border-left-color: var(--red); box-shadow: 0 0 0 1px rgba(255,94,94,0.15); }
.action-card.tier-2 { border-left-color: var(--orange); }
.action-card.tier-3 { border-left-color: var(--yellow); }
.action-card.tier-4 { border-left-color: var(--gray); }
.action-card.healthy { border-left-color: var(--green); }
.action-card.critico { border-left-color: var(--red); background: linear-gradient(180deg, rgba(255,94,94,0.06), var(--bg-elev)); }

.ac-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ac-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 11px; color: var(--text-dim); }
.ac-tier {
  font-size: 10px; font-weight: 700; padding: 3px 8px; border-radius: 6px;
  text-transform: uppercase; letter-spacing: 0.05em; background: var(--border); color: var(--text);
}
.ac-tier.t1 { background: var(--red); color: white; }
.ac-tier.t2 { background: var(--orange); color: white; }
.ac-tier.t3 { background: var(--yellow); color: #1a1f2e; }
.ac-tier.t4 { background: var(--gray); color: white; }
.ac-agent { font-size: 12px; color: var(--text-dim); font-weight: 600; }
.ac-age { font-size: 11px; color: var(--text-dim); }

.ac-title { font-size: 15px; font-weight: 600; line-height: 1.3; }

.ac-body { font-size: 13px; color: var(--text); line-height: 1.4; }

/* Jarvis suggestion box (PROEMINENTE) */
.ac-suggest {
  background: rgba(79, 142, 255, 0.08);
  border: 1px solid rgba(79, 142, 255, 0.3);
  border-radius: 10px; padding: 10px 12px;
}
.ac-suggest-label {
  font-size: 10px; font-weight: 700; color: var(--accent);
  text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 4px;
  display: flex; align-items: center; gap: 4px;
}
.ac-suggest-text { font-size: 13px; color: var(--text); line-height: 1.4; }

.ac-impact {
  font-size: 12px; font-weight: 600; color: var(--green);
  display: inline-flex; align-items: center; gap: 4px;
}
.ac-impact.alto { color: var(--orange); }

/* ==== ACTION BUTTONS V2 ==== */
.ac-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.ac-actions-row { display: flex; gap: 6px; }

.btn-jarvis {
  flex: 1; padding: 12px 14px;
  background: var(--accent); color: white;
  border: none; border-radius: 10px;
  font-size: 14px; font-weight: 700;
  cursor: pointer; transition: opacity 0.15s, transform 0.1s;
}
.btn-jarvis:active { transform: scale(0.97); opacity: 0.9; }

.btn-secondary, .btn-deny, .btn-edit, .btn-snooze {
  flex: 1; padding: 10px 12px;
  background: var(--bg-elev2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  font-size: 13px; font-weight: 600;
  cursor: pointer; transition: opacity 0.15s, transform 0.1s;
}
.btn-secondary:active, .btn-deny:active, .btn-edit:active, .btn-snooze:active { transform: scale(0.97); }
.btn-deny { color: var(--red); border-color: rgba(255, 94, 94, 0.3); }
.btn-edit { color: var(--accent); border-color: rgba(79, 142, 255, 0.3); }
.btn-snooze { color: var(--text-dim); }

.btn-trace {
  background: transparent; color: var(--text-dim);
  border: none; padding: 6px 10px; font-size: 11px; cursor: pointer;
  text-decoration: underline;
}

.btn-primary { background: var(--accent); color: white; border: 1px solid var(--accent); padding: 12px; border-radius: 10px; font-weight: 600; cursor: pointer; }

/* ==== L3 health card (compact) ==== */
.l3-card {
  background: var(--bg-elev2); border: 1px solid var(--border);
  border-left: 3px solid var(--gray); border-radius: 8px;
  padding: 8px 10px; font-size: 12px;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  cursor: pointer; transition: transform 0.1s;
}
.l3-card.healthy { border-left-color: var(--green); }
.l3-card.warn { border-left-color: var(--yellow); }
.l3-card.bad { border-left-color: var(--red); }
.l3-card:active { transform: scale(0.98); }
.l3-card .name { font-weight: 600; }

/* ==== UNIT CARD ==== */
.unit-card {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-left: 4px solid var(--gray); border-radius: 12px;
  padding: 12px; display: flex; flex-direction: column; gap: 8px;
}
.unit-card.OK { border-left-color: var(--green); }
.unit-card.WARN { border-left-color: var(--yellow); background: linear-gradient(180deg, rgba(245,197,66,0.05), var(--bg-elev)); }
.unit-card.CRITICA { border-left-color: var(--red); background: linear-gradient(180deg, rgba(255,94,94,0.08), var(--bg-elev)); }

.unit-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.unit-name { font-weight: 700; font-size: 14px; }
.unit-marca { font-size: 11px; color: var(--text-dim); }
.unit-score { font-size: 18px; font-weight: 700; }
.unit-meta { font-size: 11px; color: var(--text-dim); }

/* ==== KANBAN ==== */
.kanban {
  display: grid; grid-template-columns: 1fr; gap: 12px;
}
@media (min-width: 800px) { .kanban { grid-template-columns: repeat(3, 1fr); } }

.kanban-col {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px; min-height: 200px;
  display: flex; flex-direction: column; gap: 10px;
}
.kanban-col-head {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13px; font-weight: 600; color: var(--text-dim);
  padding-bottom: 8px; border-bottom: 1px solid var(--border);
}
.kanban-col-count {
  font-size: 11px; padding: 2px 8px; border-radius: 10px;
  background: var(--bg-elev2); color: var(--text);
}
.kanban-col-body { display: flex; flex-direction: column; gap: 8px; }

.kanban-card {
  background: var(--bg-elev2); border: 1px solid var(--border);
  border-left: 3px solid var(--gray); border-radius: 8px;
  padding: 10px; font-size: 12px;
  display: flex; flex-direction: column; gap: 4px;
  cursor: pointer; transition: transform 0.1s;
}
.kanban-card:active { transform: scale(0.98); }
.kanban-card.tier-1 { border-left-color: var(--red); }
.kanban-card.tier-2 { border-left-color: var(--orange); }
.kanban-card.tier-3 { border-left-color: var(--yellow); }
.kanban-card .kc-title { font-weight: 600; font-size: 12px; }
.kanban-card .kc-body { font-size: 11px; color: var(--text-dim); line-height: 1.3; }
.kanban-card .kc-meta { font-size: 10px; color: var(--text-dim); display: flex; gap: 6px; }

/* ==== FILTROS / SEARCH ==== */
.filters-bar {
  display: flex; flex-direction: column; gap: 8px;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 12px; padding: 10px;
}
.filter-input {
  width: 100%; padding: 10px 12px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  font-family: inherit; font-size: 14px;
}
.filter-input:focus { outline: none; border-color: var(--accent); }
.filter-pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill {
  background: var(--bg-elev2); color: var(--text-dim);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 12px; font-size: 12px; font-weight: 600;
  cursor: pointer; transition: background 0.1s, color 0.1s, border-color 0.1s;
}
.pill.active { background: var(--accent); color: white; border-color: var(--accent); }

/* ==== DECISOES (history) ==== */
.decision-card {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-left: 3px solid var(--gray); border-radius: 8px;
  padding: 10px 12px; font-size: 12px;
  display: flex; flex-direction: column; gap: 4px;
}
.decision-card.ok { border-left-color: var(--green); }
.decision-card.no { border-left-color: var(--red); }
.decision-card.snooze { border-left-color: var(--yellow); }
.decision-card .dc-title { font-weight: 600; font-size: 13px; }
.decision-card .dc-meta { font-size: 11px; color: var(--text-dim); display: flex; gap: 8px; }
.decision-card .dc-action { font-size: 11px; color: var(--text-dim); font-style: italic; }

/* ==== EMPTY ==== */
.empty {
  font-size: 13px; color: var(--text-dim); text-align: center;
  padding: 30px 12px; font-style: italic;
}

/* ==== MODAL ==== */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 100;
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0; animation: fade-in 0.15s;
}
@media (min-width: 768px) { .modal-backdrop { align-items: center; padding: 20px; } }
.modal-backdrop[hidden] { display: none !important; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 16px 16px 0 0; max-width: 600px; width: 100%;
  max-height: 88vh; display: flex; flex-direction: column; overflow: hidden;
  animation: slide-up 0.2s;
}
@media (min-width: 768px) { .modal { border-radius: 16px; max-height: 80vh; } }
@keyframes slide-up { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 16px; }
.modal-body {
  flex: 1; overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
}
.modal-body label { font-size: 12px; color: var(--text-dim); }
.modal-body textarea {
  width: 100%; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; font-family: inherit; font-size: 14px;
  resize: vertical; min-height: 120px;
}

.modal-actions { display: flex; gap: 8px; margin-top: 8px; }
.modal-actions .btn-primary, .modal-actions .btn-secondary {
  flex: 1; padding: 12px 16px; border-radius: 10px; font-size: 14px; font-weight: 600;
}
.modal-actions .btn-secondary { background: var(--bg-elev2); color: var(--text); border: 1px solid var(--border); }

.trace-row { display: flex; justify-content: space-between; font-size: 13px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.trace-row:last-child { border: none; }
.trace-key { color: var(--text-dim); }
.trace-value { font-weight: 600; max-width: 60%; text-align: right; word-break: break-word; }
.trace-value pre { font-size: 11px; white-space: pre-wrap; }

/* ==== TOAST ==== */
.toast {
  position: fixed; bottom: calc(20px + env(safe-area-inset-bottom));
  left: 50%; transform: translateX(-50%);
  background: var(--bg-elev2); border: 1px solid var(--border); color: var(--text);
  padding: 12px 18px; border-radius: 12px;
  font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow); z-index: 200;
  animation: toast-in 0.2s;
}
.toast[hidden] { display: none !important; }
.toast.success { border-color: var(--green); color: var(--green); }
.toast.error { border-color: var(--red); color: var(--red); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ==== CHAT ==== */
#chat-container {
  display: flex; flex-direction: column;
  height: calc(100vh - 200px); height: calc(100dvh - 200px);
  min-height: 400px;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 12px;
  overflow: hidden;
}
.chat-messages {
  flex: 1; overflow-y: auto; padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.chat-msg { display: flex; }
.chat-msg.user { justify-content: flex-end; }
.chat-msg.assistant, .chat-msg.system { justify-content: flex-start; }
.chat-bubble {
  max-width: 85%; padding: 10px 14px; border-radius: 14px;
  font-size: 13px; line-height: 1.45;
  white-space: pre-wrap; word-break: break-word;
}
.chat-msg.user .chat-bubble { background: var(--accent); color: white; border-bottom-right-radius: 4px; }
.chat-msg.assistant .chat-bubble { background: var(--bg-elev2); color: var(--text); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.chat-msg.system .chat-bubble { background: rgba(245,197,66,0.1); border: 1px solid rgba(245,197,66,0.3); color: var(--text-dim); font-size: 12px; max-width: 100%; }

.chat-input-row {
  display: flex; gap: 8px; padding: 12px;
  border-top: 1px solid var(--border); background: var(--bg-elev2);
}
.chat-input-row textarea {
  flex: 1; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; font-family: inherit; font-size: 14px;
  resize: none; max-height: 120px;
}
.chat-input-row textarea:focus { outline: none; border-color: var(--accent); }
.chat-input-row .btn-primary { padding: 10px 16px; }

/* ==== LOADING ==== */
.loading-state { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 60px 20px; color: var(--text-dim); }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ==== FOOTER ==== */
.footer-info {
  text-align: center; font-size: 10px; color: var(--text-dim);
  padding: 12px; padding-bottom: calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border); margin-top: 8px;
}
