/* Unified app shell — common styling shared by all tabs */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: #0e0e0e;
  color: #eee;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

.muted { color: #888; }
.small { font-size: 12px; }

/* === LOGIN SCREEN === */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.login-box {
  background: #1a1a1a;
  border: 1px solid #2a2a2a;
  border-radius: 12px;
  padding: 32px 28px;
  max-width: 400px;
  width: 100%;
  text-align: center;
}

.login-box h1 {
  margin: 0 0 12px 0;
  font-size: 20px;
}

.login-box code {
  background: #2a2a2a;
  padding: 1px 6px;
  border-radius: 4px;
  font-family: ui-monospace, 'Cascadia Mono', monospace;
}

#login-content ol {
  text-align: left;
  margin: 12px 0;
  padding-left: 22px;
}

#login-content li {
  margin: 6px 0;
}

.login-error {
  color: #f88;
  margin-top: 12px;
}

/* === APP SHELL — sidebar layout === */
#unified-app {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
}

.app-brand {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
}

/* === SIDEBAR === */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: #141414;
  border-right: 1px solid #2a2a2a;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  z-index: 20;
  /* iOS safe areas */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

.sidebar-header {
  padding: 18px 20px 14px 20px;
  border-bottom: 1px solid #222;
}

.tab-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 10px;
  flex: 1 1 auto;
  overflow-y: auto;
  scrollbar-width: thin;
}
.tab-nav::-webkit-scrollbar { width: 4px; }
.tab-nav::-webkit-scrollbar-thumb { background: #2a2a2a; border-radius: 2px; }

.tab-btn {
  background: transparent;
  border: none;
  color: #aaa;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s;
  font-family: inherit;
  /* Sidebar buttons: full width, left-aligned, with vertical accent on active */
  width: 100%;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
}

.tab-btn:hover {
  color: #eee;
  background: #1f1f1f;
}

.tab-btn.active {
  background: #1f1f1f;
  color: #fff;
}

.tab-btn.active::before {
  content: '';
  position: absolute;
  left: -10px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  background: #4a9eff;
  border-radius: 0 2px 2px 0;
}

.sidebar-footer {
  border-top: 1px solid #222;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.me-info {
  font-size: 13px;
  color: #aaa;
  line-height: 1.3;
}

.me-info .me-name {
  color: #eee;
  font-weight: 500;
  word-break: break-word;
}

.me-info .me-role {
  color: #888;
  font-size: 11px;
}

/* Compact footer tab buttons (e.g. Models activity) — de-emphasised vs the
   primary tab rail; sits just above Logout. */
.footer-tab-buttons {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.footer-tab-btn {
  background: transparent;
  color: #888;
  border: 1px solid #242424;
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  transition: color 0.12s, border-color 0.12s, background 0.12s;
  width: 100%;
}
.footer-tab-btn:hover {
  color: #ddd;
  border-color: #3a3a3a;
}
.footer-tab-btn.active {
  color: #fff;
  border-color: #4a4a4a;
  background: #1c1c1c;
}

.btn-ghost {
  background: transparent;
  color: #aaa;
  border: 1px solid #2a2a2a;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  transition: color 0.12s, border-color 0.12s;
  width: 100%;
}

.btn-ghost:hover {
  color: #eee;
  border-color: #4a4a4a;
}

/* === MAIN CONTENT === */
.tab-content {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.tab-host {
  flex: 1 1 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
}

.app-loading {
  text-align: center;
  color: #888;
  padding: 40px;
}

/* Iframe-embedded tabs (dashboard, admin, ai-models) — fill viewport height */
.tab-host.iframe-tab {
  padding: 0;
  height: 100vh;
  height: 100dvh;
  min-height: 600px;
}
.tab-iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  background: #0e0e0e;
}

/* === MOBILE TOP BAR === */
.topbar {
  display: none;
  position: sticky;
  top: 0;
  height: 56px;
  background: #1a1a1a;
  border-bottom: 1px solid #2a2a2a;
  align-items: center;
  padding: 0 14px;
  gap: 14px;
  z-index: 15;
  padding-top: env(safe-area-inset-top);
  height: calc(56px + env(safe-area-inset-top));
}

.topbar-brand {
  font-size: 15px;
}

.sidebar-toggle {
  display: none;
  background: transparent;
  border: none;
  width: 40px;
  height: 40px;
  padding: 0;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  color: #eee;
}
.sidebar-toggle:hover { background: #222; }

.hamburger,
.hamburger::before,
.hamburger::after {
  display: block;
  width: 22px;
  height: 2px;
  background: #eee;
  border-radius: 1px;
  position: relative;
}
.hamburger::before,
.hamburger::after {
  content: '';
  position: absolute;
  left: 0;
}
.hamburger::before { top: -7px; }
.hamburger::after  { top: 7px; }

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 18;
  opacity: 0;
  transition: opacity 0.2s ease;
}

/* === MOBILE LAYOUT === */
@media (max-width: 720px) {
  /* Mobile only: the drawer slides off-screen (translateX), so clip horizontal
     overflow here. On desktop overflow-x must stay VISIBLE — clipping it on the
     root breaks the sticky sidebar (it scrolls away with the page). */
  html, body { overflow-x: hidden; }
  #unified-app {
    /* Stack: top bar above main content; sidebar floats as drawer */
    flex-direction: column;
  }

  .topbar { display: flex; }
  .sidebar-toggle { display: inline-flex; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    height: 100dvh;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    width: 260px;
    z-index: 25;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.6);
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-backdrop.show {
    display: block;
    opacity: 1;
  }

  /* Iframe tabs: subtract top bar height */
  .tab-host.iframe-tab {
    height: calc(100vh - 56px - env(safe-area-inset-top));
    height: calc(100dvh - 56px - env(safe-area-inset-top));
  }
}

/* === DESKTOP — large screens get a wider sidebar === */
@media (min-width: 1280px) {
  .sidebar {
    width: 240px;
  }
}
