/* Shared mobile surface. Desktop component rules remain in their original files. */
.mobile-exclusive,
.mobile-brand,
.mobile-bottom-nav {
  display: none;
}
#sidebar-toggle {
  display: none;
}
.toolbar > form {
  flex-wrap: wrap;
}

@media (min-width: 768px) {
  .category-legend li:nth-child(n + 6) {
    display: none;
  }
}

@media (min-width: 768px) and (max-width: 1023px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.is-open {
    transform: translateX(0);
  }
  .sidebar-overlay.is-open {
    display: block;
    position: fixed;
    inset: 0;
    background: #0009;
    z-index: 45;
    border: 0;
    backdrop-filter: blur(3px);
  }
  .app-main {
    margin-left: 0;
  }
  #sidebar-toggle {
    display: inline-grid;
  }
  .content {
    padding: 24px;
  }
  .toolbar > form {
    flex-wrap: wrap;
  }
  .donut-layout {
    flex-wrap: wrap;
    justify-content: center;
  }
  .category-legend {
    min-width: 120px;
  }
  .page-header {
    flex-wrap: wrap;
  }
  .header-actions {
    flex-wrap: wrap;
  }
}

@media (max-width: 767px) {
  :root:not([data-theme="light"]) {
    --bg: #07121f;
    --surface: #101f31;
    --surface-raised: #13263a;
    --surface-hover: #1b3148;
    --text: #f5f7fa;
    --muted: #a3b1c2;
    --subtle: #94a5ba;
    --primary: #168bff;
    --primary-hover: #2d9cff;
    --success: #20c878;
    --danger: #ff5c65;
    --border: rgba(255, 255, 255, 0.07);
  }
  :root {
    --bottom-nav-height: 68px;
    --navbar-height: 72px;
  }
  html {
    scroll-padding-bottom: calc(
      var(--bottom-nav-height) + env(safe-area-inset-bottom) + 16px
    );
  }
  body {
    overflow-wrap: anywhere;
  }
  .app-main {
    margin-left: 0;
    min-height: 100dvh;
  }
  .content {
    padding: 16px max(16px, env(safe-area-inset-right))
      calc(var(--bottom-nav-height) + env(safe-area-inset-bottom) + 28px)
      max(16px, env(safe-area-inset-left));
    animation: none;
  }
  .sidebar,
  #sidebar-toggle,
  .sidebar-overlay,
  .sidebar-overlay.is-open {
    display: none;
  }
  .mobile-exclusive {
    display: block;
  }
  .desktop-label {
    display: none;
  }
  .navbar {
    height: auto;
    min-height: calc(72px + env(safe-area-inset-top));
    padding: calc(10px + env(safe-area-inset-top))
      max(16px, env(safe-area-inset-right)) 10px
      max(16px, env(safe-area-inset-left));
    gap: 12px;
    background: var(--bg);
    border: 0;
    backdrop-filter: none;
  }
  .navbar .breadcrumbs,
  .navbar .search-trigger,
  .navbar #privacy-toggle,
  .navbar .divider {
    display: none;
  }
  .navbar .mobile-brand {
    display: flex;
    padding: 0;
    font-size: 25px;
  }
  .navbar .brand-mark {
    width: 30px;
    height: 32px;
  }
  .nav-actions {
    gap: 8px;
  }
  .navbar .avatar {
    width: 44px;
    height: 44px;
    font-size: 12px;
    border: 1px solid var(--border);
  }
  .notification-panel {
    position: fixed;
    top: calc(70px + env(safe-area-inset-top));
    left: max(12px, env(safe-area-inset-left));
    right: max(12px, env(safe-area-inset-right));
    width: auto;
    max-height: calc(
      100dvh - 180px - env(safe-area-inset-top) - env(safe-area-inset-bottom)
    );
    overflow-y: auto;
    padding: 16px;
    border-radius: 18px;
  }
  .notification-panel .card-heading {
    flex-wrap: wrap;
  }
  .mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 80;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    min-height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom));
    padding: 6px max(6px, env(safe-area-inset-right))
      env(safe-area-inset-bottom) max(6px, env(safe-area-inset-left));
    background: var(--surface);
    border-top: 1px solid var(--border);
    box-shadow: 0 -8px 24px #00000014;
  }
  .mobile-bottom-nav > a,
  .mobile-bottom-nav > button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    min-width: 0;
    min-height: 56px;
    padding: 5px 0;
    background: transparent;
    border: 0;
    border-radius: 12px;
    font-size: 10px;
    font-weight: 500;
    color: var(--muted);
    transition:
      color 150ms ease,
      background 150ms ease;
  }
  .mobile-bottom-nav i {
    font-size: 18px;
  }
  .mobile-bottom-nav > [aria-current],
  .mobile-bottom-nav > .active,
  .mobile-bottom-nav > [aria-expanded="true"] {
    color: #51aaff;
    background: var(--primary-soft);
  }
  .mobile-bottom-nav > [aria-current] span,
  .mobile-bottom-nav > .active span {
    font-weight: 700;
  }
  .mobile-menu-links {
    display: grid;
    gap: 4px;
  }
  .mobile-menu-links .nav-link {
    width: 100%;
    background: none;
    text-align: left;
    min-height: 48px;
    font-size: 14px;
  }
  .mobile-menu-links .nav-link[aria-current] {
    color: #51aaff;
    background: var(--primary-soft);
  }
  .mobile-menu-links .fa-chevron-right {
    margin-left: auto;
    font-size: 10px;
  }
  .mobile-menu-logout {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
  }

  /* Shared cards, forms and controls across every authenticated route. */
  .grid,
  .stack {
    gap: 14px;
  }
  .grid-two,
  .grid-three,
  .profile-grid,
  .dashboard-aside,
  .bank-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .grid > *,
  .stack > *,
  .inline > *,
  .split > *,
  .card-heading > *,
  .field,
  .form-grid > *,
  .profile-grid > * {
    min-width: 0;
  }
  .page-header {
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    align-items: flex-start;
  }
  .page-header > div:first-child {
    min-width: 0;
  }
  .page-header h1 {
    font-size: 26px;
    letter-spacing: -0.8px;
  }
  .page-subtitle {
    font-size: 13px;
    line-height: 1.65;
  }
  .eyebrow {
    font-size: 10px;
    letter-spacing: 1.1px;
  }
  .header-actions {
    width: 100%;
    flex-wrap: wrap;
    gap: 8px;
  }
  .header-actions .button {
    flex: 1 1 auto;
    font-size: 12px;
    padding: 10px 12px;
  }
  .card {
    padding: 16px;
    border-radius: 18px;
    box-shadow: 0 4px 16px #0000000a;
  }
  .card-heading {
    gap: 10px;
    margin-bottom: 16px;
  }
  .card-heading h2 {
    font-size: 15px;
  }
  .metric-card {
    padding: 16px;
  }
  .metric-top {
    font-size: 13px;
    margin-bottom: 12px;
    gap: 6px;
  }
  .metric-icon {
    flex-shrink: 0;
    width: 30px;
    height: 30px;
  }
  .metric-value {
    font-size: 26px;
    white-space: normal;
    overflow-wrap: anywhere;
    letter-spacing: -0.8px;
  }
  .metric-value .currency {
    font-size: 16px;
  }
  .metric-footer {
    font-size: 11px;
    flex-wrap: wrap;
  }
  .metric-card.featured {
    background: var(--surface-raised);
  }
  .button,
  .button-sm,
  .text-link,
  .tab,
  .search-result,
  summary {
    min-height: 44px;
  }
  .button {
    white-space: normal;
    text-align: center;
    border-radius: 12px;
  }
  .button-primary {
    background: #086bcb;
    border-color: #086bcb;
  }
  .icon-button,
  .table .icon-button,
  .vehicle-cost-row .icon-button,
  .toast .icon-button {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
  }
  .text-link {
    font-size: 12px;
  }
  .dropdown-menu a,
  .dropdown-menu button,
  .auth-form > p a {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }
  .badge {
    white-space: normal;
  }
  .input,
  .select,
  .textarea {
    min-height: 48px;
    min-width: 0;
    max-width: 100%;
    font-size: 16px;
    border-radius: 12px;
  }
  .field label,
  .field-label {
    font-size: 13px;
  }
  .select {
    appearance: none;
    padding-right: 38px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='m1 1 5 5 5-5' fill='none' stroke='%2394a3b8' stroke-width='1.5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    background-size: 12px 8px;
  }
  .help-text {
    font-size: 12px;
  }
  .form-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .span-two {
    grid-column: auto;
  }
  .form-actions {
    flex-wrap: wrap;
    gap: 10px;
  }
  .form-actions .button {
    flex: 1 1 120px;
  }
  .form-actions > span {
    flex-basis: 100%;
  }
  .toolbar > form {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    width: 100%;
    min-width: 0;
  }
  .toolbar .search-field {
    flex-basis: 100%;
    width: 100%;
    min-width: 0;
  }
  .toolbar .filter-select {
    flex: 1 1 130px;
    width: 0;
  }
  .toolbar .button {
    flex: 1 1 100px;
  }
  .search-field i {
    top: 17px;
  }
  .toggle {
    min-width: 44px;
    min-height: 44px;
    justify-content: center;
    flex-shrink: 0;
  }
  .checkbox-label,
  .radio-label,
  .review-checkbox {
    min-height: 44px;
  }
  input[type="checkbox"],
  input[type="radio"] {
    flex-shrink: 0;
  }
  .profile-grid .split {
    flex-wrap: wrap;
  }
  .profile-grid .split > div {
    flex: 1 1 180px;
  }
  .profile-summary {
    display: flex;
    flex-wrap: wrap;
    text-align: left;
    gap: 16px;
    align-items: center;
  }
  .profile-summary .avatar {
    margin: 0;
  }
  .profile-summary .profile-meta {
    flex-basis: 100%;
    margin: 0;
  }
  .profile-summary hr {
    display: none;
  }
  .item-amount,
  .bank-card strong {
    overflow-wrap: anywhere;
  }
  .portfolio-card {
    scroll-margin: 16px;
  }
  .portfolio-card .item-title {
    font-size: 19px;
  }
  .portfolio-card .item-foot > .split {
    flex-wrap: wrap;
  }
  .vehicle-cost-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, auto) 44px;
  }
  .vehicle-costs > .split {
    flex-wrap: wrap;
  }
  .bank-card {
    min-height: auto;
    padding: 18px;
  }
  .bank-card-number {
    overflow-wrap: normal;
  }
  .bank-actions .button {
    flex: 1 1 120px;
  }
  .bank-grid .inline {
    flex-wrap: wrap;
  }
  .review-tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
  .review-tabs .button {
    padding: 10px;
    font-size: 12px;
  }
  .review-filters {
    gap: 10px;
  }
  .review-filters .field {
    margin-bottom: 0;
    flex-basis: 130px;
  }
  .review-filters .field:first-of-type {
    flex-basis: 100%;
  }
  .review-filters > .button {
    width: 100%;
  }
  .review-pair {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }
  .review-pair > div {
    padding: 14px;
    border-radius: 14px;
  }
  .review-rule-option summary {
    padding: 8px 0;
  }
  .review-pagination {
    gap: 8px;
  }
  .review-pagination > span {
    flex-basis: 100%;
    text-align: center;
    order: -1;
  }

  /* Native dialogs retain focus management, Escape and backdrop behavior. */
  .modal,
  .modal.drawer {
    position: fixed;
    inset: auto 0 0;
    margin: 0 auto;
    width: 100%;
    max-width: 600px;
    height: auto;
    max-height: calc(100dvh - env(safe-area-inset-top) - 12px);
    padding: 20px max(16px, env(safe-area-inset-right))
      calc(20px + env(safe-area-inset-bottom))
      max(16px, env(safe-area-inset-left));
    border-radius: 22px 22px 0 0;
    overscroll-behavior: contain;
    scroll-padding-block: 20px;
  }
  .modal-header {
    gap: 10px;
    margin-bottom: 20px;
  }
  .modal-header h2 {
    font-size: 20px;
  }
  .modal-header .icon-button {
    margin: -4px -4px 0 0;
  }
  .modal .form-actions {
    padding-bottom: 4px;
  }
  .search-modal {
    padding-inline: 8px;
  }
  .search-modal-header {
    padding: 0 8px 12px;
    gap: 8px;
  }
  .search-results {
    max-height: min(55dvh, 440px);
  }
  .toast-container {
    left: 12px;
    right: 12px;
    bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom) + 12px);
    max-width: none;
  }
  .toast {
    min-width: 0;
    padding: 10px 12px;
  }
  .toast > span {
    min-width: 0;
  }
  .toast .icon-button {
    margin-left: auto;
  }

  /* One set of transaction records, presented as cards instead of tiny columns. */
  .table-card {
    padding: 0;
  }
  .table-card .card-heading {
    padding: 16px 16px 0;
    flex-wrap: wrap;
  }
  .table-scroll {
    max-width: 100%;
    overscroll-behavior-x: contain;
  }
  .transaction-table {
    display: block;
    white-space: normal;
  }
  .transaction-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }
  .transaction-table tbody {
    display: grid;
    gap: 12px;
    padding: 0 12px 12px;
  }
  .transaction-table tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 10px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface-raised);
    padding: 14px;
  }
  .transaction-table td {
    display: block;
    min-width: 0;
    border: 0;
    padding: 0;
    font-size: 12px;
  }
  .transaction-table .tx-description,
  .transaction-table .tx-actions,
  .transaction-table .tx-empty {
    grid-column: 1 / -1;
  }
  .transaction-table .tx-description {
    margin-bottom: 2px;
  }
  .transaction-table .tx-amount {
    grid-column: 1 / -1;
    grid-row: 2;
    text-align: left;
    font-size: 20px;
  }
  .transaction-table .tx-date {
    text-align: right;
  }
  .transaction-table .tx-status {
    grid-column: 1 / -1;
  }
  .transaction-table .transaction-name {
    align-items: flex-start;
    font-size: 14px;
  }
  .transaction-table .transaction-name > div {
    min-width: 0;
  }
  .transaction-table .transaction-name p {
    font-size: 12px;
  }
  .transaction-symbol {
    flex-shrink: 0;
  }
  .transaction-table .tx-actions {
    padding-top: 8px;
    border-top: 1px solid var(--border);
  }
  .transaction-table .row-actions {
    justify-content: flex-end;
    gap: 10px;
  }
  .transaction-table .tx-actions > a {
    min-height: 44px;
    padding: 10px;
  }
  .table-footer {
    flex-wrap: wrap;
    gap: 12px;
    padding: 16px;
    font-size: 12px;
  }
  .table-footer .pagination {
    margin-left: auto;
  }
  .empty-state {
    padding: 28px 16px;
  }
  .design-section .dropdown-menu {
    left: 0;
    right: auto;
    max-width: calc(100vw - 64px);
  }

  /* Flatten only dashboard layout wrappers; preserve the existing desktop grid. */
  .dashboard-page {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
  }
  .dashboard-page > .page-header {
    grid-column: 1 / -1;
    order: 0;
    margin-bottom: 2px;
  }
  .dashboard-page > .page-header .eyebrow,
  .dashboard-page > .page-header .status-dot {
    display: none;
  }
  .dashboard-page > .page-header h1 {
    font-size: 25px;
  }
  .dashboard-page .metrics-grid,
  .dashboard-main,
  .dashboard-primary,
  .dashboard-secondary,
  .dashboard-aside {
    display: contents;
  }
  .dashboard-page .mobile-balance {
    grid-column: 1 / -1;
    order: 1;
    background: linear-gradient(125deg, var(--surface-raised), var(--surface));
    padding: 16px 20px 20px;
    border-color: #168bff26;
  }
  .mobile-balance h2 {
    color: var(--muted);
    font-size: 14px;
    font-weight: 500;
  }
  .balance-value {
    font-size: clamp(28px, 7.2vw, 32px);
    font-weight: 600;
    letter-spacing: -1px;
    line-height: 1.35;
    margin: 8px 0;
    font-variant-numeric: tabular-nums;
  }
  .balance-value > span {
    color: var(--muted);
    font-size: 22px;
    font-weight: 400;
  }
  .balance-period {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 12px;
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
    color: var(--muted);
  }
  .balance-period strong {
    color: var(--text);
  }
  .dashboard-income {
    order: 2;
  }
  .dashboard-expense {
    order: 3;
  }
  .dashboard-income .metric-value,
  .dashboard-expense .metric-value {
    font-size: clamp(18px, 4.5vw, 23px);
    letter-spacing: -0.6px;
  }
  .dashboard-income .metric-value .currency,
  .dashboard-expense .metric-value .currency {
    font-size: 13px;
  }
  .dashboard-income .metric-footer,
  .dashboard-expense .metric-footer {
    font-size: 10px;
  }
  .dashboard-month-balance {
    display: none;
  }
  .dashboard-page [data-widget],
  .monthly-card,
  .dashboard-wealth,
  .dashboard-tools {
    grid-column: 1 / -1;
  }
  .dashboard-page [data-widget="categories"] {
    order: 4;
  }
  .monthly-card {
    order: 5;
  }
  .dashboard-page [data-widget="goals"] {
    order: 6;
  }
  .dashboard-page [data-widget="score"] {
    order: 7;
  }
  .dashboard-wealth {
    order: 8;
  }
  .dashboard-tools {
    order: 9;
    margin: 0 !important;
    flex-wrap: wrap;
  }
  .dashboard-page [data-widget="cashflow"] {
    order: 10;
    scroll-margin-top: 16px;
  }
  .dashboard-page [data-widget="recent"] {
    order: 11;
  }
  .dashboard-page [data-widget="alerts"] {
    order: 12;
  }
  .dashboard-page [data-widget="rankings"] {
    order: 13;
  }
  .dashboard-page [data-widget="heatmap"] {
    order: 14;
  }
  .dashboard-page [data-widget="timeline"] {
    order: 15;
  }
  .dashboard-page .score-card {
    grid-row: auto;
    padding: 20px;
  }
  .score-reading {
    font-size: 44px;
  }
  .score-card .score-description {
    font-size: 13px;
  }
  .score-insight {
    font-size: 12px;
  }
  .goal h3 a {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 44px;
    font-size: 14px;
  }
  .goal h3 i {
    color: var(--muted);
    font-size: 10px;
    margin-left: auto;
  }
  .goal .inline > div {
    flex: 1;
  }
  .goal .split {
    font-size: 12px;
    flex-wrap: wrap;
  }
  .goal .progress {
    height: 6px;
  }

  /* Charts always measure a dedicated, shrinkable container. */
  .chart-container {
    width: 100%;
    min-width: 0;
    height: 210px;
  }
  .chart-card > .split {
    flex-wrap: wrap;
  }
  .chart-card .card-heading {
    flex-wrap: wrap;
  }
  .cash-summary {
    width: 100%;
    gap: 16px;
    margin-bottom: 0;
  }
  .cash-summary > div {
    flex: 1;
    min-width: 0;
  }
  .cash-summary strong {
    font-size: 19px;
  }
  .chart-legend {
    flex-wrap: wrap;
    padding: 10px 0;
    font-size: 12px;
  }
  .chart-footer {
    flex-wrap: wrap;
    gap: 8px;
    font-size: 11px;
  }
  .donut-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    justify-items: center;
    gap: 20px;
  }
  .donut-container {
    width: 172px;
    height: 172px;
  }
  .category-legend {
    width: 100%;
    gap: 12px;
  }
  .category-legend li {
    font-size: 12px;
  }
  .category-legend .category-label {
    white-space: normal;
  }
  .category-legend .mono {
    flex-shrink: 0;
  }
  .category-details {
    display: inline-flex;
    width: auto;
    min-width: 44px;
    gap: 6px;
    color: #84bfff;
    font-size: 11px;
  }
  .category-details i {
    font-size: 10px;
  }
  .monthly-switch {
    width: fit-content;
    margin-bottom: 14px;
  }
  .monthly-switch .tab {
    padding: 8px 18px;
  }
  .monthly-switch .tab[aria-pressed="true"] {
    background: var(--surface-hover);
    color: var(--text);
  }
  .monthly-details summary {
    cursor: pointer;
    color: #84bfff;
    font-size: 12px;
    padding: 12px 0;
  }
  .monthly-details dl {
    margin: 0;
    font-size: 12px;
  }
  .monthly-details dl > div {
    padding: 12px 0;
    border-top: 1px solid var(--border);
  }
  .monthly-details dt {
    margin-bottom: 8px;
  }
  .monthly-details dd {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 6px 12px;
    margin: 0;
    color: var(--muted);
  }
  .monthly-details strong {
    text-align: right;
    color: var(--text);
  }
  .rank-content,
  .timeline-content {
    min-width: 0;
  }
  .rank-content .split {
    flex-wrap: wrap;
  }
  .heatmap {
    min-width: 0;
    gap: 4px;
  }
  .footer {
    flex-wrap: wrap;
    gap: 8px;
    font-size: 11px;
    padding-top: 24px;
  }
  .footer > span:last-child {
    max-width: none;
    text-align: left;
  }
  .demo-banner {
    font-size: 11px;
    padding: 10px 16px;
    align-items: flex-start;
  }
  .auth-form-wrap {
    min-height: 100dvh;
    padding: calc(24px + env(safe-area-inset-top)) 20px
      calc(24px + env(safe-area-inset-bottom));
  }
  .auth-form {
    min-width: 0;
  }
  .landing-shell {
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
  .landing-nav {
    padding-top: env(safe-area-inset-top);
  }
  .landing-hero h1 {
    font-size: clamp(34px, 9vw, 48px);
  }
  .landing-footer {
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
  }
}

@media (min-width: 481px) and (max-width: 767px) {
  .donut-layout {
    grid-template-columns: 172px minmax(0, 1fr);
    gap: 24px;
  }
  .dashboard-page {
    gap: 16px;
  }
  .mobile-bottom-nav > a,
  .mobile-bottom-nav > button {
    font-size: 11px;
  }
}

@media (max-width: 360px) {
  .dashboard-income,
  .dashboard-expense {
    padding: 12px;
  }
  .dashboard-income .metric-icon,
  .dashboard-expense .metric-icon {
    width: 24px;
    height: 24px;
    font-size: 10px;
  }
  .dashboard-income .metric-top,
  .dashboard-expense .metric-top {
    font-size: 12px;
  }
  .category-details .mobile-exclusive {
    max-width: 48px;
  }
}
