/* ═══════════════════════════════════════
   Text2 Workspace · CSS v3
   No Tailwind. Pure CSS. ~5KB.
═══════════════════════════════════════ */

/* ─── Design Tokens ─── */
:root {
  --bg:        #f0f2f5;
  --surface:   rgba(255,255,255,0.72);
  --border:    rgba(255,255,255,0.55);
  --glass-blur: blur(24px) saturate(180%);
  --accent:    #007aff;
  --accent-dim:rgba(0,122,255,0.15);
  --text:      #1c1c1e;
  --text-2:    #636366;
  --text-3:    #aeaeb2;
  --shadow:    0 4px 24px rgba(0,0,0,0.10);
  --shadow-lg: 0 12px 48px rgba(0,0,0,0.14);
  --radius:    20px;
  --sb-w:      260px;
  --header-h:  58px;
  --tab-h:     38px;
  --ease:      cubic-bezier(.4,0,.2,1);
  --spring:    cubic-bezier(.19,1,.22,1);
}

/* ─── Reset ─── */
*, *::before, *::after { margin:0; padding:0; box-sizing:border-box; }
html, body { height:100%; overflow:hidden; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  display: flex;
}

/* ─── Scrollbar ─── */
::-webkit-scrollbar { width:4px; }
::-webkit-scrollbar-track { background:transparent; }
::-webkit-scrollbar-thumb { background:rgba(0,0,0,0.12); border-radius:4px; }

/* ═══ BACKDROP (mobile) ═══ */
#backdrop {
  display: none;
  position: fixed; inset:0; z-index:80;
  background: rgba(0,0,0,0.25);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity:0;
  transition: opacity .3s var(--ease);
}
#backdrop.visible { display:block; }
#backdrop.show    { opacity:1; }

/* ═══ SIDEBAR ═══ */
#sidebar {
  width: var(--sb-w);
  height: 100vh;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  background: var(--surface);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-right: 1px solid var(--border);
  transition: width .4s var(--spring), transform .4s var(--spring), opacity .3s var(--ease);
  overflow: hidden;
  z-index: 90;
}

/* Collapsed desktop state */
#sidebar.collapsed {
  width: 0;
  opacity: 0;
  pointer-events: none;
}

/* ── Brand ── */
.sb-brand {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px 0 18px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}

.brand-link {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
}

.brand-link img { border-radius:8px; }

.brand-name {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -.4px;
  white-space: nowrap;
}

/* ── Sidebar search ── */
.sb-search {
  position: relative;
  padding: 12px 12px 8px;
  flex-shrink: 0;
}

.sb-search .search-icon {
  position: absolute;
  left: 22px; top: 50%;
  transform: translateY(-50%);
  width: 15px; height: 15px;
  color: var(--text-3);
  pointer-events: none;
  margin-top: 2px;
}

#app-search {
  width: 100%;
  padding: 8px 12px 8px 36px;
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 12px;
  background: rgba(0,0,0,0.04);
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  outline: none;
  transition: background .2s, border-color .2s, box-shadow .2s;
}

#app-search::placeholder { color: var(--text-3); }

#app-search:focus {
  background: rgba(255,255,255,0.9);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

/* ── Nav menu ── */
#nav-menu {
  flex: 1;
  overflow-y: auto;
  padding: 6px 8px;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: 12px;
  cursor: pointer;
  text-decoration: none;
  color: var(--text-2);
  font-weight: 500;
  font-size: 13.5px;
  transition: background .18s var(--ease), color .18s var(--ease), transform .1s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border: 1px solid transparent;
}

.menu-item:hover {
  background: rgba(255,255,255,0.6);
  color: var(--text);
}

.menu-item:active { transform: scale(.97); }

.menu-item.active {
  background: white;
  color: var(--accent);
  border-color: rgba(0,122,255,0.12);
  box-shadow: 0 2px 10px rgba(0,0,0,0.06);
}

.menu-item img {
  width: 22px; height: 22px;
  border-radius: 5px;
  object-fit: cover;
  flex-shrink: 0;
}

