/* Layout: shell grid, header, navigation, page header, cards, toolbars.
   DESIGN_SYSTEM.md §5. With dir="rtl" the first grid column sits on the right,
   so the navigation is at the start of the reading direction without a single
   physical left/right. */
.app {
  display: grid;
  grid-template-columns: var(--nav-w) minmax(0, 1fr);
  grid-template-rows: var(--header-h) minmax(0, 1fr);
  grid-template-areas: "nav header" "nav main";
  min-block-size: 100vh;
}

.topbar {
  grid-area: header;
  position: sticky; inset-block-start: 0; z-index: var(--z-header);
  display: flex; align-items: center; gap: var(--s3);
  padding-inline: var(--s5);
  background: var(--surface);
  border-block-end: 1px solid var(--border);
}
.topbar .grow { flex: 1; }
.topbar .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-inline-size: 0; }
.menu-toggle { display: none; }

.env-badge {
  display: inline-flex; align-items: center; gap: var(--s1);
  padding: 2px var(--s3); border-radius: var(--r-pill);
  font-size: 12px; font-weight: 600;
  background: var(--warn-bg); color: var(--warn-fg);
}
.env-badge.lab { background: var(--info-bg); color: var(--info-fg); }

.sidenav {
  grid-area: nav;
  position: sticky; inset-block-start: 0; align-self: start;
  block-size: 100vh; overflow-y: auto;
  background: var(--surface);
  border-inline-end: 1px solid var(--border);
  padding: var(--s4) var(--s3);
  z-index: var(--z-nav);
}
.brand {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s2) var(--s3) var(--s4);
  font-weight: 700; font-size: 15px; color: var(--text);
}
.brand-mark {
  inline-size: 30px; block-size: 30px; border-radius: 8px;
  display: grid; place-items: center;
  background: var(--accent); color: var(--on-accent);
}
.nav-group { margin-block-end: var(--s4); }
.nav-group-title { padding: var(--s1) var(--s3); font-size: 12px; font-weight: 600; color: var(--text-3); }
.nav-link {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s2) var(--s3); border-radius: var(--r-control);
  color: var(--text-2); min-block-size: 36px;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.main { grid-area: main; min-inline-size: 0; padding: var(--s5); }
.page { display: grid; gap: var(--s4); align-content: start; }
/* Grid items default to `min-width: auto`, so one wide child (a tab strip, a
 * toolbar) made the whole page as wide as its min-content — measured 722 px of
 * content inside a 390 px phone, which the root clip then hid instead of fixing.
 * Letting the items shrink is what lets each one's own `overflow-x: auto` do its
 * job (the tab strip and the tables scroll, the page does not). */
.page > * { min-inline-size: 0; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-start; gap: var(--s3) var(--s5); }
.page-head .titles { flex: 1 1 320px; min-inline-size: 0; }
.page-head .sub { color: var(--text-2); margin-block-start: var(--s1); }
.page-head .actions { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; }
.crumbs { display: flex; gap: var(--s2); font-size: 12px; color: var(--text-3); margin-block-end: var(--s1); }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-card); box-shadow: var(--shadow-1);
  min-inline-size: 0;
}
a.card { color: var(--text); display: block; }
a.card:hover { text-decoration: none; border-color: var(--border-strong); }
.card-head { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4); border-block-end: 1px solid var(--border); }
.card-head h2, .card-head h3 { flex: 1; }
.card-body { padding: var(--s4); }
.card-body.flush { padding: 0; }

.grid { display: grid; gap: var(--s4); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stack { display: grid; gap: var(--s3); }
.split { display: grid; gap: var(--s4); grid-template-columns: minmax(220px, 300px) minmax(0, 1fr); align-items: start; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); }
.row.between { justify-content: space-between; }

.toolbar { display: flex; flex-wrap: wrap; align-items: end; gap: var(--s3); padding: var(--s3) var(--s4); border-block-end: 1px solid var(--border); }
.toolbar .grow { flex: 1; }

.banner {
  display: flex; gap: var(--s3); align-items: flex-start;
  padding: var(--s3) var(--s4); border-radius: var(--r-control);
  border: 1px solid transparent;
}
.banner.info { background: var(--info-bg); color: var(--info-fg); }
.banner.warn { background: var(--warn-bg); color: var(--warn-fg); }
.banner.err { background: var(--err-bg); color: var(--err-fg); }
.banner.ok { background: var(--ok-bg); color: var(--ok-fg); }
.banner .banner-body { flex: 1; min-inline-size: 0; }

.login-wrap { min-block-size: 100vh; display: grid; place-items: center; padding: var(--s5); }
.login-card { inline-size: min(100%, 400px); padding: var(--s6); }
.login-card h1 { margin-block-end: var(--s2); }

/* Narrow screens: the navigation becomes a drawer. */
@media (max-width: 1100px) {
  /* The closed drawer is a fixed panel parked off-canvas with a transform, but its
   * *layout* box still ends a few pixels past the viewport in RTL (measured 397 px
   * of scroll width at 390 px), which let the whole page scroll sideways by 7 px.
   * `clip` removes that overflow without creating a scroll container, so the
   * sticky topbar and each table's own `.table-wrap` scrolling keep working —
   * `hidden` would have made the body a scroll container and broken both. */
  html, body { overflow-x: clip; }
  .app { grid-template-columns: minmax(0, 1fr); grid-template-areas: "header" "main"; }
  .menu-toggle { display: inline-flex; }
  .sidenav {
    position: fixed; inset-block: 0; inset-inline-start: 0; inline-size: min(86vw, var(--nav-w));
    transform: translateX(var(--drawer-from, 100%)); visibility: hidden;
    transition: transform var(--dur) ease, visibility var(--dur);
    box-shadow: var(--shadow-3);
  }
  [dir="ltr"] .sidenav { --drawer-from: -100%; }
  .app.nav-open .sidenav { transform: none; visibility: visible; }
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 720px) {
  .main { padding: var(--s4); }
  .topbar { padding-inline: var(--s4); }
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: minmax(0, 1fr); }
  .topbar .optional { display: none; }
}
@media (max-width: 560px) {
  /* Four controls plus the environment badge leave the app-bar title about five
   * characters, which rendered as «کنسو…». The page's own h1 already names the
   * screen, so the bar drops the duplicate instead of truncating it. */
  .topbar .title { display: none; }
}
