/* tinymoon — app shell frame: sidebar, nav, topbar, and content column.
   The DOM this styles is built by js/shell.js (mountShell). The frame's
   bottom inset is the optional footer slot: --footer-h stays 0 unless a
   footer is configured. Requires tokens.css and base.css. */

/* ---------- skip link + screen-reader-only ---------- */

.tm-skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-16);
  z-index: 9999;
  padding: var(--space-8) var(--space-16);
  background: var(--accent);
  color: var(--on-accent);
  font-weight: var(--weight-medium);
  font-size: var(--text-xs);
}
.tm-skip-link:focus {
  top: var(--space-8);
}

.tm-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ---------- app frame ---------- */

#tm-app {
  position: fixed;
  inset: 0 0 var(--footer-h) 0;
  display: flex;
}

/* sidebar */
#tm-sidebar {
  width: var(--sidebar-w);
  flex: none;
  background: var(--surface);
  border-inline-end: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
#tm-logo {
  padding: var(--space-20) var(--space-16) var(--space-16);
  border-bottom: 1px solid var(--border);
}
#tm-logo .wordmark {
  font-family: var(--font-brand);
  font-weight: var(--weight-bold);
  font-size: var(--text-2xl);
  letter-spacing: 0.02em;
  color: var(--text);
}
#tm-logo .wordmark b { color: var(--accent-hi); font-weight: var(--weight-bold); }
#tm-logo svg { display: block; margin-top: var(--space-6); width: 100%; height: 14px; }
#tm-logo .tagline {
  margin-top: var(--space-4);
  font-family: var(--font-mono);
  font-size: var(--text-label);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-faint);
}

#tm-nav { padding: var(--space-12) var(--space-8); display: flex; flex-direction: column; gap: var(--space-2); }
.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-10);
  padding: var(--space-9) var(--space-12);
  border: 1px solid transparent;
  background: none;
  color: var(--text-dim);
  font-weight: var(--weight-medium);
  font-size: var(--text-sm);
  font-family: var(--font-ui);
  cursor: pointer;
  text-align: start;
  transition: color var(--dur-base) ease, background var(--dur-base) ease, border-color var(--dur-base) ease;
  position: relative;
}
.nav-item svg { width: 17px; height: 17px; flex: none; }
.nav-item:hover { color: var(--text); background: var(--surface-2); }
.nav-item.active {
  color: var(--text);
  background: var(--accent-soft);
  border-color: var(--accent-a35);
}
.nav-item.active::before {
  content: "";
  position: absolute;
  inset-inline-start: -9px;
  top: 6px;
  bottom: 6px;
  width: 2px;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
}

/* main column */
#tm-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

#tm-topbar {
  height: var(--topbar-h);
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--space-16);
  padding: 0 var(--space-24);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
#tm-page-title { font-size: var(--text-lg); font-weight: var(--weight-medium); letter-spacing: 0.01em; }
#tm-page-sub {
  font-family: var(--font-mono);
  font-size: var(--text-3xs);
  color: var(--text-faint);
}
#tm-busy {
  margin-inline-start: auto;
  display: flex;
  align-items: center;
  gap: var(--space-8);
  font-family: var(--font-mono);
  font-size: var(--text-3xs);
  color: var(--accent-hi);
}
#tm-busy svg { width: 13px; height: 13px; }

#tm-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-24);
  scroll-behavior: smooth;
}

.view { animation: view-in var(--dur-slow) ease; }
@keyframes view-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ---------- responsive ---------- */

@media (max-width: 1000px) and (min-width: 769px) {
  :root { --sidebar-w: 60px; }
  #tm-logo { padding: var(--space-14) 0; text-align: center; }
  #tm-logo > * { display: none; }
  #tm-logo::after {
    content: var(--brand-initial);
    font-weight: var(--weight-bold);
    font-size: var(--text-3xl);
    font-family: var(--font-brand);
    color: var(--accent-hi);
  }
  .nav-item { justify-content: center; padding: var(--space-10) 0; }
  .nav-item .nav-label { display: none; }
}

/* Narrow screens: sidebar becomes an off-canvas drawer, hidden by default.
   A hamburger button area is reserved in the topbar. The JS toggle that
   adds/removes .sidebar-open on #tm-app is NOT implemented here (CSS-only
   part); a separate JS change is needed to wire the hamburger click. */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  #tm-sidebar {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    width: 240px;
    z-index: var(--z-modal);
    transform: translateX(-100%);
    transition: transform var(--dur-slow) ease;
  }
  /* When the app has .sidebar-open, slide the drawer in */
  #tm-app.sidebar-open #tm-sidebar {
    transform: translateX(0);
  }
  /* Backdrop overlay when drawer is open */
  #tm-app.sidebar-open::before {
    content: "";
    position: fixed;
    inset: 0;
    background: var(--backdrop);
    z-index: calc(var(--z-modal) - 1);
  }
  /* Hamburger area in the topbar — visible on narrow screens */
  .tm-hamburger {
    display: flex;
    align-items: center;
    justify-content: center;
    /* touch target padding */
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    background: none;
    border: 1px solid transparent;
    color: var(--text-dim);
    cursor: pointer;
    transition: color var(--dur-base) ease;
    flex: none;
  }
  .tm-hamburger svg { width: 20px; height: 20px; }
  .tm-hamburger:hover { color: var(--text); }
}
/* Hide hamburger on wider screens */
@media (min-width: 769px) {
  .tm-hamburger { display: none; }
}

/* Touch targets: nav items on coarse-pointer devices */
@media (pointer: coarse) {
  .nav-item { min-height: 44px; /* touch target padding */ }
}

/* ---------- command palette (palette.js) ---------- */

dialog.tm-palette {
  position: fixed;
  top: 12vh;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  width: min(560px, calc(100vw - 32px));
  max-height: 60dvh;
  background: var(--surface);
  border: 1px solid var(--border-2);
  box-shadow: var(--shadow-modal);
  padding: 0;
  display: flex;
  flex-direction: column;
  animation: modal-in var(--dur-mid) ease;
}
dialog.tm-palette::backdrop { background: var(--backdrop); backdrop-filter: blur(2px); }
.tm-palette-input {
  flex: none;
  background: var(--surface-2);
  border: none;
  border-bottom: 1px solid var(--border-2);
  color: var(--text);
  font-weight: var(--weight-normal);
  font-size: var(--text-sm);
  font-family: var(--font-ui);
  padding: var(--space-14) var(--space-16);
  outline: none;
}
.tm-palette-input::placeholder { color: var(--text-faint); }
.tm-palette-list { overflow-y: auto; padding: var(--space-6); }
.tm-palette-item {
  display: flex;
  align-items: center;
  gap: var(--space-10);
  padding: var(--space-8) var(--space-12);
  color: var(--text-dim);
  cursor: pointer;
}
.tm-palette-item.active { background: var(--surface-3); color: var(--text); }
.tm-palette-icon { display: inline-flex; flex: none; color: var(--accent-hi); }
.tm-palette-icon svg { width: 15px; height: 15px; }
.tm-palette-label { flex: 1; min-width: 0; font-size: var(--text-2xs); font-family: var(--font-ui); }
.tm-palette-hint {
  flex: none;
  color: var(--text-faint);
  font-size: var(--text-3xs);
  font-family: var(--font-mono);
}
