/* ==========================================================================
   SONAA SYSTEM — design system
   Arabic-first, RTL. Enterprise SaaS: clean, minimal, spacious.
   Brand: #E80443 (primary) · #343434 (neutral)
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Tokens
   -------------------------------------------------------------------------- */
:root {
  /* Brand */
  --brand:          #E80443;
  --brand-hover:    #C90039;
  --brand-active:   #A80030;
  --brand-soft:     #FDE9EF;
  --brand-softer:   #FEF4F7;
  --brand-ring:     rgba(232, 4, 67, .18);

  --ink:            #343434;
  --ink-soft:       #F2F2F3;

  /* Surfaces */
  --surface:        #FFFFFF;
  --surface-page:   #FFFFFF;
  --surface-soft:   #F7F8FA;
  --surface-sunken: #F1F2F4;
  --surface-hover:  #F7F8FA;

  /* Text */
  --text:           #1B1B1B;
  --text-secondary: #5C6069;
  --text-muted:     #8A8F98;
  --text-inverse:   #FFFFFF;

  /* Lines */
  --border:         #EAECEF;
  --border-strong:  #DCDFE4;

  /* Status — reserved, never reused as chart series */
  --good:           #1BAF7A;
  --good-soft:      #E6F7F0;
  --warning:        #EDA100;
  --warning-soft:   #FDF3E0;
  --critical:       #E34948;
  --critical-soft:  #FDECEC;
  --info:           #2A78D6;
  --info-soft:      #E9F2FD;

  /* Chart series — validated set (see README) */
  --series-1: #E80443;
  --series-2: #2A78D6;
  --series-3: #EDA100;
  --series-4: #1BAF7A;
  --series-5: #4A3AA7;
  --series-6: #EB6834;

  /* Radius */
  --r-xs: 6px;
  --r-sm: 8px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 18px;
  --r-full: 999px;

  /* Spacing scale */
  --s-1: 4px;   --s-2: 8px;   --s-3: 12px;  --s-4: 16px;
  --s-5: 20px;  --s-6: 24px;  --s-7: 32px;  --s-8: 40px;
  --s-9: 48px;  --s-10: 64px;

  /* Elevation — restrained, borders do most of the work */
  --shadow-sm: 0 1px 2px rgba(16, 18, 22, .04);
  --shadow-md: 0 4px 16px rgba(16, 18, 22, .07);
  --shadow-lg: 0 16px 48px rgba(16, 18, 22, .13);

  /* Layout */
  --sidebar-w: 260px;
  --topbar-h:  64px;

  --font: "IBM Plex Sans Arabic", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ease: cubic-bezier(.4, 0, .2, 1);
}

/* --------------------------------------------------------------------------
   2. Reset
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--surface-page);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, p, figure { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button { cursor: pointer; border: none; background: none; padding: 0; }
a { color: inherit; text-decoration: none; }
svg { display: block; }

/* Arabic numerals stay latin — finance reads better that way */
.num { font-feature-settings: "tnum"; font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: embed; display: inline-block; }

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

::selection { background: var(--brand-soft); color: var(--brand-active); }

/* Scrollbars — thin and quiet */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: var(--r-full); }
*::-webkit-scrollbar-track { background: transparent; }

/* --------------------------------------------------------------------------
   3. Boot splash
   -------------------------------------------------------------------------- */
.boot {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background: var(--surface);
  z-index: 100;
}
.boot__mark {
  width: 40px; height: 40px;
  border-radius: var(--r-md);
  background: var(--brand);
  animation: pulse 1.1s var(--ease) infinite;
}
@keyframes pulse {
  0%, 100% { opacity: .25; transform: scale(.9); }
  50%      { opacity: 1;   transform: scale(1); }
}

/* --------------------------------------------------------------------------
   4. Typography
   -------------------------------------------------------------------------- */
.t-display { font-size: 30px; font-weight: 600; line-height: 1.25; letter-spacing: -.01em; }
.t-h1  { font-size: 22px; font-weight: 600; line-height: 1.35; }
.t-h2  { font-size: 17px; font-weight: 600; line-height: 1.4; }
.t-h3  { font-size: 15px; font-weight: 600; }
.t-body{ font-size: 14px; }
.t-sm  { font-size: 13px; }
.t-xs  { font-size: 12px; }

