/* =========================================================
   Admin panel — mobile web layer
   Loaded ONLY by /admin pages (never by the public site).
   Desktop (> 900px) is untouched: every rule below sits
   inside a media query, except the "hidden by default" part.
========================================================= */

/* ---- Hidden on desktop ---- */
.m-topbar, .m-tabbar, .m-overlay, .m-close { display: none; }

.m-icon-btn {
  width: 44px; height: 44px; flex: 0 0 44px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 0; border-radius: 12px;
  color: var(--paper); cursor: pointer; padding: 0;
  -webkit-tap-highlight-color: transparent;
}
.m-icon-btn:active { background: rgba(255, 255, 255, 0.08); }
.m-icon-btn svg, .m-tabbar svg {
  width: 22px; height: 22px; fill: none; stroke: currentColor;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}

/* =========================================================
   Phones & tablets
========================================================= */
@media (max-width: 900px) {

  html { -webkit-text-size-adjust: 100%; }
  body.admin-body { overflow-x: hidden; }
  body.admin-body.m-drawer-open { overflow: hidden; }

  /* ---- Top bar ---- */
  .m-topbar {
    display: flex; align-items: center; gap: .25rem;
    position: sticky; top: 0; z-index: 90;
    padding: env(safe-area-inset-top, 0px) .5rem 0;
    min-height: calc(56px + env(safe-area-inset-top, 0px));
    background: rgba(8, 8, 10, 0.82);
    -webkit-backdrop-filter: blur(16px) saturate(140%);
    backdrop-filter: blur(16px) saturate(140%);
    border-bottom: 1px solid var(--glass-border);
  }
  .m-title {
    flex: 1; min-width: 0; text-align: center;
    font-weight: 700; font-size: 1rem;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }

  /* ---- Layout ---- */
  .admin-shell { display: block; min-height: 0; }
  .admin-main {
    max-width: 100%; width: 100%;
    padding: 1rem 1rem calc(5.75rem + env(safe-area-inset-bottom, 0px));
  }

  /* ---- Sidebar becomes a slide-in drawer ---- */
  .admin-sidebar {
    position: fixed; z-index: 120;
    top: 0; bottom: 0; inset-inline-start: 0;
    width: min(84vw, 320px);
    padding: calc(1rem + env(safe-area-inset-top, 0px)) 1rem calc(1.25rem + env(safe-area-inset-bottom, 0px));
    overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
    transform: translateX(-105%);
    transition: transform .28s cubic-bezier(.16, 1, .3, 1);
    box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0);
  }
  html[dir="rtl"] .admin-sidebar { transform: translateX(105%); }
  body.m-drawer-open .admin-sidebar { transform: none; box-shadow: 24px 0 60px -20px rgba(0, 0, 0, .8); }
  .admin-sidebar .brand { display: flex; align-items: center; gap: .5rem; }
  .admin-sidebar .brand .m-close { display: inline-flex; margin-inline-start: auto; }
  .admin-sidebar a { padding: .85rem .9rem; font-size: .98rem; margin-bottom: .15rem; }

  .m-overlay {
    display: block; position: fixed; inset: 0; z-index: 110;
    background: rgba(0, 0, 0, .6);
    -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
  }
  .m-overlay[hidden] { display: none; }

  /* ---- Bottom tab bar ---- */
  .m-tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; z-index: 80; left: 0; right: 0; bottom: 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: rgba(19, 19, 22, 0.92);
    -webkit-backdrop-filter: blur(18px) saturate(140%);
    backdrop-filter: blur(18px) saturate(140%);
    border-top: 1px solid var(--glass-border);
  }
  .m-tabbar a, .m-tabbar button {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    min-height: 58px; padding: 6px 2px;
    background: transparent; border: 0; cursor: pointer;
    color: var(--paper-dim); font: inherit; font-size: .68rem;
    -webkit-tap-highlight-color: transparent;
  }
  .m-tabbar a.active { color: var(--signal-2); }
  .m-tabbar a:active, .m-tabbar button:active { background: rgba(255, 255, 255, .06); }

  /* ---- Page header row ---- */
  .admin-topbar { flex-wrap: wrap; gap: .75rem; align-items: flex-start; margin-bottom: 1rem; }
  /* page title is already in the sticky top bar, so the page-level heading is hidden */
  .admin-main > .admin-topbar > h2 { display: none; }
  .admin-main > .admin-topbar:has(> h2:only-child) { display: none; }
  .admin-main > .admin-topbar > div, .admin-topbar .lang-tabs {
    display: flex; flex-wrap: wrap; gap: .4rem; max-width: 100%;
  }
  .admin-topbar .lang-tabs > .btn { margin: 0 !important; }
  .admin-main > .admin-topbar > .btn { width: 100%; }

  /* ---- Cards & grids ---- */
  .admin-main .card { padding: 1.1rem; }
  .admin-main .mt-4 { margin-top: 1.5rem; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }

  /* ---- Forms: comfortable touch targets, no iOS zoom ---- */
  .admin-main input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]),
  .admin-main select,
  .admin-main textarea,
  .admin-main .form-control {
    font-size: 16px; min-height: 46px; width: 100%;
  }
  .admin-main textarea { min-height: 110px; }
  .admin-main input[type="checkbox"], .admin-main input[type="radio"] { width: 20px; height: 20px; flex: 0 0 20px; }
  .admin-main .form-label { font-size: .9rem; }
  .admin-main .btn { min-height: 46px; display: inline-flex; align-items: center; justify-content: center; }
  .admin-main form > .btn-solid, .admin-main form > button.btn-solid { width: 100%; }

  /* Long forms: Save button floats above the tab bar */
  .m-sticky-save {
    position: sticky; z-index: 60; width: 100%;
    bottom: calc(4.4rem + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 12px 30px -6px rgba(0, 0, 0, .75) !important;
  }

  /* ---- Misc ---- */
  .admin-main img { max-width: 100%; height: auto; }
  .admin-main code, .admin-main pre { white-space: pre-wrap; word-break: break-word; }
  .admin-main td, .admin-main .field-hint { word-break: break-word; overflow-wrap: anywhere; }

  /* Login */
  .login-shell { padding: calc(1rem + env(safe-area-inset-top, 0px)) 1rem calc(1rem + env(safe-area-inset-bottom, 0px)); align-items: flex-start; padding-top: 12vh; }
  .login-card { max-width: 100%; }
}

