/* ==========================================================================
   Archivly Admin — design system (P29 redesign)
   Brand: emerald #087A4F → cyan #06B6D4. Tokens follow FluentUI's live theme tokens, so light/dark/system
   switch with FluentDesignTheme. Layout uses logical properties only (RTL-first: Arabic is the default).
   ========================================================================== */

/* ---------- 1. Tokens ---------- */
body, .shell, .auth-shell {
  --brand-1: #087A4F;
  --brand-2: #06B6D4;
  --brand-grad: linear-gradient(135deg, var(--brand-1), var(--brand-2));
  --surface: var(--neutral-layer-1, #ffffff);
  --surface-2: var(--neutral-layer-2, #f6f8fa);
  --surface-3: var(--neutral-layer-3, #eef2f5);
  --canvas: color-mix(in srgb, var(--surface-2) 70%, var(--surface));
  --text: var(--neutral-foreground-rest, #0f172a);
  --muted: color-mix(in srgb, var(--text) 58%, transparent);
  --faint: color-mix(in srgb, var(--text) 38%, transparent);
  --border: color-mix(in srgb, var(--text) 11%, transparent);
  --border-strong: color-mix(in srgb, var(--text) 20%, transparent);
  --hover: color-mix(in srgb, var(--text) 5%, transparent);
  --accent-soft: color-mix(in srgb, var(--brand-1) 13%, transparent);
  --ok: #059669; --warn: #d97706; --bad: #dc2626; --info: #0284c7;
  --radius-sm: 8px; --radius: 12px; --radius-lg: 16px;
  --shadow-1: 0 1px 2px rgb(15 23 42 / .06), 0 1px 3px rgb(15 23 42 / .05);
  --shadow-2: 0 6px 18px rgb(15 23 42 / .08), 0 2px 6px rgb(15 23 42 / .05);
  --shadow-3: 0 24px 48px rgb(15 23 42 / .18);
  --sidebar-w: 276px;
  --topbar-h: 60px;
  --ease: cubic-bezier(.2, .7, .2, 1);
}

/* ---------- 2. Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "Inter", "Segoe UI Variable", "Segoe UI", system-ui, sans-serif;
  font-size: 14px; line-height: 1.5; background: var(--canvas); color: var(--text);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
html[lang="ar"] body { font-family: "Readex Pro", "Segoe UI", Tahoma, sans-serif; }
a { color: var(--brand-1); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--brand-2); outline-offset: 2px; border-radius: 4px; }
h1:focus, h1:focus-visible, h1[tabindex="-1"]:focus { outline: none; }
h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -.01em; margin: 0 0 18px; line-height: 1.25; }
h2 { font-size: 1.1rem; font-weight: 650; margin: 28px 0 12px; }
h3 { font-size: .98rem; font-weight: 650; margin: 0 0 12px; }
h4 { font-size: .9rem; font-weight: 600; margin: 12px 0 6px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }
::selection { background: color-mix(in srgb, var(--brand-2) 30%, transparent); }
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }

/* ---------- 3. App shell: sidebar + topbar ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; z-index: 30;
  background: var(--surface); border-inline-end: 1px solid var(--border);
}
.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 16px 18px; height: var(--topbar-h); border-bottom: 1px solid var(--border); }
.logo-mark {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; flex: none;
  background: var(--brand-grad); color: #fff; font-weight: 800; font-size: 1rem; box-shadow: 0 4px 12px rgb(8 122 79 / .35);
}
.logo-mark img { width: 100%; height: 100%; border-radius: inherit; display: block; object-fit: cover; }
.brand { font-weight: 750; font-size: 1.05rem; letter-spacing: .2px; line-height: 1.1; }
.brand-sub { display: block; font-weight: 500; font-size: .72rem; color: var(--muted); letter-spacing: .4px; text-transform: uppercase; }
.brand.big { font-size: 1.5rem; display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.brand.big .brand-sub { display: inline; text-transform: none; font-size: 1rem; }
.sidebar-scroll { flex: 1; overflow-y: auto; padding: 10px 10px 16px; }
.sidebar-foot { padding: 12px 18px; border-top: 1px solid var(--border); color: var(--faint); font-size: .75rem; display: flex; justify-content: space-between; }

/* FluentNavMenu skin */
.nav .fluent-nav-menu, .sidebar .fluent-nav-menu { width: 100% !important; background: transparent; }
.sidebar .fluent-nav-menu > .expander, .sidebar .fluent-nav-menu .collapsible-title { display: none; }
.sidebar .fluent-nav-link, .sidebar .fluent-nav-group > .expander {
  border-radius: var(--radius-sm); margin: 1px 0; color: var(--text); transition: background .15s var(--ease);
}
.sidebar .fluent-nav-item .positioning-region { border-radius: var(--radius-sm); }
.sidebar .fluent-nav-item .positioning-region:hover { background: var(--hover); }
.sidebar .fluent-nav-link.active, .sidebar .fluent-nav-item .active {
  font-weight: 600; color: var(--brand-1);
}
.sidebar .fluent-nav-link.active .positioning-region, .sidebar .fluent-nav-item .active .positioning-region,
.sidebar .fluent-nav-item:has(> .active) .positioning-region { background: var(--accent-soft); }
.sidebar .fluent-nav-group .fluent-nav-text { font-size: .9rem; }
.nav-badge {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; margin-inline-start: 8px;
  border-radius: 999px; background: var(--bad); color: #fff; font-size: .7rem; font-weight: 700; line-height: 1;
}

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 20; height: var(--topbar-h); display: flex; align-items: center; gap: 10px; padding: 0 24px;
  background: color-mix(in srgb, var(--surface) 82%, transparent); backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar .grow { flex: 1; }
.topbar .env { font-size: .72rem; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--brand-1); }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; border: 1px solid transparent;
  background: transparent; color: var(--text); cursor: pointer; transition: background .15s, border-color .15s;
}
.icon-btn:hover { background: var(--hover); border-color: var(--border); }
.pill-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 999px; font-size: .85rem;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none;
}
.pill-btn:hover { background: var(--hover); text-decoration: none; }
.menu-btn { display: none; }
.user-chip { display: flex; align-items: center; gap: 10px; padding-inline-start: 10px; margin-inline-start: 4px; border-inline-start: 1px solid var(--border); }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--brand-grad); color: #fff; font-weight: 700; font-size: .85rem;
}
.user-chip .who { display: flex; flex-direction: column; line-height: 1.2; max-width: 200px; }
.user-chip .who b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip .who small { color: var(--muted); font-size: .72rem; }
.user-chip form { margin: 0; }
.scrim { display: none; }