.muted     { color: var(--text-muted); }
.secondary { color: var(--text-secondary); }
.strong    { font-weight: 600; }
.truncate  { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --------------------------------------------------------------------------
   5. App shell
   -------------------------------------------------------------------------- */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* Sidebar sits on the RIGHT — RTL first.
   Placement is explicit rather than via `order`: the DOM is [main, sidebar],
   and auto-placement would drop main into column 1 (the narrow one). In RTL
   column 1 is the rightmost, so the sidebar is pinned there. */
.sidebar {
  grid-column: 1;
  grid-row: 1;
  border-inline-start: 1px solid var(--border);
  background: var(--surface);
  display: flex; flex-direction: column;
  position: sticky; top: 0;
  height: 100vh;
}
.shell > .main { grid-column: 2; grid-row: 1; }

.sidebar__brand {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-5) var(--s-5) var(--s-4);
}
.sidebar__logo {
  width: 34px; height: 34px; flex: none;
  border-radius: var(--r-sm);
  background: var(--ink);
  display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 15px;
  position: relative; overflow: hidden;
}
.sidebar__logo::after {
  content: ""; position: absolute;
  inset-block-start: 0; inset-inline-end: 0;
  width: 12px; height: 12px;
  background: var(--brand);
  border-end-start-radius: var(--r-sm);
}
.sidebar__name { font-weight: 600; font-size: 15px; letter-spacing: -.01em; }
.sidebar__tag  { font-size: 11px; color: var(--text-muted); margin-top: -3px; }

.sidebar__nav { flex: 1; overflow-y: auto; padding: var(--s-2) var(--s-3) var(--s-5); }
.nav-group { margin-bottom: var(--s-5); }
.nav-group__label {
  font-size: 11px; font-weight: 500; color: var(--text-muted);
  padding: 0 var(--s-3); margin-bottom: var(--s-2);
  letter-spacing: .02em;
}

.nav-item {
  display: flex; align-items: center; gap: var(--s-3);
  width: 100%;
  padding: 9px var(--s-3);
  border-radius: var(--r-sm);
  color: var(--text-secondary);
  font-size: 13.5px; font-weight: 500;
  transition: background .15s var(--ease), color .15s var(--ease);
  position: relative;
  text-align: start;
}
.nav-item:hover { background: var(--surface-hover); color: var(--text); }
.nav-item.is-active { background: var(--brand-soft); color: var(--brand-active); font-weight: 600; }
.nav-item.is-active::before {
  content: ""; position: absolute;
  inset-inline-start: -12px; inset-block: 8px;
  width: 3px; border-radius: var(--r-full);
  background: var(--brand);
}
.nav-item__icon { width: 18px; height: 18px; flex: none; opacity: .85; }
.nav-item__count {
  margin-inline-start: auto;
  min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: var(--r-full);
  background: var(--brand); color: #fff;
  font-size: 11px; font-weight: 600;
  display: grid; place-items: center;
}
.nav-item.is-active .nav-item__count { background: var(--brand); }

.sidebar__foot { padding: var(--s-3); border-block-start: 1px solid var(--border); }
.user-chip {
  display: flex; align-items: center; gap: var(--s-3);
  width: 100%; padding: var(--s-2); border-radius: var(--r-sm);
  transition: background .15s var(--ease);
}
.user-chip:hover { background: var(--surface-hover); }
.avatar {
  width: 32px; height: 32px; flex: none;
  border-radius: var(--r-full);
  background: var(--ink-soft); color: var(--ink);
  display: grid; place-items: center;
  font-size: 12px; font-weight: 600;
}
.avatar--brand { background: var(--brand-soft); color: var(--brand-active); }
.avatar--lg { width: 56px; height: 56px; font-size: 18px; }
/* Uploaded profile photo — same footprint as the initials it replaces. */
.avatar-img {
  width: 32px; height: 32px; flex: none;
  border-radius: var(--r-full);
  object-fit: cover;
  background: var(--ink-soft);
}
.avatar-img--lg { width: 56px; height: 56px; }

/* --- Main column --- */
.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: var(--topbar-h);
  border-block-end: 1px solid var(--border);
  display: flex; align-items: center; gap: var(--s-4);
  padding: 0 var(--s-7);
  background: var(--surface);
  position: sticky; top: 0; z-index: 20;
}
.topbar__crumbs { display: flex; align-items: center; gap: var(--s-2); font-size: 13.5px; }
.topbar__crumbs .sep { color: var(--border-strong); }
.topbar__actions { margin-inline-start: auto; display: flex; align-items: center; gap: var(--s-2); }

