/* ============================================================
   Terminal Serial Web — Premium Dark Mode Stylesheet
   ============================================================ */

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

/* ── CSS Variables ─────────────────────────────────────────── */
:root {
  --bg-base:        #0a0c10;
  --bg-surface:     #0f1117;
  --bg-elevated:    #161b22;
  --bg-glass:       rgba(22, 27, 34, 0.75);
  --bg-glass-hover: rgba(30, 37, 46, 0.85);

  --border:         rgba(255,255,255,0.07);
  --border-bright:  rgba(255,255,255,0.14);

  --accent:         #00d4ff;
  --accent-glow:    rgba(0, 212, 255, 0.25);
  --accent-dim:     rgba(0, 212, 255, 0.12);
  --accent2:        #7c3aed;
  --accent2-glow:   rgba(124, 58, 237, 0.3);

  --green:          #22c55e;
  --green-glow:     rgba(34, 197, 94, 0.35);
  --red:            #ef4444;
  --red-glow:       rgba(239, 68, 68, 0.35);
  --yellow:         #f59e0b;
  --yellow-glow:    rgba(245, 158, 11, 0.35);

  --text-primary:   #e6edf3;
  --text-secondary: #8b949e;
  --text-muted:     #484f58;

  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  16px;
  --radius-xl:  24px;

  --transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);

  --sidebar-width: 300px;
  --header-height: 56px;
}

/* ── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── Scrollbar ─────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.22); }

/* ── App Shell ─────────────────────────────────────────────── */
#app {
  display: grid;
  grid-template-rows: var(--header-height) 1fr;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-areas:
    "header header"
    "sidebar main";
  height: 100vh;
  transition: grid-template-columns var(--transition);
}

#app.sidebar-collapsed {
  grid-template-columns: 0px 1fr;
}

/* ── Header ────────────────────────────────────────────────── */
#header {
  grid-area: header;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  z-index: 50;
  position: relative;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.brand-icon {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 16px var(--accent-glow);
  flex-shrink: 0;
}

.brand-icon svg { width: 18px; height: 18px; color: #fff; }

.brand-name {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.3px;
  background: linear-gradient(90deg, #fff, var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.brand-version {
  font-size: 10px;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
  background: var(--bg-elevated);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
  align-self: center;
}

.header-divider {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 4px;
}

/* Connection status badge */
#conn-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 99px;
  font-size: 12px;
  font-weight: 500;
  transition: var(--transition);
}

#conn-status .led {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: var(--transition);
  flex-shrink: 0;
}

#conn-status.disconnected .led { background: var(--red); box-shadow: 0 0 6px var(--red-glow); }
#conn-status.connecting   .led { background: var(--yellow); box-shadow: 0 0 6px var(--yellow-glow); animation: pulse 1s infinite; }
#conn-status.connected    .led { background: var(--green); box-shadow: 0 0 8px var(--green-glow); animation: breathe 2s ease-in-out infinite; }

@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.3} }
@keyframes breathe { 0%,100%{box-shadow:0 0 6px var(--green-glow)} 50%{box-shadow:0 0 14px var(--green-glow), 0 0 24px rgba(34,197,94,0.2)} }

#conn-status .status-text { color: var(--text-secondary); }
#conn-status.connected .status-text { color: var(--green); }
#conn-status.connecting .status-text { color: var(--yellow); }
#conn-status.disconnected .status-text { color: var(--red); }

/* RX / TX indicators */
.io-indicators {
  display: flex;
  align-items: center;
  gap: 6px;
}

.io-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 99px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  font-size: 10px;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  color: var(--text-muted);
  transition: var(--transition);
}

.io-pill .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: var(--transition);
}

#rx-pill.active .dot { background: var(--green); box-shadow: 0 0 6px var(--green-glow); }
#rx-pill.active { color: var(--green); border-color: rgba(34,197,94,0.3); }
#tx-pill.active .dot { background: var(--accent); box-shadow: 0 0 6px var(--accent-glow); }
#tx-pill.active { color: var(--accent); border-color: rgba(0,212,255,0.3); }

