/* Mobile and tablet polish. Loaded last so it can tune every page. */

@media (max-width: 900px) {
  html, body { overflow-x: hidden; }
  .shell-body, .content { min-width: 0; }

  /* Topbar */
  .topbar { padding: 0 10px; gap: 4px; }
  .topbar [data-action="toggle-rail"] { display: none !important; }
  .topbar .page-crumb { display: none !important; }
  .topbar .offline-pill { display: none !important; }
  .topbar .brand { font-size: 0; padding-right: 0; gap: 0; }
  .topbar .brand .mark { width: 28px; height: 28px; font-size: 11px; }
  .topbar .top-actions { gap: 1px; margin-left: auto; }
  .biz-switch { max-width: 150px; height: 36px; }
  .biz-switch .name { font-size: 12px; }
  .topbar .new-label { display: inline; }

  /* Home/profile topbar */
  .home-topbar .inner { padding: 0 12px; gap: 8px; }
  .home-topbar .offline-pill { display: none !important; }
  .home-topbar [data-action="palette"] { gap: 0; width: 36px; padding: 0; }
  .home-topbar [data-action="palette"] .kbd { display: none; }
  .hide-sm { display: none; }

  /* Mobile sidebar drawer + backdrop */
  .nav-backdrop { display: none; }
  body.nav-open .nav-backdrop {
    display: block; position: fixed; inset: var(--header-h) 0 0 0;
    background: rgba(10, 31, 68, .42); z-index: 65;
    animation: fade-in .15s ease;
  }
  body.nav-open { overflow: hidden; }
  .sidebar { width: 82vw !important; max-width: 320px; padding-top: 10px; box-shadow: var(--shadow-lg); }

  /* Page layout */
  .content { padding: 14px 14px calc(30px + env(safe-area-inset-bottom)); }
  .content.board-content { padding: 0; }
  .page-head { gap: 10px; margin-bottom: 14px; }
  .page-head h1 { font-size: 18px; }
  .page-head .actions { width: 100%; justify-content: flex-start; }
  .grid-2, .grid-3, .grid-4, .split-2, .two-col, .invoice-layout { grid-template-columns: 1fr !important; }
  .card-head, .card-header { gap: 8px; }
}