.icon-btn {
  width: 36px; height: 36px;
  border-radius: var(--r-sm);
  display: grid; place-items: center;
  color: var(--text-secondary);
  transition: background .15s var(--ease), color .15s var(--ease);
  position: relative;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }
.icon-btn__dot {
  position: absolute; top: 7px; inset-inline-end: 7px;
  width: 7px; height: 7px; border-radius: var(--r-full);
  background: var(--brand);
  border: 2px solid var(--surface);
}

.page { padding: var(--s-7); flex: 1; max-width: 1440px; width: 100%; }
.page__head {
  display: flex; align-items: flex-start; gap: var(--s-4);
  margin-bottom: var(--s-6); flex-wrap: wrap;
}
.page__head .spacer { margin-inline-start: auto; }
.page__title { display: flex; flex-direction: column; gap: 2px; }

/* --------------------------------------------------------------------------
   6. Cards
   -------------------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-5);
}
.card--flush { padding: 0; overflow: hidden; }
.card--soft { background: var(--surface-soft); border-color: transparent; }

.card__head {
  display: flex; align-items: center; gap: var(--s-3);
  margin-bottom: var(--s-5);
}
.card__head .spacer { margin-inline-start: auto; }
.card__head--bordered {
  margin: 0; padding: var(--s-4) var(--s-5);
  border-block-end: 1px solid var(--border);
}

/* Stat tiles — the reference's tinted row */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s-4); }
.stat {
  border-radius: var(--r-lg);
  padding: var(--s-5);
  background: var(--surface-soft);
  display: flex; flex-direction: column; gap: var(--s-4);
  transition: transform .18s var(--ease);
}
.stat:hover { transform: translateY(-2px); }
.stat--brand   { background: var(--brand-soft); }
.stat--neutral { background: var(--ink-soft); }
.stat--good    { background: var(--good-soft); }
.stat--warning { background: var(--warning-soft); }
.stat--info    { background: var(--info-soft); }
.stat--critical{ background: var(--critical-soft); }

/* KPI tile — value, period-over-period delta, and a benchmark line */
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s-4); }
.kpi {
  border-radius: var(--r-lg);
  padding: var(--s-5);
  background: var(--surface-soft);
  display: flex; flex-direction: column; gap: var(--s-3);
  min-height: 132px;
  transition: transform .18s var(--ease);
}
.kpi:hover { transform: translateY(-2px); }
/* A tile you can open into its underlying records. */
.kpi--clickable { cursor: pointer; text-align: start; width: 100%; font: inherit; color: inherit; }
.kpi--clickable:hover { box-shadow: var(--shadow-md, 0 4px 16px rgba(0,0,0,.10)); }
.kpi--clickable:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.kpi__drill { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; color: var(--text-muted); }
.kpi--clickable:hover .kpi__drill { color: var(--brand); }
.kpi--brand   { background: var(--brand-soft); }
.kpi--good    { background: var(--good-soft); }
.kpi--warning { background: var(--warning-soft); }
.kpi--info    { background: var(--info-soft); }
.kpi--critical{ background: var(--critical-soft); }
.kpi--neutral { background: var(--ink-soft); }

