/* =====================================================================
   Apple Liquid Glass — Midnight palette
   ===================================================================== */

:root {
  /* Apple Midnight — the iPhone/MacBook Air finish */
  --midnight-0: #0c0e15;       /* deepest, page edges */
  --midnight-1: #14172180;     /* mid */
  --midnight-2: #1a1d29;       /* primary surface */
  --midnight-3: #232636;       /* raised surface */
  --midnight-4: #2c3045;       /* hover surface */

  --bg-0: var(--midnight-0);

  /* Translucent glass — used over Midnight bg with heavy backdrop blur */
  --glass-base:    rgba(255, 255, 255, 0.06);
  --glass-hi:      rgba(255, 255, 255, 0.10);
  --glass-strong:  rgba(255, 255, 255, 0.09);

  /* Rim highlights & shadows mimic light hitting glass edges */
  --rim-top:       rgba(255, 255, 255, 0.18);
  --rim-bottom:    rgba(0, 0, 0, 0.35);
  --rim-inner:     rgba(255, 255, 255, 0.08);

  --border-soft:   rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);

  /* Apple SF text colors for dark mode */
  --text:      #f5f5f7;
  --text-dim:  #c7c9d1;
  --muted:     #8e8e93;

  /* Apple System Blue (dark mode) */
  --blue:      #0a84ff;
  --blue-hi:   #4ca8ff;
  --blue-lo:   #0064d2;
  --blue-glow: rgba(10, 132, 255, 0.45);

  --danger: #ff453a;

  --radius:    16px;
  --radius-sm: 11px;

  --shadow-lg: 0 30px 80px rgba(0, 0, 0, 0.55), 0 2px 6px rgba(0, 0, 0, 0.4);

  --ease: cubic-bezier(0.32, 0.72, 0, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  font-feature-settings: "cv11", "ss01";
  overflow: hidden;
  user-select: none;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  /* Apple Midnight: deep blue-black with a faint indigo glow */
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(60, 70, 110, 0.22) 0%, transparent 60%),
    radial-gradient(80% 60% at 100% 100%, rgba(40, 50, 90, 0.18) 0%, transparent 60%),
    linear-gradient(180deg, #1a1d29 0%, #14172180 50%, #0c0e15 100%);
}

.hidden { display: none !important; }
.muted { color: var(--muted); }

/* =====================================================================
   Loader
   ===================================================================== */

.loader {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  background: inherit;
  z-index: 100;
  animation: fade-in 0.25s var(--ease);
}

.spinner {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 2.5px solid rgba(255, 255, 255, 0.08);
  border-top-color: rgba(255, 255, 255, 0.85);
  animation: spin 0.85s linear infinite;
  filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.18));
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-in {
  from { opacity: 0; transform: translateX(-8px); }
  to   { opacity: 1; transform: translateX(0); }
}

.loader-text { color: var(--text-dim); font-size: 14px; letter-spacing: 0.01em; }

.loader.error .spinner { display: none; }
.loader.error .loader-text {
  color: var(--danger);
  font-size: 15px;
  max-width: 520px;
  text-align: center;
  padding: 0 24px;
  font-weight: 500;
}

/* =====================================================================
   App layout
   ===================================================================== */

.app {
  position: fixed;
  inset: 0;
  display: flex;
  overflow: hidden;
  animation: fade-in 0.35s var(--ease);
}

.screen {
  flex: 1;
  position: relative;
  background: var(--midnight-0);
  outline: none;
}

.screen canvas { display: block; }

/* Smooth zoom only while the user is toggling Fit ↔ 1:1. The class is
   added on click and removed shortly after, so live resizing doesn't
   animate. */
.screen.zooming canvas {
  transition: transform 0.4s var(--ease);
}

.screen.terminal-wrap {
  padding: 0;
  background: #000;
  overflow: hidden;
}

.screen.terminal-wrap .terminal {
  padding: 6px 10px;
  height: 100% !important;
}

.screen .xterm,
.screen .xterm-viewport,
.screen .xterm-screen { height: 100% !important; }

.xterm .xterm-viewport { background-color: transparent !important; }
.xterm .xterm-rows { font-variant-ligatures: none; }

body.is-serial .tab-vnc-only { display: none; }
body:not(.is-serial) .tab-serial-only { display: none; }

/* =====================================================================
   Liquid Glass surface — shared mixin via class
   ===================================================================== */

.glass {
  background: var(--glass-base);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  backdrop-filter: blur(40px) saturate(180%);
  border: 1px solid var(--border-soft);
  box-shadow:
    inset 0 1px 0 var(--rim-top),                /* light catching top edge */
    inset 0 -1px 0 var(--rim-bottom),            /* shadow on bottom edge */
    inset 0 0 0 1px var(--rim-inner),            /* inner glow */
    var(--shadow-lg);
}

/* =====================================================================
   Sidebar
   ===================================================================== */

.sidebar {
  position: fixed;
  top: 50%;
  left: 40px;
  transform: translateY(-50%);
  z-index: 50;
  transition: transform 0.35s var(--ease), opacity 0.25s var(--ease);
}

