:root {
  --bg: #0a0f1c;
  --bg-elev: #0f1626;
  --sidebar-bg: #0c1322;
  --sidebar-border: #1a2540;
  --text: #e6ebf5;
  --text-dim: #8a96b0;
  --text-muted: #5a6580;
  --accent: #1a4789;
  --accent-bright: #2a6fd1;
  --accent-soft: rgba(42, 111, 209, 0.14);
  --accent-glow: rgba(42, 111, 209, 0.35);
  --hover: #182238;
  --active: #1a2a4d;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body, .app {
  height: 100%;
  width: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto, sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.app { display: flex; }

/* ---------------- Compact sidebar (near-fullscreen mode) ---------------- */
.app.compact .sidebar {
  width: 64px;
}
.app.compact .sidebar-header {
  padding: 16px 8px;
  justify-content: center;
}
.app.compact .logo {
  max-width: 32px;
  content: url('/assets/favicon.png');
}
.app.compact .sidebar-section-row {
  padding: 14px 8px 6px;
  justify-content: center;
}
.app.compact .sidebar-section-label { display: none; }
.app.compact .add-btn { width: 28px; height: 28px; }
.app.compact .tabs { padding: 0 6px; }
.app.compact .tab {
  padding: 8px;
  justify-content: center;
}
.app.compact .tab-name { display: none; }
.app.compact .tab.active::before {
  left: -6px;
  top: 6px;
  bottom: 6px;
}
.app.compact .tab-delete { display: none !important; }
.app.compact .add-form {
  /* Form needs space — temporarily widen sidebar when adding in compact */
  position: absolute;
  left: 64px;
  top: 90px;
  width: 240px;
  z-index: 30;
  margin: 0;
  border: 1px solid var(--accent);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.app.compact .sidebar-footer {
  grid-template-columns: 1fr;
  padding: 6px;
}
.app.compact .footer-btn {
  font-size: 0;
  padding: 8px;
  gap: 0;
}
.app.compact .footer-btn svg { margin: 0; }
.app.compact #compact-toggle svg {
  transform: rotate(180deg);
}

.topbar-btn {
  background: transparent;
  border: 1px solid var(--sidebar-border);
  color: var(--text-dim);
  width: 30px;
  height: 30px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  flex-shrink: 0;
  padding: 0;
}
.topbar-btn:hover {
  background: var(--hover);
  color: var(--text);
  border-color: var(--accent);
}
.topbar-btn svg { transition: transform 0.2s ease; }

/* ---------------- Sidebar ---------------- */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 24px 20px 20px;
  border-bottom: 1px solid var(--sidebar-border);
  display: flex;
  justify-content: flex-start;
}

.logo {
  max-width: 170px;
  height: auto;
  filter: brightness(0) invert(1) drop-shadow(0 0 14px rgba(42, 111, 209, 0.35));
}

