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

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

html { height: 100%; }

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  margin: 0;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  transition: background 240ms ease, color 240ms ease;
}

/* ─────────────────────────────────────────
   APP SHELL — mobile: header + bottom nav
   desktop: sidebar + main
───────────────────────────────────────── */
.app-shell {
  display: flex;
  flex: 1;
}

/* ── Mobile header ── */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--sidebar-bg);
  border-bottom: 2px solid var(--amber);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--sp-5);
  z-index: 200;
}

.app-header__logo {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.wordmark {
  font-size: var(--text-lg);
  font-weight: var(--w-bold);
  color: #fff;
  letter-spacing: -0.03em;
}
.wordmark span { color: var(--amber); }

.wordmark-badge {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: var(--w-medium);
  color: var(--amber);
  background: var(--amber-pale);
  border: 1px solid var(--amber-border);
  padding: 2px 8px;
  border-radius: var(--r-sm);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.app-header__status {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: rgba(255,255,255,0.45);
  letter-spacing: 0.06em;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #34D399;
  box-shadow: 0 0 0 2px rgba(52,211,153,0.25);
  flex-shrink: 0;
}
.status-dot.offline { background: #F87171; box-shadow: 0 0 0 2px rgba(248,113,113,0.25); }

.header-settings-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: none;
  border: none;
  color: rgba(255,255,255,0.6);
  cursor: pointer;
  border-radius: var(--r-md);
  transition: color var(--t-fast), background var(--t-fast);
  -webkit-tap-highlight-color: transparent;
}
.header-settings-btn:hover { color: #fff; background: rgba(255,255,255,0.08); }

/* ── Mobile bottom sheet ── */
.mobile-sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 500;
  opacity: 0;
  transition: opacity 0.25s;
}
.mobile-sheet-overlay.visible { opacity: 1; }
.mobile-sheet-overlay.hidden { display: none; }

.mobile-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  padding: var(--sp-3) var(--sp-5) calc(var(--sp-6) + env(safe-area-inset-bottom, 0px));
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.16,1,0.3,1);
  z-index: 501;
  max-height: 70vh;
  overflow-y: auto;
}
.mobile-sheet-overlay.visible .mobile-sheet { transform: translateY(0); }

.mobile-sheet__handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto var(--sp-4);
}
.mobile-sheet__identity {
  padding: var(--sp-1) 0 var(--sp-3);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--sp-3);
}
.mobile-sheet__company {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: var(--w-semi);
  color: var(--text-muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin: 0;
}
.mobile-sheet__email {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  margin: 2px 0 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mobile-sheet__ws-name {
  font-size: var(--text-card);
  font-weight: var(--w-semi);
  color: var(--amber);
  padding: var(--sp-2) 0 var(--sp-4);
}

/* Mobile sheet theme toggle icon swap */
#mobileThemeAction .theme-toggle__sun { display: none; }
#mobileThemeAction .theme-toggle__moon { display: inline-block; }
[data-theme="dark"] #mobileThemeAction .theme-toggle__sun { display: inline-block; }
[data-theme="dark"] #mobileThemeAction .theme-toggle__moon { display: none; }
.mobile-sheet__label {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: var(--sp-2);
}
.mobile-sheet__section {
  padding: var(--sp-3) 0;
  border-top: 1px solid var(--border);
}
.mobile-sheet__section.hidden { display: none; }

.mobile-sheet__ws-btn {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
  min-height: 48px;
  padding: var(--sp-3) var(--sp-3);
  font-size: var(--text-body);
  font-family: var(--font-sans);
  color: var(--text-secondary);
  background: none;
  border: none;
  border-radius: var(--r-md);
  cursor: pointer;
  text-align: left;
  transition: background var(--t-fast);
  -webkit-tap-highlight-color: transparent;
}
.mobile-sheet__ws-btn:hover { background: var(--amber-light); }
.mobile-sheet__ws-btn--active { color: var(--amber); font-weight: var(--w-medium); }
.mobile-sheet__ws-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--amber);
  flex-shrink: 0;
}

.mobile-sheet__action {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  min-height: 48px;
  padding: var(--sp-3);
  font-size: var(--text-body);
  font-family: var(--font-sans);
  color: var(--text);
  background: none;
  border: none;
  border-radius: var(--r-md);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--t-fast);
}
.mobile-sheet__action:hover { background: var(--amber-light); }
.mobile-sheet__action--danger { color: var(--error); }
.mobile-sheet__action--danger:hover { background: var(--error-bg); }

@media (min-width: 768px) {
  .mobile-sheet-overlay { display: none !important; }
  .header-settings-btn { display: none; }
}

/* ── Sidebar (desktop only) ── */
.sidebar {
  display: none;
}

/* ── Main content area ── */
.app-main {
  flex: 1;
  padding-top: var(--header-h);
  padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
}

/* ── Bottom nav (mobile only) ── */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  z-index: 200;
}

.bottom-nav__btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 100%;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  transition: color var(--t-fast);
  -webkit-tap-highlight-color: transparent;
}

.bottom-nav__btn--active {
  color: var(--amber);
}

.bottom-nav__icon {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.bottom-nav__label {
  font-size: 10px;
  font-weight: var(--w-semi);
  letter-spacing: 0.04em;
}

/* ── View sections ── */
.view {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - var(--header-h) - var(--bottom-nav-h));
  padding: var(--sp-5) var(--sp-4) var(--sp-8);
}

.view.hidden { display: none; }

.view__inner {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
}

/* ── Footer ── */
.app-footer {
  padding: var(--sp-6) var(--sp-4);
  text-align: center;
  border-top: 1px solid var(--border);
}

