/* ============================================================
   DESIGN TOKENS — warm editorial light
   ============================================================ */
:root {
  --bg:           #f4f1ea;
  --surface:      #ffffff;
  --surface-2:    #f9f7f3;
  --border:       #ddd8ce;
  --border-2:     #c9c3b8;
  --text:         #111111;
  --text-dim:     #111111;
  --text-faint:   #2f2a24;
  --accent:       #1a6b4a;
  --accent-light: #e8f5ee;
  --accent-glow:  rgba(26, 107, 74, 0.1);
  --danger:       #b91c1c;
  --danger-bg:    rgba(185, 28, 28, 0.06);
  --warn:         #92400e;
  --radius:       3px;
  --font-mono:    'JetBrains Mono', 'Courier New', monospace;
  --font-display: 'Syne', sans-serif;
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

[hidden] { display: none !important; }

html { font-size: 14px; }

body {
  font-family: var(--font-mono);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  overflow-x: hidden;
  position: relative;
}

/* Subtle grain texture overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.018;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 180px;
}

.scanlines { display: none; }

/* ============================================================
   LAYOUT
   ============================================================ */
.chat-shell {
  max-width: 1120px;
  margin: 0 auto;
  padding: 32px 28px 72px;
  position: relative;
  z-index: 1;
}

.env-banner {
  width: 100%;
  padding: 10px 18px;
  border-top: 1px solid #e8cf8b;
  border-bottom: 1px solid #e8cf8b;
  background: linear-gradient(180deg, #f8eec8 0%, #f6e6b4 100%);
  color: #95530d;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  line-height: 1.4;
  text-align: center;
  box-shadow: inset 0 -1px 0 rgba(149, 83, 13, 0.08);
}

/* ============================================================
   HEADER
   ============================================================ */
.app-header {
  margin-bottom: 36px;
  padding-top: 18px;
  padding-bottom: 28px;
  border-bottom: 1.5px solid var(--border);
  background: color-mix(in srgb, var(--bg) 88%, rgba(255, 255, 255, 0.78) 12%);
  backdrop-filter: blur(10px);
  position: relative;
  position: sticky;
  top: 0;
  z-index: 20;
}

.account-actions {
  position: absolute;
  top: 0;
  right: 0;
  font-size: 10px;
  letter-spacing: 0.1em;
}

.btn-sm {
  padding: 4px 10px;
}

.header-id {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 12px;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  animation: dot-pulse 2.4s ease-in-out infinite;
}

@keyframes dot-pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(26, 107, 74, 0.4); }
  50%       { opacity: 0.6; box-shadow: 0 0 0 5px rgba(26, 107, 74, 0); }
}

.header-sep  { color: var(--text-faint); }
.header-org  { color: var(--accent); font-weight: 600; }

.header-title {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.025em;
  line-height: 1.1;
  margin-bottom: 8px;
}

.header-sub {
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.04em;
}

.operator-note {
  margin-bottom: 18px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 11px;
  line-height: 1.6;
}

/* ============================================================
   PANELS GRID
   ============================================================ */
.panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 18px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.panel:hover {
  border-color: var(--border-2);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.panel-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}

.panel-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.panel-intent {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}

.panel-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ============================================================
   STATUS / META / ERROR TEXT
   ============================================================ */
.status {
  font-size: 11px;
  color: var(--text);
  line-height: 1.5;
}

.meta-line {
  font-size: 11px;
  color: var(--text);
  padding: 7px 10px;
  background: var(--surface-2);
  border-left: 2px solid var(--border-2);
  border-radius: 0 2px 2px 0;
}

.error-line {
  font-size: 11px;
  color: var(--danger);
  padding: 7px 10px;
  background: var(--danger-bg);
  border-left: 2px solid var(--danger);
  border-radius: 0 2px 2px 0;
}

.pulse-text {
  color: var(--accent);
  animation: text-blink 1.1s ease-in-out infinite;
}

@keyframes text-blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.35; }
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.15s ease;
  width: fit-content;
}

.btn-icon { font-size: 10px; }

.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border-2);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--text-dim);
}

.btn-accent {
  background: var(--accent);
  color: #fff;
}

.btn-accent:hover:not(:disabled) {
  background: #155a3d;
  box-shadow: 0 2px 10px rgba(26, 107, 74, 0.25);
}

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

/* ============================================================
   FORM
   ============================================================ */
#chat-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.select-wrap { position: relative; }

select {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 12px 40px 12px 14px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

select option { background: var(--surface); color: var(--text); }

.select-caret {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  pointer-events: none;
  font-size: 13px;
}

/* ============================================================
   ANSWER AREA
   ============================================================ */
.answer-area {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.answer-body { padding: 0; }

/* ============================================================
   TABLE
   ============================================================ */
table {
  width: 100%;
  border-collapse: collapse;
}

thead tr {
  background: var(--accent);
}

thead th {
  padding: 10px 16px;
  text-align: left;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #fff;
  white-space: nowrap;
}

tbody tr { border-bottom: 1px solid var(--border); transition: background 0.1s; }
tbody tr:nth-child(odd)  { background: var(--surface); }
tbody tr:nth-child(even) { background: var(--surface-2); }
tbody tr:hover { background: var(--accent-light); }

tbody td {
  padding: 9px 16px;
  vertical-align: top;
  word-break: break-word;
  font-size: 11px;
  color: var(--text);
}

tbody td:first-child { font-weight: 600; }

/* ============================================================
   PRE
   ============================================================ */
pre {
  margin: 0;
  padding: 24px;
  white-space: pre-wrap;
  font-size: 11px;
  color: var(--text);
  line-height: 1.8;
}

/* ============================================================
   MODAL
   ============================================================ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(37, 33, 24, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-backdrop[hidden] { display: none; }

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px;
  max-width: 360px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-top {
  display: flex;
  align-items: center;
  gap: 12px;
}

.modal-glyph { font-size: 22px; color: var(--accent); line-height: 1; }

.modal-title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
}

.modal-desc { font-size: 11px; color: var(--text-dim); line-height: 1.6; }

.modal-input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 10px 12px;
  letter-spacing: 0.05em;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.modal-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.modal-input::placeholder { color: var(--text-faint); }

.modal-actions { display: flex; justify-content: flex-end; }
.account-actions { display: flex; gap: 8px; }
.password-actions { gap: 8px; flex-wrap: wrap; }
#password-form .field-label { display: block; margin-top: 12px; }
#password-panel { overflow-y: auto; }
#password-panel .modal-box { margin: auto; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 620px) {
  .panels { grid-template-columns: 1fr; }
  .header-title { font-size: 20px; }
  .chat-shell { padding: 24px 16px 56px; }
  .app-header { padding-top: 14px; }
  .env-banner {
    padding: 10px 14px;
    font-size: 10px;
  }
  .operator-note {
    padding: 12px 14px;
  }
}

.service-issues { table-layout: fixed; }
.service-issues th { white-space: normal; }

@media (max-width: 600px) {
  .account-actions { position: static; justify-content: flex-end; margin: 12px 0; }
}
