/*
 * RingCraft Design V1 — responsive application contract
 *
 * Loaded after page modules and before stabilization.css.
 * Presentation only: no behavior, data, role, API or provider contracts.
 */

/* Fluid foundations */
html, body, #app-shell, #main, #content,
#callmode-screen, .callmode-body {
  min-width: 0;
}

#content {
  scrollbar-gutter: stable;
}

img, svg, canvas {
  max-width: 100%;
}

/* Compact desktop: the real working width after the 232px sidebar. */
@media (max-width: 1440px) {
  #content {
    padding: 16px !important;
  }

  .dash-shell,
  .reports-shell {
    max-width: none !important;
  }

  .stats-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  }

  .dash-pipeline-grid {
    grid-template-columns: minmax(0, 1.55fr) minmax(250px, .65fr) !important;
  }

  /* The legacy stylesheet forces flex; restore the intended operational grid. */
  #content .filters-bar:has(#f-search) {
    display: grid !important;
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    align-items: end !important;
    gap: 9px !important;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    padding: 12px !important;
  }

  #content .filters-bar:has(#f-search) > * {
    min-width: 0 !important;
    width: 100% !important;
    margin: 0 !important;
  }

  #content .filters-bar:has(#f-search) #f-search {
    grid-column: span 2;
  }

  #content .filters-bar:has(#f-search) select,
  #content .filters-bar:has(#f-search) input {
    min-width: 0 !important;
    width: 100% !important;
  }

  /* Restore the Call Mode grid that legacy flex rules override. */
  #callmode-screen .callmode-body {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) minmax(300px, 34%) !important;
    gap: 16px !important;
    padding: 16px !important;
  }

  #callmode-screen .callmode-left,
  #callmode-screen .callmode-right {
    display: grid !important;
    min-width: 0 !important;
    width: auto !important;
  }

  #callmode-screen .callmode-right {
    align-content: start !important;
    gap: 12px !important;
  }
}

@media (max-width: 1180px) {
  #sidebar {
    width: 204px !important;
    min-width: 204px !important;
  }

  #sidebar .nav-item {
    font-size: 12px !important;
  }

  #topbar {
    min-width: 0;
    gap: 8px !important;
  }

  #topbar #page-title {
    min-width: 0;
  }

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

  .dash-pipeline-grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  #content .filters-bar:has(#f-search) {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  }

  #callmode-screen .cm-hero {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 12px !important;
  }

  #callmode-screen .cm-hero-toolbar {
    justify-content: space-between !important;
  }

  #callmode-screen .callmode-body {
    grid-template-columns: minmax(0, 1fr) minmax(280px, 32%) !important;
  }
}

/* Tablet and compact laptop: icon rail plus deliberate single-column pages. */
@media (max-width: 980px) {
  #sidebar {
    width: 72px !important;
    min-width: 72px !important;
  }

  #sidebar .rc-brand__copy,
  #sidebar .workspace-block > :not(.workspace-logo),
  #sidebar .nav-label,
  #sidebar .nav-item > :not(.icon),
  #sidebar .user-info > :not(.user-avatar) {
    display: none !important;
  }

  #sidebar .logo,
  #sidebar .nav-item {
    justify-content: center !important;
  }

  #sidebar .logo {
    padding-inline: 12px !important;
  }

  #sidebar .nav-item {
    padding-inline: 8px !important;
  }

  #topbar {
    padding-inline: 14px !important;
  }

  #topbar .role-switch {
    max-width: min(42vw, 300px);
    overflow-x: auto;
  }

  #content .filters-bar:has(#f-search) {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  #content .filters-bar:has(#f-search) #f-search {
    grid-column: 1 / -1;
  }

  #callmode-screen .callmode-body {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  #callmode-screen .callmode-right {
    position: static !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  #callmode-screen #cm-script-card {
    grid-column: 1 / -1;
  }

  #telnyx-dialpad-widget .telnyx-card {
    width: min(324px, calc(100vw - 32px)) !important;
  }
}

