/* ==========================================================================
   LiteRT-LM Analog Precision - Vintage Terminal Design System
   A synthesis of Swiss International Typographic Style and 1970s laboratory equipment.
   ========================================================================== */

:root {
  /* Surfaces & Backgrounds */
  --bg-parchment: #f6f3ee;
  --bg-rack: #ece7df;
  --bg-card: #ffffff;
  --bg-inset: #e4dfd5;
  --bg-crt: #141920;
  --bg-input: #f0ebe2;

  /* Inks & Typography */
  --text-ink: #1f2421;
  --text-muted: #545c57;
  --text-dim: #7e8781;
  --text-light: #f6f3ee;

  /* Functional & Vintage Accents */
  --amber: #d97706;
  --amber-dark: #b45309;
  --amber-glow: rgba(217, 119, 6, 0.25);
  --brass: #925c1a;
  --brass-light: #c28836;
  --sage: #059669;
  --sage-glow: rgba(5, 150, 105, 0.3);
  --red-tactile: #dc2626;

  /* Borders & Dividers */
  --border: rgba(31, 36, 33, 0.16);
  --border-strong: rgba(31, 36, 33, 0.32);
  --border-inset: rgba(31, 36, 33, 0.08);

  /* Fonts */
  --font-serif: 'IBM Plex Serif', Georgia, serif;
  --font-sans: 'Public Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'Courier Prime', 'JetBrains Mono', monospace;

  /* UI Sizing & Geometry */
  --radius-sm: 3px;
  --radius-md: 5px;
  --radius-lg: 8px;
}

/* Base resets & overscroll locks */
html, body {
  margin: 0;
  padding: 0;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  overscroll-behavior: none;
  background-color: var(--bg-parchment);
  color: var(--text-ink);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

* {
  box-sizing: border-box;
}

/* Scrollbars - Vintage Fine-Line Style */
::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}
::-webkit-scrollbar-track {
  background: var(--bg-rack);
}
::-webkit-scrollbar-thumb {
  background: rgba(31, 36, 33, 0.25);
  border-radius: var(--radius-sm);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--amber-dark);
}

/* ==========================================================================
   Top Command Navigation Header (Brass Plate & Analog VU-Meter)
   ========================================================================== */
.terminal-header {
  background-color: var(--bg-rack);
  border-bottom: 2px solid var(--border-strong);
  padding: 10px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  z-index: 100;
  box-shadow: 0 2px 6px rgba(31, 36, 33, 0.04);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* Brass Hardware Plate */
.brass-plate {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(135deg, #d49f57 0%, #b87c2b 50%, #925c1a 100%);
  color: #ffffff;
  padding: 5px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid #734510;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 2px 4px rgba(0, 0, 0, 0.15);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

.brass-plate-title {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.brass-plate-tag {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  padding: 1px 5px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 2px;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

/* Model Load Badge & Pilot Lamps */
.header-status-cluster {
  display: flex;
  align-items: center;
  gap: 12px;
}

.model-badge {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-ink);
  background-color: var(--bg-card);
  border: 1px solid var(--border-strong);
  padding: 4px 9px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.04);
}

.pilot-lamp-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pilot-lamp {
  display: flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-muted);
  font-weight: 700;
}

.lamp-bulb {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.2);
  background-color: #94a3b8;
  transition: all 0.2s ease;
}

.lamp-bulb.active {
  background-color: var(--sage);
  box-shadow: 0 0 8px var(--sage-glow), inset 0 0 2px #ffffff;
}

.lamp-bulb.amber {
  background-color: var(--amber);
  box-shadow: 0 0 8px var(--amber-glow), inset 0 0 2px #ffffff;
}

/* Analog VU-Meter / Generation Speedometer */
.vu-meter-container {
  display: flex;
  align-items: center;
  gap: 10px;
  background-color: var(--bg-crt);
  border: 1px solid #2d3748;
  border-radius: var(--radius-sm);
  padding: 4px 12px;
  color: #ffffff;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
}

.vu-meter-dial {
  position: relative;
  width: 58px;
  height: 28px;
  overflow: hidden;
  border-bottom: 1px solid #4a5568;
}

.vu-dial-arc {
  width: 56px;
  height: 56px;
  border: 2px dashed #d97706;
  border-radius: 50%;
  position: absolute;
  top: 0;
  left: 0;
}

.vu-needle {
  position: absolute;
  bottom: 0;
  left: 28px;
  width: 2px;
  height: 24px;
  background-color: #ef4444;
  transform-origin: bottom center;
  transform: rotate(-45deg);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 0 4px rgba(239, 68, 68, 0.8);
}

.vu-readout {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: #fbbf24;
  letter-spacing: 0.05em;
  text-align: right;
  min-width: 65px;
}

/* Header Buttons */
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-tactile {
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: var(--bg-card);
  color: var(--text-ink);
  border: 1px solid var(--border-strong);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-tactile:hover {
  background: var(--bg-inset);
  border-color: var(--amber);
  color: var(--amber-dark);
}

.btn-tactile:active {
  transform: translateY(1px);
  box-shadow: none;
}

.btn-tactile.primary {
  background: var(--text-ink);
  color: var(--text-light);
  border-color: var(--text-ink);
}

.btn-tactile.primary:hover {
  background: #333d37;
}

/* ==========================================================================
   Main Application Layout
   ========================================================================== */
litert-lm-chat-app {
  display: flex;
  flex-direction: column;
  flex: 1;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.app-container {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
  background-color: var(--bg-parchment);
}

/* Left Hardware Rack Sidebar */
.sidebar {
  width: 320px;
  min-width: 290px;
  max-width: 380px;
  background-color: var(--bg-rack);
  border-right: 2px solid var(--border-strong);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
  padding: 16px;
  gap: 16px;
  box-shadow: 2px 0 8px rgba(31, 36, 33, 0.03);
}

/* Right Documentation Drawer */
.sidebar-right {
  width: 360px;
  background-color: var(--bg-card);
  border-left: 2px solid var(--border-strong);
  overflow-y: auto;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  height: 100vh;
  z-index: 900;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: -4px 0 16px rgba(31, 36, 33, 0.12);
  padding: 24px;
}

.sidebar-right.open {
  transform: translateX(0);
}

.sidebar-right-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(31, 36, 33, 0.4);
  backdrop-filter: blur(2px);
  z-index: 890;
}

.sidebar-right-overlay.open {
  display: block;
}

/* Center Chat Window */
litert-chat-window {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-parchment);
}

/* ==========================================================================
   Hardware Sections & Cards (Analog Precision)
   ========================================================================== */
.hardware-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 1px 3px rgba(31, 36, 33, 0.05);
}

