/* Responsive layouts for آیین مهرورزی. Loaded after app.css.

   The browser picks the layout from the screen width:
     desktop  1100px and wider   full sidebar
     tablet   700px to 1099px    narrow icon rail, larger touch targets
     phone    under 700px        top bar with the name, tabs fixed at the bottom
*/

.more-menu { display: none; }
.nav a > span { min-width: 0; }

/* Fingers need bigger targets than a mouse pointer. */
@media (pointer: coarse) {
  .btn { min-height: 44px; }
  .btn.small { min-height: 36px; }
  input[type="text"], input[type="password"], input[type="search"], input[type="number"], select { min-height: 44px; }
  .tick { width: 28px; height: 28px; }
  .pick input, .checks input, .field.check input { width: 22px; height: 22px; }
  .scores .scale-option span { padding: 10px 0; }
  .row-actions a { padding: 6px 0; display: inline-block; }
}

/* ------------------------------------------------------------------ tablet */
@media (max-width: 1099px) {
  .shell { grid-template-columns: 92px minmax(0, 1fr); }
  .sidebar { padding: 16px 8px 12px; gap: 18px; align-items: stretch; }
  .brand { justify-content: center; padding: 0; }
  .brand-text { display: none; }
  .nav { gap: 6px; }
  .nav a { flex-direction: column; gap: 3px; padding: 9px 2px; font-size: 0.72rem; text-align: center; line-height: 1.4; }
  .nav a svg { width: 22px; height: 22px; }
  .nav .long { display: none; }
  .nav .sep { margin: 4px 14px; }
  .who { padding: 12px 0 0; justify-items: center; }
  .who-text { display: none; }
  .who .btn { padding: 6px 4px; font-size: 0.8rem; min-height: 40px; }

  .page { padding: 24px 20px 56px; }
  .detail { grid-template-columns: 1fr; }
  .login { grid-template-columns: 1fr; }
  .login-brand { padding: 32px 20px; }
  .login-brand .rays { display: none; }
  .login-form { place-items: start center; }
}

@media (max-width: 860px) {
  .grid-2, .form-grid { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 120px minmax(0, 1fr) 46px; }
  .bar-row .bar-band { grid-column: 1 / -1; }
  .session-row { grid-template-columns: 1fr; }
}

