/* DOSSIER — phone / tablet mobile-first (replaces legacy osint @820) */

html.is-phone,
html.is-phone body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

/* App chrome must not cover the marketing landing */
html.syntax-on-landing .dossier-bottom-nav,
html.syntax-on-landing .dossier-graph-dock,
html.syntax-on-landing .dossier-zoom-rail,
html.syntax-on-landing .dossier-more-sheet,
html.syntax-on-landing .dossier-more-backdrop {
  display: none !important;
}

.dossier-graph-dock,
.dossier-zoom-rail {
  display: none;
}

@media (max-width: 767px) {
  html, body {
    min-height: 100%;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
  }

  html.syntax-on-landing,
  html.syntax-on-landing body {
    overflow: hidden;
    height: 100dvh;
  }

  .app-shell {
    min-height: 100dvh;
    height: 100dvh;
  }

  .app-main {
    min-width: 0;
    width: 100%;
  }

  /* Override legacy syntax-macos @820 topbar (44px + absolute recent chips → overlap search) */
  html.dossier-ui.syntax-macos body.in-app .topbar.mac-toolbar.dossier-topbar {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto !important;
    grid-template-rows: auto auto !important;
    --topbar-h: auto;
    position: sticky;
    top: 0;
    z-index: 40;
  }

  html.dossier-ui .search-recent-row,
  html.dossier-ui #searchRecentRow {
    display: none !important;
  }

  html.dossier-ui .dossier-topbar {
    padding: 8px 12px;
    padding-top: max(8px, var(--safe-top));
  }

  html.dossier-ui .search-input {
    font-size: 16px !important;
  }

  html.dossier-ui .header-status {
    display: flex !important;
  }

  .workspace {
    min-height: 0;
    height: calc(100dvh - var(--header-h) - var(--bottom-nav-h) - var(--safe-bottom));
  }

  .main-area {
    display: block;
    position: relative;
    height: 100%;
  }

  .graph-stage {
    width: 100%;
    height: 100%;
    min-height: 0;
    overscroll-behavior: none;
  }

  #graph-canvas {
    width: 100%;
    height: 100%;
    touch-action: none;
  }

  /* Profile — DOSSIER sheet (no 18px pill) */
  html.is-phone .profile-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto !important;
    max-height: min(92dvh, 720px) !important;
    height: min(60dvh, 620px) !important;
    z-index: 55;
    margin: 0;
    border: 1px solid var(--line);
    border-bottom: none;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    box-shadow: none;
    background: var(--surface-1);
    padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom));
  }

  html.is-phone .profile-panel::before,
  html.is-phone .profile-panel::after {
    content: '';
    position: absolute;
    width: 10px;
    height: 10px;
    border-color: var(--text-muted);
    border-style: solid;
    pointer-events: none;
    z-index: 2;
  }

  html.is-phone .profile-panel::before {
    top: 8px;
    left: 8px;
    border-width: 1px 0 0 1px;
  }

  html.is-phone .profile-panel::after {
    top: 8px;
    right: 8px;
    border-width: 1px 1px 0 0;
  }

  html.is-phone .profile-sheet-handle {
    width: 32px;
    height: 2px;
    background: var(--line);
    border-radius: 0;
    margin: 8px auto 4px;
  }

  html.is-phone .profile-avatar {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-sm);
  }

  html.is-phone .profile-header {
    padding: 12px 16px;
  }

  html.is-phone .profile-section {
    padding: 12px 16px;
  }

  html.is-phone .entity-profile-tabs {
    position: sticky;
    top: 0;
    z-index: 3;
    background: var(--surface-1);
    overflow-x: auto;
    border-bottom: 1px solid var(--line);
  }

  html.is-phone .profile-sheet-backdrop.show {
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: none;
  }

  /* Graph HUD */
  .graph-hud-tl {
    top: 8px;
    left: 8px;
  }

  .graph-hud-tr {
    display: none !important;
  }

  body.in-app[data-shell-nav="graph"] .graph-hud-bc {
    bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 52px);
  }

  body.in-app:not([data-shell-nav="graph"]) .graph-hud-bc {
    bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 8px);
  }

  .graph-hud-bc {
    left: 8px;
    right: 8px;
    width: auto;
    padding: 0;
  }

  html.graph-fullscreen .graph-hud-bc {
    bottom: calc(52px + var(--safe-bottom));
  }

  html.graph-fullscreen .dossier-topbar,
  html.graph-fullscreen .dossier-bottom-nav {
    display: none !important;
  }

  .graph-mode-seg button {
    min-height: 32px;
    font-size: 10px;
  }

  .stats-bar {
    max-width: 100%;
    padding: 4px;
    gap: 4px;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    border: 1px solid var(--line);
    background: var(--surface-1);
  }

  .stat-item {
    flex: 0 0 auto;
    padding: 4px 8px;
    font-size: var(--text-xs);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
  }

  .graph-hud-tl .graph-enrich-fab,
  .graph-hud-tl .graph-report-btn,
  .graph-hud-tl .graph-report-share-btn {
    display: none !important;
  }

  .mobile-graph-hint {
    display: none !important;
  }

  /* Graph dock — only in workspace on the Graph tab (not on landing) */
  body.in-app[data-shell-nav="graph"] .dossier-graph-dock {
    display: flex;
    justify-content: space-around;
    align-items: stretch;
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(var(--bottom-nav-h) + var(--safe-bottom));
    z-index: 54;
    background: var(--surface-1);
    border-top: 1px solid var(--line);
    padding: 4px 8px;
    gap: 4px;
  }

  body.in-app[data-shell-nav="graph"] .dossier-zoom-rail {
    display: flex;
  }

  html.graph-fullscreen .dossier-graph-dock {
    bottom: var(--safe-bottom);
  }

  html.keyboard-open .dossier-graph-dock {
    display: none;
  }

  .dossier-graph-dock__btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 48px;
    max-width: 72px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font-display);
    font-size: 9px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    cursor: pointer;
  }

  .dossier-graph-dock__btn:active {
    background: var(--surface-2);
    color: var(--text);
  }

  .graph-mobile-bar {
    display: none !important;
  }

  html.is-phone #zoomControls,
  html.is-phone .graph-hud-tl .zoom-controls {
    display: none !important;
  }

  .dossier-graph-dock__btn .syntax-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    color: var(--text-secondary);
  }

  .dossier-graph-dock__btn .syntax-icon svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.5;
  }

  .dossier-graph-dock__lbl {
    font-size: 11px;
    line-height: 1.15;
    letter-spacing: 0.03em;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .dossier-graph-dock__btn {
    min-height: 52px;
    max-width: none;
    padding: 4px 2px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
  }

  .dossier-bottom-nav {
    min-height: 60px;
    padding-top: 4px;
  }

  .dossier-bottom-nav__btn span:not(.syntax-icon) {
    font-size: 11px;
    line-height: 1.2;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  html.syntax-on-landing .landing-header {
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
  }

  html.syntax-on-landing .landing-logo {
    flex-shrink: 0;
  }

  html.syntax-on-landing .landing-nav {
    flex: 1 1 auto;
    min-width: 0;
    flex-wrap: nowrap !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    justify-content: flex-end;
  }

  html.syntax-on-landing .landing-nav::-webkit-scrollbar {
    display: none;
  }

  .dossier-zoom-rail {
    position: fixed;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 53;
    flex-direction: column;
    gap: 4px;
  }

  .dossier-zoom-rail button {
    width: 44px;
    height: 44px;
    border: 1px solid var(--line);
    background: var(--surface-1);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 18px;
    cursor: pointer;
  }

  /* Float panels → full bleed DOSSIER */
  .float-panel,
  .float-panel.ai-panel,
  .float-panel.chain-panel,
  #analystPanel {
    left: 0 !important;
    right: 0 !important;
    top: auto !important;
    bottom: 0 !important;
    width: auto !important;
    max-height: min(92dvh, 720px) !important;
    height: min(85dvh, 640px) !important;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0 !important;
    border: 1px solid var(--line) !important;
    box-shadow: none !important;
  }

  #analystPanel.open {
    display: flex !important;
    flex-direction: column;
  }

  .analyst-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
  }

  .analyst-input-row {
    flex-shrink: 0;
    padding-bottom: max(8px, var(--safe-bottom));
  }

  .sources-panel,
  .graph-enrich-panel,
  .settings-panel.mac-sheet {
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    top: auto !important;
    width: auto !important;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0 !important;
    box-shadow: none !important;
    max-height: 92dvh !important;
  }

  .auth-gate {
    padding: max(14px, var(--safe-top)) 16px max(14px, var(--safe-bottom));
    overflow-y: auto;
  }

  .auth-card {
    width: min(100%, 430px);
    max-height: calc(100dvh - 24px);
    border-radius: var(--radius-sm);
    box-shadow: none;
    border: 1px solid var(--line);
  }

  .auth-input {
    font-size: 16px;
    min-height: 48px;
  }

  .auth-btn {
    min-height: 48px;
    width: 100%;
  }

  button,
  .nav-item {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }
}

