/* AMOSHA phone/tablet responsive layer.
 *
 * Loaded after the existing desktop/foundation styles. This intentionally keeps
 * desktop CSS unchanged and only corrects tablet/phone behavior.
 */

.mobile-settings-actions {
  display: none;
}

@media (min-width: 721px) and (max-width: 1050px) {
  .sidebar {
    overflow: visible;
  }

  .sidebar-footer {
    display: flex !important;
    flex-direction: column;
    justify-content: flex-end !important;
    align-items: center;
    gap: 8px !important;
    width: 100%;
    margin-top: auto !important;
    padding: 12px 0 0 !important;
  }

  .sidebar-footer > :is(#theme-toggle, #settings-button, #logout-button) {
    display: grid !important;
    width: 40px !important;
    min-width: 40px !important;
    height: 40px !important;
    flex: 0 0 40px !important;
    margin: 0 !important;
  }

  #logout-button {
    margin-left: 0 !important;
  }

  .workspace,
  .content,
  .modal,
  .modal-body,
  .form-grid,
  .form-grid > *,
  .task-recurrence-block,
  .recurrence-inject,
  .session-section {
    min-width: 0;
    max-width: 100%;
  }

  .modal-backdrop {
    padding: 24px !important;
  }

  .modal {
    width: min(720px, calc(100vw - 48px)) !important;
    max-width: calc(100vw - 48px) !important;
    overflow-x: hidden;
  }

  .modal-body {
    overflow-x: hidden;
  }

  .modal-body :is(input, textarea, select) {
    max-width: 100%;
  }
}