.hardware-card-title {
  font-family: var(--font-serif);
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-ink);
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.hardware-tag {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--amber-dark);
  background: rgba(217, 119, 6, 0.1);
  padding: 1px 6px;
  border-radius: 2px;
  border: 1px solid rgba(217, 119, 6, 0.2);
}

/* Hardware Fader / Slider with Nixie Readout */
.fader-control {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.fader-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
}

.nixie-badge {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  color: #fbbf24;
  background: #1e1b18;
  padding: 1px 6px;
  border-radius: 2px;
  border: 1px solid #453723;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.8);
}

.hardware-slider {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  outline: none;
}

.hardware-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 18px;
  border-radius: 2px;
  background: linear-gradient(180deg, #f0f0f0 0%, #b8b8b8 100%);
  border: 1px solid #666666;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* Vacuum-Tube Cache Meter */
.vacuum-meter {
  background-color: var(--bg-crt);
  border: 1px solid #2d3748;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  color: #ffffff;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tube-bar-track {
  width: 100%;
  height: 10px;
  background-color: #1e293b;
  border-radius: 5px;
  overflow: hidden;
  border: 1px solid #334155;
  position: relative;
}

.tube-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--sage) 0%, var(--amber) 80%, #ef4444 100%);
  transition: width 0.3s ease;
}

/* ==========================================================================
   Chat Messages & Conversation Ledger (Manila Card Look)
   ========================================================================== */
.chat-scroll-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.message-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 2px 4px rgba(31, 36, 33, 0.04);
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
}

.message-card.operator {
  border-left: 4px solid var(--text-ink);
  background-color: #faf8f5;
}

.message-card.assistant {
  border-left: 4px solid var(--amber-dark);
  background-color: #ffffff;
}

.message-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
  font-family: var(--font-serif);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.message-body {
  font-family: var(--font-sans);
  font-size: 0.95rem;
  color: var(--text-ink);
  line-height: 1.65;
}

.message-body p {
  margin: 0 0 10px 0;
}

.message-body p:last-child {
  margin-bottom: 0;
}

/* Punch-Card Code Blocks */
.punch-card-code {
  background-color: #f8f6f0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  margin: 12px 0;
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(31, 36, 33, 0.05);
}

.punch-card-header {
  background-color: var(--bg-inset);
  border-bottom: 1px solid var(--border);
  padding: 6px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
}

.punch-card-actions {
  display: flex;
  gap: 6px;
}

.btn-punch-action {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 700;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: 2px;
  padding: 2px 7px;
  cursor: pointer;
  color: var(--text-ink);
}

.btn-punch-action:hover {
  background: var(--amber);
  color: #ffffff;
  border-color: var(--amber-dark);
}

.punch-card-pre {
  margin: 0;
  padding: 14px 18px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.5;
  overflow-x: auto;
  color: #1a201c;
}

/* ==========================================================================
   Typewriter Ribbon Input Bar
   ========================================================================== */
.typewriter-input-dock {
  background-color: var(--bg-rack);
  border-top: 2px solid var(--border-strong);
  padding: 14px 24px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 -2px 8px rgba(31, 36, 33, 0.04);
}

