/* ==========================================================================
   mo3alemi - layout.css - app shell, sticky header, buttons, cards, badges
   Stage 1 (mobile-first redesign).

   Stage-1 rules applied here:
     - 360px phones first; enhancements at 520px / 768px / 1024px. No max-width
       media queries anywhere.
     - Every tappable control is at least var(--tap) (44px) tall.
     - Cards: >=16px padding, var(--r-lg) radius, var(--surface) background,
       1px var(--line) border, var(--shadow-1). No hard offset shadows.
     - Buttons carry normal / hover / active (scale .97) / disabled states with
       transition:var(--t) var(--ease).
     - Buttons are pills on phones, softly rounded rectangles from 520px up.
     - RTL + LTR safe: logical properties only, no physical left/right.
     - NEW: the fixed bottom navigation (.bnav / .bnavin) plus the
       body.hasbnav / .shell.hasnav bottom clearance so page content, toasts and
       the shell never sit under the bar.
     - Fixed / sticky surfaces respect env(safe-area-inset-*) via the --sat /
       --sab / --sal / --sar tokens.
   Design tokens live in base.css and are never redefined here.
   ========================================================================== */

/* ------------------------------------------------------------------ shell --- */
.shell{
  max-width:var(--shell);
  margin-inline:auto;
  display:flex;
  flex-direction:column;
  gap:16px;
  min-width:0;
}
.shell.wide{max-width:var(--shell-wide)}

/* Keep the last row of content clear of the fixed bottom nav. base.css already
   reserves --sab at the bottom of body, so the safe area is added once here. */
body.hasbnav{
  padding-bottom:max(calc(var(--nav-h) + var(--sab) + 12px),calc(28px + var(--sab)));
}
.shell.hasnav{padding-bottom:calc(var(--nav-h) + var(--sab) + 12px)}

/* ------------------------------------------------------------- flex utils --- */
.stack{display:flex;flex-direction:column;gap:12px;min-width:0}
.row{display:flex;flex-wrap:wrap;gap:10px;align-items:center;min-width:0}
.row.between{justify-content:space-between}
.grow{flex:1 1 140px;min-width:0}
.hr{display:flex;gap:8px;align-items:center;min-width:0}

/* ------------------------------------------------------- sticky top header --- */
.hd{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:10px;
  position:sticky;
  top:0;
  z-index:20;
  margin-inline:calc(-1 * var(--gutter));
  padding-block:10px;
  padding-inline-start:calc(var(--gutter) + var(--sal));
  padding-inline-end:calc(var(--gutter) + var(--sar));
  background:color-mix(in srgb,var(--bg) 86%,transparent);
  backdrop-filter:blur(10px) saturate(160%);
  -webkit-backdrop-filter:blur(10px) saturate(160%);
  border-bottom:1px solid var(--line);
}
@supports (padding-top:env(safe-area-inset-top)){
  .hd{padding-top:calc(10px + var(--sat))}
}
/* the LTR brand pill stays on the visual left in both directions */
[dir="rtl"] .hd{direction:ltr}

.logo{
  font-family:var(--display);
  font-size:26px;
  font-weight:700;
  color:var(--accent);
  line-height:1.1;
  background:none;
  border:0;
  border-radius:var(--r-sm);
  padding:6px 2px;
  margin:0;
  cursor:pointer;
}

/* ------------------------------------------------------- header icon btns --- */
.lang,
.ibtn{
  position:relative;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:6px;
  min-height:var(--tap);
  min-width:var(--tap);
  padding:0 12px;
  border-radius:var(--r-pill);
  border:1px solid var(--line);
  background:var(--surface);
  color:var(--fg);
  font-size:var(--fs-sm);
  font-weight:600;
  cursor:pointer;
  transition:var(--t) var(--ease);
}
.ibtn{padding:0}
.lang svg,.ibtn svg{width:19px;height:19px}
.lang:hover,.ibtn:hover{background:var(--surface-2);border-color:var(--line-2)}
.lang:active,.ibtn:active{transform:scale(.97)}
.lang[disabled],.ibtn[disabled]{opacity:.5;cursor:not-allowed}
/* unread count bubble: position must survive an inner svg */
.ibtn .dot{
  position:absolute;
  top:8px;
  inset-inline-end:8px;
  margin:0;
}

/* ---------------------------------------------------------------- buttons --- */
.btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:8px;
  min-height:var(--tap);
  padding:0 20px;
  border-radius:var(--r-pill);
  border:1px solid transparent;
  background:var(--accent);
  color:var(--accent-fg);
  font-family:var(--body);
  font-size:var(--fs-body);
  font-weight:600;
  line-height:1.2;
  text-align:center;
  text-decoration:none;
  cursor:pointer;
  user-select:none;
  transition:var(--t) var(--ease);
}
.btn:hover{background:var(--accent-2)}
.btn:active{transform:scale(.97)}
.btn[disabled],.btn[aria-disabled="true"]{
  opacity:.5;
  cursor:not-allowed;
  transform:none;
}
.btn.sec{background:var(--secondary);color:var(--accent-fg)}
.btn.sec:hover{background:color-mix(in srgb,var(--secondary) 84%,var(--fg))}
.btn.out{background:var(--surface);color:var(--fg);border-color:var(--line)}
.btn.out:hover{background:var(--surface-2);border-color:var(--line-2)}
.btn.danger{background:var(--err);color:var(--bg)}
.btn.danger:hover{background:color-mix(in srgb,var(--err) 82%,var(--fg))}
.btn.full{width:100%}
.btn.sm{
  min-height:var(--tap);
  padding:0 16px;
  border-radius:var(--r-pill);
  font-size:var(--fs-sm);
}
/* icon-only buttons keep a full square tap target */
.btn.sm:not(:has(span)){min-width:var(--tap)}