.app-footer__text {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

/* ─────────────────────────────────────────
   DESKTOP (≥768px) — sidebar layout
───────────────────────────────────────── */
@media (min-width: 768px) {
  .app-header { display: none; }
  .bottom-nav { display: none; }

  .sidebar {
    display: flex;
    flex-direction: column;
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--sidebar-bg);
    min-height: 100vh;
    position: sticky;
    top: 0;
    align-self: flex-start;
    height: 100vh;
    overflow-y: auto;
    border-right: 1px solid var(--sidebar-border);
  }

  .sidebar__top {
    padding: var(--sp-6) var(--sp-5);
    border-bottom: 1px solid rgba(255,255,255,0.08);
  }

  .sidebar__logo {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    margin-bottom: var(--sp-5);
  }

  .sidebar__status {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: rgba(255,255,255,0.40);
    letter-spacing: 0.06em;
  }

  .sidebar__nav {
    padding: var(--sp-4) var(--sp-3);
    flex: 1;
  }

  .sidebar-link {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    width: 100%;
    padding: var(--sp-3) var(--sp-3);
    border-radius: var(--r-md);
    background: none;
    border: none;
    cursor: pointer;
    color: rgba(255,255,255,0.55);
    font-size: var(--text-sm);
    font-weight: var(--w-medium);
    font-family: var(--font-sans);
    text-align: left;
    transition: background var(--t-fast), color var(--t-fast);
    margin-bottom: 2px;
  }

  .sidebar-link:hover {
    background: rgba(255,255,255,0.07);
    color: rgba(255,255,255,0.85);
  }

  .sidebar-link--active {
    background: var(--amber-pale);
    color: var(--amber);
    border-left: 3px solid var(--amber);
    padding-left: calc(var(--sp-3) - 3px);
  }

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

  /* Workspace switcher */
  .sidebar__workspaces {
    padding: var(--sp-4) var(--sp-5);
    border-top: 1px solid rgba(255,255,255,0.08);
  }
  .sidebar__workspaces.hidden { display: none; }

  .sidebar__ws-item {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    width: 100%;
    padding: var(--sp-2) var(--sp-3);
    font-size: var(--text-xs);
    font-family: var(--font-sans);
    color: rgba(255,255,255,0.50);
    background: none;
    border: none;
    border-radius: var(--r-sm);
    cursor: pointer;
    text-align: left;
    transition: color 0.15s, background 0.15s;
  }
  .sidebar__ws-item:hover { color: #fff; background: rgba(255,255,255,0.06); }
  .sidebar__ws-item--active { color: var(--amber); font-weight: var(--w-medium); }
  .sidebar__ws-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--amber);
    flex-shrink: 0;
  }

  .sidebar__create-ws {
    display: block;
    width: 100%;
    padding: var(--sp-2) var(--sp-3);
    margin-top: var(--sp-2);
    font-size: var(--text-xs);
    font-family: var(--font-mono);
    color: rgba(255,255,255,0.30);
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
    transition: color 0.15s;
  }
  .sidebar__create-ws:hover { color: var(--amber); }

  .sidebar__create-ws-form {
    padding: var(--sp-2) 0;
  }
  .sidebar__create-ws-form.hidden { display: none; }

  .sidebar__ws-row {
    display: flex;
    align-items: center;
    gap: 0;
  }
  .sidebar__ws-row .sidebar__ws-item { flex: 1; min-width: 0; }
  .sidebar__ws-share {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    flex-shrink: 0;
    background: none;
    border: none;
    color: rgba(255,255,255,0.20);
    cursor: pointer;
    border-radius: var(--r-sm);
    transition: color 0.15s, background 0.15s;
  }
  .sidebar__ws-share:hover {
    color: var(--amber);
    background: rgba(255,255,255,0.06);
  }

  .form-input--dark {
    background: rgba(255,255,255,0.06);
    border-color: rgba(255,255,255,0.12);
    color: #fff;
    font-size: var(--text-xs);
    padding: var(--sp-2) var(--sp-3);
  }

  .sidebar__create-ws-actions {
    display: flex;
    gap: var(--sp-2);
    margin-top: var(--sp-2);
  }
  .sidebar__create-ws-save {
    font-size: var(--text-xs);
    font-family: var(--font-mono);
    padding: var(--sp-1) var(--sp-3);
    background: var(--amber);
    color: var(--navy);
    border: none;
    border-radius: var(--r-sm);
    cursor: pointer;
    font-weight: var(--w-semi);
  }
  .sidebar__create-ws-cancel {
    font-size: var(--text-xs);
    font-family: var(--font-mono);
    padding: var(--sp-1) var(--sp-3);
    background: none;
    color: rgba(255,255,255,0.40);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: var(--r-sm);
    cursor: pointer;
  }

  .sidebar__docs {
    padding: var(--sp-4) var(--sp-5);
    border-top: 1px solid rgba(255,255,255,0.08);
    margin-top: auto;
  }

  .sidebar__docs-label {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: rgba(255,255,255,0.30);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    margin-bottom: var(--sp-3);
  }

  .sidebar__docs-list {
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
  }

  .sidebar__doc-item {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    font-size: var(--text-xs);
    color: rgba(255,255,255,0.45);
    overflow: hidden;
  }

  .sidebar__doc-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--amber);
    opacity: 0.6;
    flex-shrink: 0;
  }

  .sidebar__doc-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .sidebar__docs-more {
    display: block;
    margin-top: var(--sp-2);
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--amber);
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    text-align: left;
    transition: color var(--t-fast);
  }
  .sidebar__docs-more:hover { color: var(--amber-hover); }

  .app-main {
    padding-top: 0;
    padding-bottom: 0;
  }

  .view {
    padding: var(--sp-8) var(--sp-8) var(--sp-12);
    min-height: 100vh;
  }
}
