/**
 * Tabla I/O — Native App Shell Styles (Refined Apple HIG Architecture)
 * ──────────────────────────────────────────────────────────────────
 * Applied only when <html class="native-app"> is set.
 *
 * Scoped strictly to the native mobile/desktop application:
 * The public website is 100% UNTOUCHED.
 */

/* ── 1. Hide Web-Only Elements in App Mode ──────────────── */

html.native-app footer.site-footer,
html.native-app #cookie-banner,
html.native-app #pricing,
html.native-app #free-beta-banner,
html.native-app #about,
html.native-app #contact,
html.native-app .hero-demo,
html.native-app #announcement-banner,
html.native-app #maintenance-banner,
html.native-app #jump-to-top,
html.native-app #jump-to-top-btn,
html.native-app a[href*="tabla-io-guide.pdf"] {
  display: none !important;
}

/* Hide marketing-only anchor links in app mode */
html.native-app nav .nav-links li:has(a[href^="#features"]),
html.native-app nav .nav-links li:has(a[href^="#guide"]),
html.native-app nav .nav-links li:has(a[href^="#pricing"]),
html.native-app nav .nav-links li:has(a[href^="blog/"]),
html.native-app nav .nav-links li:has(a[href^="#contact"]) {
  display: none !important;
}

html.native-app .hero-builder {
  display: none !important;
}

/* In native app, Library is Home screen: hide back button on Library */
html.native-app .library-shell #header-back-btn {
  display: none !important;
}

/* ── 2. Viewport & Safe Area Resets ─────────────────────── */

html.native-app .library-shell.has-footer {
  padding-bottom: 0 !important;
}