/* ------------------------------------------------------------------- phone */
@media (max-width: 699px) {
  html { font-size: 15px; }
  h1 { font-size: 1.35rem; }

  /* Top bar with the name; the sidebar's own nav becomes the bottom tab bar. */
  .shell { display: block; }
  .sidebar { position: sticky; top: 0; z-index: 20; height: auto; flex-direction: row; align-items: center; padding: 8px 14px; padding-top: calc(8px + env(safe-area-inset-top, 0px)); }
  .brand { justify-content: flex-start; gap: 10px; }
  .brand .mark { width: 34px; height: 34px; border-radius: 10px; }
  .brand-text { display: inline; }
  .brand .name { font-size: 1.05rem; }
  .brand .tag, .brand-text br { display: none; }
  .who { display: none; }

  .nav {
    position: fixed; z-index: 30; inset-inline: 0; bottom: 0;
    display: flex; gap: 0; justify-content: space-around; align-items: stretch;
    background: var(--teal-900); border-top: 1px solid rgba(255, 255, 255, 0.12);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom, 0px));
  }
  .nav a, .more-menu > summary {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    min-height: 52px; padding: 5px 2px; border-radius: 10px;
    font-size: 0.72rem; font-weight: 500; line-height: 1.3; color: rgba(255, 255, 255, 0.7); text-decoration: none;
  }
  .nav a.extra, .nav .sep { display: none; }
  .nav a.current, .more-menu > summary.current, .more-menu[open] > summary { background: rgba(255, 255, 255, 0.13); color: #fff; }
  .nav a.current svg, .more-menu > summary.current svg { color: var(--sun); }

  .more-menu { display: flex; flex: 1; }
  .more-menu > summary { list-style: none; cursor: pointer; }
  .more-menu > summary::-webkit-details-marker { display: none; }
  .more-sheet {
    position: fixed; inset-inline: 10px; bottom: calc(68px + env(safe-area-inset-bottom, 0px));
    display: grid; gap: 4px; padding: 16px; border-radius: 16px;
    background: var(--surface); color: var(--ink); box-shadow: 0 12px 40px rgba(11, 59, 61, 0.35);
  }
  .more-sheet .who-id { padding-bottom: 12px; margin-bottom: 6px; border-bottom: 1px solid var(--line); }
  .more-sheet a { flex-direction: row; justify-content: flex-start; gap: 12px; min-height: 48px; padding: 8px 10px; font-size: 1rem; color: var(--ink); }
  .more-sheet a svg { color: var(--teal-700); }
  .more-sheet form { margin-top: 8px; }
  .more-sheet .btn { width: 100%; }

  /* Content */
  .page { padding: 16px 14px calc(92px + env(safe-area-inset-bottom, 0px)); gap: 16px; }
  .page-head { align-items: flex-start; }
  .page-head .actions { width: 100%; }
  .page-head > .btn, .page-head .actions > .btn, .page-head .actions > form > .btn, .page-head .actions > details > summary { flex: 1; }
  .page-head .actions > form, .page-head .actions > details { flex: 1; display: flex; }
  .card { padding: 16px 14px; border-radius: 10px; }
  .card.narrow, .stack.narrow { max-width: none; }

  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .stat { padding: 10px 12px; }
  .stat .icon { display: none; }
  .stat .n { font-size: 1.5rem; }
  .stat .k { font-size: 0.78rem; }

  .inline-form { flex-direction: column; align-items: stretch; }
  .inline-form .field { min-width: 0; }
  .filters { flex-direction: column; align-items: stretch; }
  .filters .chips, .card > .chips { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
  .chip-link { white-space: nowrap; }
  .search input { min-width: 0; flex: 1; }
  dl.kv { grid-template-columns: minmax(84px, auto) 1fr; }
  .rows li { align-items: flex-start; }
  .copy-row input { min-width: 0; flex-basis: 100%; }
  .sticky-actions { bottom: calc(60px + env(safe-area-inset-bottom, 0px)); }
  .sticky-actions .btn.big { flex: 1; }

  /* Lists become cards: each row is a block, each cell a labelled line. */
  table.cards-on-phone thead { display: none; }
  table.cards-on-phone, table.cards-on-phone tbody, table.cards-on-phone tr, table.cards-on-phone td { display: block; }
  table.cards-on-phone tr { padding: 12px 14px; border-bottom: 1px solid var(--line); }
  table.cards-on-phone tr:last-child { border-bottom: 0; }
  table.cards-on-phone td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 3px 0; border: 0; white-space: normal; }
  table.cards-on-phone td::before { content: attr(data-label); color: var(--muted); font-size: 0.82rem; flex: none; }
  table.cards-on-phone td:first-child { padding-bottom: 6px; }
  table.cards-on-phone td:first-child::before, table.cards-on-phone td.row-actions::before { content: none; }
  table.cards-on-phone td.row-actions { justify-content: flex-start; gap: 18px; padding-top: 8px; }
  table.cards-on-phone td.row-actions a + a { margin: 0; }
  table.cards-on-phone tbody tr:hover { background: none; }

  /* The program sheet scrolls sideways while the description stays in view. */
  table.sheet .num, table.sheet .spark-cell { display: none; }
  table.sheet .desc { position: sticky; inset-inline-start: 0; z-index: 1; min-width: 170px; max-width: 58vw; background: var(--surface); font-size: 0.86rem; box-shadow: -6px 0 8px -6px rgba(11, 59, 61, 0.18); }
  table.sheet thead .desc { background: var(--paper); }
  table.sheet .cell { width: 50px; min-width: 50px; }
  .legend { font-size: 0.74rem; }

  /* Grading: five buttons per line so each one is easy to hit. */
  .scores { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
  .scores .scale-option span { padding: 11px 0; font-size: 1rem; }
  .scale { gap: 5px; }
  .scale-option span { padding: 10px 2px; }

  .confirm-box { position: fixed; inset-inline: 12px; top: auto; bottom: calc(76px + env(safe-area-inset-bottom, 0px)); width: auto; max-width: none; }
  .question-list { padding-inline-start: 18px; }
  .reeval { align-items: flex-start; }
  svg.trend .axis { font-size: 20px; }
  svg.trend .value { font-size: 22px; }

  .login-brand { padding: 24px 16px; }
  .login-brand .mark { width: 60px; height: 60px; border-radius: 18px; }
  .login-brand h1 { font-size: 1.6rem; }
  .login-form { padding: 24px 16px; }
}

@media (max-width: 380px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .nav a, .more-menu > summary { font-size: 0.66rem; }
}

/* Nothing may push the page wider than the screen. */
.page { grid-template-columns: minmax(0, 1fr); }
.page > *, .stack > *, .filters > * { min-width: 0; }
@media (max-width: 699px) {
  /* A wrapping column would size itself to its widest child and push the page sideways. */
  .filters { flex-wrap: nowrap; }
}
@media (max-width: 699px) {
  .filters .chips, .card > .chips { scrollbar-width: none; }
  .filters .chips::-webkit-scrollbar, .card > .chips::-webkit-scrollbar { display: none; }
}

@media (max-width: 699px) {
  .section-tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
  .section-tabs::-webkit-scrollbar { display: none; }
  .section-tab { white-space: nowrap; flex: none; min-height: 40px; }
  .step-option span { padding: 8px 12px; }
  ol.step-edit li { grid-template-columns: 28px minmax(0, 1fr); }
  ol.step-edit .mini-check { grid-column: 2; }
  table.sheet ol.step-track li { font-size: 0.74rem; }
}

/* Profile and section bars. Tablet: name, bar, number on one line, the note under them.
   Phone: the name on its own line above the bar. */
@media (max-width: 860px) {
  .bar-row { grid-template-columns: 130px minmax(0, 1fr) 48px; row-gap: 2px; }
  .bar-row .bar-label { grid-column: auto; font-weight: 400; }
  .bar-row .bar-band { grid-column: 1 / -1; }
  .bar-row .bar-band:empty { display: none; }
}
@media (max-width: 699px) {
  .bar-row { grid-template-columns: minmax(0, 1fr) 48px; }
  .bar-row .bar-label { grid-column: 1 / -1; font-weight: 500; }
  .step-actions .btn.small { min-height: 38px; }
}
@media (max-width: 699px) {
  /* Editing rows (section names, questionnaire questions): the text box on its own line, its buttons in a row under it. */
  .inline-form.grow, .question-list .inline-form, .inline-form.add-row { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 6px; }
  .inline-form.grow .field, .question-list .inline-form .field, .inline-form.add-row .field { flex: 1 1 100%; }
  .inline-form .mini-check { padding-bottom: 0; }
  .inline-form .btn.small { margin-bottom: 0; }
  .card-head { align-items: flex-start; }
}

@media (max-width: 699px) {
  .messages { top: calc(58px + env(safe-area-inset-top, 0px)); }
}