.kpi__label { font-size: 13px; font-weight: 500; color: var(--text-secondary); }
.kpi__value { font-size: 28px; font-weight: 600; letter-spacing: -.02em; line-height: 1.05; }
.kpi__delta {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 500;
  padding: 2px 7px; border-radius: var(--r-full);
  background: rgba(255,255,255,.7);
  width: fit-content;
}
.kpi__delta--up   { color: #10805A; }
.kpi__delta--down { color: #B32B2A; }
.kpi__delta--flat { color: var(--text-muted); }
.kpi__delta svg { width: 13px; height: 13px; }
.kpi__compare { font-size: 11.5px; color: var(--text-muted); }
.kpi__bench {
  font-size: 11.5px; color: var(--text-secondary);
  padding-top: var(--s-2);
  border-top: 1px solid rgba(0,0,0,.06);
  margin-top: auto;
}

.stat__label { font-size: 13px; font-weight: 500; color: var(--text-secondary); }
.stat__row { display: flex; align-items: flex-end; gap: var(--s-3); }
.stat__value { font-size: 26px; font-weight: 600; letter-spacing: -.02em; line-height: 1.1; }
.stat__delta { font-size: 12px; font-weight: 500; display: flex; align-items: center; gap: 3px; padding-bottom: 3px; }
.stat__delta--up   { color: var(--good); }
.stat__delta--down { color: var(--critical); }
.stat__sub { font-size: 12px; color: var(--text-muted); }

/* --------------------------------------------------------------------------
   7. Buttons
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  height: 38px; padding: 0 var(--s-4);
  border-radius: var(--r-sm);
  font-size: 13.5px; font-weight: 500;
  transition: background .15s var(--ease), border-color .15s var(--ease), color .15s var(--ease);
  white-space: nowrap;
  border: 1px solid transparent;
}
.btn:disabled { opacity: .5; pointer-events: none; }
.btn svg { width: 16px; height: 16px; }

.btn--primary { background: var(--brand); color: #fff; }
.btn--primary:hover { background: var(--brand-hover); }
.btn--primary:active { background: var(--brand-active); }

.btn--secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn--secondary:hover { background: var(--surface-hover); border-color: var(--text-muted); }

.btn--ghost { background: transparent; color: var(--text-secondary); }
.btn--ghost:hover { background: var(--surface-hover); color: var(--text); }

.btn--danger { background: var(--critical); color: #fff; }
.btn--danger:hover { filter: brightness(.94); }

.btn--dark { background: var(--ink); color: #fff; }
.btn--dark:hover { filter: brightness(1.25); }

.btn--sm { height: 32px; padding: 0 var(--s-3); font-size: 12.5px; }
.btn--lg { height: 44px; padding: 0 var(--s-5); font-size: 14.5px; }
.btn--block { width: 100%; }

/* --------------------------------------------------------------------------
   8. Forms
   -------------------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--s-4); }
.field__label { font-size: 13px; font-weight: 500; color: var(--text-secondary); }
.field__label .req { color: var(--brand); }
.field__hint { font-size: 12px; color: var(--text-muted); }
.field__error { font-size: 12px; color: var(--critical); }

.input, .select, .textarea {
  width: 100%;
  height: 40px;
  padding: 0 var(--s-3);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
  color: var(--text);
}
.textarea { height: auto; min-height: 96px; padding: var(--s-3); resize: vertical; line-height: 1.6; }
.input::placeholder, .textarea::placeholder { color: var(--text-muted); }

.input:hover, .select:hover, .textarea:hover { border-color: var(--text-muted); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-ring);
}
.input.has-error, .select.has-error { border-color: var(--critical); }
.input:disabled, .select:disabled { background: var(--surface-sunken); color: var(--text-muted); }

.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%238A8F98' stroke-width='1.75' stroke-linecap='round'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left var(--s-3) center;
  padding-inline-start: var(--s-8);
}

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-4); }
.field-row--3 { grid-template-columns: repeat(3, 1fr); }

/* Input with a trailing affix button (password visibility) */
.input-wrap { position: relative; display: flex; align-items: center; }
/* The affix sits at the RTL trailing edge (physical left), but the field
   itself is dir="ltr" for latin credentials — so its padding must be stated
   physically, or the logical value lands on the opposite side and the text
   runs under the button. */
.input-wrap .input { padding-left: 42px; padding-right: var(--s-3); }
.input-affix {
  position: absolute; left: 4px;
  width: 32px; height: 32px;
  border-radius: var(--r-xs);
  display: grid; place-items: center;
  color: var(--text-muted);
  transition: color .15s var(--ease), background .15s var(--ease);
}
.input-affix:hover { color: var(--text); background: var(--surface-hover); }

/* Search */
.search {
  position: relative;
  display: flex; align-items: center;
  min-width: 260px;
}
.search svg {
  position: absolute; inset-inline-start: var(--s-3);
  width: 16px; height: 16px; color: var(--text-muted); pointer-events: none;
}
.search .input { padding-inline-start: var(--s-8); }

/* Checkbox */
.check { display: inline-flex; align-items: center; gap: var(--s-2); cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--brand); cursor: pointer; }

/* File drop */
.dropzone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--r-md);
  padding: var(--s-6);
  text-align: center;
  transition: border-color .15s var(--ease), background .15s var(--ease);
  cursor: pointer;
  display: block;
}
.dropzone:hover, .dropzone.is-over { border-color: var(--brand); background: var(--brand-softer); }
.dropzone__icon { color: var(--text-muted); margin: 0 auto var(--s-2); width: 26px; height: 26px; }
.dropzone.has-file { border-style: solid; border-color: var(--good); background: var(--good-soft); }

