:root {
  --tab-height:   48px;
  --font-body:    'DM Sans', sans-serif;
  --font-mono:    'DM Mono', monospace;
}

/* ── Dark theme (default) ──────────── */
body {
  --bg:           #0F0F0F;
  --bg-elevated:  #272727;
  --bg-hover:     #3A3A3A;
  --text-primary: #F1F1F1;
  --text-secondary: #AAAAAA;
  --accent:       #FF0000;
  --accent-hover: #CC0000;
  --border:       rgba(255,255,255,0.1);
  --input-bg:     #181818;
  --input-border: rgba(255,255,255,0.15);
  --logo-filter:  none;
}

/* ── Light theme ───────────────────── */
body.light-mode,
html.light-mode body {
  --bg:           #F5F5F5;
  --bg-elevated:  #FFFFFF;
  --bg-hover:     #E8E8E8;
  --text-primary: #1A1A1A;
  --text-secondary: #666666;
  --accent:       #DD0000;
  --accent-hover: #BB0000;
  --border:       rgba(0,0,0,0.1);
  --input-bg:     #FFFFFF;
  --input-border: rgba(0,0,0,0.15);
  --logo-filter:  brightness(0) saturate(100%);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font-body);
}

/* ── Login Page ──────────────────────── */
.login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
  overflow: auto;
}

.login-box {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  width: 100%;
  max-width: 380px;
}

.login-logo {
  display: block;
  height: 28px;
  margin: 0 auto 8px;
}

.login-title {
  text-align: center;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 32px;
}

.login-field {
  margin-bottom: 16px;
}

.login-field label {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.login-field input[type="text"],
.login-field input[type="password"] {
  width: 100%;
  padding: 10px 14px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 8px;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

.login-field input:focus {
  border-color: var(--accent);
}

.login-remember {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 24px;
  cursor: pointer;
}

.login-remember input[type="checkbox"] {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.login-remember span {
  font-size: 13px;
  color: var(--text-secondary);
}

.login-btn {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: background 0.15s;
}

.login-btn:hover {
  background: var(--accent-hover);
}

.login-error {
  background: rgba(255, 78, 69, 0.1);
  border: 1px solid rgba(255, 78, 69, 0.3);
  color: #FF4E45;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 16px;
  text-align: center;
}

/* ── Tab Bar ─────────────────────────── */
.tab-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--tab-height);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  z-index: 1000;
  display: flex;
  align-items: center;
}

.tab-bar-inner {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 0 16px;
  gap: 12px;
}

.hub-logo {
  height: 22px;
  flex-shrink: 0;
  filter: var(--logo-filter);
}

/* Light-mode login logo also needs inverting */
body.light-mode .login-logo {
  filter: brightness(0) saturate(100%);
}

.tabs {
  display: flex;
  gap: 2px;
  flex: 1;
}

.tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 18px;
  height: var(--tab-height);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.03em;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.tab:hover { color: var(--text-primary); }
.tab.active {
  color: var(--text-primary);
  border-bottom-color: var(--accent);
}

.tab-icon { display: inline-flex; width: 16px; height: 16px; flex-shrink: 0; }

.tab-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-info {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
  letter-spacing: 0.03em;
}

.user-info a {
  color: var(--text-secondary);
  text-decoration: none;
  margin-left: 8px;
  opacity: 0.7;
  transition: opacity 0.15s;
}

.user-info a:hover { opacity: 1; }

.external-link {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 18px;
  padding: 6px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
  line-height: 1;
}

.external-link:hover {
  color: var(--text-primary);
  background: rgba(255,255,255,0.06);
}

/* ── Edit / Reorder Mode ─────────────── */
.edit-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
  flex-shrink: 0;
}

.edit-btn:hover {
  color: var(--text-primary);
  background: rgba(255,255,255,0.06);
}

.edit-btn.active {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(255,0,0,0.08);
}

.theme-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
  padding: 0;
}

.theme-btn:hover {
  color: var(--text-primary);
  background: rgba(128,128,128,0.1);
}

.theme-btn svg {
  width: 16px;
  height: 16px;
}

/* Dark mode: show sun, hide moon */
.theme-btn .icon-light { display: block; }
.theme-btn .icon-dark  { display: none; }

/* Light mode: show moon, hide sun */
body.light-mode .theme-btn .icon-light,
html.light-mode .theme-btn .icon-light { display: none; }
body.light-mode .theme-btn .icon-dark,
html.light-mode .theme-btn .icon-dark  { display: block; }

/* Light-mode login error tweak */
body.light-mode .login-error {
  background: rgba(221, 0, 0, 0.06);
  border-color: rgba(221, 0, 0, 0.2);
  color: #CC0000;
}

/* Drag handle — only visible in edit mode */
.tab .drag-handle {
  display: none;
  font-size: 11px;
  color: var(--text-secondary);
  cursor: grab;
  margin-right: 2px;
  opacity: 0.5;
}

body.edit-mode .tab .drag-handle {
  display: inline;
}

body.edit-mode .tab {
  cursor: grab;
  border: 1px dashed rgba(255,255,255,0.15);
  border-bottom: 2px solid transparent;
  border-radius: 6px 6px 0 0;
  margin: 0 1px;
}

body.edit-mode .tab.active {
  border-bottom-color: var(--accent);
}

body.edit-mode .tab:active {
  cursor: grabbing;
}

.tab.dragging {
  opacity: 0.4;
}

.tab.drag-over {
  border-color: var(--accent) !important;
  background: rgba(255,0,0,0.06);
}

/* ── Iframe Container ────────────────── */
.iframe-wrap {
  position: fixed;
  top: var(--tab-height);
  left: 0;
  right: 0;
  bottom: 0;
  bottom: env(safe-area-inset-bottom, 0);
}

.iframe-wrap iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: none;
  -webkit-overflow-scrolling: touch;
}

.iframe-wrap iframe.active {
  display: block;
}

/* ── CSS Theme Select ────────────────── */
.css-theme-select {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 0 8px;
  height: 30px;
  border-radius: 6px;
  font-size: 11px;
  font-family: var(--font-body);
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.15s, border-color 0.15s;
}
.css-theme-select:hover { color: var(--text-primary); border-color: var(--accent); }
.css-theme-select:focus { outline: none; border-color: var(--accent); }

/* ── Mobile ──────────────────────────── */
@media (max-width: 600px) {
  :root { --tab-height: 44px; }
  .hub-logo { height: 18px; }
  .tab { padding: 0 12px; font-size: 11px; }
  .user-info { display: none; }
  .login-box { padding: 28px 24px; }
}

@media (max-width: 380px) {
  .tab-label { display: none; }
  .tab-icon { width: 20px; height: 20px; }
  .tab { padding: 0 14px; }
}