.menu-item svg {
  width: 18px; height: 18px;
  flex-shrink: 0;
  opacity: .7;
}

.menu-item.active svg { opacity:1; }

.menu-item .item-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}

.no-results {
  padding: 20px 16px;
  color: var(--text-3);
  font-size: 13px;
  text-align: center;
}

/* ── User block ── */
.sb-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.sb-user img {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.8);
  object-fit: cover;
  flex-shrink: 0;
}

.user-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#user-name {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#user-sub {
  font-size: 11px;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: .5px;
  font-weight: 600;
}

/* ═══ WORKSPACE (main area) ═══ */
#workspace {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ═══ TOPBAR ═══ */
#topbar {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px 0 14px;
  background: var(--surface);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

#app-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -.3px;
  white-space: nowrap;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  margin-left: auto;
}

/* ── Icon button ── */
.icon-btn {
  width: 34px; height: 34px;
  border-radius: 10px;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  transition: background .15s, transform .1s;
  flex-shrink: 0;
}

.icon-btn svg { width:18px; height:18px; }

.icon-btn:hover  { background: rgba(0,0,0,0.06); }
.icon-btn:active { transform: scale(.91); }

#sidebar-close { display: none; }

/* ═══ TAB BAR ═══ */
#tab-bar {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  padding: 0 4px;
}

#tab-bar::-webkit-scrollbar { display:none; }

.tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px 5px 9px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  flex-shrink: 0;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-2);
  background: transparent;
  max-width: 160px;
  transition: background .18s, color .18s, border-color .18s;
  white-space: nowrap;
  overflow: hidden;
}

.tab:hover {
  background: rgba(0,0,0,0.05);
  color: var(--text);
}

.tab.active {
  background: white;
  color: var(--accent);
  border-color: rgba(0,122,255,0.14);
  box-shadow: 0 2px 8px rgba(0,0,0,0.07);
}

.tab img {
  width: 16px; height: 16px;
  border-radius: 3px;
  flex-shrink: 0;
}

.tab svg {
  width: 14px; height: 14px;
  flex-shrink: 0;
  opacity: .6;
}

.tab .tab-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tab-close {
  width: 16px; height: 16px;
  border-radius: 50%;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: inherit;
  opacity: 0;
  flex-shrink: 0;
  padding: 0;
  transition: opacity .15s, background .15s;
}

.tab-close svg { width:10px; height:10px; }

.tab:hover .tab-close,
.tab.active .tab-close { opacity:.55; }
.tab-close:hover { opacity:1 !important; background:rgba(0,0,0,0.08); }

/* ═══ IFRAME STAGE ═══ */
#iframe-stage {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #fff;
}

#iframe-stage iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
  opacity: 0;
  pointer-events: none;
  transition: opacity .35s var(--ease);
  background: #fff;
  z-index: 1;
}

#iframe-stage iframe.visible {
  opacity: 1;
  pointer-events: auto;
  z-index: 2;
}

/* ── Loading overlay ── */
#load-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(255,255,255,0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 5;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s var(--ease);
}

#load-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

#load-overlay p {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 1px;
  animation: pulse 1.4s ease infinite;
}

@keyframes pulse {
  0%,100% { opacity:.5; }
  50%      { opacity:1; }
}

.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--accent-dim);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform:rotate(360deg); } }

/* ═══ MOBILE ═══ */
@media (max-width: 768px) {
  #sidebar {
    position: fixed;
    left: 0; top: 0;
    height: 100%;
    transform: translateX(-100%);
    width: var(--sb-w) !important;
    opacity: 1 !important;
    pointer-events: auto !important;
  }

  #sidebar.mobile-open { transform: translateX(0); }
  #sidebar-close { display: flex; }

  #app-title {
    max-width: 100px;
    font-size: 14px;
  }

  #tab-bar { display: none; }

  .topbar-right { display: flex; }
}

/* ─── Utility animations ─── */
@keyframes slideInLeft {
  from { transform:translateX(-8px); opacity:0; }
  to   { transform:translateX(0);    opacity:1; }
}

.menu-item { animation: slideInLeft .18s var(--ease) both; }