@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=Fira+Code:wght@400;500&display=swap');

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

:root {
  --color-bg:           #0D1117;
  --color-surface:      #161B22;
  --color-surface-alt:  #1C2128;
  --color-border:       #21262D;
  --color-border-sub:   #30363D;
  --color-text:         #E6EDF3;
  --color-text-muted:   #7D8590;
  --color-accent:       #F6821F;
  --color-accent-dim:   rgba(246, 130, 31, 0.12);
  --color-accent-ring:  rgba(246, 130, 31, 0.25);
  --color-user-text:    #0D1117;
  --color-ok:           #3FB950;
  --color-warn:         #D29922;
  --color-danger:       #F85149;
  --color-error-bg:     rgba(248, 81, 73, 0.08);
  --color-error-border: rgba(248, 81, 73, 0.35);
  --color-error-text:   #F85149;
  --radius:             6px;
  --font-sans:          'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono:          'Fira Code', 'Cascadia Code', 'SF Mono', 'Consolas', monospace;
}

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--color-border-sub); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--color-text-muted); }

::selection { background: var(--color-accent); color: var(--color-user-text); }

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ── App shell ─────────────────────────────────────────────────────────── */

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  width: 100%;
}

/* ── Header ────────────────────────────────────────────────────────────── */

.app-header {
  padding: 0 20px;
  height: 48px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--color-surface);
}

.app-header__icon {
  width: 18px;
  height: 18px;
  color: var(--color-accent);
  flex-shrink: 0;
}

.app-header h1 {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--color-text);
  white-space: nowrap;
}

.app-header__sep {
  color: var(--color-border-sub);
  font-size: 14px;
  font-weight: 300;
}

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

.app-header__meta {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.app-header__action {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  background: transparent;
  border: 1px solid var(--color-border-sub);
  padding: 3px 9px;
  border-radius: 3px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.app-header__action:hover:not(:disabled) {
  color: var(--color-text);
  border-color: var(--color-text-muted);
}

.app-header__action:disabled { opacity: 0.4; cursor: not-allowed; }

.app-header__action--primary {
  color: var(--color-accent);
  border-color: rgba(246, 130, 31, 0.35);
}

.app-header__action--primary:hover:not(:disabled) {
  color: var(--color-accent);
  border-color: var(--color-accent);
  background: var(--color-accent-dim);
}


.app-header__badge {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  border: 1px solid var(--color-border-sub);
  padding: 2px 7px;
  border-radius: 3px;
}


/* ── Icon buttons (header) ─────────────────────────────────────────────── */

.app-header__icon-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  border-radius: 4px;
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
}

.app-header__icon-btn:hover {
  color: var(--color-text);
  background: var(--color-surface-alt);
}

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

/* ── Three-panel layout ────────────────────────────────────────────────── */

.main-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ── Sessions panel (left) ─────────────────────────────────────────────── */

.sessions-panel {
  width: 196px;
  min-width: 196px;
  flex-shrink: 0;
  border-right: 1px solid var(--color-border);
  background: var(--color-surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.2s ease, min-width 0.2s ease, border-right-width 0.2s ease;
}

.sessions-panel.collapsed {
  width: 0;
  min-width: 0;
  border-right-width: 0;
}

.sessions-panel__top {
  padding: 10px 8px 4px;
  flex-shrink: 0;
}

.sessions-new-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 400;
  cursor: pointer;
  transition: background 0.15s;
  text-align: left;
}

.sessions-new-btn:hover {
  background: rgba(255, 255, 255, 0.06);
}

.sessions-new-btn svg {
  flex-shrink: 0;
  color: var(--color-text-muted);
}

.sessions-panel__body {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0 8px;
}

/* ── Session list ──────────────────────────────────────────────────────── */

.sessions-list {
  list-style: none;
  padding: 0;
}

.sessions-section-label {
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  color: var(--color-text-muted);
  padding: 10px 20px 4px;
  letter-spacing: 0.01em;
}

.session-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  margin: 1px 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s;
  white-space: nowrap;
}

