:root {
  color-scheme: dark;
  --bg: #070b10;
  --panel: rgba(16, 23, 32, 0.88);
  --panel-strong: #101821;
  --line: rgba(148, 163, 184, 0.18);
  --ink: #ecf4ff;
  --muted: #8fa1b5;
  --green: #34d399;
  --red: #fb7185;
  --blue: #60a5fa;
  --cyan: #22d3ee;
  --amber: #fbbf24;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(34, 211, 238, 0.12), transparent 34rem),
    radial-gradient(circle at 75% 0%, rgba(52, 211, 153, 0.1), transparent 32rem),
    linear-gradient(135deg, #070b10 0%, #0b1118 58%, #081015 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.hidden {
  display: none !important;
}

.login-view {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(460px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 30px;
  background: rgba(16, 24, 33, 0.92);
  box-shadow: var(--shadow);
}

.brand-mark {
  display: grid;
  width: 58px;
  height: 58px;
  place-items: center;
  border-radius: 8px;
  margin-bottom: 22px;
  background: linear-gradient(135deg, var(--cyan), var(--green));
  color: #031015;
  font-size: 22px;
  font-weight: 950;
}

.login-form {
  display: grid;
  gap: 14px;
  margin-top: 24px;
}

.password-field {
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(3, 9, 14, 0.55);
}

.password-field input {
  border: 0;
  background: transparent;
}

.password-field input:focus {
  box-shadow: none;
}

.password-field:focus-within {
  border-color: rgba(34, 211, 238, 0.7);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.1);
}

.password-toggle {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  min-height: 42px;
  min-width: 42px;
  border: 0;
  border-radius: 0 8px 8px 0;
  padding: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  flex-shrink: 0;
}

.password-toggle:hover {
  color: var(--cyan);
}

.shell {
  width: min(1480px, calc(100% - 32px));
  margin: 0 auto;
  padding: 26px 0 52px;
}

.topbar,
.panel-head,
.top-actions,
.hero-grid,
.tabs,
.two-fields {
  display: flex;
}

.topbar {
  align-items: flex-end;
  justify-content: space-between;
  gap: 22px;
  margin-bottom: 18px;
}

.top-actions {
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.eyebrow,
.card-label {
  color: var(--cyan);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 34px;
  line-height: 1.05;
}

h2 {
  font-size: 17px;
}

.muted,
.panel-head p,
.system-card p,
small,
.hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.status-chip,
.mini-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 12px;
  background: rgba(15, 23, 32, 0.8);
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

.status-chip i {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--muted);
}

.status-chip.ok {
  border-color: rgba(52, 211, 153, 0.38);
  color: var(--green);
}

.status-chip.ok i {
  background: var(--green);
  box-shadow: 0 0 16px var(--green);
}

.status-chip.error {
  border-color: rgba(251, 113, 133, 0.38);
  color: var(--red);
}

.status-chip.error i {
  background: var(--red);
  box-shadow: 0 0 16px var(--red);
}

.hero-grid {
  display: grid;
  grid-template-columns: 1.35fr repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.system-card,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.system-card {
  min-height: 138px;
  padding: 18px;
}

.primary-card {
  background:
    linear-gradient(135deg, rgba(34, 211, 238, 0.18), rgba(52, 211, 153, 0.08)),
    var(--panel-strong);
}

.system-card strong {
  display: block;
  margin: 10px 0 8px;
  overflow-wrap: anywhere;
  font-size: 25px;
  line-height: 1.1;
}

.tabs {
  gap: 8px;
  margin: 18px 0 14px;
  overflow-x: auto;
}

.tab {
  min-width: 118px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 16px;
  background: rgba(15, 23, 32, 0.7);
  color: var(--muted);
}

.tab.active {
  border-color: rgba(96, 165, 250, 0.55);
  background: rgba(96, 165, 250, 0.14);
  color: var(--ink);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.72fr);
  gap: 14px;
}

.panel {
  min-width: 0;
  padding: 18px;
}

.panel.full {
  width: 100%;
}

.panel-head {
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

button {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  padding: 0 15px;
  background: linear-gradient(135deg, var(--blue), var(--cyan));
  color: #041019;
  cursor: pointer;
  font-weight: 900;
}

button.primary {
  background: linear-gradient(135deg, var(--green), var(--cyan));
}

button.ghost {
  border: 1px solid var(--line);
  background: rgba(15, 23, 32, 0.7);
  color: var(--ink);
}

.action-link {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  border: 1px solid rgba(34, 211, 238, 0.42);
  border-radius: 8px;
  padding: 0 14px;
  background: rgba(34, 211, 238, 0.1);
  color: var(--cyan);
  font-size: 13px;
  font-weight: 900;
  text-decoration: none;
}

.form-stack {
  display: grid;
  gap: 13px;
}

.two-fields {
  gap: 12px;
}

.two-fields label {
  flex: 1;
}

label {
  display: grid;
  gap: 7px;
  color: #c9d7e6;
  font-size: 13px;
  font-weight: 850;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: rgba(3, 9, 14, 0.55);
  color: var(--ink);
  font: inherit;
  outline: none;
}

input:focus,
textarea:focus {
  border-color: rgba(34, 211, 238, 0.7);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.1);
}

input:disabled {
  color: var(--muted);
  cursor: not-allowed;
}

textarea {
  resize: vertical;
}

.context-editor {
  min-height: 560px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.55;
}

.profile-preview {
  display: flex;
  min-height: 70px;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: rgba(3, 9, 14, 0.4);
}

.profile-preview img {
  display: none;
  width: 52px;
  height: 52px;
  border-radius: 8px;
  object-fit: cover;
}

.advanced {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: rgba(3, 9, 14, 0.35);
}

.advanced summary {
  cursor: pointer;
  color: var(--cyan);
  font-weight: 900;
}

.advanced label {
  margin-top: 12px;
}

.diagnostics {
  display: grid;
  gap: 10px;
}

.diag-row,
.log-row,
.conversation {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: rgba(3, 9, 14, 0.38);
}

.conversation.active {
  border-color: rgba(34, 211, 238, 0.72);
  background: rgba(34, 211, 238, 0.08);
}

.conversation-actions,
.handoff-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.conversation-actions button,
.handoff-actions button {
  min-height: 34px;
  font-size: 12px;
}

.handoff-box {
  display: grid;
  gap: 12px;
}

.summary-box {
  border: 1px solid rgba(251, 191, 36, 0.35);
  border-radius: 8px;
  padding: 10px;
  background: rgba(251, 191, 36, 0.08);
  color: #f8ddb0;
  font-size: 13px;
  line-height: 1.45;
}

.diag-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.diag-row strong {
  font-size: 14px;
}

.diag-row span {
  color: var(--muted);
  font-size: 12px;
}

.log-list,
.conversation-list {
  display: grid;
  gap: 8px;
  max-height: 68vh;
  overflow: auto;
  padding-right: 4px;
}

.log-top,
.conversation-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.log-level {
  font-size: 12px;
  font-weight: 950;
  text-transform: uppercase;
}

.log-level.info {
  color: var(--blue);
}

.log-level.warn {
  color: var(--amber);
}

.log-level.error {
  color: var(--red);
}

.log-time {
  color: var(--muted);
  font-size: 12px;
}

.log-message {
  margin-top: 7px;
  font-weight: 780;
}

.log-meta,
.message-list {
  margin: 8px 0 0;
  color: #b6c5d6;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.form-error {
  min-height: 18px;
  color: var(--red);
  font-size: 13px;
}

@media (max-width: 1060px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .hero-grid,
  .grid {
    grid-template-columns: 1fr;
  }

  .two-fields {
    flex-direction: column;
  }
}

/* ─── Chat Interface ─────────────────────────────────────────────────────── */

.chat-container {
  display: flex;
  height: calc(100vh - 280px);
  min-height: 520px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel-strong);
  box-shadow: var(--shadow);
}