/* Mobile: content owns the viewport; navigation becomes a compact rail. */
@media (max-width: 680px) {
  body {
    overflow: hidden;
  }

  #sidebar {
    width: 58px !important;
    min-width: 58px !important;
  }

  #sidebar .logo {
    min-height: 56px !important;
    padding: 10px 8px !important;
  }

  #sidebar .rc-brand__mark {
    width: 30px;
    height: 30px;
  }

  #sidebar .workspace-block {
    margin-inline: 6px !important;
    padding: 6px !important;
    justify-content: center !important;
  }

  #sidebar .workspace-logo,
  #sidebar .user-avatar {
    width: 30px !important;
    height: 30px !important;
    min-width: 30px !important;
  }

  #sidebar .nav {
    padding-inline: 5px !important;
  }

  #sidebar .nav-item {
    min-height: 42px !important;
    margin-block: 2px !important;
    border-radius: 10px !important;
  }

  #topbar {
    min-height: 54px !important;
    height: auto !important;
    padding: 8px 10px !important;
    flex-wrap: wrap !important;
  }

  #topbar h2 {
    flex: 1 1 auto !important;
    font-size: 14px !important;
  }

  #topbar .role-switch {
    order: 3;
    flex: 1 1 100%;
    max-width: 100%;
  }

  #topbar-actions {
    min-width: 0 !important;
    flex-wrap: wrap !important;
  }

  #content {
    padding: 10px !important;
  }

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

  .stat-card {
    min-width: 0 !important;
    min-height: 108px !important;
    padding: 12px !important;
  }

  .dash-filter-bar,
  .dash-quick-actions {
    overflow-x: auto;
    flex-wrap: nowrap !important;
    scrollbar-width: none;
  }

  #content .filters-bar:has(#f-search) {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 8px !important;
    padding: 10px !important;
  }

  #content .filters-bar:has(#f-search) #f-search {
    grid-column: auto;
  }

  #leads-table-wrap,
  .table-wrap {
    max-width: 100%;
    overflow-x: auto !important;
    overscroll-behavior-inline: contain;
  }

  #leads-table-wrap table {
    min-width: 760px;
  }

  #detail-panel {
    width: calc(100vw - 58px) !important;
    max-width: calc(100vw - 58px) !important;
  }

  #detail-panel .detail-header {
    padding: 13px 12px !important;
  }

  #detail-panel #detail-body > .tabs {
    padding-inline: 10px !important;
  }

  #detail-panel [id^="detail-tab-"] {
    padding: 12px 12px 24px !important;
  }

  #detail-panel .detail-field {
    grid-template-columns: minmax(88px, .45fr) minmax(0, 1fr) !important;
    gap: 10px !important;
  }

  #detail-panel .detail-field .val,
  #detail-panel .detail-field .val a,
  #detail-panel .tag {
    color: var(--rc-blue) !important;
  }

  #detail-panel .note-add,
  #detail-panel .note-item {
    width: 100%;
    min-width: 0;
  }

  #detail-panel #new-note-text,
  #detail-panel #lc-notes {
    width: 100% !important;
    min-width: 0 !important;
  }

  #callmode-screen .cm-hero {
    padding: 13px 12px 11px !important;
  }

  #callmode-screen .cm-hero-toolbar {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    width: 100% !important;
  }

  #callmode-screen .cm-toolbar-left,
  #callmode-screen .cm-toolbar-right {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  #callmode-screen .callmode-body,
  #callmode-screen .callmode-right {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  #callmode-screen .callmode-body {
    gap: 12px !important;
    padding: 10px !important;
  }

  #callmode-screen #cm-lead-card,
  #callmode-screen #cm-log-section,
  #callmode-screen .callmode-right > .card {
    min-width: 0 !important;
    padding: 14px !important;
  }

  #callmode-screen .cm-filter-grid,
  #callmode-screen .outcome-grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  #telnyx-dialpad-widget.telnyx-widget {
    right: 10px !important;
    bottom: max(10px, env(safe-area-inset-bottom)) !important;
  }

  #telnyx-dialpad-widget .telnyx-card {
    position: fixed !important;
    right: 10px !important;
    bottom: 68px !important;
    left: 68px !important;
    width: auto !important;
    max-height: calc(100dvh - 88px) !important;
    overflow-y: auto !important;
  }
}

@media (max-width: 440px) {
  #sidebar {
    width: 52px !important;
    min-width: 52px !important;
  }

  #detail-panel {
    width: calc(100vw - 52px) !important;
    max-width: calc(100vw - 52px) !important;
  }

  #detail-panel .detail-field {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 4px !important;
  }

  .stats-grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  #telnyx-dialpad-widget .telnyx-card {
    left: 60px !important;
  }
}

@media (hover: none) and (pointer: coarse) {
  .btn,
  button,
  select,
  input[type="checkbox"],
  .nav-item,
  .tab {
    min-height: 44px;
  }

  .btn:hover,
  .nav-item:hover,
  .pipeline-card:hover {
    transform: none !important;
  }
}