/* --------------------------------------------------------------------------
   9. Badges & pills
   -------------------------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 24px; padding: 0 9px;
  border-radius: var(--r-full);
  font-size: 12px; font-weight: 500;
  background: var(--surface-sunken); color: var(--text-secondary);
  white-space: nowrap;
}
.badge__dot { width: 6px; height: 6px; border-radius: var(--r-full); background: currentColor; flex: none; }

.badge--good     { background: var(--good-soft);     color: #10805A; }
.badge--warning  { background: var(--warning-soft);  color: #9A6A00; }
.badge--critical { background: var(--critical-soft); color: #B32B2A; }
.badge--info     { background: var(--info-soft);     color: #1C5CAB; }
.badge--brand    { background: var(--brand-soft);    color: var(--brand-active); }
.badge--neutral  { background: var(--ink-soft);      color: var(--ink); }

/* --------------------------------------------------------------------------
   10. Tables
   -------------------------------------------------------------------------- */
.table-wrap { width: 100%; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }

.table th {
  text-align: start;
  font-size: 12px; font-weight: 500; color: var(--text-muted);
  padding: var(--s-3) var(--s-4);
  border-block-end: 1px solid var(--border);
  white-space: nowrap;
  background: var(--surface);
  position: sticky; top: 0;
}
.table td {
  padding: var(--s-4);
  border-block-end: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr { transition: background .12s var(--ease); }
.table tbody tr:hover { background: var(--surface-hover); }
.table tbody tr:last-child td { border-block-end: none; }
.table .is-clickable { cursor: pointer; }
.table .cell-actions { text-align: end; white-space: nowrap; }

.cell-primary { display: flex; align-items: center; gap: var(--s-3); }
.cell-primary__text { display: flex; flex-direction: column; min-width: 0; }
.cell-primary__name { font-weight: 500; }

/* Filter row + pager */
.filters {
  display: flex; align-items: center; gap: var(--s-3);
  flex-wrap: wrap;
  margin-bottom: var(--s-4);
}
.filters .spacer { margin-inline-start: auto; }
.filters .select { width: auto; min-width: 150px; }

.pager {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-4);
  border-block-start: 1px solid var(--border);
}

/* Two-column profile layout */
.profile { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: var(--s-4); align-items: start; }
@media (max-width: 1100px) { .profile { grid-template-columns: 1fr; } }

.profile-hero {
  display: flex; align-items: center; gap: var(--s-4);
  padding: var(--s-5);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  margin-bottom: var(--s-4);
  flex-wrap: wrap;
}
.profile-hero .spacer { margin-inline-start: auto; }

/* --------------------------------------------------------------------------
   11. Empty / loading states
   -------------------------------------------------------------------------- */
.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center;
  padding: var(--s-10) var(--s-6);
  gap: var(--s-3);
}
.empty__icon {
  width: 52px; height: 52px;
  border-radius: var(--r-lg);
  background: var(--surface-sunken);
  display: grid; place-items: center;
  color: var(--text-muted);
  margin-bottom: var(--s-1);
}
.empty__title { font-size: 15px; font-weight: 600; }
.empty__text { font-size: 13px; color: var(--text-muted); max-width: 380px; }

.skeleton {
  background: linear-gradient(90deg, var(--surface-sunken) 25%, var(--surface-soft) 50%, var(--surface-sunken) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--r-sm);
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.skeleton--text { height: 12px; margin: 6px 0; }
.skeleton--row  { height: 52px; margin-bottom: 1px; border-radius: 0; }

.spinner {
  width: 16px; height: 16px;
  border: 2px solid currentColor; border-top-color: transparent;
  border-radius: var(--r-full);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------------------------
   12. Modals
   -------------------------------------------------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(20, 22, 26, .42);
  backdrop-filter: blur(2px);
  z-index: 60;
  display: grid; place-items: center;
  padding: var(--s-5);
  animation: fade .18s var(--ease);
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--surface);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 520px;
  max-height: calc(100vh - 80px);
  display: flex; flex-direction: column;
  animation: rise .22s var(--ease);
}
@keyframes rise { from { opacity: 0; transform: translateY(12px) scale(.99); } to { opacity: 1; transform: none; } }