.sidebar.collapsed {
  transform: translate(calc(-100% - 40px), -50%);
  opacity: 0;
  pointer-events: none;
}

.sidebar-tabs {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 7px;
  background: var(--glass-base);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  backdrop-filter: blur(40px) saturate(180%);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  box-shadow:
    inset 0 1px 0 var(--rim-top),
    inset 0 -1px 0 var(--rim-bottom),
    inset 0 0 0 1px var(--rim-inner),
    var(--shadow-lg);
}

.sidebar-tabs .tab {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 0;
  color: var(--muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.18s, color 0.18s, transform 0.08s, box-shadow 0.18s;
  padding: 0;
}

.sidebar-tabs .tab:hover {
  background: var(--glass-hi);
  color: var(--text);
}

.sidebar-tabs .tab:active { transform: scale(0.96); }

.sidebar-tabs .tab.active {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.10) 0%, rgba(255, 255, 255, 0.04) 100%);
  color: var(--text);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.16),
    inset 0 0 0 1px rgba(255, 255, 255, 0.10);
}

.tab-divider {
  height: 1px;
  margin: 3px 8px;
  background: var(--border-soft);
}

/* Panels — absolutely positioned so showing/hiding never reflows the tabs */
.panels {
  position: absolute;
  top: 0;
  left: calc(100% + 16px);
  width: 272px;
}

.panel {
  display: none;
  background: var(--glass-strong);
  -webkit-backdrop-filter: blur(50px) saturate(200%);
  backdrop-filter: blur(50px) saturate(200%);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow:
    inset 0 1px 0 var(--rim-top),
    inset 0 -1px 0 var(--rim-bottom),
    inset 0 0 0 1px var(--rim-inner),
    var(--shadow-lg);
}

.panel.open { display: block; animation: slide-in 0.22s var(--ease); }

.panel header {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.005em;
  margin-bottom: 16px;
  color: var(--text);
}

.panel header svg { opacity: 0.85; }

.panel > * + * { margin-top: 10px; }
.panel > header + * { margin-top: 0; }

/* =====================================================================
   Buttons — Apple System Blue with Liquid Glass overlay
   ===================================================================== */

.btn {
  width: 100%;
  padding: 11px 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--glass-base);
  color: var(--text);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  letter-spacing: 0.01em;
  cursor: pointer;
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  box-shadow:
    inset 0 1px 0 var(--rim-top),
    inset 0 -1px 0 var(--rim-bottom),
    0 4px 14px -4px rgba(0, 0, 0, 0.5);
  transition: background 0.18s, border-color 0.18s, transform 0.06s, box-shadow 0.18s;
}

.btn:hover {
  background: var(--glass-hi);
  border-color: var(--border-strong);
}

.btn:active { transform: scale(0.985); }

.btn-primary {
  /* Flat brand-blue primary button — matches the Exbil Cloud design system
     (bg-primary #2563eb, rounded-xl, semibold, subtle shadow). */
  height: 44px;
  padding: 0 20px;
  background: #2563eb;
  color: #fff;
  border: 1px solid transparent;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0;
  text-shadow: none;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.28);
  transition: background 0.15s ease, transform 0.06s ease, box-shadow 0.15s ease;
}

.btn-primary:hover {
  /* Tailwind hover:bg-primary/90 */
  background: rgba(37, 99, 235, 0.9);
  border-color: transparent;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.28);
}

.btn-primary:active {
  /* Tailwind active:translate-y-px */
  transform: translateY(1px);
  background: rgba(37, 99, 235, 0.9);
  border-color: transparent;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.28);
}

.btn-primary:focus-visible {
  /* Tailwind ring-2 ring-ring ring-offset-2 ring-offset-background */
  outline: none;
  box-shadow:
    0 0 0 2px var(--midnight-2),
    0 0 0 4px #2563eb;
}

/* =====================================================================
   Textarea
   ===================================================================== */

textarea {
  width: 100%;
  min-height: 80px;
  margin: 0;
  background: rgba(0, 0, 0, 0.28);
  color: var(--text);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  font-size: 13px;
  font-family: inherit;
  line-height: 1.45;
  resize: vertical;
  user-select: text;
  transition: border-color 0.18s, background 0.18s, box-shadow 0.18s;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.25);
}

textarea:hover { background: rgba(0, 0, 0, 0.34); }
textarea:focus {
  outline: none;
  border-color: rgba(10, 132, 255, 0.55);
  box-shadow:
    inset 0 1px 2px rgba(0, 0, 0, 0.25),
    0 0 0 3px var(--blue-glow);
  background: rgba(0, 0, 0, 0.34);
}
textarea::placeholder { color: var(--muted); }

/* =====================================================================
   Keys panel
   ===================================================================== */

.key-btn {
  padding: 10px 8px;
  min-height: 36px;
  background: var(--glass-base);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.10),
    inset 0 -1px 0 rgba(0, 0, 0, 0.25),
    0 2px 6px -2px rgba(0, 0, 0, 0.4);
  transition: background 0.15s, border-color 0.15s, transform 0.06s;
}