/* Header actions */
.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-size: 13px;
  font-family: 'Inter', sans-serif;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  text-decoration: none;
}

.btn:hover {
  background: var(--bg-glass-hover);
  border-color: var(--border-bright);
  color: var(--text-primary);
}

.btn svg { width: 15px; height: 15px; flex-shrink: 0; }

.btn-icon {
  padding: 7px;
  aspect-ratio: 1;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #0099bb);
  border-color: transparent;
  color: #000;
  font-weight: 600;
  box-shadow: 0 0 20px var(--accent-glow);
}
.btn-primary:hover {
  background: linear-gradient(135deg, #1ae0ff, var(--accent));
  box-shadow: 0 0 28px var(--accent-glow);
  color: #000;
}

.btn-danger {
  background: rgba(239,68,68,0.1);
  border-color: rgba(239,68,68,0.3);
  color: var(--red);
}
.btn-danger:hover {
  background: rgba(239,68,68,0.2);
  box-shadow: 0 0 16px var(--red-glow);
}

.btn-success {
  background: rgba(34,197,94,0.1);
  border-color: rgba(34,197,94,0.3);
  color: var(--green);
}
.btn-success:hover {
  background: rgba(34,197,94,0.2);
  box-shadow: 0 0 16px var(--green-glow);
}

/* ── Sidebar ────────────────────────────────────────────────── */
#sidebar {
  grid-area: sidebar;
  display: flex;
  flex-direction: column;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-right: 1px solid var(--border);
  overflow: hidden;
  transition: var(--transition);
}

#app.sidebar-collapsed #sidebar {
  visibility: hidden;
  opacity: 0;
}

/* ── Sidebar Tab Nav ────────────────────────────────────────── */
.sidebar-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 6px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--text-muted);
  cursor: pointer;
  border: none;
  background: transparent;
  border-bottom: 2px solid transparent;
  transition: var(--transition);
  position: relative;
  bottom: -1px;
  font-family: 'Inter', sans-serif;
}

.sidebar-tab svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.sidebar-tab:hover {
  color: var(--text-secondary);
  background: rgba(255,255,255,0.03);
}

.sidebar-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: rgba(0,212,255,0.04);
}

/* ── Sidebar Panels ─────────────────────────────────────────── */
.sidebar-panel {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  flex-direction: column;
  gap: 12px;
  /* Prevent children from filling all available height */
  align-content: flex-start;
}

.sidebar-panel.active {
  display: flex;
}

/* Sidebar sub-sections — shrink to content, never stretch */
.section {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  flex-shrink: 0;   /* ← critical: cards stay at their natural height */
}

/* Macros panel: the section grows to fill remaining space so the list scrolls */
.macros-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;    /* ← allows flex child to shrink below content size */
}

.macros-body {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
}

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-secondary);
}

.section-title svg { width: 13px; height: 13px; color: var(--accent); }

.section-body { padding: 14px; display: flex; flex-direction: column; gap: 10px; }

/* Form fields */
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

select, input[type="text"], input[type="number"] {
  width: 100%;
  padding: 7px 10px;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  font-family: 'Inter', sans-serif;
  transition: var(--transition);
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}

select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b949e' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; }

select:focus, input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
  background: #0d1117;
}

/* Toggle switch */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
}

.toggle-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.toggle {
  position: relative;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: 99px;
  cursor: pointer;
  transition: var(--transition);
}

.toggle-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 12px;
  height: 12px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: var(--transition);
}

.toggle input:checked ~ .toggle-track {
  background: var(--accent-dim);
  border-color: var(--accent);
}
.toggle input:checked ~ .toggle-track::after {
  transform: translateX(16px);
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent-glow);
}