.input-ribbon-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  max-width: 980px;
  width: 100%;
  margin: 0 auto;
}

.typewriter-textarea-wrap {
  flex: 1;
  background-color: var(--bg-card);
  border: 2px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  box-shadow: inset 0 1px 3px rgba(31, 36, 33, 0.06);
}

.typewriter-textarea {
  width: 100%;
  border: none;
  background: transparent;
  outline: none;
  resize: none;
  font-family: var(--font-mono);
  font-size: 0.92rem;
  color: var(--text-ink);
  line-height: 1.5;
  min-height: 48px;
  max-height: 160px;
}

.ribbon-tag-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--border-inset);
  padding-top: 4px;
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-muted);
}

.btn-typewriter-key {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.82rem;
  padding: 12px 20px;
  background: linear-gradient(180deg, #2b332e 0%, #171c19 100%);
  color: #f6f3ee;
  border: 1px solid #0d110f;
  border-radius: var(--radius-sm);
  cursor: pointer;
  box-shadow: 0 3px 0 #0d110f, 0 4px 6px rgba(0, 0, 0, 0.2);
  transition: all 0.1s ease;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-typewriter-key:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #0d110f, 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* ==========================================================================
   Procedural Avatar Cathode Frame
   ========================================================================== */
.avatar-cathode-frame {
  background-color: var(--bg-crt);
  border: 3px solid #334155;
  border-radius: var(--radius-md);
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.8), 0 2px 6px rgba(0, 0, 0, 0.15);
}

.avatar-cathode-screen {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-sm);
}

/* Subtle CRT Scanline overlay */
.avatar-cathode-screen::after {
  content: " ";
  display: block;
  position: absolute;
  top: 0; left: 0; bottom: 0; right: 0;
  background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%);
  background-size: 100% 4px;
  pointer-events: none;
  opacity: 0.6;
}

/* ==========================================================================
   Modular Feature Switchboard Modal
   ========================================================================== */
.switchboard-overlay {
  position: fixed;
  inset: 0;
  background: rgba(31, 36, 33, 0.55);
  backdrop-filter: blur(4px);
  z-index: 10000;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.switchboard-modal {
  background: var(--bg-rack);
  border: 3px solid var(--border-strong);
  border-radius: var(--radius-md);
  max-width: 680px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
}

.switchboard-header {
  background: linear-gradient(180deg, #d49f57 0%, #b87c2b 100%);
  color: #ffffff;
  padding: 14px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px solid #734510;
}

.switchboard-grid {
  padding: 20px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.switchboard-tile {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.switch-label-title {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-ink);
  margin-bottom: 2px;
}

.switch-label-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Mechanical Heavy-Duty Toggle Switch */
.toggle-switch-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
}

.retro-toggle {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 22px;
}

.retro-toggle input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0.001;
  cursor: pointer;
  z-index: 2;
  margin: 0;
}

.retro-toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: #cbd5e1;
  border: 1px solid #64748b;
  transition: 0.2s;
  border-radius: 22px;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.2);
  pointer-events: none;
}

.retro-toggle-slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 2px;
  bottom: 2px;
  background: linear-gradient(180deg, #ffffff 0%, #d1d5db 100%);
  border: 1px solid #9ca3af;
  transition: 0.2s;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.retro-toggle input:checked + .retro-toggle-slider {
  background-color: var(--sage);
  border-color: #047857;
}

.retro-toggle input:checked + .retro-toggle-slider:before {
  transform: translateX(22px);
}

@keyframes pulse-rec {
  0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.7); }
  50% { transform: scale(1.05); box-shadow: 0 0 0 6px rgba(220, 38, 38, 0); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(220, 38, 38, 0); }
}

.listening-pulse {
  animation: pulse-rec 1.2s infinite ease-in-out !important;
  background: #dc2626 !important;
  border-color: #991b1b !important;
  color: #ffffff !important;
}

/* ==========================================================================
   Full Screen HTML Preview Overlay
   ========================================================================== */
.preview-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(31, 36, 33, 0.85);
  backdrop-filter: blur(6px);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  padding: 24px;
  box-sizing: border-box;
}

.preview-overlay iframe {
  width: 100%;
  height: 100%;
  background: #ffffff;
  border: 2px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.btn-close-preview {
  position: absolute;
  top: 36px;
  right: 36px;
  background-color: #dc2626;
  color: #ffffff;
  border: none;
  padding: 8px 16px;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  z-index: 10001;
}

/* Responsive Mobile Rules */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1000;
    width: 85%;
    max-width: 320px;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    box-shadow: none;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 8px 0 24px rgba(0, 0, 0, 0.4);
  }
  .vu-meter-container {
    display: none; /* Hide wide VU-meter on small screens */
  }
  .chat-scroll-area {
    padding: 14px;
  }
}