@media (max-width: 720px) {
  :root {
    --amosha-mobile-nav-height: 82px;
  }

  .app {
    padding-bottom: calc(var(--amosha-mobile-nav-height) + env(safe-area-inset-bottom)) !important;
  }

  .sidebar {
    height: calc(var(--amosha-mobile-nav-height) + env(safe-area-inset-bottom)) !important;
    padding:
      8px
      10px
      calc(8px + env(safe-area-inset-bottom))
      10px !important;
    border: 0 !important;
    background: transparent !important;
    backdrop-filter: none !important;
    pointer-events: none;
  }

  .navigation {
    width: min(520px, 100%);
    min-width: 0;
    margin: 0 auto;
    padding: 5px;
    gap: 2px;
    border: 1px solid color-mix(in srgb, var(--border) 82%, transparent);
    border-radius: 20px;
    background: color-mix(in srgb, var(--surface-solid) 94%, transparent);
    box-shadow:
      0 12px 32px rgb(15 23 42 / 14%),
      inset 0 1px 0 rgb(255 255 255 / 55%);
    backdrop-filter: blur(22px) saturate(145%);
    -webkit-backdrop-filter: blur(22px) saturate(145%);
    pointer-events: auto;
  }

  .nav-item {
    min-width: 0;
    min-height: 54px !important;
    padding: 6px 2px 5px !important;
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    border-radius: 15px !important;
    color: var(--muted);
    transition:
      color 150ms ease,
      background 150ms ease,
      transform 150ms ease;
  }

  .nav-item > span:last-child {
    display: block !important;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 9px;
    line-height: 1.05;
    font-weight: 650;
    letter-spacing: -.01em;
  }

  .nav-item .nav-icon {
    width: 22px;
    height: 22px;
    flex-basis: 22px;
    color: currentColor;
  }

  .nav-item .nav-icon svg {
    width: 20px;
    height: 20px;
  }

  .nav-item.active {
    background: var(--accent-soft) !important;
    color: var(--accent) !important;
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 15%, transparent);
  }

  .nav-item.active .nav-icon {
    transform: translateY(-1px) scale(1.04);
  }

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

  /* Mobile bottom bar is navigation only. Utility actions live in Profile. */
  .sidebar-footer {
    display: none !important;
  }

  .mobile-settings-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
  }

  .topbar {
    min-width: 0;
    padding:
      max(12px, env(safe-area-inset-top))
      max(14px, env(safe-area-inset-right))
      12px
      max(14px, env(safe-area-inset-left)) !important;
  }

  .topbar > div:first-child {
    min-width: 0;
  }

  .topbar h1 {
    overflow-wrap: anywhere;
  }

  .topbar-actions {
    flex: 0 0 auto;
    gap: 8px !important;
  }

  #profile-button,
  #primary-action {
    min-width: 44px;
    min-height: 44px;
  }

  input,
  textarea,
  select,
  .button {
    min-height: 44px;
  }

  input,
  textarea,
  select {
    font-size: 16px;
  }

  .modal-backdrop {
    padding-top: max(12px, env(safe-area-inset-top)) !important;
  }

  .modal {
    width: 100% !important;
    max-width: none !important;
    max-height: calc(100dvh - max(12px, env(safe-area-inset-top))) !important;
    padding-bottom: env(safe-area-inset-bottom);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .modal-actions,
  .form-actions {
    gap: 10px;
    flex-wrap: wrap;
  }

  .modal-actions > .button,
  .form-actions > .button {
    min-height: 46px;
  }

  html,
  body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  .app,
  .workspace,
  .content,
  .card,
  .dashboard-main,
  .dashboard-main > *,
  .stack {
    min-width: 0;
    max-width: 100%;
  }

  .content {
    padding: 12px 10px 24px !important;
  }

  .sidebar {
    left: 0;
    right: 0;
    overflow: hidden;
  }

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

  .status-item {
    padding: 12px 13px;
    gap: 2px 8px;
  }

  .status-item strong,
  .finance-status-item .finance-private-value {
    font-size: 18px;
  }

  .status-item small {
    font-size: 10px;
  }

  .hero-card {
    padding: 16px;
  }

  .hero-row {
    align-items: flex-start;
    gap: 12px;
  }

  .hero-card h2 {
    font-size: 22px;
  }

  .progress-ring {
    width: 64px;
  }

  .progress-ring::before {
    width: 50px;
    font-size: 12px;
  }

  .card-header {
    gap: 10px;
    padding: 12px 14px;
  }

  .card-body {
    padding: 14px;
  }

  .toolbar {
    align-items: stretch;
  }

  .toolbar .search {
    flex-basis: 100%;
    min-width: 0;
  }

  .toolbar .segmented {
    width: 100%;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .toolbar .segmented::-webkit-scrollbar {
    display: none;
  }

  .toolbar .segmented button {
    flex: 1 0 auto;
    white-space: nowrap;
  }

  /* Secondary navigation on narrow screens behaves like native mobile tabs:
     one row, swipeable, no browser scrollbar chrome. */
  .settings-menu,
  .admin-tabs {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    gap: 6px !important;
    width: 100%;
    min-width: 0;
    overflow-x: auto !important;
    overflow-y: hidden;
    padding: 0 2px 5px !important;
    scroll-snap-type: x proximity;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .settings-menu::-webkit-scrollbar,
  .admin-tabs::-webkit-scrollbar {
    display: none;
  }

  .settings-menu button,
  .admin-tabs button {
    flex: 0 0 auto !important;
    min-height: 44px;
    white-space: nowrap;
    scroll-snap-align: start;
  }

  .settings-menu button {
    padding-inline: 12px;
  }

  .admin-tabs button {
    padding-inline: 13px !important;
  }

  .table-wrap:has(.task-table) {
    overflow: visible;
  }

  .task-table {
    display: block;
    width: 100%;
    min-width: 0;
  }

  .task-table thead {
    display: none;
  }

  .task-table tbody {
    display: block;
  }

  .task-table tr {
    display: grid;
    grid-template-columns: 32px minmax(0, 1fr);
    gap: 4px 8px;
    padding: 11px 12px;
    border-bottom: 1px solid var(--border);
  }

  .task-table tr:last-child {
    border-bottom: 0;
  }

  .task-table td {
    display: block;
    min-width: 0;
    padding: 0;
    border: 0;
  }

  .task-table td:first-child {
    grid-column: 1;
    grid-row: 1 / span 2;
    align-self: start;
    padding-top: 1px;
  }

  .task-table td:nth-child(2) {
    grid-column: 2;
  }

  .task-table td:nth-child(3) {
    grid-column: 2;
    margin-top: 4px;
  }

  .task-table td:nth-child(n + 4) {
    display: none;
  }

  .task-table .task-description {
    max-width: 100%;
    display: -webkit-box;
    overflow: hidden;
    white-space: normal;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .task-table .tags,
  .modal .tags {
    min-width: 0;
    max-width: 100%;
    flex-wrap: wrap;
    gap: 4px;
  }

  .modal-backdrop {
    align-items: end !important;
    padding:
      max(12px, env(safe-area-inset-top))
      0
      0 !important;
  }

  .modal {
    width: 100% !important;
    max-width: 100% !important;
    border-right: 0;
    border-left: 0;
    border-radius: 16px 16px 0 0 !important;
    overflow-x: hidden;
  }

  .modal-header,
  .modal-body,
  .modal-footer {
    padding-left: max(14px, env(safe-area-inset-left)) !important;
    padding-right: max(14px, env(safe-area-inset-right)) !important;
  }

  .modal-body,
  .form-grid,
  .form-grid > *,
  .task-recurrence-block,
  .recurrence-inject,
  .session-section,
  .session-task-summary {
    min-width: 0;
    max-width: 100%;
  }

  .modal-footer {
    position: sticky;
    bottom: 0;
    z-index: 3;
    flex-wrap: wrap;
    background: color-mix(in srgb, var(--surface-solid) 94%, transparent);
    backdrop-filter: blur(20px);
  }

  .modal-footer > div:last-child {
    flex: 1 1 auto;
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  .session-section > header,
  .session-task-summary {
    align-items: stretch;
    flex-direction: column;
  }

  /* Apple-inspired mobile visual pass.
     Deliberately scoped to phones: desktop/tablet remain unchanged. */
  html {
    -webkit-tap-highlight-color: transparent;
  }

  body {
    background: color-mix(in srgb, var(--bg) 97%, #dce8f3);
  }

  .topbar {
    min-height: 84px !important;
    border-bottom-color: color-mix(in srgb, var(--border) 62%, transparent) !important;
    background: color-mix(in srgb, var(--bg) 82%, transparent) !important;
    box-shadow: 0 1px 0 rgb(255 255 255 / 48%);
    backdrop-filter: blur(24px) saturate(165%) !important;
    -webkit-backdrop-filter: blur(24px) saturate(165%) !important;
  }

  .topbar .eyebrow {
    margin-bottom: 3px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .01em;
  }

  .topbar h1 {
    font-size: clamp(24px, 7vw, 29px) !important;
    line-height: 1.04;
    font-weight: 720;
    letter-spacing: -.035em;
  }

  #profile-button {
    border: 1px solid color-mix(in srgb, var(--accent) 14%, var(--border));
    background: color-mix(in srgb, var(--accent-soft) 72%, var(--surface-solid));
    box-shadow:
      inset 0 1px 0 rgb(255 255 255 / 64%),
      0 2px 7px rgb(15 23 42 / 5%);
  }

  .content {
    padding-top: 14px !important;
  }

  .card {
    border-color: color-mix(in srgb, var(--border) 72%, transparent) !important;
    border-radius: 16px !important;
    background: color-mix(in srgb, var(--surface-solid) 98%, var(--bg)) !important;
    box-shadow:
      0 1px 2px rgb(15 23 42 / 4%),
      0 7px 22px rgb(15 23 42 / 3%);
  }

  .hero-card {
    border-color: color-mix(in srgb, var(--accent) 18%, transparent) !important;
    background: color-mix(in srgb, var(--accent-soft) 86%, var(--surface-solid)) !important;
    box-shadow: none !important;
  }

  :is(.button, input, textarea, select, .amosha-select-trigger) {
    border-radius: 12px !important;
  }

  .button.primary {
    box-shadow:
      0 4px 12px color-mix(in srgb, var(--accent) 18%, transparent),
      inset 0 1px 0 rgb(255 255 255 / 18%) !important;
  }

  .settings-menu button,
  .admin-tabs button,
  .segmented button {
    border-radius: 11px !important;
  }

  .settings-menu button.active,
  .admin-tabs button.active,
  .segmented button.active {
    box-shadow:
      inset 0 0 0 1px color-mix(in srgb, var(--accent) 11%, transparent),
      0 1px 3px rgb(15 23 42 / 5%);
  }

  /* Navigation is the primary glass surface on mobile. */
  .navigation {
    width: min(520px, calc(100% - 4px));
    padding: 5px !important;
    border-color: rgb(255 255 255 / 58%) !important;
    border-radius: 23px !important;
    background: color-mix(in srgb, var(--surface-solid) 78%, transparent) !important;
    box-shadow:
      0 14px 38px rgb(15 23 42 / 17%),
      0 2px 8px rgb(15 23 42 / 7%),
      inset 0 1px 0 rgb(255 255 255 / 76%);
    backdrop-filter: blur(28px) saturate(180%) !important;
    -webkit-backdrop-filter: blur(28px) saturate(180%) !important;
  }

  .nav-item {
    border-radius: 18px !important;
  }

  .nav-item.active {
    background: color-mix(in srgb, var(--accent-soft) 84%, transparent) !important;
    box-shadow:
      inset 0 0 0 1px color-mix(in srgb, var(--accent) 11%, transparent),
      0 2px 6px rgb(15 23 42 / 5%) !important;
  }

  .nav-item > span:last-child {
    font-weight: 620;
  }

  .nav-item.active > span:last-child {
    font-weight: 720;
  }

  /* Mobile dialogs read as bottom sheets rather than desktop modals. */
  .modal {
    border-top-left-radius: 24px !important;
    border-top-right-radius: 24px !important;
    border-top-color: rgb(255 255 255 / 66%) !important;
    box-shadow: 0 -18px 48px rgb(15 23 42 / 20%) !important;
  }

  .modal-header {
    position: sticky;
    padding-top: 25px !important;
  }

  .modal-header::before {
    content: "";
    position: absolute;
    top: 8px;
    left: 50%;
    width: 36px;
    height: 5px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--muted) 42%, transparent);
    transform: translateX(-50%);
  }

  .modal-close {
    width: 32px;
    height: 32px;
    background: color-mix(in srgb, var(--surface-2) 82%, transparent);
  }

  .modal-footer {
    border-top-color: color-mix(in srgb, var(--border) 58%, transparent);
    background: color-mix(in srgb, var(--surface-solid) 84%, transparent) !important;
    backdrop-filter: blur(24px) saturate(155%) !important;
    -webkit-backdrop-filter: blur(24px) saturate(155%) !important;
  }

  .mobile-settings-actions {
    border-top-color: color-mix(in srgb, var(--border) 64%, transparent);
  }

  @media (orientation: portrait) {
    /* Finance uses a dedicated mobile topbar action so legacy finance
       renderers cannot hide the visible create control. */
    html[data-app-route="finance"] #primary-action {
    display: none !important;
  }

  #finance-mobile-create {
    min-height: 44px;
    padding-inline: 13px;
    white-space: nowrap;
    border-radius: 12px !important;
  }

  #finance-mobile-create .button-leading-icon {
    margin: 0;
  }

  html[data-app-route="finance"] .finance-v4-head {
    grid-template-columns: minmax(0, 1fr) auto !important;
    gap: 8px 10px !important;
    align-items: center;
  }

  html[data-app-route="finance"] .finance-v4-month {
    min-width: 0;
    gap: 6px;
  }

  html[data-app-route="finance"] .finance-v4-month strong {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
  }

  html[data-app-route="finance"] .finance-v4-head-actions {
    display: flex !important;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
  }

  html[data-app-route="finance"] .finance-v4-head-actions [data-quick-transaction] {
    display: none !important;
  }

  html[data-app-route="finance"] .finance-v4-head-actions [data-v4-more],
  html[data-app-route="finance"] .finance-v4-head-actions [data-analytics-more] {
    width: 44px;
    min-width: 44px;
    height: 44px;
  }

  html[data-app-route="finance"] .finance-v4-head .finance-view-switch {
    display: flex !important;
    grid-column: 1 / -1 !important;
    grid-row: 2 !important;
    width: 100% !important;
    min-width: 0;
    justify-self: stretch !important;
    margin: 0 !important;
  }

    html[data-app-route="finance"] .finance-v4-head .finance-view-switch button {
      flex: 1 1 0 !important;
      min-width: 0;
      min-height: 42px;
    }
  }
}

@media (max-width: 380px) {
  .sidebar {
    padding-inline: 7px !important;
  }

  .navigation {
    padding: 4px;
    border-radius: 18px;
  }

  .nav-item {
    min-height: 52px !important;
    padding-inline: 1px !important;
  }

  .nav-item > span:last-child {
    font-size: 8.5px;
  }
}