.session-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.session-item.active {
  background: rgba(255, 255, 255, 0.1);
}

.session-item__icon {
  flex-shrink: 0;
  color: var(--color-text-muted);
  opacity: 0.7;
}

.session-item__label {
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 400;
  color: var(--color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.session-item.active .session-item__label {
  color: var(--color-text);
  font-weight: 500;
}

.session-item__del {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  border-radius: 4px;
  font-size: 14px;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
  padding: 0;
}

.session-item:hover .session-item__del {
  opacity: 0.6;
}

.session-item__del:hover {
  opacity: 1 !important;
  color: var(--color-danger);
}

/* ── Chat panel (left) ─────────────────────────────────────────────────── */

.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  background: var(--color-bg);
}

/* ── Message list ──────────────────────────────────────────────────────── */

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 24px 8px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* ── Individual message ────────────────────────────────────────────────── */

.message {
  display: flex;
  flex-direction: column;
  margin-bottom: 22px;
}

.message--user      { align-self: flex-end;   align-items: flex-end;   max-width: 62%; }
.message--assistant { align-self: flex-start; align-items: flex-start; max-width: 88%; }

.message__frame {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--color-text-muted);
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 5px;
  letter-spacing: 0.04em;
  opacity: 0.7;
}

.message__frame-arrow {
  color: var(--color-accent);
}

.message__body {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}

.message--user .message__body {
  background: var(--color-accent);
  color: var(--color-user-text);
  font-weight: 500;
  border-bottom-right-radius: 2px;
}

.message--assistant .message__body {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-left: 2px solid var(--color-border-sub);
  color: var(--color-text);
  border-bottom-left-radius: 2px;
  padding: 11px 16px;
}

.message--assistant .message__body code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--color-surface-alt);
  color: var(--color-accent);
  padding: 1px 5px;
  border-radius: 3px;
  border: 1px solid var(--color-border-sub);
}

.message__code-block {
  position: relative;
  background: var(--color-bg);
  border: 1px solid var(--color-border-sub);
  border-left: 2px solid var(--color-accent);
  border-radius: 4px;
  padding: 10px 14px;
  padding-right: 60px;
  margin-top: 8px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--color-text);
  white-space: pre;
  overflow-x: auto;
  line-height: 1.5;
}

.message__code-copy {
  position: absolute;
  top: 7px;
  right: 8px;
  background: transparent;
  border: 1px solid var(--color-border-sub);
  color: var(--color-text-muted);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  border-radius: 3px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.message__code-copy:hover {
  color: var(--color-text);
  border-color: var(--color-text-muted);
}

.message__body pre {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--color-bg);
  color: var(--color-text);
  padding: 10px 14px;
  border-radius: 4px;
  border: 1px solid var(--color-border);
  overflow-x: auto;
  margin-top: 8px;
  white-space: pre;
  line-height: 1.5;
}

/* Loading dots */
.loading-dots {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  padding: 2px 0;
}

.loading-dots span {
  width: 5px;
  height: 5px;
  background: var(--color-text-muted);
  border-radius: 50%;
  animation: dot-pulse 1.2s ease-in-out infinite;
}
.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot-pulse {
  0%, 80%, 100% { opacity: 0.2; transform: scale(0.75); }
  40%           { opacity: 1;   transform: scale(1); }
}

/* ── Error banner ──────────────────────────────────────────────────────── */

.error-banner {
  margin: 0 20px 6px;
  padding: 8px 12px;
  background: var(--color-error-bg);
  border: 1px solid var(--color-error-border);
  border-radius: var(--radius);
  color: var(--color-error-text);
  font-family: var(--font-mono);
  font-size: 12px;
  flex-shrink: 0;
}

/* ── Input area ────────────────────────────────────────────────────────── */

.input-area {
  padding: 12px 20px;
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}

/* Wrapper gives the beam a surface to anchor to - needed because ::before
   cannot be placed directly on a <textarea> element. */
.input-area__field {
  flex: 1;
  min-width: 0;
  position: relative;
  display: flex;
}