@media (min-width: 768px) and (max-width: 1023px) {
  .workspace {
    min-height: 0;
    flex: 1;
  }

  html.is-tablet .profile-panel {
    width: var(--panel-w, 340px) !important;
    border-radius: var(--radius-sm);
    box-shadow: none;
    border: 1px solid var(--line);
  }

  .dossier-bottom-nav,
  .dossier-graph-dock,
  .dossier-zoom-rail {
    display: none !important;
  }
}

@media (min-width: 768px) {
  .dossier-search-fs,
  .dossier-graph-dock,
  .dossier-zoom-rail {
    display: none !important;
  }
}

/* Fullscreen search (phone) */
.dossier-search-fs {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--bg);
  display: none;
  flex-direction: column;
  padding: var(--safe-top) 16px var(--safe-bottom);
}

.dossier-search-fs.is-open {
  display: flex;
}

.dossier-search-fs__head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  margin-bottom: 12px;
}

.dossier-search-fs__back {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--line);
  background: var(--surface-1);
  color: var(--text);
  font-family: var(--font-display);
  font-size: var(--text-xs);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.dossier-search-fs__title {
  font-family: var(--font-display);
  font-size: var(--text-sm);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.dossier-search-fs__chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  scrollbar-width: none;
  margin-bottom: 12px;
}

