/*
 * Linksy mobile layout
 *
 * This file intentionally contains presentation-only overrides.  It does not
 * change any selectors used by the application logic and is loaded after the
 * main stylesheet so desktop rules remain the source of truth.
 */

@media (max-width: 980px) {
  html,
  body {
    min-height: 100%;
    height: auto;
  }

  body {
    overflow-x: hidden;
    overflow-y: auto;
  }

  .app {
    width: 100%;
    min-height: 100dvh;
    height: auto;
  }

  .panel-shell {
    width: 100%;
    min-height: 100dvh;
    height: auto;
    flex-direction: column;
    gap: 10px;
    padding: 10px;
  }

  .sidebar,
  .workspace {
    width: 100%;
    min-width: 0;
  }

  .sidebar {
    flex: 0 0 auto;
    border-radius: 16px;
  }

  .brand {
    min-width: 0;
    padding: 13px 14px;
  }

  .brand-copy {
    min-width: 0;
  }

  .brand-copy strong,
  .brand-copy span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    padding: 8px;
  }

  .tab-button {
    min-width: 0;
    min-height: 42px;
    gap: 8px;
    padding: 8px 9px;
    border-radius: 10px;
    font-size: 12px;
  }

  .tab-button > span:last-child {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .tab-icon {
    width: 24px;
    min-width: 24px;
    height: 24px;
    border-radius: 8px;
  }

  /* Keep language and logout available on mobile instead of hiding the footer. */
  .sidebar .sidebar-control-footer {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 10px 14px;
  }

  .sidebar .sidebar-control-footer .sidebar-status-row {
    grid-column: 1 / -1;
  }

  .sidebar .sidebar-control-footer button {
    min-width: 0;
  }

  .sidebar .sidebar-control-footer #logoutButton {
    justify-content: flex-end;
  }

  .workspace {
    flex: 0 0 auto;
    min-height: 0;
    border-radius: 16px;
  }

  .topbar {
    align-items: flex-start;
    gap: 12px;
    padding: 14px;
  }

  .topbar h1 {
    max-width: 100%;
    overflow: hidden;
    font-size: clamp(23px, 6vw, 30px);
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .topbar-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .topbar-actions > * {
    min-width: 0;
    flex: 1 1 140px;
  }

  .content-grid {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    height: auto;
    flex: 0 0 auto;
    min-width: 0;
    min-height: 0;
    gap: 8px;
    padding: 8px;
    align-content: initial;
  }

  /* Desktop stacks every tab in a full-height grid.  On a phone inactive
   * panels must leave the flow; otherwise the active panel inherits the
   * viewport height and every tab gets a large empty tail below its content. */
  .content-grid > .tab-panel:not(.is-active) {
    display: none;
  }

  .content-grid > .tab-panel.is-active {
    display: flex;
    align-self: stretch;
    flex: 0 0 auto;
    width: 100%;
    height: auto;
    min-height: 0;
  }

  .content-panel {
    flex: 0 0 auto;
    height: auto;
    min-height: 0;
  }

  /* The workspace desktop layout has a dedicated 306px side column.  On a
   * phone the navigation is moved above the active section so the section
   * keeps the full viewport width and remains easy to reach. */
  .panel-shell:is(
    .is-offerup-workspace,
    .is-wallapop-workspace,
    .is-carousell-workspace,
    .is-olx-workspace,
    .is-leboncoin-workspace
  ) .content-grid {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    grid-template-columns: none;
    gap: 8px;
  }

  .panel-shell:is(
    .is-offerup-workspace,
    .is-wallapop-workspace,
    .is-carousell-workspace,
    .is-olx-workspace,
    .is-leboncoin-workspace
  ) .content-grid > .tab-panel:not(.is-active) {
    display: none;
  }

  .panel-shell:is(
    .is-offerup-workspace,
    .is-wallapop-workspace,
    .is-carousell-workspace,
    .is-olx-workspace,
    .is-leboncoin-workspace
  ) .content-grid > .tab-panel.is-active {
    display: flex;
    flex: 0 0 auto;
    width: 100%;
    height: auto;
  }

  .panel-shell.is-offerup-workspace .content-grid > .right-panel:not(.wallapop-right-panel):not(.carousell-right-panel):not(.olx-right-panel):not(.leboncoin-right-panel),
  .panel-shell.is-wallapop-workspace .content-grid > .wallapop-right-panel,
  .panel-shell.is-carousell-workspace .content-grid > .carousell-right-panel,
  .panel-shell.is-olx-workspace .content-grid > .olx-right-panel,
  .panel-shell.is-leboncoin-workspace .content-grid > .leboncoin-right-panel {
    display: flex;
    order: -1;
    width: 100%;
    min-width: 0;
    flex: 0 0 auto;
    padding: 0;
    border: 0;
    overflow: visible;
    background: transparent;
  }

  .panel-shell:is(
    .is-offerup-workspace,
    .is-wallapop-workspace,
    .is-carousell-workspace,
    .is-olx-workspace,
    .is-leboncoin-workspace
  ) .workspace-side-menu {
    display: block;
    width: 100%;
    height: auto;
    flex: none;
    padding: 12px;
  }

  .panel-shell:is(
    .is-offerup-workspace,
    .is-wallapop-workspace,
    .is-carousell-workspace,
    .is-olx-workspace,
    .is-leboncoin-workspace
  ) .workspace-side-menu .side-menu-note {
    margin-bottom: 10px;
  }

  .panel-shell:is(
    .is-offerup-workspace,
    .is-wallapop-workspace,
    .is-carousell-workspace,
    .is-olx-workspace,
    .is-leboncoin-workspace
  ) .workspace-tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    overflow: visible;
    padding-bottom: 0;
  }

  .panel-shell:is(
    .is-offerup-workspace,
    .is-wallapop-workspace,
    .is-carousell-workspace,
    .is-olx-workspace,
    .is-leboncoin-workspace
  ) .workspace-tab-button {
    width: 100%;
    min-height: 44px;
    flex: none;
    min-width: 0;
    padding: 9px;
    font-size: 12px;
    white-space: normal;
  }

  .panel-shell:is(
    .is-offerup-workspace,
    .is-wallapop-workspace,
    .is-carousell-workspace,
    .is-olx-workspace,
    .is-leboncoin-workspace
  ) .workspace-tab-button > span:last-child {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .panel-shell:is(
    .is-offerup-workspace,
    .is-wallapop-workspace,
    .is-carousell-workspace,
    .is-olx-workspace,
    .is-leboncoin-workspace
  ) .workspace-content {
    display: flex;
    flex-direction: column;
    flex: 0 0 auto;
    min-height: 0;
    margin-top: 14px;
  }

  /* Workspace sections use an animated, overlapping grid on desktop.  Their
   * invisible siblings still contribute intrinsic height on a narrow screen,
   * so a long configuration section can leave a large blank area beneath a
   * short presets/accounts section.  Keep the transition for desktop and use
   * normal flow sizing on mobile. */
  .panel-shell:is(
    .is-offerup-workspace,
    .is-wallapop-workspace,
    .is-carousell-workspace,
    .is-olx-workspace,
    .is-leboncoin-workspace
  ) .workspace-content > .workspace-section:not(.is-active) {
    display: none;
  }

  .panel-shell:is(
    .is-offerup-workspace,
    .is-wallapop-workspace,
    .is-carousell-workspace,
    .is-olx-workspace,
    .is-leboncoin-workspace
  ) .workspace-content > .workspace-section.is-active {
    display: flex;
    grid-column: auto;
    grid-row: auto;
    width: 100%;
    height: auto;
    min-height: 0;
  }

  .panel-shell.is-offerup-workspace .workspace-section[data-workspace-content="api"] {
    overflow: visible;
    padding-right: 0;
  }

  .panel-shell.is-wallapop-workspace .workspace-section[data-wallapop-workspace-content="api"],
  .panel-shell.is-carousell-workspace .workspace-section[data-carousell-workspace-content="api"],
  .panel-shell.is-olx-workspace .workspace-section[data-olx-workspace-content="api"] {
    overflow: visible;
    padding-right: 0;
  }

  .panel-shell.is-offerup-workspace .content-panel[data-panel="offerup-workspace"],
  .panel-shell.is-wallapop-workspace .content-panel[data-panel="wallapop-workspace"],
  .panel-shell.is-carousell-workspace .content-panel[data-panel="carousell-workspace"],
  .panel-shell.is-olx-workspace .content-panel[data-panel="olx-workspace"] {
    height: auto;
  }

  .content-panel {
    min-width: 0;
    min-height: 0;
    padding: 14px;
    overflow: visible;
    border-radius: 14px;
  }

  /* Let short tabs (for example an accounts table with one row) end after
   * their content instead of inheriting the desktop fill-height behavior. */
  .content-grid {
    align-content: start;
    grid-auto-rows: max-content;
  }

  .content-grid > .tab-panel.is-active {
    align-self: start;
    height: auto;
  }

  .accounts-manager,
  .global-accounts-panel,
  .proxy-manager-panel {
    flex: 0 0 auto;
  }

  .accounts-table-wrap,
  .proxy-table-wrap,
  .global-accounts-table-wrap {
    flex: 0 0 auto;
    max-height: min(62vh, 560px);
  }

  .tab-panel[data-panel="messenger"] {
    overflow: hidden;
  }

  .panel-heading-row,
  .workspace-section-head,
  .accounts-toolbar,
  .proxy-list-head,
  .workspace-console-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }

  .workspace-header-actions,
  .accounts-actions,
  .workspace-console-actions {
    width: 100%;
    justify-content: stretch;
    flex-wrap: wrap;
  }

  .workspace-header-actions > *,
  .accounts-actions > *,
  .workspace-console-actions > * {
    min-width: 0;
    flex: 1 1 calc(50% - 8px);
  }

  .accounts-actions :is(
    #openCookieModalButton,
    #wallapopOpenCookieModalButton,
    #carousellOpenCookieModalButton
  ) {
    flex-basis: 100%;
  }

  .account-filters {
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 2px;
    scrollbar-width: thin;
  }

  .account-filters button {
    flex: 0 0 auto;
  }

  .accounts-table-wrap,
  .proxy-table-wrap,
  .global-accounts-table-wrap,
  .admin-table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }

  .accounts-table,
  .proxy-table,
  .global-accounts-table,
  .admin-table {
    min-width: 760px;
  }

  .bulk-actions {
    gap: 8px;
  }

  .bulk-actions.is-visible {
    max-height: 320px;
  }

  .bulk-actions > span {
    min-width: 0;
    flex: 1 0 100%;
    margin-right: 0;
  }

  .bulk-actions select,
  .bulk-actions button {
    min-width: 0;
    flex: 1 1 calc(50% - 8px);
  }

  .proxy-import-grid,
  .console-url-row,
  .admin-console-grid {
    grid-template-columns: 1fr;
  }

  .proxy-import-grid textarea {
    min-height: 136px;
  }

  .workspace-console {
    min-height: 320px;
    max-height: 60vh;
  }

  .workspace-console-line {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 4px 10px;
  }

  .workspace-console-line code {
    grid-column: 1 / -1;
  }

  .api-actions,
  .modal-actions {
    flex-wrap: wrap;
  }

  .api-actions > *,
  .modal-actions > * {
    min-width: 0;
    flex: 1 1 140px;
  }

  .provider-select-button {
    min-width: 0;
    gap: 10px;
  }

  .provider-select-button > span {
    min-width: 0;
  }

  .provider-select-button strong,
  .provider-select-button small {
    overflow-wrap: anywhere;
    white-space: normal;
  }

  .period-control {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .random-pause-fields {
    width: 100%;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto;
  }

  .messenger-panel {
    width: 100%;
    min-width: 0;
    height: auto;
    min-height: 0;
    grid-template-columns: minmax(0, 1fr);
  }

  .messenger-sidebar {
    min-width: 0;
    min-height: 300px;
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .chat-workspace {
    width: 100%;
    min-width: 0;
    min-height: 560px;
    overflow-x: hidden;
  }

  .chat-list,
  .chat-messages {
    min-width: 0;
  }

  .chat-list-item {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  .chat-list-side,
  .chat-header > div,
  .chat-header-top,
  .chat-seller-line {
    min-width: 0;
  }

  .chat-list-side {
    overflow: hidden;
  }

  .chat-header-top,
  .chat-seller-line {
    flex-wrap: wrap;
  }

  .chat-header-top span,
  .chat-seller-line strong,
  .chat-header small {
    overflow-wrap: anywhere;
  }

  .chat-compose input {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  .message-bubble {
    box-sizing: border-box;
  }

  .message-row {
    gap: 6px;
  }

  .message-copy-button {
    width: 28px;
    height: 28px;
    flex-basis: 28px;
  }

  .message-photo-wrap img {
    max-width: 100%;
  }

  .chat-header {
    grid-template-columns: 48px minmax(0, 1fr) auto;
    gap: 9px;
    padding: 12px;
  }

  .chat-header h3 {
    font-size: 15px;
  }

  .chat-header-top span {
    font-size: 13px;
  }

  .chat-compose {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    padding: 10px;
  }

  .chat-list-item {
    grid-template-columns: 42px minmax(0, 1fr) minmax(0, 48px);
    gap: 8px;
    flex-basis: 92px;
    height: 92px;
    min-height: 92px;
    max-height: 92px;
    padding: 8px;
    overflow: hidden;
  }

  .chat-list-item img {
    width: 42px;
    height: 42px;
  }

  .modal-layer {
    align-items: start;
    overflow-y: auto;
    padding: 12px;
  }

  .modal-card {
    width: 100%;
    max-width: none;
    border-radius: 14px;
  }

  .parser-states-modal-card {
    max-height: calc(100dvh - 24px);
  }

  .parser-states-toolbar {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .parser-states-search {
    grid-column: 1 / -1;
  }

  .parser-states-toolbar .ghost-button {
    width: 100%;
  }

  .parser-states-list {
    grid-template-columns: 1fr;
    max-height: min(54vh, 430px);
  }

  .cookie-viewer-card,
  .cookie-modal-card,
  .proxy-assign-card,
  .proxy-edit-card,
  .custom-api-modal-card {
    width: 100%;
    max-width: none;
    max-height: calc(100dvh - 24px);
  }

  .cookie-viewer-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .cookie-viewer-actions {
    width: 100%;
    justify-content: space-between;
  }
}

@media (max-width: 620px) {
  .panel-shell {
    padding: 8px;
  }

  .tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tab-button {
    min-height: 38px;
    padding: 7px;
    font-size: 11px;
  }

  .tab-icon {
    width: 22px;
    min-width: 22px;
    height: 22px;
  }

  .topbar {
    padding: 13px;
  }

  .topbar-actions > *,
  .workspace-header-actions > *,
  .accounts-actions > *,
  .bulk-actions select,
  .bulk-actions button,
  .modal-actions > * {
    flex-basis: 100%;
    width: 100%;
  }

  .content-grid {
    padding: 6px;
  }

  .content-panel {
    padding: 12px;
  }

  .panel-heading-row > div:first-child,
  .workspace-section-head > * {
    min-width: 0;
  }

  .panel-heading h2,
  .workspace-console-head h2 {
    overflow-wrap: anywhere;
  }

  .workspace-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .workspace-tab-button {
    gap: 7px;
    padding: 8px;
  }

  .workspace-tab-icon {
    width: 26px;
    min-width: 26px;
    height: 26px;
  }

  .preset-row {
    grid-template-columns: minmax(0, 1fr);
    gap: 9px;
    min-height: 0;
    padding: 12px;
  }

  .preset-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .preset-actions .selected-label {
    margin-right: auto;
  }

  .preset-actions .outline-action-button {
    min-width: 0;
    flex: 1 1 120px;
  }

  /* Saved Carousell messages use compact icon actions.  The generic mobile
   * preset rule above makes action groups full-width, which leaves this tiny
   * grid column without enough room and wraps edit/delete vertically. */
  .panel-shell.is-carousell-workspace .carousell-saved-message {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }

  .panel-shell.is-carousell-workspace .carousell-saved-message .carousell-message-thumbs {
    grid-column: 1 / -1;
  }

  .panel-shell.is-carousell-workspace .carousell-saved-message .message-item-text {
    grid-column: 1;
  }

  .panel-shell.is-carousell-workspace .carousell-saved-message .preset-actions {
    grid-column: 2;
    width: auto;
    flex-wrap: nowrap;
    align-self: center;
    justify-content: flex-end;
  }

  .panel-shell.is-carousell-workspace .carousell-saved-message .icon-button {
    flex: 0 0 34px;
  }

  .config-block,
  .seller-filter-card {
    min-width: 0;
  }

  .period-control {
    grid-template-columns: minmax(0, 1fr);
  }

  .provider-select-button {
    align-items: flex-start;
  }

  .provider-select-button em {
    flex: 0 0 auto;
  }

  .workspace-console-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
  }

  .workspace-console-actions > * {
    width: 100%;
  }

  #carousellMessageModal .carousell-message-line-control {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
  }

  #carousellMessageModal .carousell-message-line-actions {
    display: flex;
    width: 100%;
    justify-content: flex-end;
    flex-wrap: nowrap;
    gap: 5px;
  }

  #carousellMessageModal .carousell-message-line-button {
    flex: 0 0 36px;
    width: 36px;
    height: 36px;
  }

  #carousellMessageModal .carousell-attachment-preview {
    width: 100%;
  }

  .bulk-actions.is-visible {
    max-height: 420px;
  }

  .modal-layer {
    padding: 10px;
  }

  .modal-card {
    padding: 16px;
  }

  .modal-card.cookie-viewer-card {
    padding: 0;
  }

  .cookie-json-box {
    max-height: calc(100dvh - 180px);
    margin-right: 10px;
    margin-left: 10px;
  }

  .cookie-viewer-count {
    margin-right: 10px;
    margin-left: 10px;
  }

  .auth-screen {
    padding: 14px;
  }

  .auth-logo {
    top: 14px;
    left: 14px;
  }

  .auth-card {
    width: 100%;
    padding: 34px 18px 26px;
    border-radius: 16px;
  }

  .auth-card-head h1 {
    font-size: clamp(27px, 9vw, 36px);
  }

  .auth-key-field {
    margin-top: 26px;
    padding-right: 58px;
  }

  .auth-divider {
    gap: 10px;
    margin: 24px 0;
  }

  .auth-link-button {
    grid-template-columns: 24px minmax(0, 1fr) 34px;
    min-height: 56px;
    padding-left: 14px;
  }
}