.sidebar-section-row {
  padding: 18px 14px 8px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.add-btn {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  background: transparent;
  border: 1px solid var(--sidebar-border);
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  padding: 0;
}

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

.add-form {
  margin: 4px 12px 10px;
  padding: 12px;
  background: var(--bg-elev);
  border: 1px solid var(--sidebar-border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.add-form.hidden { display: none; }

.add-form input {
  background: var(--sidebar-bg);
  border: 1px solid var(--sidebar-border);
  border-radius: 5px;
  padding: 7px 9px;
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s ease;
}

.add-form input::placeholder { color: var(--text-muted); }
.add-form input:focus { border-color: var(--accent-bright); }

.add-error {
  font-size: 11px;
  color: #f08080;
  padding: 2px 0;
}
.add-error.hidden { display: none; }

.add-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.add-btn-primary, .add-btn-secondary {
  font-family: inherit;
  font-size: 11px;
  padding: 6px 12px;
  border-radius: 5px;
  cursor: pointer;
  border: 1px solid var(--sidebar-border);
}

.add-btn-secondary {
  background: transparent;
  color: var(--text-dim);
}
.add-btn-secondary:hover { background: var(--hover); color: var(--text); }

.add-btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.add-btn-primary:hover { background: var(--accent-bright); border-color: var(--accent-bright); }
.add-btn-primary:disabled { opacity: 0.6; cursor: wait; }

.tab-delete {
  margin-left: auto;
  width: 20px;
  height: 20px;
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  color: var(--text-muted);
  background: transparent;
  border: 0;
  cursor: pointer;
  flex-shrink: 0;
}
.tab:hover .tab-delete { display: flex; }
.tab-delete:hover { background: rgba(217, 83, 79, 0.2); color: #f08080; }

.tabs {
  flex: 1;
  overflow-y: auto;
  padding: 0 10px;
}

.tab {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  margin: 2px 0;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-dim);
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease;
  position: relative;
  user-select: none;
}

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

.tab.dragging {
  opacity: 0.4;
}

.tab.drop-above {
  box-shadow: inset 0 2px 0 0 var(--accent-bright);
}

.tab.drop-below {
  box-shadow: inset 0 -2px 0 0 var(--accent-bright);
}

.tab.active {
  background: var(--accent-soft);
  color: #ffffff;
}

.tab.active::before {
  content: '';
  position: absolute;
  left: -10px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent-bright);
  box-shadow: 0 0 10px var(--accent-glow);
}

.tab-icon {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: linear-gradient(135deg, #1a4789, #2a6fd1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.tab-name {
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-footer {
  border-top: 1px solid var(--sidebar-border);
  padding: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.footer-btn {
  background: transparent;
  border: 1px solid var(--sidebar-border);
  color: var(--text-dim);
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: inherit;
  transition: all 0.15s ease;
}

.footer-btn:hover {
  background: var(--hover);
  color: var(--text);
  border-color: var(--accent);
}

.footer-btn.primary {
  grid-column: 1 / -1;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.footer-btn.primary:hover {
  background: var(--accent-bright);
  border-color: var(--accent-bright);
}

#signout-btn {
  grid-column: 1 / -1;
}

#signout-btn:hover {
  border-color: #d9534f;
  color: #f08080;
}

/* ---------------- Content ---------------- */
.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}

.topbar {
  height: 52px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--sidebar-border);
  background: var(--bg-elev);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
}

.topbar-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.topbar-url {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  font-family: 'SF Mono', Monaco, monospace;
}

.browser-stage {
  flex: 1;
  position: relative;
  background: #fff;
  overflow: hidden;
}

iframe.portal-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

iframe.portal-frame.hidden { display: none !important; }

/* ---------------- Welcome screen ---------------- */
.welcome {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  background:
    radial-gradient(circle at 50% 35%, rgba(42, 111, 209, 0.18), transparent 55%),
    var(--bg);
  padding: 40px;
}

.welcome.hidden { display: none; }

.welcome-logo {
  max-width: 280px;
  margin-bottom: 28px;
  filter: drop-shadow(0 0 24px rgba(42, 111, 209, 0.4));
}

.welcome h1 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 10px;
  letter-spacing: -0.02em;
}

.welcome p {
  color: var(--text-dim);
  font-size: 14px;
  max-width: 420px;
  line-height: 1.5;
}

/* ---------------- Loading bar ---------------- */
.loading-bar {
  position: absolute;
  top: 0;
  left: 0;
  height: 2px;
  background: var(--accent-bright);
  box-shadow: 0 0 8px var(--accent-glow);
  width: 0;
  z-index: 5;
  pointer-events: none;
  transition: width 0.3s ease, opacity 0.4s ease;
}

.loading-bar.loading { width: 80%; }
.loading-bar.done { width: 100%; opacity: 0; }

.tabs::-webkit-scrollbar { width: 6px; }
.tabs::-webkit-scrollbar-thumb { background: var(--sidebar-border); border-radius: 3px; }
.tabs::-webkit-scrollbar-thumb:hover { background: var(--accent); }