html.native-app body {
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

html.native-app,
html.native-app body {
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

/* ── 3. Native Bottom Tab Bar (Mobile) ──────────────────── */

.native-tab-bar {
  display: none;
}

@media (max-width: 900px) {
  html.native-app .native-tab-bar {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(52px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: rgba(18, 16, 14, 0.94);
    backdrop-filter: blur(24px) saturate(180%);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 9999;
    align-items: center;
    justify-content: space-around;
  }

  /* Themes */
  html.light.native-app .native-tab-bar {
    background: rgba(255, 255, 255, 0.94);
    border-top-color: rgba(0, 0, 0, 0.08);
  }

  html.cream.native-app .native-tab-bar {
    background: rgba(253, 248, 242, 0.96);
    border-top-color: rgba(180, 110, 50, 0.15);
  }

  html.stone.native-app .native-tab-bar {
    background: rgba(24, 20, 18, 0.94);
    border-top-color: rgba(255, 255, 255, 0.08);
  }

  /* Tab items */
  html.native-app .native-tab-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted, #888888);
    text-decoration: none;
    font-size: 0.68rem;
    font-weight: 500;
    gap: 3px;
    transition: color 0.15s ease, transform 0.1s ease;
    -webkit-tap-highlight-color: transparent;
  }

  html.native-app .native-tab-item svg {
    width: 21px;
    height: 21px;
    stroke-width: 1.9;
    transition: transform 0.15s ease;
  }

  /* Only active tab is highlighted with accent color */
  html.native-app .native-tab-item.active {
    color: var(--accent-primary, #ea6500) !important;
    font-weight: 600;
  }

  html.native-app .native-tab-item.active svg {
    stroke-width: 2.2;
    transform: scale(1.05);
  }

  /* Compose center button (clean outline when inactive to avoid duplicate active state) */
  html.native-app .native-tab-compose .native-tab-compose-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1.5px solid currentColor;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease, background 0.15s ease;
  }

  html.native-app .native-tab-compose.active .native-tab-compose-icon {
    background: var(--accent-primary, #ea6500);
    border-color: var(--accent-primary, #ea6500);
    color: #ffffff !important;
  }

  html.native-app .native-tab-compose .native-tab-compose-icon svg {
    width: 16px;
    height: 16px;
    stroke-width: 2.4;
  }

  /* Bottom padding so content is never hidden behind tab bar */
  html.native-app body.has-native-tabs,
  html.native-app body.has-native-tabs .library-shell {
    padding-bottom: calc(68px + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* Hide floating assistant FAB on mobile */
  html.native-app .assistant-fab {
    display: none !important;
  }
}

/* ── 4. Apple HIG Mobile Library Redesign (Mobile App Only) ── */

@media (max-width: 900px) {
  /* Minimal Top Header Bar: Tabla Ring + Compositions on Left, Theme, Script, and Avatar all in one line on Right */
  html.native-app .lib-header {
    background: transparent !important;
    border-bottom: none !important;
    box-shadow: none !important;
    padding: max(env(safe-area-inset-top, 0px), 12px) 16px 8px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    width: 100% !important;
    box-sizing: border-box !important;
    gap: 10px !important;
  }

  /* Hide web breadcrumbs & compose button from top bar */
  html.native-app .lib-header .lib-header-sep,
  html.native-app .lib-header .lib-title-dropdown,
  html.native-app .lib-header .lib-brand-text,
  html.native-app .lib-header .nav-cta,
  html.native-app .lib-header .lib-brand {
    display: none !important;
  }

  html.native-app .lib-header-left {
    display: flex !important;
    align-items: center !important;
    min-width: 0 !important;
    flex: 1 1 auto !important;
  }

  html.native-app .native-title-with-drum {
    display: inline-flex !important;
    align-items: center !important;
    gap: 8px !important;
    min-width: 0 !important;
  }

  html.native-app .native-title-drum {
    width: 28px !important;
    height: 28px !important;
    flex-shrink: 0 !important;
  }

  html.native-app .native-large-title {
    font-size: 1.35rem !important;
    font-weight: 700 !important;
    letter-spacing: -0.025em !important;
    color: var(--text-primary) !important;
    margin: 0 !important;
    line-height: 1.2 !important;
    font-family: var(--font-system) !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  /* Top Right Row: Theme, Script, and Avatar all in one line */
  html.native-app .lib-header .lib-header-right {
    display: flex !important;
    align-items: center !important;
    gap: 6px !important;
    margin-left: auto !important;
    flex-shrink: 0 !important;
  }

  html.native-app .lib-header #lib-theme-toggle,
  html.native-app .lib-header #lib-script-toggle,
  html.native-app .lib-header #authWidget {
    display: inline-flex !important;
  }

  html.native-app .lib-header .theme-toggle {
    width: 30px !important;
    height: 30px !important;
    border-radius: 50% !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  html.native-app .lib-header .header-script-btn {
    height: 30px !important;
    padding: 0 8px !important;
    border-radius: 15px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 0.78rem !important;
  }

  .native-mobile-header {
    display: none !important;
  }

  /* ── KILL THE PEACH BAND COMPLETELY ── */
  html.native-app .lib-toolbar,
  html.native-app[data-theme="cream"] .lib-toolbar,
  html.cream.native-app .lib-toolbar,
  [data-theme="cream"] html.native-app .lib-toolbar {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    margin: 0 !important;
    padding: 0 18px 12px !important;
    gap: 10px !important;
    border-radius: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  /* ── SEARCH BOX + ••• BUTTON SIDE-BY-SIDE ON SAME ROW ── */
  html.native-app .lib-toolbar-controls {
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    gap: 8px !important;
    width: 100% !important;
    padding: 0 !important;
    margin: 0 0 10px 0 !important;
  }

  html.native-app .lib-toolbar-controls .lib-search-box {
    position: relative !important;
    flex: 1 0 100% !important;
    height: 40px !important;
    margin: 0 !important;
    padding: 0 !important;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
  }

  html.native-app .lib-search-icon {
    position: absolute !important;
    left: 12px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    width: 16px !important;
    height: 16px !important;
    color: var(--text-muted, #888888) !important;
    pointer-events: none !important;
    z-index: 2 !important;
  }

  html.native-app .lib-search-input {
    width: 100% !important;
    height: 40px !important;
    padding: 0 36px 0 36px !important; /* Exactly 36px left & right padding clears the icon and clear button */
    font-size: 0.90rem !important;
    border-radius: 12px !important;
    background: rgba(0, 0, 0, 0.05) !important;
    border: 1px solid rgba(0, 0, 0, 0.08) !important;
    color: var(--text-primary) !important;
    outline: none !important;
    box-shadow: none !important;
    box-sizing: border-box !important;
    transition: border-color 0.15s ease, background 0.15s ease !important;
  }

  [data-theme="cream"] html.native-app .lib-search-input,
  html.cream.native-app .lib-search-input {
    background: rgba(255, 255, 255, 0.65) !important;
    border-color: rgba(180, 110, 50, 0.22) !important;
    color: #2C1A0E !important;
  }

  html.native-app .lib-search-input:focus {
    border-color: var(--accent-primary, #ea6500) !important;
    background: #ffffff !important;
  }

  /* Native More / Filters '•••' Button (Alongside Search Box) */
  html.native-app .native-more-btn {
    flex: 0 0 40px !important;
    width: 40px !important;
    height: 40px !important;
    border-radius: 12px !important;
    background: rgba(0, 0, 0, 0.05) !important;
    border: 1px solid rgba(0, 0, 0, 0.08) !important;
    color: var(--text-primary, #f0f0f0);
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer !important;
    position: relative !important;
    box-sizing: border-box !important;
    padding: 0 !important;
    margin: 0 !important;
    transition: background 0.15s ease, transform 0.1s ease !important;
    -webkit-tap-highlight-color: transparent !important;
  }

  [data-theme="cream"] html.native-app .native-more-btn,
  html.cream.native-app .native-more-btn {
    background: rgba(255, 255, 255, 0.65) !important;
    border-color: rgba(180, 110, 50, 0.22) !important;
    color: #2C1A0E !important;
  }

  html.native-app .native-more-btn:active {
    transform: scale(0.92);
  }

  html.native-app .native-filter-dot {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-primary, #ea6500);
    border: 1.5px solid var(--bg-primary, #fff);
  }

  /* ── TAB SWITCHERS: RESTORED TO WEBSITE CAPSULE WITH ORANGE INDICATOR ── */
  html.native-app .lib-toolbar-navigation {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    border-top: none !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow-x: auto !important;
    scrollbar-width: none !important;
    -webkit-overflow-scrolling: touch !important;
  }

  html.native-app .lib-toolbar-navigation::-webkit-scrollbar {
    display: none !important;
  }

  html.native-app .lib-toolbar-navigation .lib-tabs {
    display: flex !important;
    flex-wrap: nowrap !important;
    width: 100% !important;
    gap: 3px !important;
    padding: 3px !important;
    border-radius: 9999px !important;
    box-sizing: border-box !important;
  }

  html.native-app .lib-toolbar-navigation .lib-tab {
    flex: 1 1 0 !important;
    min-width: max-content !important;
    text-align: center !important;
    padding: 7px 4px !important;
    font-size: 0.78rem !important;
    white-space: nowrap !important;
    border-radius: 9999px !important;
    letter-spacing: -0.01em !important;
  }

  /* Hide Trash from the horizontal segment (accessible in ••• sheet) */


  /* Unbox Main Content */
  html.native-app .lib-main {
    padding: 2px 18px 24px !important;
    background: transparent !important;
  }

  /* Clean Edge-to-Edge Empty State */
  html.native-app .lib-empty,
  html.native-app .lib-empty-card {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding: 32px 16px !important;
  }
}

/* ── 5. Apple Bottom Sheet Modal (Filter & Options) ───────── */

.native-sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 99998;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.native-sheet-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

.native-sheet-modal {
  width: 100%;
  max-width: 480px;
  max-height: 82vh;
  overflow-y: auto;
  background: var(--bg-card, #ffffff);
  border-top-left-radius: 24px;
  border-top-right-radius: 24px;
  padding: 14px 20px calc(24px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.2);
  border-top: 1px solid var(--border-color, rgba(255, 255, 255, 0.1));
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

.native-sheet-backdrop.active .native-sheet-modal {
  transform: translateY(0);
}

.native-sheet-grabber {
  width: 36px;
  height: 5px;
  border-radius: 3px;
  background: var(--border-strong, rgba(255, 255, 255, 0.25));
  margin: 0 auto 14px;
}

.native-sheet-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.native-sheet-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.native-sheet-done-btn {
  background: none;
  border: none;
  color: var(--accent-primary, #ea6500);
  font-size: 1.0rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 8px;
}

.native-sheet-content {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.native-sheet-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.native-sheet-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.native-sheet-select {
  width: 100%;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 0.95rem;
  outline: none;
}

.native-sheet-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--border-color);
}

.native-sheet-action-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
}

.native-sheet-reset-btn {
  padding: 10px 14px;
  border-radius: 12px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.88rem;
  cursor: pointer;
  text-align: center;
}

/* Cream Theme Overrides for Sheet */
[data-theme="cream"] .native-sheet-modal,
html.cream .native-sheet-modal {
  background: #FDF8F2 !important;
  border-top-color: rgba(180, 110, 50, 0.2) !important;
}

[data-theme="cream"] .native-sheet-grabber,
html.cream .native-sheet-grabber {
  background: rgba(180, 110, 50, 0.35) !important;
}

[data-theme="cream"] .native-sheet-select,
html.cream .native-sheet-select,
[data-theme="cream"] .native-sheet-action-btn,
html.cream .native-sheet-action-btn {
  background: #F7EFE4 !important;
  border-color: rgba(180, 110, 50, 0.2) !important;
  color: #2C1A0E !important;
}