/* Beam: orange glow that orbits the textarea border.
   Technique: conic-gradient fills the wrapper; mask-composite:exclude
   cuts out the content area, leaving only the 1px border ring visible. */
@property --beam-angle {
  syntax: '<angle>';
  initial-value: 0deg;
  inherits: false;
}

.input-area__field::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  padding: 1px;
  background: conic-gradient(
    from var(--beam-angle) at 50% 50%,
    transparent              0deg,
    transparent            300deg,
    rgba(246, 130, 31, 0.1) 330deg,
    rgba(246, 130, 31, 0.6) 348deg,
    #F6821F                 353deg,
    rgba(246, 130, 31, 0.6) 358deg,
    transparent            360deg
  );
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  animation: beam-rotate 3s linear infinite;
  pointer-events: none;
  z-index: 1;
}

@keyframes beam-rotate {
  from { --beam-angle:   0deg; }
  to   { --beam-angle: 360deg; }
}

.input-area__prompt {
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--color-accent);
  flex-shrink: 0;
  user-select: none;
  line-height: 1;
}

.input-area__textarea {
  flex: 1;
  min-width: 0;
  padding: 9px 12px;
  border: 1px solid var(--color-border-sub);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.55;
  resize: none;
  outline: none;
  color: var(--color-text);
  background: var(--color-bg);
  transition: border-color 0.15s, box-shadow 0.15s;
  caret-color: var(--color-accent);
}

.input-area__textarea::placeholder { color: var(--color-text-muted); }

.input-area__textarea:focus {
  border-color: var(--color-border-sub);
  outline: none;
}

.input-area__textarea:disabled { opacity: 0.45; cursor: not-allowed; }

.input-area__send {
  padding: 9px 16px;
  background: var(--color-accent);
  color: var(--color-user-text);
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.15s;
  display: flex;
  align-items: center;
  gap: 6px;
  line-height: 1;
}

.input-area__send:hover:not(:disabled) { opacity: 0.86; }
.input-area__send:disabled             { opacity: 0.4; cursor: not-allowed; }

/* ── Incident panel (right) - packet inspector ─────────────────────────── */

.incident-panel {
  width: 284px;
  min-width: 284px;
  flex-shrink: 0;
  border-left: 1px solid var(--color-border);
  background: var(--color-surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.2s ease, min-width 0.2s ease, border-left-width 0.2s ease;
}

.incident-panel.collapsed {
  width: 0;
  min-width: 0;
  border-left-width: 0;
}

.incident-panel__header {
  height: 36px;
  padding: 0 16px;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  background: var(--color-surface-alt);
}

.incident-panel__header-icon {
  width: 13px;
  height: 13px;
  color: var(--color-text-muted);
  flex-shrink: 0;
}

.incident-panel__title {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-muted);
}

.incident-panel__body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
}

.incident-summary-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 16px;
  padding: 5px 0;
  background: transparent;
  border: none;
  color: var(--color-text-muted);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color 0.15s;
}

.incident-summary-btn:hover:not(:disabled) {
  color: var(--color-accent);
}

.incident-summary-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.incident-empty {
  color: var(--color-text-muted);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 2;
  padding-top: 4px;
}

/* Status badge */
.incident-status {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.07em;
  margin-bottom: 14px;
}

.incident-status::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.incident-status--investigating { background: rgba(210,153,34,.12); color: var(--color-warn);   border: 1px solid rgba(210,153,34,.3); }
.incident-status--resolved      { background: rgba(63,185,80,.12);  color: var(--color-ok);     border: 1px solid rgba(63,185,80,.3);  }
.incident-status--escalated     { background: rgba(248,81,73,.12);  color: var(--color-danger); border: 1px solid rgba(248,81,73,.3);  }

/* Inspector section */
.incident-section {
  margin-bottom: 14px;
  border-left: 1px solid var(--color-accent);
  padding-left: 10px;
}

.incident-section__label {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-muted);
  margin-bottom: 6px;
}