@media (max-width: 768px) {
  /* Board header and tabs */
  .board-head { padding: 10px 12px; gap: 8px; align-items: flex-start; }
  .board-head .titles { flex: 1 1 100%; min-width: 0; }
  .board-head h1 { font-size: 16px; flex-wrap: wrap; gap: 6px; }
  .board-head .sub { font-size: 11.5px; }
  .board-head .actions { width: 100%; gap: 6px; }
  .board-head .actions .search-input { flex: 1 1 100%; width: 100%; order: -1; }
  .board-head .actions .btn { height: 38px; flex: 1 1 0; }
  .board-tabs { padding: 0 6px; }
  .board-tabs .tab { padding: 9px 8px; font-size: 11.5px; }
  .board-tabs .tab svg { width: 14px; height: 14px; }
  .board-tabs .meta { display: none; }

  .board-page { height: calc(100dvh - var(--header-h)); min-height: 0; }
  .board-scroll {
    flex: 1; min-height: 0; padding: 10px 10px calc(16px + env(safe-area-inset-bottom));
    gap: 10px; scroll-snap-type: x proximity; -webkit-overflow-scrolling: touch;
  }
  .kanban-col { flex: 0 0 84vw; min-width: 260px; max-width: 340px; max-height: 100%; scroll-snap-align: start; }
  .kanban-col.col-add { flex: 0 0 62vw; min-width: 220px; max-width: 260px; }
  .kanban-cards { -webkit-overflow-scrolling: touch; }
  .k-card { padding: 10px; }
  .k-card .card-title { font-size: 13px; }
  .k-card .card-kebab { opacity: 1; }
  .task-check { width: 24px; height: 24px; }
  .task-check-box { width: 18px; height: 18px; }
  .col-add-btn { min-height: 44px; }

  /* Prevent iOS focus zoom while keeping layout readable */
  .input, .select, .textarea, .search-input .input { font-size: 16px; }

  /* Right detail panel */
  .detail-panel { width: 100vw; max-width: 100vw; height: 100dvh; border-left: 0; }
  .detail-header { padding: 10px 12px; }
  .detail-header h2 { font-size: 15px; }
  .detail-header .sub { font-size: 11px; }
  .detail-tabs-bar { margin: -12px -12px 14px !important; padding: 0 8px !important; }
  .detail-tabs .tab { padding: 9px 8px; font-size: 11.5px; }
  .detail-body { padding: 12px 12px calc(20px + env(safe-area-inset-bottom)); }
  .detail-footer { padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); gap: 6px; }
  .detail-footer .btn { height: 38px; }
  .panel-grid { grid-template-columns: 1fr; gap: 12px; }
  .panel-side { flex-direction: column; }
  .panel-main { max-width: none; }
  .title-input { font-size: 16px; }
  .panel-block .input, .panel-block .select, .panel-block .textarea { min-height: 38px; font-size: 16px; }
  .todo-title { font-size: 16px; }
  .todo-editor { grid-template-columns: 1fr; }
  .todo-editor .input { min-height: 38px; height: 38px; font-size: 16px; }
  .todo-add input { height: 36px; font-size: 16px; }
  .todo-del { opacity: 1; }
  .panel-main .swatch, .panel-side .swatch { width: 24px; height: 24px; }
  .slideover { width: 100%; max-width: 100%; height: 100dvh; }
  .modal { max-height: calc(100dvh - 16px); }

  /* Calendar keeps a readable grid and scrolls horizontally */
  .cal-card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .cal-weekdays, .cal-grid { min-width: 680px; }
  .cal-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cal-task-title { display: block; }
  .cal-task { justify-content: flex-start; }
  .cal-month-label { font-size: 14px; }

  /* Reports */
  .report-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .report-kpi { padding: 10px 12px; }
  .report-kpi .val { font-size: 18px; }
  .gantt-toolbar { padding: 10px 12px; }
  .gantt-head .row-label, .gantt-row .row-label { width: 120px; flex-basis: 120px; }
  .workload-row { flex-wrap: wrap; gap: 6px; }
  .workload-row .w-name { width: 100%; }
  .workload-row .w-bar { flex: 1 1 100%; }
  .workload-row .w-num { width: auto; flex: 1 1 100%; text-align: left; }

  /* Cards / lists / tables */
  .pill-toggle { flex-wrap: wrap; }
  .card-head { align-items: flex-start; }
  .card-head h3 { font-size: 13px; }
  .matrix-wrap { -webkit-overflow-scrolling: touch; }
  .definition { font-size: 12px; }
}

@media (max-width: 480px) {
  .topbar .brand .mark { width: 26px; height: 26px; }
  .biz-switch { max-width: 58px; padding: 3px 5px; }
  .biz-switch .name { display: none; }
  .topbar .btn[data-action="quick-menu"] { width: 36px; padding: 0; }
  .topbar .new-label { display: none; }
  .home-topbar .strong { display: none; }
  .home-head h1 { font-size: 20px; }
  .home-head .search-input { width: 100%; }
  .home-head .btn { width: 100%; justify-content: center; }
  .board-head .actions .btn { flex: 1 1 0; padding: 0 8px; }
  .kanban-col { flex-basis: 88vw; min-width: 250px; }
  .cal-summary { grid-template-columns: 1fr; }
  .page-head .actions .btn { flex: 1 1 auto; }
}

@media (max-width: 480px) {
  .cal-card { overflow-x: hidden; }
  .cal-weekdays, .cal-grid { min-width: 0; }
  .cal-cell { min-height: 64px; padding: 3px 3px 5px; }
  .cal-weekdays > div { padding: 6px 3px; font-size: 9px; text-align: center; }
  .cal-date { justify-content: center; font-size: 10px; gap: 3px; }
  .cal-date em { display: none; }
  .cal-cell.today .cal-date span { width: 18px; height: 18px; }
  .cal-tasks { align-items: center; }
  .cal-task { width: 100%; justify-content: center; border: 0; background: transparent; padding: 0; }
  .cal-task-title, .cal-pri { display: none; }
  .cal-task-dot { width: 6px; height: 6px; border-radius: 50%; }
  .cal-more { width: 100%; text-align: center; font-size: 9px; padding: 0; }
}