.content { flex: 1; min-width: 0; width: 100%; max-width: 1480px; margin: 0 auto; padding: 26px 28px 48px; animation: page-in .25s var(--ease); }
@keyframes page-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* Tenant self-service shell */
.tenant-nav { display: flex; flex-direction: column; gap: 2px; padding: 10px; }
.tenant-nav .fluent-nav-link .positioning-region { border-radius: var(--radius-sm); }

/* ---------- 4. Page header & toolbars ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--muted); margin: 4px 0 0; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar, .grid-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar h1 { margin: 0 !important; }
.tabs-bar { display: flex; gap: 4px; padding: 4px; background: var(--surface-3); border-radius: 10px; width: fit-content; margin-bottom: 16px; flex-wrap: wrap; }
.tabs-bar button { border: 0; background: transparent; color: var(--muted); padding: 6px 14px; border-radius: 8px; cursor: pointer; font: inherit; font-weight: 550; }
.tabs-bar button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }

/* ---------- 5. Surfaces ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px;
  box-shadow: var(--shadow-1); margin-bottom: 18px; min-width: 0;
}
.card > h3:first-child, .card > h2:first-child { margin-top: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h3 { margin: 0; }
.card-head .sub { color: var(--muted); font-size: .82rem; }
.cards-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 18px; }
.cards-2 > .card { margin-bottom: 0; }
.stack { display: grid; gap: 18px; }

/* ---------- 6. KPI tiles ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; margin-bottom: 8px; }
.kpi {
  position: relative; display: flex; flex-direction: column; gap: 6px; padding: 18px; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-1);
  color: var(--text); text-decoration: none; transition: transform .18s var(--ease), box-shadow .18s var(--ease), border-color .18s;
}
a.kpi:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); border-color: var(--border-strong); text-decoration: none; }
.kpi .kpi-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.kpi .ico { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); color: var(--brand-1); }
.kpi .value { font-size: 1.85rem; font-weight: 750; letter-spacing: -.02em; direction: ltr; unicode-bidi: isolate; line-height: 1.15; }
.kpi .label { color: var(--muted); font-size: .85rem; }
.kpi .meta { color: var(--faint); font-size: .76rem; }
.kpi.warn .ico { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.kpi.warn::after, .kpi.bad::after { content: ""; position: absolute; inset-block: 0; inset-inline-start: 0; width: 3px; background: var(--warn); }
.kpi.bad .ico { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad); }
.kpi.bad::after { background: var(--bad); }
.kpi.hero { background: var(--brand-grad); color: #fff; border: 0; }
.kpi.hero .label, .kpi.hero .meta { color: rgb(255 255 255 / .85); }
.kpi.hero .ico { background: rgb(255 255 255 / .18); color: #fff; }
.delta { font-size: .76rem; font-weight: 650; padding: 2px 8px; border-radius: 999px; direction: ltr; unicode-bidi: isolate; }
.delta.up { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.delta.down { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad); }

/* ---------- 7. Tables ---------- */
table.simple { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .88rem; }
table.simple th {
  text-align: start; font-weight: 600; font-size: .74rem; letter-spacing: .04em; text-transform: uppercase; color: var(--muted);
  background: var(--surface-2); padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.simple th:first-child { border-start-start-radius: var(--radius-sm); }
table.simple th:last-child { border-start-end-radius: var(--radius-sm); }
table.simple td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.simple tbody tr:hover td, table.simple > tr:hover td { background: var(--hover); }
table.simple tr:last-child td { border-bottom: 0; }
table.simple .num, table.simple td.money { text-align: end; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.table-wrap table.simple th:first-child, .table-wrap table.simple th:last-child { border-radius: 0; }
.card table.simple { margin: 0 -4px; width: calc(100% + 8px); }

/* FluentDataGrid skin (PagedGrid) */
fluent-data-grid, .fluent-data-grid { background: var(--surface); border-radius: var(--radius); }
.grid { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: auto; box-shadow: var(--shadow-1); }
.grid.loading { opacity: .55; pointer-events: none; }
.grid fluent-data-grid-row[row-type="header"], .grid .fluent-data-grid-row[row-type="header"] { background: var(--surface-2); }
.grid fluent-data-grid-cell[cell-type="columnheader"], .grid .column-header { font-weight: 600; color: var(--muted); font-size: .8rem; }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 12px; color: var(--muted); font-size: .85rem; }
.pager select { padding: 5px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.skeleton-rows { display: grid; gap: 8px; }

/* ---------- 8. Chips, badges, states ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; font-size: .75rem; font-weight: 600;
  line-height: 1.6; white-space: nowrap; background: var(--surface-3); color: var(--muted); border: 1px solid transparent;
}
.chip.ok, .chip.Published, .chip.Active, .chip.Pending, .chip.Approved.lic { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.chip.error, .chip.Withdrawn, .chip.Revoked, .chip.Rejected, .chip.OnHold, .chip.Expired.sub { background: color-mix(in srgb, var(--bad) 13%, transparent); color: var(--bad); }
.chip.warning, .chip.InReview, .chip.Approved, .chip.Suspended, .chip.InfoRequested, .chip.Expired, .chip.InGracePeriod, .chip.Canceled, .chip.Paused { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.chip.Draft, .chip.info { background: color-mix(in srgb, var(--info) 13%, transparent); color: var(--info); }
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.chip.plain::before, .chip.mono::before, .chip[style]::before { display: none; }

.state { padding: 40px 24px; text-align: center; border: 1px dashed var(--border-strong); border-radius: var(--radius); color: var(--muted); background: var(--surface); }
.state.error { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.empty { padding: 36px 16px; text-align: center; color: var(--muted); }
.empty .empty-ico { font-size: 2rem; opacity: .5; display: block; margin-bottom: 6px; }
.error { color: var(--bad); } .hint { color: var(--muted); } .small { font-size: .8rem; word-break: break-all; }
.issue.error { color: var(--bad); } .issue.warning { color: var(--warn); }
.ok-text { color: var(--ok); }

.alerts { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.alerts li {
  display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border-radius: var(--radius); font-size: .9rem;
  background: color-mix(in srgb, var(--warn) 9%, var(--surface)); border: 1px solid color-mix(in srgb, var(--warn) 28%, transparent);
}
.alerts li::before { content: "!"; flex: none; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: .75rem; font-weight: 800; color: #fff; background: var(--warn); }
.alerts li.error { background: color-mix(in srgb, var(--bad) 8%, var(--surface)); border-color: color-mix(in srgb, var(--bad) 28%, transparent); }
.alerts li.error::before { background: var(--bad); }
.alerts li.info { background: color-mix(in srgb, var(--info) 8%, var(--surface)); border-color: color-mix(in srgb, var(--info) 25%, transparent); }
.alerts li.info::before { content: "i"; background: var(--info); }
.alerts a { color: inherit; font-weight: 550; }
.all-clear { display: flex; align-items: center; gap: 10px; padding: 14px; border-radius: var(--radius); color: var(--ok);
  background: color-mix(in srgb, var(--ok) 8%, var(--surface)); border: 1px solid color-mix(in srgb, var(--ok) 25%, transparent); }

/* ---------- 9. Charts (pure CSS / SVG) ---------- */
.bars { display: grid; gap: 8px; }
.bars .bar { display: grid; grid-template-columns: minmax(90px, 160px) 1fr 70px; gap: 12px; align-items: center; font-size: .86rem; }
.bars .bar > div:not(.fill) { height: 10px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.bars .fill { height: 100%; border-radius: 999px; background: var(--brand-grad); transition: width .5s var(--ease); }
.bars .bar > span:last-child { text-align: end; font-variant-numeric: tabular-nums; }
.bars .fill.warn { background: var(--warn); } .bars .fill.bad { background: var(--bad); }
.spark { width: 100%; height: 180px; display: block; overflow: visible; }
.spark .area { fill: url(#sparkGrad); }
.spark .line { fill: none; stroke: var(--brand-1); stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.spark .grid-line { stroke: var(--border); stroke-width: 1; vector-effect: non-scaling-stroke; }
.spark-axis { display: flex; justify-content: space-between; color: var(--faint); font-size: .72rem; margin-top: 6px; direction: ltr; }
.meter { height: 8px; border-radius: 999px; background: var(--surface-3); overflow: hidden; min-width: 80px; }
.meter > i { display: block; height: 100%; border-radius: inherit; background: var(--ok); }
.meter.warn > i { background: var(--warn); } .meter.bad > i { background: var(--bad); }
.rate { display: flex; align-items: center; gap: 8px; }
.rate b { min-width: 52px; text-align: end; font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; color: var(--muted); font-size: .8rem; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: 6px; vertical-align: -1px; }

/* ---------- 10. Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; align-items: end; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.settings-grid > .card { margin: 0; }
textarea, select, input:not([type=checkbox]):not([type=radio]) { font: inherit; color: var(--text); }
textarea { background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 8px 10px; }
textarea:focus { outline: 2px solid var(--brand-2); outline-offset: 0; border-color: transparent; }
.mono, textarea.mono, .pattern { font-family: "Cascadia Code", "JetBrains Mono", Consolas, monospace; direction: ltr; unicode-bidi: isolate; font-size: .9em; }
.money { direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; }
.key { font-family: "Cascadia Code", Consolas, monospace; font-size: 1.1rem; letter-spacing: .06em; padding: 8px 14px; border-radius: var(--radius-sm); background: var(--surface-3); display: inline-block; border: 1px dashed var(--border-strong); }
.secret { display: block; font-size: 1.15rem; letter-spacing: 2px; padding: 10px; background: var(--surface-3); border-radius: var(--radius-sm); margin: 8px 0; }
.download-link { font-weight: 600; }

/* ---------- 11. Template studio, diff, wizard, timeline, permissions ---------- */
.studio { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 18px; }
.tpl-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 12px; align-self: start; position: sticky; top: calc(var(--topbar-h) + 16px); }
.tpl-list .group-title { margin: 12px 4px 6px; font-weight: 650; font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.tpl-item { padding: 8px 10px; border-radius: var(--radius-sm); cursor: grab; display: flex; justify-content: space-between; align-items: center; gap: 6px; transition: background .12s; }
.tpl-item:hover { background: var(--hover); }
.tpl-item.active { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--brand-1); }
[dir="rtl"] .tpl-item.active { box-shadow: inset -3px 0 0 var(--brand-1); }
.tpl-item.drag-over { outline: 2px dashed var(--brand-2); }
.sample-view { white-space: pre-wrap; line-height: 2.1; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); }
.sample-view mark { color: #fff; border-radius: 4px; padding: 1px 4px; }
.cases { display: grid; gap: 6px; }
.diff { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.diff pre { white-space: pre-wrap; margin: 0; padding: 10px; border-radius: var(--radius-sm); background: var(--surface-2); }
.diff .added { background: color-mix(in srgb, var(--ok) 16%, transparent); } .diff .removed { background: color-mix(in srgb, var(--bad) 14%, transparent); }
table.diff { display: table; font-family: "Cascadia Code", Consolas, monospace; font-size: .8rem; border-collapse: collapse; }
table.diff td { padding: 3px 8px; vertical-align: top; }
.diff .before { background: color-mix(in srgb, var(--bad) 12%, transparent); }
.diff .after { background: color-mix(in srgb, var(--ok) 14%, transparent); }

.steps { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0 20px; counter-reset: step; }
.steps .step { counter-increment: step; display: inline-flex; align-items: center; gap: 8px; padding: 6px 14px 6px 6px; border-radius: 999px; background: var(--surface-3); font-size: .85rem; color: var(--muted); }
[dir="rtl"] .steps .step { padding: 6px 6px 6px 14px; }
.steps .step::before { content: counter(step); width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); font-weight: 700; font-size: .75rem; }
.steps .step.current { background: var(--brand-grad); color: #fff; }
.steps .step.current::before { color: var(--brand-1); }
.steps .step.done { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.steps .step.done::before { content: "✓"; }
.wizard { max-width: 820px; }
.wizard .form-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { border-inline-start: 2px solid var(--border); padding: 4px 16px 14px; position: relative; }
.timeline li::before { content: ""; position: absolute; inset-inline-start: -7px; top: 8px; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 3px solid var(--brand-1); }

.perm-group { margin: 8px 0; }
.perm { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.perm.blocked { opacity: .45; }
.perm .req { font-size: .72rem; padding: 0 6px; border-radius: 999px; background: color-mix(in srgb, var(--info) 13%, transparent); color: var(--info); }

/* ---------- 12. Auth pages ---------- */
.auth-shell {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 10% -10%, rgb(6 182 212 / .35), transparent 60%),
              radial-gradient(900px 600px at 110% 110%, rgb(8 122 79 / .45), transparent 60%), #0b1f1a;
}
.auth-card { background: var(--surface, #fff); color: var(--text, #111); width: min(440px, 100%); padding: 32px; border-radius: 20px; box-shadow: var(--shadow-3); border: 1px solid rgb(255 255 255 / .08); }
.auth-form { display: grid; gap: 10px; }
.auth-form label { font-weight: 550; font-size: .86rem; }
.auth-form input { padding: 11px 13px; border: 1px solid var(--border-strong); border-radius: 10px; font-size: 1rem; background: var(--surface); color: var(--text); }
.auth-form input:focus { outline: 2px solid var(--brand-2); outline-offset: 0; border-color: transparent; }
.auth-form button.primary {
  margin-top: 10px; padding: 12px; border: 0; border-radius: 10px; color: #fff; font-size: 1rem; font-weight: 650; cursor: pointer;
  background: var(--brand-grad); box-shadow: 0 8px 20px rgb(8 122 79 / .3); transition: transform .15s var(--ease), box-shadow .15s;
}
.auth-form button.primary:hover { transform: translateY(-1px); box-shadow: 0 12px 24px rgb(8 122 79 / .35); }
.auth-form button.primary:focus-visible, .auth-form input:focus-visible { outline: 3px solid #0e7490; outline-offset: 2px; }
.lang-switch { margin-top: 20px; text-align: center; font-size: .9rem; }
@media (prefers-color-scheme: dark) { .auth-card { --surface: #111827; --text: #f9fafb; } }

/* ---------- 13. Responsive ---------- */
@media (max-width: 1100px) { .studio { grid-template-columns: 1fr; } .tpl-list { position: static; } }
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset-block: 0; inset-inline-start: 0; width: min(var(--sidebar-w), 86vw); transform: translateX(-105%); transition: transform .25s var(--ease); box-shadow: var(--shadow-3); }
  [dir="rtl"] .sidebar { transform: translateX(105%); }
  .shell.nav-open .sidebar { transform: none; }
  .shell.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 25; background: rgb(15 23 42 / .45); animation: page-in .2s; }
  .menu-btn { display: inline-grid; }
  .topbar { padding: 0 14px; }
  .user-chip .who, .topbar .env { display: none; }
  .content { padding: 18px 14px 40px; }
  .cards-2 { grid-template-columns: 1fr; }
  .diff { grid-template-columns: 1fr; }
  .bars .bar { grid-template-columns: 90px 1fr 50px; }
  .tenant-nav { flex-direction: row; overflow-x: auto; }
  .shell.tenant .sidebar { position: static; transform: none; width: auto; height: auto; box-shadow: none; border-inline-end: 0; border-bottom: 1px solid var(--border); }
  .shell.tenant .sidebar-brand { border-bottom: 0; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
@media print { .sidebar, .topbar, .scrim { display: none !important; } .shell { display: block; } .card { box-shadow: none; } }

/* ── P42 in-app ads: editor + phone preview, targeting tree, report bars, area pickers */
.ad-editor { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
@media (max-width: 1100px) { .ad-editor { grid-template-columns: 1fr; } }
.phone-col { position: sticky; top: 16px; }
.phone { width: 300px; min-height: 540px; border-radius: 34px; border: 10px solid #111827; background: #F8FAFC; color: #0F172A; padding: 12px; box-shadow: var(--shadow-2); display: flex; flex-direction: column; gap: 10px; }
.phone.dark { background: #0B1220; color: #E2E8F0; }
.phone-bar { display: flex; justify-content: space-between; font-size: .75rem; opacity: .7; }
.phone-skel { height: 56px; border-radius: 12px; background: color-mix(in srgb, currentColor 8%, transparent); }
.phone-skel.short { height: 32px; width: 60%; }
.ad-card { position: relative; border-radius: 14px; overflow: hidden; color: #fff; padding: 14px; min-height: 110px; display: flex; flex-direction: column; gap: 6px; justify-content: center; }
.ad-card img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.ad-card strong { font-size: 1.05rem; } .ad-card p { margin: 0; font-size: .85rem; opacity: .92; }
.ad-x { position: absolute; top: 6px; inset-inline-end: 8px; font-size: .75rem; opacity: .85; z-index: 1; }
.ad-tag { position: absolute; bottom: 6px; inset-inline-end: 8px; font-size: .65rem; background: rgb(0 0 0 / .35); padding: 1px 6px; border-radius: 6px; z-index: 1; }
.ad-btn { align-self: flex-start; background: #fff; color: #0F172A; border-radius: 999px; padding: 4px 12px; font-size: .8rem; font-weight: 600; }
.swatch { width: 34px; height: 24px; border-radius: 6px; border: 2px solid var(--border); cursor: pointer; background: var(--surface-3); }
.swatch.on { border-color: var(--text); }
.creatives { display: flex; flex-wrap: wrap; gap: 12px; }
.creatives figure { margin: 0; width: 220px; } .creatives img { width: 100%; border-radius: 8px; border: 1px solid var(--border); }
.target-tree { display: flex; flex-direction: column; gap: 6px; }
.target-tree .cities { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 4px; padding-inline-start: 18px; }
.mark { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 999px; padding: 3px 10px; cursor: pointer; font: inherit; }
.mark.Include { background: color-mix(in srgb, var(--ok) 14%, transparent); border-color: var(--ok); color: var(--ok); }
.mark.Exclude { background: color-mix(in srgb, var(--bad) 13%, transparent); border-color: var(--bad); color: var(--bad); text-decoration: line-through; }
.checks { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin: 8px 0; }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 140px; padding: 8px 0; border-bottom: 1px solid var(--border); margin-bottom: 16px; direction: ltr; }
.bars .bar { flex: 1; height: 100%; position: relative; display: flex; align-items: flex-end; }
.bars .bar span { position: absolute; bottom: 0; inset-inline: 0; background: var(--accent-soft); border-radius: 3px 3px 0 0; }
.bars .bar span.click { background: var(--brand-1); inset-inline: 30%; }
table.simple tr.hl td { background: var(--accent-soft); }
.area-picker { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; }
.area-picker select, .ad-editor select, .grid-toolbar select { min-width: 160px; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.area-editor { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 12px 0; }
.loc-tree, .loc-tree ul { list-style: none; padding-inline-start: 14px; margin: 4px 0; }
.loc-tree .off { opacity: .5; text-decoration: line-through; }

/* ---------- 14. Field-level validation (P16) ----------
   Red border on the invalid input itself + message directly below; no validation summary. Works for FluentUI web
   components (parts) and native inputs. Wrap input + <FieldError> in .field so grid alignment is kept. */
.form-grid { align-items: start; }
.field { display: grid; gap: 4px; min-width: 0; align-content: start; }
.field.span-2 { grid-column: span 2; }
.field.span-all { grid-column: 1 / -1; }
.field > fluent-text-field, .field > fluent-number-field, .field > fluent-select, .field > fluent-combobox,
.field > fluent-text-area, .field > fluent-autocomplete, .field > .fluent-autocomplete-multiselect { width: 100%; }
.field-label { font-weight: 550; font-size: .86rem; }
.field-label .req, .req-mark { color: var(--bad); margin-inline-start: 2px; }
.field-hint { color: var(--muted); font-size: .78rem; }
.field-error { color: var(--bad); font-size: .78rem; font-weight: 550; line-height: 1.35; display: flex; gap: 4px; align-items: flex-start; }
.field-error::before { content: "!"; flex: none; width: 14px; height: 14px; border-radius: 50%; background: var(--bad); color: #fff; font-size: .62rem; font-weight: 800; display: inline-grid; place-items: center; margin-top: 1px; }
.invalid::part(root), .invalid::part(control), .invalid::part(listbox) { border-color: var(--bad) !important; }
.invalid::part(root), fluent-text-area.invalid::part(control), fluent-select.invalid::part(control) { box-shadow: 0 0 0 1px var(--bad) !important; }
input.invalid, select.invalid, textarea.invalid, .invalid > .chip-group, .invalid.check-group { border: 1px solid var(--bad) !important; box-shadow: 0 0 0 1px var(--bad); }
fluent-text-field[required]::part(label)::after { content: " *"; color: var(--bad); }
.check-group { display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.form-actions { display: flex; gap: 8px; align-items: center; justify-content: flex-end; flex-wrap: wrap; padding-top: 14px; margin-top: 14px; border-top: 1px solid var(--border); }
.form-section { margin-bottom: 18px; }
.form-section > h3 { margin: 0 0 10px; font-size: .95rem; }
.lookup-option { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: baseline; }
.lookup-option small { color: var(--muted); }
.row-actions { display: flex; flex-wrap: wrap; gap: 2px; align-items: center; }
fluent-button.danger { color: var(--bad); }
fluent-button.danger::part(control) { color: var(--bad); }
.field-errors { display: grid; gap: 2px; margin-top: 4px; max-height: 180px; overflow: auto; }

/* ---------- 15. Shared page header (P17) ---------- */
.page-head-main { min-width: 0; display: grid; gap: 2px; }
.page-head-main h1 { overflow-wrap: anywhere; }
.page-head .crumbs { margin-bottom: 2px; font-size: .8rem; }
.page-head .crumbs::part(list) { flex-wrap: wrap; }
.page-head .meta { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }
.page-head .actions fluent-button { white-space: nowrap; }
@media (max-width: 720px) { .page-head { align-items: stretch; } .page-head .actions { width: 100%; } }
/* Wizard / tab step bubbles already show the number via CSS counters. */
button.step { border: 0; font: inherit; cursor: pointer; }
button.step:disabled { cursor: default; }
.row-error td { padding-top: 0 !important; border-top: 0 !important; }
select.invalid { border-color: var(--bad) !important; }
/* Text-style buttons (inline remove ✕, "Open →", sign-out on /denied) and the primary link of auth pages. */
button.link { background: none; border: 0; padding: 0 2px; margin: 0; font: inherit; color: var(--brand-1); cursor: pointer; text-decoration: none; border-radius: 4px; }
button.link:hover { text-decoration: underline; }
button.link:focus-visible { outline: 2px solid var(--brand-2); outline-offset: 1px; }
.chip button.link, .fluent-badge button.link { color: inherit; opacity: .7; margin-inline-start: 4px; }
.chip button.link:hover { opacity: 1; text-decoration: none; }
a.primary-link { display: block; text-align: center; padding: 11px 13px; border-radius: 10px; color: #fff; font-weight: 600; text-decoration: none; background: var(--brand-grad); box-shadow: 0 8px 20px rgb(8 122 79 / .3); }
a.primary-link:hover { filter: brightness(1.05); }
.auth-form form { margin: 0; text-align: center; }