/* =========================================================
   Phones: tables turn into stacked cards
========================================================= */
@media (max-width: 700px) {
  .admin-table.is-stacked, .admin-table.is-stacked tbody { display: block; width: 100%; }
  .admin-table.is-stacked thead, .admin-table.is-stacked .m-head-row { display: none; }
  /* the table itself was a card: each row is the card now */
  .admin-table.card.is-stacked { padding: 0; background: none; border: 0; box-shadow: none; -webkit-backdrop-filter: none; backdrop-filter: none; }
  .admin-table.card.is-stacked::before { display: none; }
  .admin-table.is-stacked tr {
    display: block; margin-bottom: .85rem; padding: .35rem .9rem;
    background: var(--glass-bg); border: 1px solid var(--glass-border); border-radius: var(--radius);
  }
  .admin-table.is-stacked td {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding: .6rem 0; border-bottom: 1px solid rgba(255, 255, 255, .06);
    text-align: start !important;
  }
  .admin-table.is-stacked td:last-child { border-bottom: 0; }
  .admin-table.is-stacked td[data-label]::before {
    content: attr(data-label); flex: 0 0 38%; max-width: 38%;
    color: var(--paper-dim); font-size: .72rem; font-weight: 600; text-transform: uppercase;
  }
  .admin-table.is-stacked td[data-label] { text-align: end !important; }
  .admin-table.is-stacked td[data-label] > * { text-align: end; }
  .admin-table.is-stacked td[colspan] { display: block; text-align: center !important; }
  .admin-table.is-stacked .badge { padding: .4rem .9rem; font-size: .78rem; display: inline-block; }

  /* action cells (Edit / Delete ...): buttons share the row equally */
  .admin-table.is-stacked td.m-actions {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: .5rem;
    padding-top: .8rem;
  }
  .admin-table.is-stacked td.m-actions > a, .admin-table.is-stacked td.m-actions > form { display: block; margin: 0; width: 100%; }
  .admin-table.is-stacked td.m-actions .btn { width: 100%; min-height: 44px; font-size: .85rem !important; padding: .5rem .75rem !important; }
}

/* ---- Contact Messages ---- */
@media (max-width: 900px) {
  .admin-main .card > .msg-head, .admin-main .card .admin-topbar {
    display: block; margin-bottom: .6rem !important;
  }
  .admin-main .card .admin-topbar > div { display: block; max-width: 100%; }
  .admin-main .card .admin-topbar > div + div { margin-top: .35rem; }
  .admin-main .card .admin-topbar a { overflow-wrap: anywhere; word-break: break-word; }
  .admin-main .card > p { overflow-wrap: anywhere; line-height: 1.7; }
  .msg-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .5rem; }
  .msg-actions form { display: block !important; margin: 0; }
  .msg-actions .btn { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .admin-sidebar { transition: none; }
}


/* =========================================================
   Hardening pass (phones/tablets)
   1) nothing may be wider than the screen (a too-wide page makes the
      browser zoom out, which also pushes the bottom bar out of view)
   2) long words / e-mails / URLs wrap inside their box
   3) the site's 3D hover / scroll-reveal effects are switched off in the admin
========================================================= */
@media (max-width: 900px) {

  /* --- 1) never wider than the screen --- */
  .admin-shell, .admin-main { min-width: 0; max-width: 100%; overflow-x: clip; }
  .admin-main div, .admin-main form, .admin-main label, .admin-main td, .admin-main li, .admin-main p, .admin-main section { min-width: 0; }
  .admin-main .card, .admin-main table, .admin-main form, .admin-main .alert { max-width: 100%; }
  .admin-main table { table-layout: fixed; }
  .admin-main iframe, .admin-main video, .admin-main canvas, .admin-main svg { max-width: 100%; }

  /* --- 2) text stays inside its box --- */
  .admin-main { overflow-wrap: anywhere; word-break: break-word; }
  .admin-main .card { overflow: hidden; }
  .admin-main .card p, .admin-main .card a, .admin-main .card strong, .admin-main .card div { overflow-wrap: anywhere; word-break: break-word; }
  .admin-main td { overflow-wrap: anywhere; word-break: break-word; }

  /* --- 3) calm the 3D effects so boxes never jump or float out --- */
  .admin-main .card, .admin-main .btn, .admin-main .alert, .admin-main tr, .admin-main td {
    animation: none !important;
    transform: none !important;
    transform-style: flat !important;
    -webkit-backdrop-filter: none; backdrop-filter: none;
  }
  .admin-main .card:hover, .admin-main .btn:hover, .admin-main .btn:active { transform: none !important; }

  /* --- bottom bar: always glued to the screen bottom --- */
  .m-tabbar {
    position: fixed !important; left: 0 !important; right: 0 !important; bottom: 0 !important; top: auto !important;
    width: 100%; max-width: 100vw; z-index: 100;
    transform: translateZ(0);
    -webkit-backface-visibility: hidden; backface-visibility: hidden;
  }
}