.modal--lg { max-width: 720px; }
.modal--sm { max-width: 420px; }

.modal__head {
  display: flex; align-items: flex-start; gap: var(--s-3);
  padding: var(--s-5) var(--s-5) var(--s-4);
  border-block-end: 1px solid var(--border);
}
.modal__title { font-size: 16px; font-weight: 600; }
.modal__sub { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.modal__close { margin-inline-start: auto; }
.modal__body { padding: var(--s-5); overflow-y: auto; flex: 1; }
.modal__foot {
  display: flex; align-items: center; gap: var(--s-2);
  padding: var(--s-4) var(--s-5);
  border-block-start: 1px solid var(--border);
}
.modal__foot .spacer { margin-inline-start: auto; }

/* --------------------------------------------------------------------------
   13. Toasts
   -------------------------------------------------------------------------- */
.toast-root {
  position: fixed;
  inset-block-end: var(--s-6); inset-inline-start: var(--s-6);
  z-index: 90;
  display: flex; flex-direction: column; gap: var(--s-2);
}
.toast {
  display: flex; align-items: center; gap: var(--s-3);
  min-width: 280px; max-width: 400px;
  padding: var(--s-3) var(--s-4);
  background: var(--ink); color: #fff;
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  font-size: 13.5px;
  animation: toast-in .22s var(--ease);
}
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.toast.is-out { animation: toast-out .18s var(--ease) forwards; }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px); } }
.toast__icon { width: 18px; height: 18px; flex: none; }
.toast--success .toast__icon { color: #4ADE9B; }
.toast--error   .toast__icon { color: #FF8785; }

/* --------------------------------------------------------------------------
   14. Tabs
   -------------------------------------------------------------------------- */
.tabs {
  display: flex; align-items: center; gap: var(--s-1);
  border-block-end: 1px solid var(--border);
  margin-bottom: var(--s-5);
  overflow-x: auto;
}
.tab {
  padding: var(--s-3) var(--s-4);
  font-size: 13.5px; font-weight: 500;
  color: var(--text-secondary);
  border-block-end: 2px solid transparent;
  margin-block-end: -1px;
  white-space: nowrap;
  transition: color .15s var(--ease), border-color .15s var(--ease);
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--brand); border-block-end-color: var(--brand); font-weight: 600; }
.tab__count {
  margin-inline-start: 6px;
  font-size: 11px; padding: 1px 6px;
  border-radius: var(--r-full);
  background: var(--surface-sunken); color: var(--text-secondary);
}
.tab.is-active .tab__count { background: var(--brand-soft); color: var(--brand-active); }

/* Segmented control */
.segment {
  display: inline-flex; padding: 3px;
  background: var(--surface-sunken);
  border-radius: var(--r-sm);
  gap: 2px;
}
.segment button {
  padding: 6px var(--s-3);
  border-radius: var(--r-xs);
  font-size: 12.5px; font-weight: 500;
  color: var(--text-secondary);
  transition: background .15s var(--ease), color .15s var(--ease);
}
.segment button.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* --------------------------------------------------------------------------
   15. Charts
   -------------------------------------------------------------------------- */
.chart { position: relative; width: 100%; }
.chart svg { width: 100%; overflow: visible; }

.chart-grid line { stroke: var(--border); stroke-width: 1; }
.chart-axis text { fill: var(--text-muted); font-size: 11px; }
.chart-line { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chart-dot { stroke: var(--surface); stroke-width: 2; }

.chart-tip {
  position: absolute;
  background: var(--ink); color: #fff;
  border-radius: var(--r-sm);
  padding: var(--s-2) var(--s-3);
  font-size: 12px;
  pointer-events: none;
  box-shadow: var(--shadow-md);
  z-index: 5;
  white-space: nowrap;
  transform: translate(50%, -100%);
  opacity: 0; transition: opacity .12s var(--ease);
}
.chart-tip.is-on { opacity: 1; }
.chart-tip__row { display: flex; align-items: center; gap: 6px; }
.chart-tip__swatch { width: 8px; height: 8px; border-radius: 2px; flex: none; }

.legend { display: flex; flex-wrap: wrap; gap: var(--s-4); align-items: center; }
.legend__item { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-secondary); }
.legend__swatch { width: 9px; height: 9px; border-radius: 3px; flex: none; }

/* Horizontal bar list (traffic-by-website style) */
.barlist { display: flex; flex-direction: column; gap: var(--s-4); }
.barlist__row { display: grid; grid-template-columns: 1fr 100px auto; align-items: center; gap: var(--s-3); }
.barlist__label { font-size: 13px; }
.barlist__track { height: 6px; background: var(--surface-sunken); border-radius: var(--r-full); overflow: hidden; }
.barlist__fill { height: 100%; border-radius: var(--r-full); transition: width .5s var(--ease); }
.barlist__value { font-size: 12.5px; color: var(--text-secondary); min-width: 42px; text-align: end; }

/* --------------------------------------------------------------------------
   16. Timeline / activity
   -------------------------------------------------------------------------- */
.feed { display: flex; flex-direction: column; }
.feed__item { display: flex; gap: var(--s-3); padding: var(--s-3) 0; position: relative; }
.feed__item:not(:last-child)::before {
  content: ""; position: absolute;
  inset-block-start: 34px; inset-block-end: -6px;
  inset-inline-start: 15px;
  width: 1px; background: var(--border);
}
.feed__icon {
  width: 32px; height: 32px; flex: none;
  border-radius: var(--r-full);
  display: grid; place-items: center;
  background: var(--surface-sunken); color: var(--text-secondary);
  position: relative; z-index: 1;
}
.feed__body { min-width: 0; flex: 1; }
.feed__title { font-size: 13.5px; }
.feed__time { font-size: 12px; color: var(--text-muted); }

/* --------------------------------------------------------------------------
   17. Login
   -------------------------------------------------------------------------- */
.auth {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
}
.auth__panel {
  display: flex; flex-direction: column; justify-content: center;
  padding: var(--s-10) var(--s-9);
  max-width: 460px; width: 100%; margin: 0 auto;
}
.auth__brand { display: flex; align-items: center; gap: var(--s-3); margin-bottom: var(--s-8); }
.auth__title { font-size: 24px; font-weight: 600; letter-spacing: -.01em; }
.auth__sub { color: var(--text-muted); margin-top: var(--s-1); margin-bottom: var(--s-7); }

.auth__art {
  background: var(--ink);
  color: #fff;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: var(--s-9);
  position: relative; overflow: hidden;
}
.auth__art::before {
  content: ""; position: absolute;
  width: 460px; height: 460px; border-radius: 50%;
  background: var(--brand); opacity: .16;
  filter: blur(70px);
  inset-block-start: -110px; inset-inline-start: -110px;
}
.auth__art::after {
  content: ""; position: absolute;
  width: 320px; height: 320px; border-radius: 50%;
  background: var(--brand); opacity: .12;
  filter: blur(60px);
  inset-block-end: -90px; inset-inline-end: -70px;
}
.auth__art-inner { position: relative; z-index: 1; }
.auth__quote { font-size: 26px; font-weight: 300; line-height: 1.55; letter-spacing: -.01em; }
.auth__quote b { font-weight: 600; color: #fff; }
.auth__stats { display: flex; gap: var(--s-7); position: relative; z-index: 1; }
.auth__stat-value { font-size: 22px; font-weight: 600; }
.auth__stat-label { font-size: 12.5px; opacity: .6; }

.alert {
  display: flex; align-items: flex-start; gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-sm);
  font-size: 13px;
  margin-bottom: var(--s-4);
}
.alert--error   { background: var(--critical-soft); color: #B32B2A; }
.alert--info    { background: var(--info-soft);     color: #1C5CAB; }
.alert--warning { background: var(--warning-soft);  color: #9A6A00; }
.alert--good    { background: var(--good-soft);     color: #10805A; }
.alert svg { width: 17px; height: 17px; flex: none; margin-top: 1px; }

/* --------------------------------------------------------------------------
   18. Layout helpers
   -------------------------------------------------------------------------- */
.grid { display: grid; gap: var(--s-4); }
.grid--2 { grid-template-columns: repeat(2, 1fr); }
.grid--3 { grid-template-columns: repeat(3, 1fr); }
.grid--4 { grid-template-columns: repeat(4, 1fr); }
.grid--main-side { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.grid--side-main { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }

.row { display: flex; align-items: center; gap: var(--s-3); }
.row--wrap { flex-wrap: wrap; }
.row .spacer { margin-inline-start: auto; }
.col { display: flex; flex-direction: column; gap: var(--s-3); }

.mt-0{margin-top:0}.mt-2{margin-top:var(--s-2)}.mt-3{margin-top:var(--s-3)}
.mt-4{margin-top:var(--s-4)}.mt-5{margin-top:var(--s-5)}.mt-6{margin-top:var(--s-6)}
.mb-2{margin-bottom:var(--s-2)}.mb-3{margin-bottom:var(--s-3)}
.mb-4{margin-bottom:var(--s-4)}.mb-5{margin-bottom:var(--s-5)}.mb-6{margin-bottom:var(--s-6)}

.divider { height: 1px; background: var(--border); margin: var(--s-5) 0; }

/* Definition list used across profile panels */
.dl { display: grid; grid-template-columns: 140px 1fr; gap: var(--s-3) var(--s-4); }
.dl dt { font-size: 13px; color: var(--text-muted); }
.dl dd { margin: 0; font-size: 13.5px; }

/* File chips */
.file-chip {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-3);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  transition: border-color .15s var(--ease), background .15s var(--ease);
}
.file-chip:hover { border-color: var(--border-strong); background: var(--surface-soft); }
.file-chip__icon {
  width: 34px; height: 34px; flex: none;
  border-radius: var(--r-sm);
  background: var(--surface-sunken);
  display: grid; place-items: center;
  color: var(--text-secondary);
}
.file-chip__meta { font-size: 12px; color: var(--text-muted); }

/* Outcome picker — the three renewal choices */
.outcome-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s-3); }
.outcome {
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s-4);
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: var(--s-2);
  transition: border-color .15s var(--ease), background .15s var(--ease);
}
.outcome:hover { border-color: var(--border-strong); background: var(--surface-soft); }
.outcome.is-selected { border-color: var(--brand); background: var(--brand-softer); }
.outcome__icon {
  width: 38px; height: 38px; border-radius: var(--r-full);
  display: grid; place-items: center;
}
.outcome--renewed .outcome__icon { background: var(--good-soft); color: #10805A; }
.outcome--pending .outcome__icon { background: var(--warning-soft); color: #9A6A00; }
.outcome--lost    .outcome__icon { background: var(--critical-soft); color: #B32B2A; }
.outcome__title { font-size: 13.5px; font-weight: 600; }
.outcome__desc { font-size: 11.5px; color: var(--text-muted); line-height: 1.45; }

/* Approval banner */
.approval-bar {
  display: flex; align-items: center; gap: var(--s-4);
  padding: var(--s-4) var(--s-5);
  background: var(--warning-soft);
  border-radius: var(--r-md);
  margin-bottom: var(--s-5);
}
.approval-bar .spacer { margin-inline-start: auto; }

/* --------------------------------------------------------------------------
   19. Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 1200px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .grid--4 { grid-template-columns: repeat(2, 1fr); }
  .grid--main-side, .grid--side-main { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  :root { --sidebar-w: 0px; }
  .shell { grid-template-columns: 1fr; }
  /* Single column now — drop the desktop placement or main lands off-grid */
  .shell > .main { grid-column: 1; }
  .sidebar {
    grid-column: 1;
    position: fixed; inset-block: 0; inset-inline-end: 0;
    width: 260px; z-index: 50;
    transform: translateX(100%);
    transition: transform .24s var(--ease);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.is-open { transform: none; }
  .sidebar-scrim {
    position: fixed; inset: 0; background: rgba(20,22,26,.35);
    z-index: 45;
  }
  .page { padding: var(--s-5); }
  .topbar { padding: 0 var(--s-5); }
  .auth { grid-template-columns: 1fr; }
  .auth__art { display: none; }
  .grid--2, .grid--3 { grid-template-columns: 1fr; }
  .outcome-grid { grid-template-columns: 1fr; }
  .field-row, .field-row--3 { grid-template-columns: 1fr; }
  .dl { grid-template-columns: 1fr; gap: var(--s-1) 0; }
  .dl dd { margin-bottom: var(--s-3); }
}

@media (max-width: 600px) {
  .kpis { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr; }
  .toast-root { inset-inline: var(--s-4); inset-block-end: var(--s-4); }
  .toast { min-width: 0; max-width: none; }
}

/* Desktop: hide the mobile menu trigger */
@media (min-width: 901px) { .menu-trigger { display: none; } }

@media print {
  .sidebar, .topbar, .btn, .toast-root { display: none !important; }
  .page { padding: 0; }
  .card { break-inside: avoid; border-color: #ccc; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