.link{
  background:none;
  border:0;
  color:var(--accent);
  cursor:pointer;
  font-family:inherit;
  font-weight:600;
  font-size:var(--fs-sm);
  min-height:var(--tap);
  padding:6px 4px;
  border-radius:var(--r-sm);
  text-decoration:underline;
  text-underline-offset:3px;
  transition:var(--t) var(--ease);
}
.link:hover{color:var(--accent-2)}
.link:active{transform:scale(.97)}

/* ------------------------------------------------------------------ cards --- */
.card{
  background:var(--surface);
  border:1px solid var(--line);
  border-radius:var(--r-lg);
  box-shadow:var(--shadow-1);
  padding:18px;
  display:flex;
  flex-direction:column;
  gap:14px;
  min-width:0;
}
.card.tight{padding:16px;gap:10px}

/* ------------------------------------------------------------ pills / dot --- */
.pill{
  display:inline-flex;
  align-items:center;
  gap:4px;
  font-size:var(--fs-xs);
  font-weight:600;
  line-height:1.5;
  padding:2px 10px;
  border-radius:var(--r-pill);
  background:var(--accent-soft);
  color:var(--accent);
  white-space:nowrap;
}
.pill.ok{background:var(--ok-bg);color:var(--ok)}
.pill.err{background:var(--err-bg);color:var(--err)}
.pill.gray{background:var(--raised);color:var(--muted)}
.pill.warn{background:var(--warn-bg);color:var(--warn)}

.dot{
  display:inline-block;
  width:9px;
  height:9px;
  border-radius:50%;
  background:var(--accent);
  margin-inline-start:6px;
  vertical-align:middle;
  flex:none;
}

/* ================================================== stage 1: bottom nav ====
   Emitted by the JS only for a signed-in user, right after the .shell element:
     <nav class="bnav"><div class="bnavin"><button class="on" ...>...</button></div></nav>
   Three layers are covered: the bar (.bnav), the row (.bnavin) and each
   button (icon + label, aria-current marks the active tab).
   ========================================================================== */
.bnav{
  position:fixed;
  inset-inline:0;
  bottom:0;
  z-index:40;
  background:color-mix(in srgb,var(--surface) 92%,transparent);
  backdrop-filter:blur(12px) saturate(170%);
  -webkit-backdrop-filter:blur(12px) saturate(170%);
  border-top:1px solid var(--line);
  padding-bottom:var(--sab);
  padding-inline-start:var(--sal);
  padding-inline-end:var(--sar);
}
.bnavin{
  max-width:var(--shell);
  margin-inline:auto;
  display:flex;
  align-items:stretch;
  height:var(--nav-h);
}
.bnavin button{
  flex:1;
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap:3px;
  min-width:0;
  min-height:var(--tap);
  padding:4px 2px;
  background:none;
  border:0;
  color:var(--muted);
  font-family:inherit;
  font-size:11px;
  font-weight:600;
  line-height:1.2;
  cursor:pointer;
  -webkit-tap-highlight-color:transparent;
  transition:var(--t) var(--ease);
}
.bnavin button svg{width:22px;height:22px;display:block}
/* the soft pill sits behind the icon of the active tab */
.bnavin button.on svg,
.bnavin button[aria-current="page"] svg{
  background:var(--accent-soft);
  border-radius:var(--r-pill);
  padding:5px;
  box-sizing:content-box;
}
.bnavin button.on,
.bnavin button[aria-current="page"]{color:var(--accent)}
.bnavin button:hover{color:var(--fg-2)}
.bnavin button.on:hover,
.bnavin button[aria-current="page"]:hover{color:var(--accent)}
.bnavin button:active{transform:scale(.96)}
.bnavin button[disabled]{opacity:.45;cursor:not-allowed;transform:none}

/* ============================================================ 520px up ==== */
@media (min-width:520px){
  .shell{gap:18px}
  .btn{border-radius:var(--r)}
  .btn.sm{border-radius:var(--r-sm)}
  .card{padding:20px}
  .card.tight{padding:16px}
}

/* ============================================================ 768px up ==== */
@media (min-width:768px){
  .shell{gap:20px}
  .logo{font-size:28px}
  .ibtn svg{width:20px;height:20px}
  .card{padding:22px}
  .card.tight{padding:18px}
  .hd{padding-block:12px}
  @supports (padding-top:env(safe-area-inset-top)){
    .hd{padding-top:calc(12px + var(--sat))}
  }
}

/* =========================================================== 1024px up ==== */
@media (min-width:1024px){
  .shell{gap:22px}
  .card{padding:24px}
}
