/* FOLIO — Mobile & small-viewport responsive layer (zero horizontal overflow down to 320px) */

@media (max-width: 820px) {
  body {
    font-size: 14px;
  }

  .shell {
    padding-bottom: calc(92px + env(safe-area-inset-bottom));
  }

  .main {
    margin-left: 0;
  }

  /* Floating Dark-Obsidian Glass Dock */
  .sidebar {
    position: fixed;
    inset: auto 10px calc(10px + env(safe-area-inset-bottom)) 10px;
    width: auto;
    height: 66px;
    padding: 6px 8px;
    flex-direction: row;
    align-items: center;
    justify-content: space-around;
    gap: 4px;
    border-radius: 18px;
    background: rgba(24, 25, 28, 0.94);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.07);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    z-index: 30;
  }

  .sidebar .brand-wrap,
  .sidebar .brand,
  .workspace-label,
  .side-spacer,
  .side-status,
  .sidebar .logout {
    display: none;
  }

  .nav {
    flex: 1 1 0;
    min-width: 0;
    min-height: 52px;
    margin: 0;
    padding: 4px 2px;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 3px;
    border-radius: 12px;
    color: #9ba0ad;
    font-size: clamp(9.5px, 2.5vw, 11px);
    font-weight: 550;
    line-height: 1.1;
    text-align: center;
  }

  .nav-text {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .nav span {
    width: 42px;
    height: 28px;
    flex: 0 0 28px;
    border-radius: 999px;
    transition: background 0.16s ease, color 0.16s ease, transform 0.16s ease;
  }

  .nav svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
  }

  .nav b {
    position: absolute;
    top: 2px;
    right: calc(50% - 22px);
    min-width: 17px;
    padding: 1px 5px;
    border-radius: 999px;
    border: 1.5px solid #18191c;
    background: #10b981;
    color: #071912;
    font-size: 9px;
    font-weight: 800;
    line-height: 1.25;
  }

  .nav:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #ffffff;
  }

  .nav.active {
    background: transparent;
    color: #ffffff;
    box-shadow: none;
    font-weight: 700;
  }

  .nav.active span {
    background: rgba(16, 185, 129, 0.22);
    color: #34d399;
    box-shadow: inset 0 0 0 1px rgba(16, 185, 129, 0.35);
  }

  .nav.active svg {
    stroke: #34d399;
  }

  .nav.active b {
    background: #34d399;
    color: #061810;
  }

  /* Compact topbar */
  .topbar {
    height: 52px;
    padding: 0 14px;
  }

  .mobile-brand-mark {
    display: grid;
  }

  .secure {
    display: none;
  }

  .mobile-logout {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 5px 10px;
    border: 1px solid var(--line-subtle);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    color: var(--ink-primary);
    font-size: 12px;
    font-weight: 600;
  }

  .avatar {
    width: 30px;
    height: 30px;
  }

  /* View padding & header actions */
  .view {
    padding: 16px 12px 32px;
  }

  .page-head {
    gap: 12px;
    margin-bottom: 14px;
  }

  .head-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    gap: 8px;
  }

  .head-actions > label.primary {
    grid-column: 1 / -1;
  }

  .head-actions > *,
  .drive-hero-actions > *,
  .empty-actions > * {
    min-height: 40px;
    width: 100%;
    font-size: 12.5px;
  }

  .primary,
  .secondary,
  .upload-btn {
    min-height: 38px;
    font-size: 12.5px;
  }

  /* 1-click Drive hero stacks cleanly on mobile */
  .drive-hero {
    flex-direction: column;
    align-items: stretch;
    padding: 14px;
    gap: 12px;
  }

  .drive-hero-actions {
    width: 100%;
  }

  /* Search & discovery row */
  .search-discovery-row {
    padding: 8px;
    gap: 8px;
    min-width: 0;
  }

  .search-discovery-row .search-bar {
    height: 42px;
    padding: 0 6px 0 10px;
    border: 1px solid var(--line-subtle);
    background: var(--bg-subtle);
    min-width: 0;
  }

  .quick-prompts-inline {
    min-width: 0;
    max-width: 100%;
    padding: 2px 0;
  }

  .search-bar {
    height: 44px;
    padding: 0 8px 0 10px;
    gap: 8px;
  }

  .search-bar kbd {
    display: none;
  }

  .search-bar input,
  .large-search input,
  .login-card input,
  .edit-grid input,
  .edit-grid select,
  .edit-grid textarea,
  .inline-form input,
  .inline-form select,
  .stack-form input,
  .drive-tools input {
    font-size: 16px;
  }

  .search-bar button {
    min-height: 32px;
    padding: 0 12px;
  }

  .large-search {
    height: auto;
    min-height: 52px;
    flex-wrap: wrap;
    padding: 10px;
  }

  .large-search input {
    min-width: calc(100% - 34px);
  }

  .large-search .primary {
    width: 100%;
    min-height: 42px;
  }

  /* KPI Strip & Toolbar */
  .overview-strip,
  .overview-strip-integrated {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .overview-strip-integrated > div {
    padding: 10px 12px;
    border-bottom: 1px solid var(--line-hairline);
  }

  .overview-strip-integrated > div:nth-child(2n) {
    border-right: 0;
  }

  .overview-strip-integrated > div:nth-last-child(-n+2) {
    border-bottom: 0;
  }

  .toolbar,
  .registry-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 10px 12px;
  }

  .filters {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
    width: 100%;
  }

  .filters > * {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    min-height: 38px;
  }

  .filters #sortFilter {
    grid-column: 1 / -1;
  }

  .view-count {
    align-self: flex-end;
  }

  /* Responsive Registry Table -> Clean CSS Grid Cards (Zero Overlap) */
  .table-scroll {
    overflow-x: visible;
  }

  .legal-table,
  .legal-table tbody {
    display: block;
    width: 100%;
  }

  .legal-table thead {
    display: none;
  }

  .legal-table tbody tr.doc-card {
    display: grid;
    grid-template-columns: 26px 32px minmax(0, 1fr) auto;
    gap: 8px 8px;
    align-items: start;
    padding: 14px 12px;
    border-bottom: 1px solid var(--line-subtle);
  }

  .legal-table tbody tr.doc-card:last-child {
    border-bottom: 0;
  }

  .legal-table tbody tr.doc-card td {
    display: block;
    width: auto;
    min-width: 0;
    max-width: none;
    padding: 0;
    border-bottom: 0;
    white-space: normal;
  }

  .legal-table tbody tr.doc-card td.col-check {
    grid-column: 1;
    grid-row: 1;
    padding-top: 3px;
    text-align: left;
  }

  .legal-table tbody tr.doc-card td.col-type {
    grid-column: 2;
    grid-row: 1;
    padding-top: 1px !important;
  }

  .legal-table tbody tr.doc-card td.dossier-cell {
    grid-column: 3 / 5;
    grid-row: 1;
  }

  .legal-table tbody tr.doc-card td.snippet-cell {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .legal-table tbody tr.doc-card td.tags-cell {
    grid-column: 1 / -1;
    grid-row: 3;
  }

  .legal-table tbody tr.doc-card td.amount-cell {
    grid-column: 1 / 4;
    grid-row: 4;
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex-wrap: wrap;
    align-self: center;
  }

  .legal-table tbody tr.doc-card td.amount-cell .amount-date {
    margin-top: 0;
  }

  .legal-table tbody tr.doc-card td.status-cell {
    grid-column: 4;
    grid-row: 4;
    justify-self: end;
    align-self: center;
  }

  .legal-table tbody tr.doc-card td.actions-cell {
    grid-column: 1 / -1;
    grid-row: 5;
    text-align: left;
    padding-top: 8px;
    border-top: 1px solid var(--line-hairline);
  }

  .actions-group {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
  }

  .legal-table .actions-group .text-action {
    min-height: 34px;
    padding: 5px 10px;
    border: 1px solid var(--line-subtle);
    border-radius: var(--radius-sm);
    background: var(--bg-subtle);
    color: var(--ink-primary);
  }

  .legal-table .actions-group .doc-menu {
    margin-left: auto;
    width: 34px;
    height: 34px;
    border: 1px solid var(--line-subtle);
    border-radius: var(--radius-sm);
    background: var(--bg-subtle);
  }

  /* Single column cards */
  .document-grid,
  .case-grid,
  .settings-grid,
  .drive-result-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .search-filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .drive-tools {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .drive-tools input {
    min-width: 0;
    min-height: 40px;
  }

  .task-row {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 14px;
  }

  .task-actions {
    width: 100%;
  }

  .task-actions > * {
    flex: 1;
    min-height: 40px;
  }

  .drive-file {
    flex-direction: column;
    align-items: flex-start;
  }

  .drive-file button {
    width: 100%;
  }

  .inline-form > * {
    width: 100%;
  }

  /* Bottom-sheet modals on mobile */
  .modal {
    align-items: end;
    padding: 0;
  }

  .modal-card {
    width: 100%;
    max-height: 92dvh;
    padding: 20px 16px calc(16px + env(safe-area-inset-bottom));
    border-radius: 16px 16px 0 0;
  }

  .edit-grid {
    grid-template-columns: 1fr;
  }

  .edit-actions {
    position: sticky;
    bottom: -16px;
    padding: 10px 0 max(8px, env(safe-area-inset-bottom));
    background: var(--bg-surface);
  }

  .edit-actions > * {
    flex: 1;
  }

  .scan-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .toast {
    left: 12px;
    right: 12px;
    bottom: calc(92px + env(safe-area-inset-bottom));
    text-align: center;
  }

  .login-wrap {
    padding: 14px;
  }

  .login-card {
    padding: 24px 18px;
  }

  .brain-strip {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .brain-strip-copy {
    flex-wrap: wrap;
  }

  .brain-strip-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .brain-strip-actions > * {
    width: 100%;
    min-height: 40px;
  }

  .brain-chat-input {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 10px;
  }

  .brain-chat-input > span {
    display: none;
  }

  .brain-chat-input button {
    width: 100%;
    min-height: 42px;
  }

  .platform-config-grid,
  .platform-create-grid {
    grid-template-columns: 1fr;
  }

  .platform-row {
    flex-direction: column;
    align-items: stretch;
  }

  .platform-row-actions {
    width: 100%;
  }

  .platform-row-actions > * {
    flex: 1 1 auto;
    min-height: 38px;
  }

  .auth-tab {
    font-size: 12.5px;
    padding: 7px 6px;
  }

  .scan-cam-box video {
    max-height: 230px;
  }

  .sig-pad {
    height: 110px;
  }

  .bulk-bar {
    top: 58px;
    padding: 12px;
    gap: 10px;
    border-radius: 12px;
  }

  .bulk-bar-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .bulk-bar-actions > select {
    grid-column: 1 / -1;
    min-height: 40px;
  }

  .bulk-bar-actions > button {
    min-height: 40px;
  }

  .theme-toggle {
    padding: 4px 8px;
    font-size: 11px;
  }

  .search-bar .voice-btn,
  .large-search .voice-btn {
    width: 38px;
    height: 38px;
    min-height: 38px;
  }
}

@media (max-width: 390px) {
  .search-filters {
    grid-template-columns: 1fr;
  }

  .nav {
    font-size: clamp(8.5px, 2.3vw, 10.5px);
    padding: 4px 1px;
  }

  .brain-strip-actions {
    grid-template-columns: 1fr;
  }
}
