/* ============================================================
   Design tokens
   ============================================================ */
:root {
  --color-pitch-900: #0b3d2e;
  --color-pitch-700: #146c43;
  --color-pitch-600: #1a7a4c;
  --color-pitch-100: #e3f1e8;
  --color-gold-500: #f2b705;
  --color-gold-600: #d9a300;

  --color-bg: #f5f7f6;
  --color-surface: #ffffff;
  --color-text: #16241f;
  --color-text-muted: #55655d;
  --color-border: #e0e6e2;

  --color-danger-bg: #fdecea;
  --color-danger-text: #7a1f1f;
  --color-danger-border: #f3b9b4;

  --color-density-low: #1a7a4c;
  --color-density-medium: #b8860b;
  --color-density-high: #b3261e;

  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-full: 999px;

  --shadow-sm: 0 1px 2px rgba(11, 61, 46, 0.08);
  --shadow-md: 0 8px 24px rgba(11, 61, 46, 0.12);

  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

/* ============================================================
   Reset & base
   ============================================================ */
* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
  cursor: pointer;
}

textarea {
  font-family: inherit;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 3px solid var(--color-gold-600);
  outline-offset: 2px;
}

/* Author rules like `.typing-indicator { display: flex }` otherwise beat the
   UA stylesheet's `[hidden] { display: none }` at equal specificity. */
[hidden] {
  display: none !important;
}

/* ============================================================
   App shell
   ============================================================ */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 960px;
  margin: 0 auto;
  background: var(--color-bg);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  background: linear-gradient(135deg, var(--color-pitch-900), var(--color-pitch-700));
  color: #fff;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  font-size: 28px;
  line-height: 1;
  background: var(--color-gold-500);
  color: var(--color-pitch-900);
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-text h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.subtitle {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: rgba(255, 255, 255, 0.88);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ops-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #fff;
  padding: 9px 14px;
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  transition: background 0.15s ease;
}

.ops-toggle:hover {
  background: rgba(255, 255, 255, 0.22);
}

.ops-toggle[aria-pressed='true'] {
  background: var(--color-gold-500);
  border-color: var(--color-gold-500);
  color: var(--color-pitch-900);
}

/* ============================================================
   Main layout
   ============================================================ */
.app-main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr;
}

.app-main:has(.ops-panel:not([hidden])) {
  grid-template-columns: 1fr 300px;
}

.chat-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
}

/* ============================================================
   Message list
   ============================================================ */
.message-list {
  flex: 1;
  overflow-y: auto;
  padding: 20px 20px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.message {
  max-width: 78%;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  animation: message-in 0.18s ease-out;
}

@keyframes message-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message.from-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message.from-assistant {
  align-self: flex-start;
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
}

.avatar-assistant {
  background: var(--color-pitch-100);
  color: var(--color-pitch-900);
}

.avatar-user {
  background: var(--color-pitch-700);
  color: #fff;
  font-weight: 700;
  font-size: 12px;
}

.message-body {
  min-width: 0;
}

.bubble {
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  font-size: 15px;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.from-assistant .bubble {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm);
}

.from-user .bubble {
  background: var(--color-pitch-700);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.message-meta {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.from-user .message-meta {
  justify-content: flex-end;
}

.badge {
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.badge-language {
  background: var(--color-pitch-100);
  color: var(--color-pitch-900);
}

.badge-tool {
  background: #fff6dc;
  color: #7a5c00;
  border: 1px solid #f0dca0;
}

/* ============================================================
   Typing indicator
   ============================================================ */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px 10px;
}

.typing-dots {
  display: flex;
  gap: 4px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  border-bottom-left-radius: 4px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-text-muted);
  animation: typing-bounce 1.2s infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}
.typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes typing-bounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.5;
  }
  30% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

/* ============================================================
   Error banner
   ============================================================ */
.error-banner {
  margin: 0 20px 10px;
  padding: 10px 14px;
  background: var(--color-danger-bg);
  color: var(--color-danger-text);
  border: 1px solid var(--color-danger-border);
  border-radius: var(--radius-md);
  font-size: 13.5px;
}

/* ============================================================
   Quick replies
   ============================================================ */
.quick-replies {
  display: flex;
  gap: 8px;
  padding: 0 20px 12px;
  overflow-x: auto;
  flex-shrink: 0;
}

.chip {
  flex-shrink: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-pitch-900);
  padding: 8px 14px;
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 600;
  transition:
    border-color 0.15s ease,
    background 0.15s ease;
}

.chip:hover {
  border-color: var(--color-pitch-600);
  background: var(--color-pitch-100);
}

.chip:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ============================================================
   Chat input form
   ============================================================ */
.chat-form {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 20px 20px;
  border-top: 1px solid var(--color-border);
  background: var(--color-bg);
  flex-shrink: 0;
}

.chat-form textarea {
  flex: 1;
  resize: none;
  overflow-y: auto;
  max-height: 120px;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  font-size: 15px;
  color: var(--color-text);
  line-height: 1.4;
}

.chat-form textarea:focus {
  border-color: var(--color-pitch-600);
}

.send-button {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  border: none;
  background: var(--color-pitch-700);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    background 0.15s ease,
    transform 0.1s ease;
}

.send-button:hover {
  background: var(--color-pitch-900);
}

.send-button:active {
  transform: scale(0.94);
}

.send-button:disabled {
  background: var(--color-text-muted);
  cursor: not-allowed;
}

/* ============================================================
   Operations panel (stretch feature)
   ============================================================ */
.ops-panel {
  border-left: 1px solid var(--color-border);
  background: var(--color-surface);
  padding: 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.ops-panel-header h2 {
  font-size: 15px;
  margin: 0 0 4px;
}

.ops-panel-note {
  font-size: 11.5px;
  color: var(--color-text-muted);
  margin: 0;
  line-height: 1.4;
}

.ops-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ops-card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  animation: ops-card-in 0.25s ease-out;
}

@keyframes ops-card-in {
  from {
    opacity: 0;
    transform: translateY(2px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.ops-card-title {
  font-size: 13px;
  font-weight: 700;
  margin: 0 0 6px;
}

.ops-card-row {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  color: var(--color-text-muted);
}

.density-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 5px;
}

.density-low {
  background: var(--color-density-low);
}
.density-medium {
  background: var(--color-density-medium);
}
.density-high {
  background: var(--color-density-high);
}

.ops-panel-footer {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ops-refresh {
  flex-shrink: 0;
  background: var(--color-pitch-100);
  color: var(--color-pitch-900);
  border: none;
  padding: 8px 14px;
  border-radius: var(--radius-full);
  font-size: 12.5px;
  font-weight: 700;
}

.ops-refresh:hover {
  background: var(--color-gold-500);
}

.ops-last-updated {
  margin: 0;
  font-size: 11px;
  color: var(--color-text-muted);
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 720px) {
  .app-main:has(.ops-panel:not([hidden])) {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
  }

  .ops-panel {
    border-left: none;
    border-top: 1px solid var(--color-border);
    max-height: 45vh;
  }

  .subtitle {
    display: none;
  }

  .ops-toggle-label {
    display: none;
  }

  .message {
    max-width: 88%;
  }
}

/* ============================================================
   Reduced motion
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  .message,
  .typing-dots span,
  .ops-card {
    animation: none !important;
  }
}