/* Macros section */
.macros-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.macro-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.macro-btn {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 12px;
  font-family: 'JetBrains Mono', monospace;
  cursor: pointer;
  transition: var(--transition);
  text-align: left;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  min-width: 0;
}

.macro-btn:hover {
  background: var(--accent-dim);
  border-color: rgba(0,212,255,0.3);
  color: var(--accent);
}

.macro-btn:active { transform: scale(0.97); }

.macro-btn .macro-icon { font-size: 13px; flex-shrink: 0; }
.macro-btn .macro-name { overflow: hidden; text-overflow: ellipsis; }

.macro-actions {
  display: flex;
  gap: 4px;
}

.btn-tiny {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
  flex-shrink: 0;
}

.btn-tiny:hover { color: var(--text-primary); border-color: var(--border-bright); }
.btn-tiny svg { width: 12px; height: 12px; }
.btn-tiny.danger:hover { color: var(--red); border-color: rgba(239,68,68,0.4); }

.add-macro-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px;
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  transition: var(--transition);
  width: 100%;
}

.add-macro-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

/* Stats row */
.stats-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stat-card {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  text-align: center;
}

.stat-value {
  font-size: 16px;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  color: var(--accent);
}

.stat-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 2px;
}

/* ── Firebase / Cloud panel ─────────────────────────────────── */

/* Connection status badge */
#fb-status-badge {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 12px;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
}

#fb-status-badge .fb-led {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
  transition: var(--transition);
}

#fb-status-badge.connected    .fb-led { background: var(--green);  box-shadow: 0 0 8px var(--green-glow);  animation: breathe 2s ease-in-out infinite; }
#fb-status-badge.connecting   .fb-led { background: var(--yellow); box-shadow: 0 0 6px var(--yellow-glow); animation: pulse 1s infinite; }
#fb-status-badge.error        .fb-led { background: var(--red);    box-shadow: 0 0 6px var(--red-glow); }
#fb-status-badge .fb-status-text { color: var(--text-secondary); flex: 1; }
#fb-status-badge.connected  .fb-status-text { color: var(--green); }
#fb-status-badge.error      .fb-status-text { color: var(--red); }

/* Session history list */
.session-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.session-card {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  transition: var(--transition);
  cursor: default;
}

.session-card:hover {
  border-color: var(--border-bright);
  background: rgba(255,255,255,0.02);
}

.session-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.session-device {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  font-family: 'JetBrains Mono', monospace;
}

.session-ts {
  font-size: 10px;
  color: var(--text-muted);
}

.session-meta {
  display: flex;
  gap: 10px;
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
  flex-wrap: wrap;
}

.session-meta span { display: flex; align-items: center; gap: 3px; }