.chat-sidebar {
  width: 300px;
  min-width: 200px;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  background: rgba(3, 9, 14, 0.5);
}

.chat-sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.chat-sidebar-head h2 {
  font-size: 15px;
}

.chat-refresh {
  min-height: 30px;
  font-size: 11px;
  padding: 0 10px;
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}

.chat-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}

.chat-item:hover {
  background: rgba(34, 211, 238, 0.06);
}

.chat-item.active {
  background: rgba(34, 211, 238, 0.12);
}

.chat-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.chat-item-name {
  font-size: 14px;
  font-weight: 800;
}

.chat-item-time {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.chat-item-preview {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-item-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--green);
}

.chat-window {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-empty {
  flex: 1;
  display: grid;
  place-items: center;
}

.chat-active {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(3, 9, 14, 0.5);
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-header-info strong {
  font-size: 15px;
}

.chat-mode-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 800;
}

.chat-mode-badge.ia {
  background: rgba(96, 165, 250, 0.15);
  color: var(--blue);
  border: 1px solid rgba(96, 165, 250, 0.3);
}

.chat-mode-badge.human {
  background: rgba(52, 211, 153, 0.15);
  color: var(--green);
  border: 1px solid rgba(52, 211, 153, 0.3);
}

.chat-mode-badge.internal {
  background: rgba(251, 191, 36, 0.15);
  color: var(--amber);
  border: 1px solid rgba(251, 191, 36, 0.3);
}

#chatToggleMode {
  min-height: 34px;
  font-size: 12px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.msg-bubble {
  max-width: 72%;
  padding: 9px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.4;
  word-break: break-word;
  white-space: pre-wrap;
}

.msg-bubble.incoming {
  align-self: flex-start;
  background: rgba(30, 41, 56, 0.9);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}

.msg-bubble.outgoing {
  align-self: flex-end;
  background: rgba(34, 211, 153, 0.15);
  border: 1px solid rgba(52, 211, 153, 0.25);
  border-bottom-right-radius: 4px;
}

.msg-bubble.outgoing.human {
  background: rgba(96, 165, 250, 0.12);
  border-color: rgba(96, 165, 250, 0.25);
}

.msg-role {
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 3px;
  opacity: 0.6;
}

.msg-image-placeholder {
  display: flex;
  align-items: center;
  gap: 6px;
  font-style: italic;
  opacity: 0.7;
}

.chat-image-preview {
  padding: 8px 18px;
  border-top: 1px solid var(--line);
  background: rgba(3, 9, 14, 0.4);
}

.chat-image-preview img {
  max-height: 80px;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.chat-image-preview .remove-preview {
  display: inline-flex;
  align-items: center;
  margin-left: 8px;
  color: var(--red);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.chat-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  background: rgba(3, 9, 14, 0.5);
}

.chat-icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  min-height: 40px;
  min-width: 40px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0;
  background: rgba(15, 23, 32, 0.7);
  color: var(--muted);
  cursor: pointer;
  flex-shrink: 0;
}

.chat-icon-btn:hover {
  color: var(--cyan);
  border-color: rgba(34, 211, 238, 0.4);
}

.chat-text-input {
  flex: 1;
  resize: none;
  max-height: 120px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  background: rgba(3, 9, 14, 0.55);
  color: var(--ink);
  font: inherit;
  outline: none;
  line-height: 1.4;
}

.chat-text-input:focus {
  border-color: rgba(34, 211, 238, 0.5);
}

.chat-send-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  min-height: 40px;
  min-width: 40px;
  border: 0;
  border-radius: 999px;
  padding: 0;
  background: linear-gradient(135deg, var(--green), var(--cyan));
  color: #041019;
  cursor: pointer;
  flex-shrink: 0;
}

.chat-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

@media (max-width: 760px) {
  .chat-sidebar {
    width: 220px;
    min-width: 160px;
  }

  .msg-bubble {
    max-width: 85%;
  }
}
