/* Responsive layout contract
 * mobile: width <= 768px; tablet: 768px < width <= 1200px; desktop: width > 1200px.
 * Shared component safety comes first. Device-specific layouts follow below.
 * Keep these boundaries aligned with responsive.js (checked by ui:check).
 */

/* Intrinsic sizing prevents long titles/forms from stretching their parents. */
.workspace,
.page-content,
.project-main,
.project-detail-main,
.task-studio-shell > *,
.schedule-read-view > * {
  min-width: 0;
}

/* Tables retain their columns; only their container scrolls on narrow space. */
#inventory .asset-modern-table,
#consumableAssets .asset-modern-table,
#page-project .project-table-wrap {
  max-width: 100%;
  overflow-x: auto !important;
}

/* No extra 360/380/420px device modes: these fields wrap when space runs out. */
#modal-schedule .schedule-read-lines {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)) !important;
}

@media (max-width: 768px) {
  /* Mobile uses a readable fixed text scale instead of a modal zoom toolbar. */
  :root { --hmpm-modal-zoom: 1 !important; }

  /* 카드 묶음은 칸 수를 카드 개수에 맞춰 못 박는다(auto-fit이면 폭에 따라 3개+1개로 한 장만 아래로 밀렸음).
     4장짜리 KPI(소모품·청구)는 768px 이하에서 항상 2줄 2칸씩(대칭). 재고 KPI는 5장이라 5칸. */
  #consumableKpiGrid,
  #billingKpiGrid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
  }
  #inventoryKpiGrid {
    grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
    gap: 8px !important;
  }
  #inventoryKpiGrid .inventory-kpi-card span,
  #consumableKpiGrid .inventory-kpi-card span,
  #billingKpiGrid .inventory-kpi-card span {
    font-size: 12px !important;
    white-space: normal !important;
    overflow-wrap: anywhere;
    line-height: 1.5;
  }
  #inventoryKpiGrid .inventory-kpi-card,
  #consumableKpiGrid .inventory-kpi-card { min-width: 0; padding: 12px 8px !important; }

  .contract-date-row,
  .asset-card-meta,
  .asset-card-actions {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr)) !important;
  }

  #modal-schedule .schedule-period-row {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 130px), 1fr)) !important;
  }

  #modal-schedule .schedule-form > .modal-actions,
  .client-detail-modal-actions,
  .asset-detail-modal-actions {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 120px), 1fr)) !important;
  }

  #page-project .project-table-wrap { overflow: visible !important; }

  /* Visible event count has its own space, including on public holidays. */
  #page-calendar.page-view.active #calBody .cal-cell {
    min-height: 0 !important;
    height: var(--calendar-row-height) !important;
    box-sizing: border-box !important;
  }
}

@media (max-width: 1200px) {
  #page-integrated .integrated-toolbar select,
  #page-integrated .integrated-toolbar .ghost-button,
  #page-integrated .integrated-toolbar .client-search-box input,
  #page-integrated .integrated-toolbar .client-search-box .icon-button {
    min-height: 44px !important;
    height: 44px !important;
    font-size: 14px !important;
  }
  #page-integrated .integrated-toolbar .client-search-box .icon-button {
    min-width: 44px !important;
    width: 44px !important;
  }
  #modal-project .project-attachment-field { min-height: 44px; padding: 10px 12px !important; }
  #modal-project .project-attachment-head strong,
  #modal-project .project-attachment-list.is-empty { font-size: 13px !important; line-height: 1.5; }
}

@media (width > 768px) and (max-width: 1200px) {
  /* Tablet uses the shared sidebar, with a compact single-column workspace. */
  #page-project .project-layout,
  #page-project .project-detail-main,
  .task-studio-shell,
  .task-board {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  #page-project .project-filters,
  .task-filterbar {
    min-width: 0;
    width: 100%;
  }

  #page-project .project-table tr {
    grid-template-columns: minmax(0, 1fr) 100px 100px;
  }

  #modal-project.project-modal,
  #modal-consumable.consumable-modal,
  .task-modal.erp-modal {
    width: min(900px, calc(100vw - 40px)) !important;
    max-width: calc(100vw - 40px) !important;
  }

  #modal-project .project-form-columns,
  #modal-consumable .form-columns,
  .task-modal .form-columns {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
  }
}

/* Both tablet and PC have room for the toolbar and a scrolling month grid. */
@media (width > 768px) {
  #page-calendar.page-view.active #calendar {
    grid-template-rows: auto auto minmax(0, 1fr) !important;
  }

  #modal-item-search .item-search-table {
    max-height: 65dvh;
    overflow-y: auto !important;
  }
}

@media (width > 1200px) {
  /* Dense desktop tables scroll inside the panel, never outside the page. */
  #page-project .project-main { overflow: hidden; }
  #page-project .project-toolbar,
  #page-project .project-filters { flex-wrap: wrap; }
}