.incident-section__list {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.incident-section__list li {
  font-size: 12px;
  color: var(--color-text);
  line-height: 1.5;
  display: flex;
  gap: 6px;
  align-items: flex-start;
}

.incident-section__list li::before {
  content: '·';
  font-family: var(--font-mono);
  color: var(--color-text-muted);
  flex-shrink: 0;
  line-height: 1.5;
}

.incident-section--confirmed .incident-section__list li::before {
  content: '✓';
  color: var(--color-ok);
}

/* Next step */
.incident-next-step-section {
  border-left: 1px solid var(--color-accent);
  padding-left: 10px;
  margin-top: 2px;
}

.incident-next-step-label {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-accent);
  margin-bottom: 6px;
}

.incident-next-step {
  font-size: 12px;
  font-family: var(--font-sans);
  padding: 9px 11px;
  background: var(--color-accent-dim);
  border: 1px solid var(--color-accent-ring);
  border-radius: var(--radius);
  color: var(--color-text);
  line-height: 1.55;
  display: flex;
  gap: 7px;
  align-items: flex-start;
}

.incident-next-step::before {
  content: '→';
  font-family: var(--font-mono);
  color: var(--color-accent);
  flex-shrink: 0;
  line-height: 1.55;
  font-size: 11px;
}

/* ── Connectivity grid ─────────────────────────────────────────────────── */

.conn-list {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.conn-row {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  line-height: 1.4;
}

.conn-sym {
  font-family: var(--font-mono);
  font-size: 11px;
  width: 12px;
  flex-shrink: 0;
  text-align: center;
}

.conn-label {
  flex: 1;
  color: var(--color-text);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conn-val {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.conn-row--reachable .conn-sym,
.conn-row--working   .conn-sym  { color: var(--color-ok); }
.conn-row--unreachable .conn-sym,
.conn-row--failing   .conn-sym  { color: var(--color-danger); }
.conn-row--unknown   .conn-sym  { color: var(--color-text-muted); }

.conn-row--reachable .conn-val,
.conn-row--working   .conn-val  { color: var(--color-ok); }
.conn-row--unreachable .conn-val,
.conn-row--failing   .conn-val  { color: var(--color-danger); }
.conn-row--unknown   .conn-val  { color: var(--color-text-muted); }

/* ── Responsive ────────────────────────────────────────────────────────── */

@media (max-width: 640px) {
  .main-layout      { flex-direction: column; }
  .sessions-panel   { width: 100%; min-width: 100%; border-right: none; border-bottom: 1px solid var(--color-border); max-height: 180px; }
  .incident-panel   { width: 100%; min-width: 100%; border-left: none; border-top: 1px solid var(--color-border); max-height: 220px; }
  .app-header__sub  { display: none; }
}

/* ── Light theme ───────────────────────────────────────────────────────── */

[data-theme="light"] {
  --color-bg:           #F6F8FA;
  --color-surface:      #FFFFFF;
  --color-surface-alt:  #EAEEF2;
  --color-border:       #D0D7DE;
  --color-border-sub:   #BABFC5;
  --color-text:         #24292F;
  --color-text-muted:   #57606A;
  --color-accent:       #E07A10;
  --color-accent-dim:   rgba(224, 122, 16, 0.08);
  --color-accent-ring:  rgba(224, 122, 16, 0.22);
  --color-user-text:    #FFFFFF;
  --color-ok:           #1A7F37;
  --color-warn:         #9A6700;
  --color-danger:       #CF222E;
  --color-error-bg:     rgba(207, 34, 46, 0.06);
  --color-error-border: rgba(207, 34, 46, 0.25);
  --color-error-text:   #CF222E;
}

[data-theme="light"] .message--assistant .message__body code {
  background: rgba(224, 122, 16, 0.07);
  color: #A85200;
  border-color: rgba(224, 122, 16, 0.2);
}

[data-theme="light"] .message__body pre {
  background: var(--color-surface-alt);
  border-color: var(--color-border);
  color: var(--color-text);
}