.dossier-search-fs__field-wrap {
  position: relative;
  margin-bottom: 8px;
}

.dossier-search-fs__input {
  width: 100%;
  min-height: 52px;
  padding: 0 44px 0 12px;
  font-size: 16px;
  font-family: var(--font-mono);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--radius-sm);
}

.dossier-search-fs__clear {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  min-width: 44px;
  min-height: 44px;
  border: none;
  background: transparent;
  color: var(--text-muted);
}

.dossier-search-fs__hint {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-bottom: 16px;
}

.dossier-search-fs__error {
  font-size: var(--text-sm);
  color: var(--status-error);
  margin-top: 8px;
}

.dossier-search-fs__history {
  flex: 1;
  overflow-y: auto;
  list-style: none;
  margin: 0;
  padding: 0;
}

.dossier-search-fs__history li {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  border-bottom: 1px solid var(--line);
}

.dossier-search-fs__history button {
  flex: 1;
  text-align: left;
  min-height: 48px;
  padding: 0 4px;
  border: none;
  background: transparent;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--data);
}

.dossier-search-fs__history-del {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--line);
  background: var(--surface-1);
  color: var(--text-muted);
}

.dossier-search-fs__actions {
  display: flex;
  gap: 8px;
  padding: 8px 0;
  margin-top: auto;
}

.dossier-search-fs__submit {
  flex: 1;
  min-height: 48px;
}

.dossier-search-fs__clear-all {
  min-height: 48px;
  padding: 0 12px;
}

.dossier-search-fs__submit-wrap {
  position: sticky;
  bottom: 0;
  padding-top: 8px;
  background: var(--bg);
}

html.keyboard-open .dossier-search-fs__submit-wrap {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: max(8px, var(--safe-bottom));
  z-index: 201;
}

/* More sheet rows */
.dossier-more-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  width: 100%;
  padding: 0 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
  font-size: var(--text-sm);
  margin-bottom: 6px;
  cursor: pointer;
}

.dossier-more-row:active {
  background: var(--surface-1);
}

.dossier-more-row__arrow {
  margin-left: auto;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* Ext DB mobile */
@media (max-width: 767px) {
  .ext-db-block {
    border-radius: var(--radius-sm);
    box-shadow: none;
  }

  .ext-db-record {
    border: 1px solid var(--line);
    margin-bottom: 12px;
  }

  .dossier-kv {
    grid-template-columns: 1fr;
  }
}
