/* Small-screen layout overrides; desktop styles remain in styles.css. */
.chart-small { display: none; }

@media (max-width: 960px) {
  :root { font-size: 14px; }
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  body { font-size: 14px; line-height: 1.5; }
  button, a, input, select, textarea { touch-action: manipulation; }
  input:not([type="checkbox"]), select, textarea { font-size: 16px; }
  input:not([type="checkbox"]), select { min-height: 44px; }
  input[type="checkbox"] { width: 20px; height: 20px; flex-shrink: 0; }
  button, input, select, textarea { max-width: 100%; }
  select { text-overflow: ellipsis; }
  .app-shell, .main-shell, #main, .panel, .panel-title > div,
  .toolbar, .product-filters, .modal, .modal form, .drawer,
  .detail-info, .account-home, .login-layout, .login-card,
  .login-card-inner { min-width: 0; }
  .app-shell { padding-bottom: calc(82px + env(safe-area-inset-bottom)); }
  .app-shell main { padding: 14px max(12px, env(safe-area-inset-right)) 20px max(12px, env(safe-area-inset-left)); }
  .sidebar { padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left)); min-height: 64px; }
  .sidebar .brand { font-size: 18px; }
  .app-shell .topbar:has(.connection.offline) { min-height: 44px; }
  .app-shell .connection.offline { font-size: 13px; }
  .mobile-nav { padding: 7px 10px calc(8px + env(safe-area-inset-bottom)); }
  .mobile-nav button { min-height: 54px; font-size: 12px; }
  body.mobile-keyboard-open .mobile-nav { display: none; }
  .page-heading { flex-direction: row; align-items: center; gap: 10px; margin-bottom: 16px; }
  .page-heading > div { min-width: 0; }
  .page-heading h1 { margin: 0; font-size: 22px; line-height: 1.4; }
  .heading-actions { margin: 0; align-self: auto; flex-shrink: 0; }
  .panel { border-radius: 14px; }
  .panel-title { padding: 14px 16px; gap: 10px; }
  .panel-title h2 { font-size: 16px; line-height: 1.5; gap: 7px; flex-wrap: wrap; }
  .panel-count { font-size: 12px; }
  .panel-subtitle { font-size: 12px; line-height: 1.6; }
  .btn, .btn-small, .toolbar > .btn,
  .toolbar > .mobile-filter-toggle, .selection-bar .btn {
    min-height: 44px; font-size: 14px; padding: 10px 12px; gap: 6px; border-radius: 9px;
  }
  .btn .icon, .btn-small .icon { width: 17px; height: 17px; }
  .btn-icon { width: 44px; height: 44px; padding: 10px; }
  .text-btn { display: inline-flex; align-items: center; min-height: 44px; font-size: 14px; }
  .badge { font-size: 12px; padding: 5px 8px; line-height: 1.3; }
  .note-text { font-size: 12px; line-height: 1.6; }
  .empty { padding: 28px 16px; }
  .empty h3 { font-size: 17px; }
  .empty p, .empty-inline { font-size: 14px; line-height: 1.7; }
  .empty p { margin-bottom: 16px; }
  .empty .btn { margin: 4px; }
  .task-banner, .notice { font-size: 13px; line-height: 1.65; padding: 12px; gap: 8px; }
  .task-banner > div, .notice > div { min-width: 0; overflow-wrap: anywhere; }
  .task-banner > .icon, .notice > .icon { width: 18px; height: 18px; }
  .collection-progress { flex-wrap: wrap; }
  .collection-progress > div { flex: 1 1 180px; }
  .collection-progress small { font-size: 12px; line-height: 1.6; }
  .collection-progress > .text-btn { margin-left: 26px; }

  /* Products: search and filters above compact, readable cards. */
  .product-panel-title { align-items: flex-start; flex-wrap: wrap; }
  .product-panel-title h2 { font-size: 17px; }
  .product-panel-actions { width: auto; margin: 0; }
  .product-panel-actions > .badge { margin: 0; font-size: 12px; }
  .product-panel-actions > .btn { display: none; }
  .toolbar { padding: 12px; gap: 8px; }
  .toolbar .search-box { min-width: 0; flex: 1 0 100%; }
  .toolbar .search-box input { height: 46px; padding: 10px 12px 10px 37px; font-size: 16px; }
  .toolbar .search-box .icon { top: 14px; left: 12px; width: 18px; height: 18px; }
  .toolbar > .btn { flex: 1 1 120px; }
  .toolbar > .mobile-filter-toggle { flex: 1 1 120px; }
  .toolbar .product-filters.expanded { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; padding-top: 0; }
  .toolbar .product-filters select { font-size: 16px; width: 100%; min-width: 0; max-width: 100%; height: 46px; padding: 10px 24px 10px 10px; }
  .toolbar .product-filters #mobile-sort { grid-column: 1 / -1; }
  .selection-bar { padding: 12px; gap: 8px; }
  .selection-bar .selection-count { font-size: 14px; }
  .selection-bar .btn { flex: 1 1 100px; }
  .mobile-product-list { padding: 10px; }
  .mobile-select-scope { min-height: 44px; padding: 0 2px 8px; font-size: 13px; line-height: 1.5; }
  .mobile-select-scope input, .mobile-product-head > input { width: 20px; height: 20px; }
  .mobile-product-card { padding: 14px; margin-bottom: 10px; border-radius: 12px; }
  .mobile-product-head { gap: 10px; }
  .mobile-product-head > .product-thumb { width: 62px; height: 62px; }
  .mobile-product-copy .product-name { font-size: 15px; line-height: 1.5; min-height: 44px; overflow-wrap: anywhere; }
  .mobile-product-copy > span { font-size: 12px; margin-top: 4px; }
  .mobile-product-copy > .price { font-size: 14px; margin-top: 4px; }
  .mobile-product-metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); padding: 12px 4px; gap: 0; margin-top: 12px; }
  .mobile-product-metrics > div { padding: 0 4px; min-width: 0; }
  .mobile-product-metrics span:not(.metric) { font-size: 12px; margin-bottom: 6px; }
  .mobile-product-metrics strong { font-size: 21px; line-height: 1.3; min-height: 27px; overflow-wrap: anywhere; }
  .mobile-product-metrics .metric, .mobile-product-metrics .metric.partial { font-size: 21px; }
  .mobile-product-metrics .metric.missing { font-size: 20px; }
  .mobile-product-status { margin-top: 12px; gap: 8px; flex-wrap: wrap; }
  .mobile-product-status > .freshness { font-size: 12px; }
  .mobile-product-status > span:last-child { font-size: 12px; max-width: 100%; overflow-wrap: anywhere; }
  .mobile-product-footer { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 7px; padding-top: 10px; margin-top: 10px; }
  .mobile-product-footer > span { min-width: 0; font-size: 12px; line-height: 1.6; overflow-wrap: anywhere; }
  .mobile-product-footer > span strong { font-size: 12px; }
  .mobile-product-footer .btn { font-size: 14px; min-height: 44px; padding: 10px; }
  .mobile-product-footer .btn .icon { width: 15px; }
  .pagination { padding: 12px; gap: 12px; font-size: 13px; }
  .pagination > span { width: 100%; }
  .pagination-controls { width: 100%; margin: 0; display: flex; justify-content: space-between; gap: 6px; flex-wrap: wrap; }
  .pagination .page-size { font-size: 16px; min-height: 44px; width: auto; min-width: 90px; max-width: 120px; }
  .pagination .page-number { min-width: 42px; padding: 0 2px; font-size: 13px; }
  .pagination .btn { font-size: 14px; min-height: 44px; padding: 10px; }
  .pagination .btn .icon { width: 15px; }

  /* Product settings keep the same phone-sized fields as other dialogs. */
  .product-settings-summary { gap: 12px; padding-bottom: 16px; margin-bottom: 18px; }
  .product-settings-summary strong { font-size: 15px; line-height: 1.5; }
  .product-settings-summary > div > span { font-size: 13px; }
  .product-settings-body .form-field { margin-bottom: 18px; }
  .product-settings-body .form-field > .settings-select,
  .product-settings-body .settings-select select,
  .product-settings-body .new-category-field input { font-size: 16px; }

  .product-monitor-toggle { min-height: 48px; font-size: 14px; }
  .product-monitor-toggle input { width: 20px; height: 20px; }
  .mobile-product-copy > span { overflow-wrap: anywhere; }

  /* Logs and history become rows of cards instead of sideways tables. */
  .logs-panel-title { gap: 12px; }
  .logs-panel-title .panel-subtitle { display: none; }
  .logs-controls { width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
  .logs-page-size { font-size: 13px; gap: 7px; min-width: 0; }
  .logs-controls select { font-size: 16px; min-height: 44px; width: 100%; max-width: 100%; }
  .logs-page-size select { flex: 1; min-width: 0; }
  .table-scroll:has(.responsive-records) { overflow: visible; }
  .responsive-records, .responsive-records tbody { display: block; min-width: 0; width: 100%; white-space: normal; }
  .responsive-records thead { display: none; }
  .responsive-records tr { display: grid; gap: 8px 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
  .responsive-records tr:last-child { border-bottom: 0; }
  .responsive-records td, .responsive-records td:first-child, .responsive-records td:nth-child(2) {
    display: block; width: auto; height: auto; min-width: 0; padding: 0; border: 0; font-size: 14px; white-space: normal; line-height: 1.65; overflow-wrap: anywhere;
  }
  .logs-table tr { grid-template-columns: minmax(0, 1fr) auto; }
  .logs-table td:first-child { color: #8595ab; font-size: 12px; align-self: center; }
  .logs-table td:nth-child(2) { text-align: right; }
  .logs-table .record-message, .logs-table td:last-child { grid-column: 1 / -1; color: #526780; font-size: 14px; }
  .logs-table .record-message .text-btn { padding-right: 8px; font-size: 14px; }
  .logs-pagination .pagination-controls { justify-content: center; gap: 16px; }
  .history-table tr { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 16px; }
  .history-table td:first-child { grid-column: 1 / -1; padding-bottom: 9px; border-bottom: 1px solid #f0f3f8; color: #687e9c; font-size: 13px; }
  .history-table td:not(:first-child)::before { content: attr(data-label); display: block; font-size: 12px; color: #96a3b5; margin-bottom: 3px; }
  .history-table .badge { white-space: normal; line-height: 1.4; }

  /* Settings: full-width values where dates need room, generous controls. */
  .settings-layout { gap: 14px; }
  .settings-body { padding: 0 16px 16px; }
  .setting-row { padding: 18px 0; gap: 12px; flex-wrap: wrap; }
  .setting-row > div:first-child { min-width: 0; flex: 1 1 110px; }
  .setting-row h3 { font-size: 15px; line-height: 1.5; margin: 0; }
  .setting-row p { font-size: 13px; line-height: 1.6; margin-top: 6px; }
  .setting-row:nth-child(2) p, .setting-row:nth-child(3) p, .setting-row:nth-child(4) p { display: none; }
  .setting-row select { min-height: 46px; font-size: 16px; width: 130px; max-width: 100%; }
  .setting-row:has(.setting-value) { display: block; }
  .setting-value { font-size: 14px; line-height: 1.8; text-align: left; margin-top: 8px; overflow-wrap: anywhere; }
  .setting-value .note-text { font-size: 12px; }
  .settings-body > .notice { margin-top: 4px; font-size: 12px; }
  .switch { width: 50px; height: 44px; }
  .switch input { width: 100%; height: 100%; min-height: 44px; }
  .switch-track { top: 9px; bottom: 9px; border-radius: 16px; }
  .switch-track::before { width: 20px; height: 20px; top: 3px; left: 3px; }
  .switch input:checked + .switch-track::before { transform: translateX(24px); }

  /* Dialogs follow the visible viewport when the phone keyboard opens. */
  .modal-overlay, .account-overlay, .drawer-overlay {
    top: var(--visual-top, 0px); bottom: auto; height: var(--visual-height, 100dvh);
    padding: 0; align-items: flex-end; justify-content: center;
  }
  .modal, .account-overlay .account-dialog {
    width: 100%; max-width: 100%; max-height: calc(var(--visual-height, 100dvh) - max(12px, env(safe-area-inset-top)));
    border: 0; border-radius: 20px 20px 0 0; padding-bottom: env(safe-area-inset-bottom);
    overflow-y: auto; overscroll-behavior: contain; scroll-padding-block: 76px 16px;
  }
  .modal-header, .account-dialog .modal-header {
    position: sticky; top: 0; z-index: 3; padding: 12px 16px; align-items: center;
    gap: 12px; background: #fff;
  }
  .modal-header > div { min-width: 0; }
  .modal-header h2, .account-dialog .modal-header h2 { font-size: 19px; line-height: 1.4; margin: 0; }
  .modal-header p, .account-dialog .modal-header p { font-size: 13px; line-height: 1.6; margin-top: 6px; }
  .close-btn, .account-dialog .close-btn { width: 44px; height: 44px; min-height: 44px; border-radius: 10px; }
  .close-btn .icon { width: 20px; height: 20px; }
  .modal-body, .account-dialog .modal-body { padding: 18px 16px; }
  .modal-footer, .account-dialog .modal-footer { position: static; padding: 14px 16px 18px; gap: 10px; background: #fff; }
  .modal-footer > .btn { flex: 1; min-width: 0; min-height: 46px; font-size: 15px; padding: 11px 10px; white-space: normal; }
  .form-field { margin-bottom: 18px; }
  .form-field > span, .account-dialog .form-field > span { font-size: 14px; margin-bottom: 8px; }
  .form-field small { font-size: 12px; line-height: 1.6; }
  .form-field input, .form-field textarea, .form-field select,
  .account-dialog .form-field input { min-height: 48px; font-size: 16px; padding: 11px 12px; line-height: 1.5; }
  .form-field textarea { min-height: 140px; }
  .password-wrap button, .account-dialog .password-wrap button { min-width: 54px; min-height: 44px; font-size: 13px; right: 3px; padding: 10px; }
  .password-wrap input { padding-right: 66px !important; }
  .form-error, .account-dialog .form-error { font-size: 13px; line-height: 1.65; overflow-wrap: anywhere; }
  .danger-note, .account-dialog .danger-note, .import-results { font-size: 14px; line-height: 1.75; overflow-wrap: anywhere; }
  .import-field-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
  .import-field-heading label { font-size: 14px; font-weight: 600; color: #697b96; }
  .import-textarea { display: block; width: 100%; min-height: 164px; resize: vertical; padding: 12px; font-size: 16px; line-height: 1.6; }
  .import-help { margin-top: 10px; font-size: 13px; color: #8d9bb0; line-height: 1.65; }
  .import-help summary { display: flex; align-items: center; min-height: 44px; cursor: pointer; list-style-position: inside; }
  .import-help summary::before { content: "›"; margin-right: 7px; font-size: 18px; }
  .import-help[open] summary::before { transform: rotate(90deg); }
  .import-help summary::-webkit-details-marker { display: none; }
  .import-help p { margin: 0 0 10px; }
  .account-home { padding: 0 16px; }
  .account-identity { padding: 16px 0 18px; }
  .account-identity small { font-size: 12px; }
  .account-identity strong { font-size: 19px; }
  .account-option { min-height: 58px; font-size: 15px; }
  .account-option small { font-size: 12px; }
  .account-dialog .session-row { gap: 8px; }
  .account-dialog .session-row strong { font-size: 14px; }
  .account-dialog .session-row small { font-size: 12px; line-height: 1.7; }
  .account-dialog .session-row > .badge { font-size: 11px; padding: 4px 6px; }
  .account-devices { padding: 0 10px; }
  .account-devices .text-btn { font-size: 14px; }
  .account-bottom { padding: 16px 0 20px; }
  .account-dialog .account-logout { font-size: 15px; min-height: 48px; }

  /* Details use the whole screen, with their own vertical scroll. */
  .drawer-overlay { align-items: stretch; }
  .drawer { width: 100%; height: var(--visual-height, 100dvh); max-height: var(--visual-height, 100dvh); padding-bottom: env(safe-area-inset-bottom); overscroll-behavior: contain; scroll-padding-block: 78px 20px; }
  .drawer-header { padding: 10px 14px; min-height: 64px; gap: 10px; }
  .drawer-header h2 { font-size: 18px; }
  .drawer-header small { display: none; }
  .drawer-body { padding: 12px; }
  .detail-product { padding: 14px; gap: 12px; margin-bottom: 12px; }
  .detail-product .product-thumb { width: 64px; height: 64px; }
  .detail-info h3 { font-size: 15px; line-height: 1.6; overflow-wrap: anywhere; }
  .detail-info p { font-size: 12px; line-height: 1.6; }
  .detail-info .price { font-size: 15px; }
  .detail-links { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 8px; font-size: 14px; }
  .detail-links a, .detail-links .text-btn { display: inline-flex; align-items: center; min-height: 44px; font-size: 14px; }
  .detail-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin-bottom: 14px; }
  .detail-metric { min-width: 0; padding: 13px 12px; }
  .detail-metric > span { font-size: 13px; margin-bottom: 8px; }
  .detail-metric strong, .detail-metric .metric.partial { font-size: 23px; line-height: 1.4; overflow-wrap: anywhere; }
  .detail-metric .metric.missing { font-size: 22px; }
  .detail-metric small { font-size: 12px; line-height: 1.6; overflow-wrap: anywhere; }
  .detail-section { margin-top: 14px; }
  .detail-section .panel-title { padding: 12px 14px; }
  .detail-settings { grid-template-columns: minmax(0, 1fr); padding: 16px; gap: 16px; }
  .detail-chart { padding: 12px 8px 4px; }
  .chart-wide { display: none; }
  .chart-small { display: block; width: 100%; max-width: 400px; margin: 0 auto; }
  .chart-small .history-chart, .history-chart.chart-small { width: 100%; min-width: 0; height: auto; }
  .chart-small text { font-size: 14px; }
  .chart-note { padding: 0 14px 14px; font-size: 12px; line-height: 1.65; }

  /* Ranking, More, and notifications share the same comfortable sizing. */
  .overview-summary { font-size: 13px; }
  .ranking-panel { padding: 0 14px; }
  .ranking-heading h2 { font-size: 21px; }
  .ranking-row { gap: 9px; grid-template-columns: 24px 48px minmax(0, 1fr) auto; }
  .ranking-row .product-thumb { width: 48px; height: 48px; }
  .ranking-value { max-width: 88px; }
  .ranking-expand { min-height: 50px; font-size: 14px; }
  .ranking-explanation { font-size: 14px; line-height: 1.75; }
  .more-panel { padding: 4px 16px 12px; }
  .more-item { min-height: 68px; font-size: 16px; }
  .toast-region { top: max(12px, env(safe-area-inset-top)); left: 12px; right: 12px; width: auto; }
  .toast { font-size: 14px; line-height: 1.6; padding: 12px; gap: 8px; }
  .toast > div, .toast > span { min-width: 0; overflow-wrap: anywhere; }
  .toast button { width: 44px; height: 44px; min-width: 44px; display: grid; place-items: center; margin-top: -5px; margin-right: -5px; }

  /* Login is a short, single-column form instead of a scaled desktop cover. */
  .login-page { display: block; padding: 0; background: #fff; min-height: 100dvh; }
  .login-layout { min-height: 100dvh; display: block; border: 0; border-radius: 0; padding: 0; background: #fff; overflow: visible; }
  .login-intro { padding: calc(24px + env(safe-area-inset-top)) 24px 20px; background: #fff; }
  .login-intro .brand { font-size: 20px; margin: 0; gap: 11px; }
  .login-intro .brand-mark { width: 36px; height: 36px; font-size: 32px; }
  .login-intro .brand small, .login-editorial, .login-footnote, .login-kicker, .login-security { display: none; }
  .login-card { display: block; padding: 12px 24px calc(28px + env(safe-area-inset-bottom)); }
  .login-card-inner { max-width: 420px; margin: 0 auto; }
  .login-card h2 { font-size: 25px; line-height: 1.4; margin: 0 0 12px; }
  .login-description { font-size: 14px; line-height: 1.65; margin-bottom: 24px; }
  .login-card .form-field { margin-bottom: 18px; }
  .login-card .form-field > span { font-size: 14px; margin-bottom: 8px; }
  .login-card .form-field input { min-height: 50px; height: auto; font-size: 16px; padding: 12px; }
  .login-card .form-field small, .login-card .notice { font-size: 13px; }
  .login-preferences { gap: 8px 24px; margin: 0 0 6px; }
  .login-preferences .remember-row { min-height: 44px; font-size: 14px; margin: 0; }
  .remember-row input { width: 20px; height: 20px; }
  .remember-help { font-size: 12px; line-height: 1.65; margin: 0 0 14px; }
  .login-submit { min-height: 50px; height: auto; font-size: 16px; margin-top: 8px; padding: 12px 16px; }
  .login-card .form-error { font-size: 14px; }
}

@media (max-width: 360px) {
  .app-shell main { padding: 12px 10px 18px; }
  .sidebar { padding: 9px 12px; }
  .sidebar .brand { font-size: 17px; }
  .panel-title { padding-left: 12px; padding-right: 12px; }
  .product-panel-title h2 { font-size: 16px; }
  .mobile-product-list { padding: 8px; }
  .mobile-product-card { padding: 12px; }
  .mobile-product-head > .product-thumb { width: 54px; height: 54px; }
  .mobile-product-copy .product-name { font-size: 14px; }
  .mobile-product-footer { gap: 5px; }
  .mobile-product-footer .btn { padding: 10px 8px; }
  .mobile-product-footer .btn .icon { display: none; }
  .pagination .pagination-controls { gap: 5px; }
  .pagination .btn { padding: 10px 8px; }
  .logs-pagination .btn .icon { display: none; }
  .pagination .page-size { min-width: 80px; }
  .ranking-panel { padding: 0 12px; }
  .ranking-heading { gap: 6px; }
  .ranking-heading h2 { font-size: 18px; }
  .ranking-actions { gap: 2px; }
  .ranking-refresh { padding-inline: 9px; }
  .ranking-row { grid-template-columns: 20px 40px minmax(0, 1fr) auto; gap: 7px; }
  .ranking-row .product-thumb { width: 40px; height: 40px; }
  .ranking-place { width: 20px; }
  .ranking-value { max-width: 76px; min-width: 36px; }
  .ranking-value .metric { font-size: 20px; }
  .detail-product { padding: 12px; gap: 10px; }
  .detail-product .product-thumb { width: 52px; height: 52px; }
  .detail-info h3 { font-size: 14px; }
  .detail-metric { padding: 12px 10px; }
  .login-intro { padding-left: 20px; padding-right: 20px; }
  .login-card { padding-left: 20px; padding-right: 20px; }
}

@media (max-width: 960px) and (max-height: 480px) {
  .modal-header, .account-dialog .modal-header { padding-top: 6px; padding-bottom: 6px; }
  .modal-body, .account-dialog .modal-body { padding-top: 12px; padding-bottom: 12px; }
  .login-intro { padding-top: 16px; padding-bottom: 12px; }
  .login-card { padding-top: 4px; }
}
