/* ─────────────────────────────────────────────────────────────
   HAMYAR — phone layer
   The older stylesheets only collapsed the outer grid on phones.
   This pass fixes what is left: horizontal scroll for wide content
   (tables, board, gantt) instead of squeezing, one-column forms,
   44px controls, 16px inputs (no iOS zoom), safe-area padding and
   no clipped text anywhere around the edges.
   Everything is inside a media query, so the desktop layout is
   untouched.
   ───────────────────────────────────────────────────────────── */

/* global guards (safe at any width) */
html[data-theme] img,html[data-theme] svg,html[data-theme] canvas,html[data-theme] video{max-width:100%}
html[data-theme] .main,html[data-theme] .content,html[data-theme] .layout{min-width:0}
html[data-theme] .panel b,html[data-theme] .list-row b,html[data-theme] .project-card h3,
html[data-theme] .board-card h4,html[data-theme] .data-table td,html[data-theme] .table td,html[data-theme] .unit-head b{overflow-wrap:anywhere}

@media(max-width:860px){
  /* ── chrome ── */
  .layout{overflow-x:clip}
  .sidebar{height:100dvh;width:min(84vw,310px);right:0;transform:translateX(102%);padding-bottom:env(safe-area-inset-bottom);box-shadow:0 12px 50px #0f28404d}
  .sidebar.open{transform:translateX(0)}
  .brand{height:auto;padding:14px 16px}
  .topbar{height:auto;min-height:60px;padding:9px 12px;gap:8px;flex-wrap:wrap}
  .top-heading{font-size:16px;line-height:1.5}
  .top-caption{display:none}
  .top-right{gap:8px;min-width:0;flex:1 1 auto}
  .top-left{flex:0 0 auto;gap:6px}
  .top-left .search{display:none}
  .content{padding:16px 13px calc(26px + env(safe-area-inset-bottom));max-width:none}

  /* ── headings and actions ── */
  .page-head{gap:10px;margin-bottom:14px}
  .page-title{font-size:19px;line-height:1.5}
  .page-sub{font-size:12px;line-height:1.9}
  .page-head .head-actions,.head-actions{display:grid!important;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px;width:100%;flex-wrap:initial}
  .head-actions .btn{min-height:44px;justify-content:center;width:auto;font-size:12.5px}
  .head-actions .btn.mini{min-height:44px}

  /* ── cards and grids ── */
  .stats{grid-template-columns:repeat(2,minmax(0,1fr));gap:9px}
  .stat{padding:12px;display:grid;grid-template-columns:34px minmax(0,1fr);grid-template-areas:"icon num" "icon label" "foot foot";column-gap:10px;align-items:center;overflow:visible}
  .stat-icon{grid-area:icon;margin:0}
  .stat-number{grid-area:num;font-size:21px;line-height:1.35}
  .stat-label{grid-area:label;margin:0}
  .stat-foot{grid-area:foot;margin-top:8px}
  .stat-label{font-size:11.5px;line-height:1.7}
  .stat-foot{font-size:10.5px;line-height:1.7}
  .stat-icon{width:32px;height:32px;font-size:15px}
  .stat:after{display:none}
  .grid-2,.grid-3,.split,.project-grid,.org-grid,.user-grid{grid-template-columns:1fr}
  .panel{padding:13px 12px;border-radius:14px}
  .panel-head{flex-wrap:wrap;gap:7px;margin-bottom:10px}
  .summary-strip{grid-template-columns:repeat(2,minmax(0,1fr))}
  .quick-list li,.list-row{padding:10px 2px;gap:9px}

  /* ── forms: one column, 16px so phones never zoom ── */
  .form-grid,.task-side,.v13-account-grid,.v15-account-grid{grid-template-columns:1fr!important}
  .form-item.full{grid-column:auto}
  .filters{grid-template-columns:1fr;gap:9px;padding:11px}
  .form-item label,.filters label{font-size:12px}
  input,select,textarea,.field,.filters input,.filters select{font-size:16px!important;min-height:46px}
  textarea{min-height:110px;line-height:1.8}
  .form-item small,.help-text{font-size:11px;line-height:1.8}
  .checkbox-row,.pick-members label{min-height:44px;align-items:center}

  /* ── tabs and segmented controls ── */
  .tabs{width:100%;max-width:100%;flex-wrap:nowrap;overflow-x:auto;overflow-y:hidden;scrollbar-width:none;-webkit-overflow-scrolling:touch;scroll-snap-type:x proximity}
  .tabs::-webkit-scrollbar{display:none}
  .tab{white-space:nowrap;flex:0 0 auto;min-height:40px;scroll-snap-align:center}
  .v11-profile-tabs,.v14-mail-tabs,.v9-letter-tabs,.v10-account-tabs{overflow-x:auto;scrollbar-width:none;-webkit-overflow-scrolling:touch}
  .v11-profile-tabs::-webkit-scrollbar,.v14-mail-tabs::-webkit-scrollbar{display:none}
  .v11-profile-tabs button{white-space:nowrap;flex:0 0 auto}

  /* ── wide content scrolls sideways instead of shrinking ── */
  .table-scroll,.v8-task-grid,.gantt,.org-wrap,.org-panel,.v14-mailbox,.v14-thread{overflow-x:auto;-webkit-overflow-scrolling:touch}
  .table-scroll{margin-inline:-12px;padding-inline:12px}
  .data-table{min-width:560px}
  .data-table th,.data-table td{padding:11px 10px;white-space:nowrap}
  .gantt-row{min-width:620px}

  /* ── kanban: one column per swipe ── */
  .board{display:flex;gap:10px;overflow-x:auto;scroll-snap-type:x mandatory;-webkit-overflow-scrolling:touch;padding-bottom:8px;margin-inline:-13px;padding-inline:13px}
  .board-col{flex:0 0 86%;min-width:0;scroll-snap-align:start}
  /* ── kanban (server pages): one column per swipe, like .board ── */
  .kanban{display:flex;gap:10px;overflow-x:auto;scroll-snap-type:x mandatory;-webkit-overflow-scrolling:touch;padding-bottom:8px;margin-inline:-13px;padding-inline:13px}
  .kanban-col{flex:0 0 86%;min-width:0;scroll-snap-align:start}
  .board-card{padding:11px 12px}
  /* ── task rows: let the date drop to a second line instead of squeezing ── */
  .data-row{flex-wrap:wrap}

  /* ── calendar ── */
  .cal-layout{grid-template-columns:1fr;gap:8px}
  .cal-cell{min-height:auto;padding:9px}
  .cal-event{font-size:10.5px;border-radius:7px;padding:2px 5px;overflow:hidden;text-overflow:ellipsis}

  /* ── dialogs: full height, sticky footer ── */
  .modal,.modal.wide{max-width:100%;max-height:100dvh}
  .modal-head{position:sticky;top:0;z-index:2;background:var(--card)}
  .modal-foot,.v13-task-footer,.v15-footer{position:sticky;bottom:0;z-index:2;background:var(--card)}
  .modal-foot .btn,.v15-footer .btn{flex:1 1 auto;min-height:46px}
  #overlay .modal-foot{gap:8px;flex-wrap:wrap;padding-bottom:calc(10px + env(safe-area-inset-bottom))}

  /* ── feedback ── */
  .notice a,.v10-feedback a,.v10-feedback button{display:inline-block;min-height:24px;padding-block:3px}
  .toast-zone{right:10px;left:10px;bottom:calc(10px + env(safe-area-inset-bottom))}
  .toast{width:100%;font-size:12px;padding:12px 14px;line-height:1.7}
  .notice{font-size:12px;line-height:1.95;padding:11px 12px}

  /* ── chat / letters: keep the composer reachable ── */
  .chat-wrap{grid-template-columns:1fr;grid-template-rows:auto 1fr}
  .chat-rooms{display:flex;gap:6px;overflow-x:auto;padding:6px;border-bottom:1px solid var(--line);scrollbar-width:none}
  .chat-rooms::-webkit-scrollbar{display:none}
  .chat-room{flex:0 0 auto;white-space:nowrap;border-radius:12px;padding:8px 10px;font-size:11.5px}
  .chat-messages{padding:12px 10px}
  .bubble,.pc-msgbody{max-width:92%}
  .chat-input,.pc-compose{padding-bottom:calc(8px + env(safe-area-inset-bottom))}
  .v14-thread-footer{gap:6px;overflow-x:auto;scrollbar-width:none}
  .v14-thread-footer .btn{flex:0 0 auto}

  /* ── settings / account ── */
  .v11-profile-shell,.v12-profile-shell{padding:0}
  .v11-profile-body .panel,.v12-panel{border-radius:14px;padding:13px 12px}
  .v13-account-popup{width:calc(100vw - 20px);max-width:none}

  /* ── readable small print ── */
  .footnote,.top-caption,.nav-group,.section-label,.overline{font-size:11px}
  .pill,.tag{white-space:nowrap}
  .pill{font-size:10.5px;padding:3px 9px}
  .tag{font-size:10.5px}
}

/* very small phones */
@media(max-width:430px){
  .content{padding-inline:11px}
  .stat{padding:12px 10px}
  .stat-number{font-size:19px}
  .page-title{font-size:18px}
  .head-actions{grid-template-columns:1fr 1fr}
  .head-actions .btn{font-size:12px;padding-inline:8px}
  .board-col{flex-basis:92%}
  .kanban-col{flex-basis:92%}
  .data-table{min-width:500px}
  .top-left .btn.primary span{display:none}
  .modal-foot .btn{font-size:12.5px}
}

/* touch devices: no sticky hover states */
@media(hover:none){
  .btn:hover,.project-card:hover,.unit-card:hover,.palette-option:hover,.cs-option:hover{transform:none}
  .btn:hover{border-color:var(--line)}
  .nav-item:hover{background:transparent;color:var(--muted)}
  .nav-item.active:hover{background:var(--p-brand-soft);color:var(--p-brand)}
}

/* keep the iOS keyboard from pushing the whole layout */
@supports(height:100dvh){
  .sidebar{height:100dvh}
  .chat-wrap{height:calc(100dvh - 150px)}
}

/* drawer scrim (server-rendered pages) */
.nav-scrim{display:none}
@media(max-width:860px){
  .nav-scrim{display:block;position:fixed;inset:0;z-index:19;background:color-mix(in srgb,var(--p-ink,#122) 42%,transparent);opacity:0;pointer-events:none;transition:opacity .2s}
  .nav-scrim.is-visible{opacity:1;pointer-events:auto}
  body.nav-open{overflow:hidden}
  .sidebar{z-index:20}
}

/* ---- menu opening motion (both shells) ---- */
@keyframes hy-drawer-item{from{opacity:0;transform:translateX(16px)}to{opacity:1;transform:none}}
@keyframes hy-fade-in{from{opacity:0}to{opacity:1}}
@media(max-width:860px){
  .sidebar{
    transition:transform .32s cubic-bezier(.22,.75,.28,1),box-shadow .32s ease;
    will-change:transform;
  }
  .sidebar.open{box-shadow:-20px 0 60px rgba(6,40,38,.3)}
  .sidebar.open .nav-item,
  .sidebar.open .nav-link,
  .sidebar.open .nav-group-title{animation:hy-drawer-item .36s cubic-bezier(.22,.75,.28,1) both}
  .sidebar.open .nav-item:nth-child(1),.sidebar.open .nav-link:nth-child(1){animation-delay:.03s}
  .sidebar.open .nav-item:nth-child(2),.sidebar.open .nav-link:nth-child(2){animation-delay:.055s}
  .sidebar.open .nav-item:nth-child(3),.sidebar.open .nav-link:nth-child(3){animation-delay:.08s}
  .sidebar.open .nav-item:nth-child(4),.sidebar.open .nav-link:nth-child(4){animation-delay:.105s}
  .sidebar.open .nav-item:nth-child(5),.sidebar.open .nav-link:nth-child(5){animation-delay:.13s}
  .sidebar.open .nav-item:nth-child(6),.sidebar.open .nav-link:nth-child(6){animation-delay:.155s}
  .sidebar.open .nav-item:nth-child(7),.sidebar.open .nav-link:nth-child(7){animation-delay:.18s}
  .sidebar.open .nav-item:nth-child(8),.sidebar.open .nav-link:nth-child(8){animation-delay:.20s}
  .sidebar.open .nav-item:nth-child(n+9),.sidebar.open .nav-link:nth-child(n+9){animation-delay:.22s}
  .mobile-fade{display:block;position:fixed;inset:0;z-index:19;background:#0b24455c;opacity:0;visibility:hidden;pointer-events:none;transition:opacity .26s ease,visibility .26s ease;-webkit-backdrop-filter:blur(2px);backdrop-filter:blur(2px)}
  .mobile-fade.visible{opacity:1;visibility:visible;pointer-events:auto}
  .nav-scrim{transition:opacity .26s ease;-webkit-backdrop-filter:blur(2px);backdrop-filter:blur(2px)}
}
@media(prefers-reduced-motion:reduce){
  .sidebar,.mobile-fade,.nav-scrim{transition:none!important}
  .sidebar.open .nav-item,.sidebar.open .nav-link,.sidebar.open .nav-group-title{animation:none!important}
}