.session-note-preview {
  margin-top: 5px;
  font-size: 11px;
  color: var(--text-secondary);
  font-style: italic;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-actions {
  display: flex;
  gap: 4px;
  margin-top: 6px;
}

.session-empty {
  text-align: center;
  padding: 24px 12px;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.8;
}

/* Notes */
.notes-composer {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.notes-composer input[type="text"] {
  padding: 7px 10px;
  font-size: 13px;
  font-weight: 500;
}

.notes-composer textarea {
  width: 100%;
  min-height: 80px;
  max-height: 160px;
  padding: 8px 10px;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  font-family: 'Inter', sans-serif;
  resize: vertical;
  outline: none;
  transition: var(--transition);
  line-height: 1.5;
}

.notes-composer textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.note-color-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.note-color-row span { font-size: 11px; color: var(--text-muted); }

.color-dot {
  width: 16px; height: 16px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: var(--transition);
  flex-shrink: 0;
}

.color-dot:hover, .color-dot.selected { border-color: #fff; transform: scale(1.15); }
.color-dot[data-color="default"] { background: var(--bg-elevated); border: 2px solid var(--border-bright); }
.color-dot[data-color="cyan"]    { background: #00d4ff44; border: 2px solid var(--accent); }
.color-dot[data-color="green"]   { background: #22c55e44; border: 2px solid var(--green); }
.color-dot[data-color="yellow"]  { background: #f59e0b44; border: 2px solid var(--yellow); }
.color-dot[data-color="purple"]  { background: #7c3aed44; border: 2px solid var(--accent2); }
.color-dot[data-color="red"]     { background: #ef444444; border: 2px solid var(--red); }

/* Note cards */
.notes-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.note-card {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  transition: var(--transition);
  position: relative;
}

.note-card[data-color="cyan"]   { border-left-color: var(--accent);  background: rgba(0,212,255,0.04); }
.note-card[data-color="green"]  { border-left-color: var(--green);   background: rgba(34,197,94,0.04); }
.note-card[data-color="yellow"] { border-left-color: var(--yellow);  background: rgba(245,158,11,0.04); }
.note-card[data-color="purple"] { border-left-color: var(--accent2); background: rgba(124,58,237,0.04); }
.note-card[data-color="red"]    { border-left-color: var(--red);     background: rgba(239,68,68,0.04); }

.note-card:hover { border-color: var(--border-bright); border-left-color: inherit; }

.note-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 5px;
}

.note-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
}

.note-pin-icon {
  font-size: 12px;
  opacity: 0.7;
  flex-shrink: 0;
}

.note-content {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 80px;
  overflow: hidden;
}

.note-content.expanded { max-height: none; }

.note-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 7px;
}

.note-ts {
  font-size: 10px;
  color: var(--text-muted);
}

.note-actions {
  display: flex;
  gap: 3px;
}

.notes-empty {
  text-align: center;
  padding: 20px 12px;
  color: var(--text-muted);
  font-size: 12px;
}

/* Cloud syncing spinner */
@keyframes spin { to { transform: rotate(360deg); } }
.syncing { animation: spin 1s linear infinite; display: inline-block; }

/* ── Main Area ──────────────────────────────────────────────── */
#main {
  grid-area: main;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* Terminal tabs bar */
#tabs-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 16px;
  height: 38px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
}

#tabs-bar::-webkit-scrollbar { height: 2px; }

.tab {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  border: 1px solid transparent;
  border-bottom: none;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  position: relative;
  bottom: -1px;
}

.tab:hover { color: var(--text-secondary); background: var(--bg-elevated); }

.tab.active {
  background: var(--bg-base);
  border-color: var(--border);
  color: var(--accent);
}

.tab.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0; right: 0;
  height: 2px;
  background: var(--bg-base);
}

.tab .tab-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
}
.tab.active .tab-dot { background: var(--green); box-shadow: 0 0 6px var(--green-glow); }

/* Toolbar */
#toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.toolbar-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
}

/* Input mode indicator */
#input-mode-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 99px;
  font-size: 10px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-muted);
  font-weight: 600;
  margin-left: auto;
}

/* kbd shortcut pills in toolbar */
.kbd {
  font-size: 10px;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 2px 5px;
  font-family: 'JetBrains Mono', monospace;
}

.kbd-label {
  font-size: 10px;
  color: var(--text-muted);
  margin-right: 6px;
}

/* Terminal container */
#terminal-wrap {
  flex: 1;
  min-height: 0;        /* ← critical: allows flex child to shrink properly */
  overflow: hidden;
  position: relative;
  background: #0a0c10;
}

#terminal-container {
  position: absolute;
  inset: 0;
  /* Large bottom padding so fitAddon calculates one fewer row,
     guaranteeing the prompt line is never clipped by the input bar border */
  padding: 6px 6px 28px 6px;
  box-sizing: border-box;
}

/* xterm overrides */
.xterm { height: 100% !important; }
.xterm-viewport { background: transparent !important; }
.xterm-screen canvas { border-radius: 4px; }
/* Ensure the last row is never hidden — adds visual breathing room at bottom */
.xterm-rows { padding-bottom: 4px !important; }