.key-btn:hover {
  background: var(--glass-hi);
  border-color: var(--border-strong);
}

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

.key-btn.key-primary {
  position: relative;
  background:
    linear-gradient(180deg,
      rgba(255, 255, 255, 0.28) 0%,
      rgba(255, 255, 255, 0.02) 45%,
      rgba(255, 255, 255, 0) 70%),
    linear-gradient(180deg, var(--blue-hi) 0%, var(--blue) 50%, var(--blue-lo) 100%);
  color: #fff;
  border: 1px solid rgba(0, 60, 150, 0.7);
  width: 100%;
  padding: 14px;
  margin-bottom: 12px;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.025em;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.22);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.45),
    inset 0 -1px 0 rgba(0, 0, 0, 0.18),
    0 1px 2px rgba(0, 0, 0, 0.3),
    0 10px 30px -6px var(--blue-glow);
}

.key-btn.key-primary:hover {
  background:
    linear-gradient(180deg,
      rgba(255, 255, 255, 0.34) 0%,
      rgba(255, 255, 255, 0.04) 45%,
      rgba(255, 255, 255, 0) 70%),
    linear-gradient(180deg, #5fb1ff 0%, #218eff 50%, #006ddb 100%);
  border-color: rgba(0, 70, 165, 0.8);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.5),
    inset 0 -1px 0 rgba(0, 0, 0, 0.18),
    0 2px 4px rgba(0, 0, 0, 0.35),
    0 14px 40px -6px var(--blue-glow);
}

.key-btn.key-primary:active {
  transform: scale(0.985);
  background:
    linear-gradient(180deg,
      rgba(255, 255, 255, 0.18) 0%,
      rgba(255, 255, 255, 0) 70%),
    linear-gradient(180deg, var(--blue) 0%, var(--blue-lo) 60%, #00529e 100%);
  border-color: rgba(0, 50, 130, 0.85);
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, 0.35),
    0 1px 2px rgba(0, 0, 0, 0.3);
}

.key-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
}

.key-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.key-grid.cols-2 { grid-template-columns: repeat(2, 1fr); }

/* =====================================================================
   Segmented control
   ===================================================================== */

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: rgba(0, 0, 0, 0.32);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.2);
}

.seg-btn {
  padding: 9px 10px;
  background: transparent;
  border: 0;
  border-radius: 7px;
  color: var(--text-dim);
  font-size: 12.5px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}

.seg-btn:hover { color: var(--text); }

.seg-btn.active {
  background:
    linear-gradient(180deg,
      rgba(255, 255, 255, 0.28) 0%,
      rgba(255, 255, 255, 0.02) 60%),
    linear-gradient(180deg, var(--blue-hi) 0%, var(--blue) 100%);
  color: #fff;
  font-weight: 600;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.22);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    inset 0 -1px 0 rgba(0, 0, 0, 0.22),
    inset 0 0 0 1px rgba(255, 255, 255, 0.08),
    0 2px 8px -2px var(--blue-glow);
}

/* =====================================================================
   Edge collapse handle — same glass language as the sidebar
   ===================================================================== */

.edge-toggle {
  position: fixed;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
  width: 22px;
  height: 68px;
  background: var(--glass-base);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  backdrop-filter: blur(40px) saturate(180%);
  border: 1px solid var(--border-soft);
  border-left: 0;
  border-radius: 0 14px 14px 0;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 49;
  transition: background 0.18s, color 0.18s, width 0.18s, transform 0.25s var(--ease);
  box-shadow:
    inset 0 1px 0 var(--rim-top),
    inset 0 -1px 0 var(--rim-bottom),
    inset 0 0 0 1px var(--rim-inner),
    4px 0 18px rgba(0, 0, 0, 0.4);
}

.edge-toggle:hover {
  background: var(--glass-hi);
  color: var(--text);
  width: 26px;
}

.edge-toggle:active { transform: translateY(-50%) scale(0.96); }

.edge-toggle svg { transition: transform 0.3s var(--ease); }
.edge-toggle.flipped svg { transform: rotate(180deg); }

/* =====================================================================
   Toasts
   ===================================================================== */

.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translate(-50%, 8px);
  background: var(--glass-strong);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  backdrop-filter: blur(40px) saturate(180%);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  padding: 11px 18px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s var(--ease);
  box-shadow:
    inset 0 1px 0 var(--rim-top),
    inset 0 -1px 0 var(--rim-bottom),
    var(--shadow-lg);
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* =====================================================================
   Responsive
   ===================================================================== */

@media (max-width: 640px) {
  .sidebar { left: 24px; }
  .panels { width: 220px; left: calc(100% + 12px); }
  .sidebar-tabs .tab { width: 34px; height: 34px; }
}

@media (max-height: 520px) {
  .panel { padding: 12px; }
  .panel header { margin-bottom: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.05s !important;
  }
  .spinner { animation-duration: 1.5s !important; }
}