/* Bottom input bar — always visible, never hidden */
#input-bar {
  display: flex !important;   /* macros need this always visible */
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

#cmd-input {
  flex: 1;
  padding: 8px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  font-family: 'JetBrains Mono', monospace;
  outline: none;
  transition: var(--transition);
}

#cmd-input::placeholder { color: var(--text-muted); }
#cmd-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
  background: #0d1117;
}

#cmd-input:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#line-ending-select {
  width: auto;
  padding: 8px 30px 8px 10px;
  flex-shrink: 0;
}

/* ── Empty / Welcome State ─────────────────────────────────── */
#welcome-screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 40px;
  background: radial-gradient(ellipse at 50% 0%, rgba(0,212,255,0.06) 0%, transparent 70%),
              radial-gradient(ellipse at 80% 80%, rgba(124,58,237,0.05) 0%, transparent 60%),
              var(--bg-base);
  z-index: 10;
  transition: opacity 0.4s ease, visibility 0.4s;
}

#welcome-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.welcome-icon {
  width: 80px;
  height: 80px;
  background: linear-gradient(135deg, rgba(0,212,255,0.15), rgba(124,58,237,0.15));
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-xl);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 60px var(--accent-glow), 0 0 100px rgba(124,58,237,0.1);
  animation: float 4s ease-in-out infinite;
}

@keyframes float {
  0%,100% { transform: translateY(0); }
  50%      { transform: translateY(-8px); }
}

.welcome-icon svg { width: 36px; height: 36px; color: var(--accent); }

.welcome-title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #fff 30%, var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-align: center;
}

.welcome-subtitle {
  color: var(--text-secondary);
  text-align: center;
  max-width: 420px;
  line-height: 1.7;
}

.welcome-steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  max-width: 560px;
  width: 100%;
}

.step-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  transition: var(--transition);
}

.step-card:hover {
  border-color: var(--border-bright);
  background: var(--bg-glass-hover);
}

.step-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-dim);
  border: 1px solid rgba(0,212,255,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
}

.step-text {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.browser-warning {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: rgba(245,158,11,0.08);
  border: 1px solid rgba(245,158,11,0.25);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--yellow);
}

/* ── Hex View Overlay ──────────────────────────────────────── */
#hex-panel {
  display: none;
  flex-direction: column;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  max-height: 200px;
  flex-shrink: 0;
}

#hex-panel.visible { display: flex; }

#hex-panel .panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-secondary);
}

#hex-content {
  flex: 1;
  overflow-y: auto;
  padding: 10px 14px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.8;
}

.hex-row { display: flex; gap: 12px; }
.hex-offset { color: var(--text-muted); width: 50px; flex-shrink: 0; }
.hex-bytes { flex: 1; color: var(--accent); letter-spacing: 0.5px; }
.hex-ascii { color: var(--text-secondary); }

/* ── Toast Notifications ───────────────────────────────────── */
#toast-container {
  position: fixed;
  top: 70px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  font-size: 13px;
  color: var(--text-primary);
  max-width: 320px;
  pointer-events: auto;
  animation: slideIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes slideIn {
  from { transform: translateX(110%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

.toast.out { animation: slideOut 0.3s ease forwards; }
@keyframes slideOut {
  to { transform: translateX(110%); opacity: 0; }
}

.toast-icon { width: 18px; height: 18px; flex-shrink: 0; }
.toast.success { border-color: rgba(34,197,94,0.4); }
.toast.success .toast-icon { color: var(--green); }
.toast.error   { border-color: rgba(239,68,68,0.4); }
.toast.error   .toast-icon { color: var(--red); }
.toast.info    { border-color: rgba(0,212,255,0.3); }
.toast.info    .toast-icon { color: var(--accent); }
.toast.warning { border-color: rgba(245,158,11,0.4); }
.toast.warning .toast-icon { color: var(--yellow); }

/* ── Modal ─────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn { from{opacity:0} to{opacity:1} }

.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.5);
  animation: modalIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modalIn { from{transform:scale(0.9);opacity:0} to{transform:scale(1);opacity:1} }

.modal-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--text-primary);
}

.modal-field { margin-bottom: 14px; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* Detail modal variant */
.modal-detail {
  max-width: 500px;
  padding: 24px;
}

.modal-detail .modal-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 18px;
  color: var(--accent);
}

/* Session detail grid */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.detail-item {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.detail-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.detail-value {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.detail-value.mono  { font-family: 'JetBrains Mono', monospace; }
.detail-value.accent{ color: var(--accent); }
.detail-value.green { color: var(--green); }
.detail-value.cyan  { color: var(--accent); }

.detail-note-section {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 4px;
}

.detail-note-body {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Note detail modal */
.note-modal-ts {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.note-modal-body {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  max-height: 320px;
  overflow-y: auto;
  margin-bottom: 4px;
}

/* Danger button variant */
.btn-danger {
  background: rgba(239,68,68,0.12);
  border: 1px solid rgba(239,68,68,0.3);
  color: var(--red);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.btn-danger:hover {
  background: rgba(239,68,68,0.22);
  border-color: var(--red);
}

/* Session detail modal — wider for log viewer */
.modal-session-detail {
  max-width: 640px;
}

.session-log-section {
  margin-bottom: 4px;
}

.session-log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.session-log-body {
  background: #0a0c10;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-family: 'JetBrains Mono', 'Consolas', monospace;
  font-size: 11px;
  line-height: 1.5;
  color: #c9d1d9;
  max-height: 280px;
  overflow-y: auto;
  overflow-x: auto;
  white-space: pre;
  word-break: break-all;
  margin: 0;
}

.session-log-body::-webkit-scrollbar { width: 6px; height: 6px; }
.session-log-body::-webkit-scrollbar-track { background: transparent; }
.session-log-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.session-log-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  color: var(--text-muted);
  font-size: 13px;
  background: var(--bg-base);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 4px;
}

/* Session card delete row */
.session-actions {
  display: flex;
  justify-content: flex-end;
  padding-top: 6px;
  margin-top: 4px;
  border-top: 1px solid var(--border);
}

.session-actions .btn-tiny {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
}

/* ── Search bar ─────────────────────────────────────────────── */
#search-bar {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
}

#search-bar.visible { display: flex; }

#search-input {
  flex: 1;
  padding: 5px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  font-family: 'JetBrains Mono', monospace;
  outline: none;
}

#search-input:focus { border-color: var(--accent); }

.search-count {
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
  white-space: nowrap;
}

/* ── Resize handle ─────────────────────────────────────────── */
#resize-handle {
  position: absolute;
  top: 0; bottom: 0;
  left: var(--sidebar-width);
  width: 4px;
  cursor: col-resize;
  background: transparent;
  transition: background var(--transition);
  z-index: 30;
}

#resize-handle:hover { background: var(--accent); }
#app.sidebar-collapsed #resize-handle { display: none; }

/* ── Misc ───────────────────────────────────────────────────── */
.hidden { display: none !important; }

.blink {
  animation: blink 1s step-end infinite;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0} }

/* Grid scan lines overlay */
#terminal-wrap::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0,0,0,0.08) 2px,
    rgba(0,0,0,0.08) 4px
  );
  pointer-events: none;
  z-index: 1;
  opacity: 0.5;
}

/* Glow corners on terminal */
#terminal-wrap::after {
  content: '';
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 60px rgba(0,0,0,0.5);
  pointer-events: none;
  z-index: 2;
}

/* Auth Overlay */
.auth-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(3px);
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
  border-radius: 6px;
}
.auth-overlay.hidden {
  display: none !important;
}
.auth-overlay-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.auth-overlay-content p {
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.4;
  margin: 0;
}

