/* ──────────────────────────────────────────────────────────────────────────
   AVS App Stylesheet — composes from tokens.css
   ──────────────────────────────────────────────────────────────────────────
   Rule: no raw hex, no raw px outside this file's grid utilities.
   Every component below has variants + states (hover/focus/disabled/error).
   ────────────────────────────────────────────────────────────────────────── */

@import url('tokens.css');

/* ── RESET ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-base);
  color: var(--text);
  background: var(--bg);
  font-feature-settings: var(--font-feature);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; transition: color var(--t-fast); }
a:hover { color: var(--accent-hover); }
a:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--r-1); }

/* ── TYPOGRAPHY UTILITIES ───────────────────────────────────────────── */
.t-xs   { font-size: var(--fs-xs);   line-height: var(--lh-xs); }
.t-sm   { font-size: var(--fs-sm);   line-height: var(--lh-sm); }
.t-md   { font-size: var(--fs-md);   line-height: var(--lh-md); }
.t-lg   { font-size: var(--fs-lg);   line-height: var(--lh-lg); }
.t-xl   { font-size: var(--fs-xl);   line-height: var(--lh-xl); letter-spacing: var(--tracking-tight); }
.t-2xl  { font-size: var(--fs-2xl);  line-height: var(--lh-2xl); letter-spacing: var(--tracking-tight); }
.t-3xl  { font-size: var(--fs-3xl);  line-height: var(--lh-3xl); letter-spacing: var(--tracking-tight); }
.t-mut  { color: var(--text-muted); }
.t-sub  { color: var(--text-subtle); }
.t-med  { font-weight: var(--fw-medium); }
.t-semi { font-weight: var(--fw-semi); }
.t-num  { font-feature-settings: var(--font-feature-num); font-variant-numeric: tabular-nums; }
.t-label {
  font-size: var(--fs-xs); line-height: var(--lh-xs);
  font-weight: var(--fw-medium);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
}

/* ── LAYOUT ─────────────────────────────────────────────────────────── */
.container { max-width: var(--content-max); margin: 0 auto; padding: 0 var(--s-6); }
.stack    > * + * { margin-top: var(--s-4); }
.stack-sm > * + * { margin-top: var(--s-2); }
.stack-lg > * + * { margin-top: var(--s-6); }
.row { display: flex; gap: var(--s-3); align-items: center; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: var(--s-3); }
.col { display: flex; flex-direction: column; gap: var(--s-3); }
.grow { flex: 1 1 auto; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s-4); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s-4); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s-4); }
.hidden { display: none; }

/* ── PAGE HEADER — compact, 1-line ellipsis title ───────────────────── */
.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s-4);
  height: var(--header-h);
  padding: 0 var(--s-6);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: var(--z-sticky);
}
.page-head__title {
  font-size: var(--fs-md);
  font-weight: var(--fw-semi);
  letter-spacing: var(--tracking-tight);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex: 1 1 auto; min-width: 0;
}
.page-head__sub {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  margin-left: var(--s-2);
}
.page-head__actions { display: flex; gap: var(--s-2); align-items: center; flex-shrink: 0; }

/* ── CARD ───────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-3);
  padding: var(--s-6);
}
.card--inset { background: var(--surface-2); border: none; }
.card--clickable { transition: border-color var(--t-fast), box-shadow var(--t-fast); cursor: pointer; }
.card--clickable:hover { border-color: var(--border-strong); box-shadow: var(--sh-sm); }
.card__head {
  display: flex; justify-content: space-between; align-items: center;
  margin: calc(var(--s-6) * -1) calc(var(--s-6) * -1) var(--s-5);
  padding: var(--s-4) var(--s-6);
  border-bottom: 1px solid var(--border);
}
.card__head h3 { margin: 0; font-size: var(--fs-md); font-weight: var(--fw-semi); }

/* ── BUTTONS ────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  height: 40px;
  padding: 0 var(--s-4);
  border-radius: var(--r-2);
  border: 1px solid transparent;
  background: transparent;
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
  line-height: 1;
  cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
  white-space: nowrap;
  text-decoration: none;
}
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn--primary  { background: var(--accent);   color: var(--text-inverse); }
.btn--primary:hover:not(:disabled)  { background: var(--accent-hover); }

.btn--secondary { background: var(--surface); color: var(--accent-ink); border-color: var(--border-strong); }
.btn--secondary:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }

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

.btn--danger   { background: var(--bad); color: var(--text-inverse); }
.btn--danger:hover:not(:disabled)   { background: var(--bad-ink); }

.btn--sm { height: 32px; padding: 0 var(--s-3); font-size: var(--fs-sm); }
.btn--lg { height: 48px; padding: 0 var(--s-5); font-size: var(--fs-md); }
.btn--icon-only { width: 40px; padding: 0; }
.btn--icon-only.btn--sm { width: 32px; }

.btn__spinner {
  width: 14px; height: 14px;
  border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%;
  animation: spin 600ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── INPUTS ─────────────────────────────────────────────────────────── */
.field {
  display: flex; flex-direction: column; gap: var(--s-1);
  min-width: 0;
}
.field__label {
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--text-muted);
}
.field__label .req { color: var(--bad); margin-left: 2px; }
.field__hint {
  font-size: var(--fs-xs);
  color: var(--text-subtle);
}
.field__error {
  font-size: var(--fs-xs);
  color: var(--bad);
}

.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-2);
  color: var(--text);
  font-size: var(--fs-base);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.input::placeholder { color: var(--text-subtle); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-subtle); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}
.input:disabled, .select:disabled, .textarea:disabled {
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: not-allowed;
}
.field--error .input,
.field--error .select,
.field--error .textarea { border-color: var(--bad); }
.field--error .input:focus,
.field--error .select:focus,
.field--error .textarea:focus { box-shadow: var(--ring-bad); }

.textarea { height: auto; padding: var(--s-2) var(--s-3); min-height: 96px; resize: vertical; }
.input--num { text-align: right; font-feature-settings: var(--font-feature-num); font-variant-numeric: tabular-nums; }

/* Native select with custom caret (no JS) */
.select {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='none' stroke='%236E6B62' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round' d='M3 4.5l3 3 3-3'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--s-3) center;
  padding-right: var(--s-7);
  cursor: pointer;
}

/* Input with leading icon */
.input-wrap { position: relative; }
.input-wrap > .input { padding-left: var(--s-8); }
.input-wrap__icon {
  position: absolute; left: var(--s-3); top: 50%; transform: translateY(-50%);
  color: var(--text-subtle); pointer-events: none;
}

/* Checkbox / Radio */
.check {
  display: inline-flex; align-items: center; gap: var(--s-2);
  cursor: pointer; user-select: none;
  font-size: var(--fs-base);
}
.check input { position: absolute; opacity: 0; pointer-events: none; }
.check__box {
  width: 18px; height: 18px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--r-1);
  background: var(--surface);
  display: inline-flex; align-items: center; justify-content: center;
  transition: border-color var(--t-fast), background var(--t-fast);
  flex-shrink: 0;
}
.check input:checked + .check__box {
  background: var(--accent);
  border-color: var(--accent);
}
.check input:checked + .check__box::after {
  content: '';
  width: 10px; height: 6px;
  border: 1.5px solid var(--text-inverse);
  border-top: none; border-right: none;
  transform: rotate(-45deg) translateY(-1px);
}
.check input:focus-visible + .check__box { box-shadow: var(--ring); }

/* Toggle switch — for binary on/off */
.switch { display: inline-flex; align-items: center; gap: var(--s-2); cursor: pointer; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch__track {
  width: 36px; height: 20px; border-radius: var(--r-pill);
  background: var(--border-strong);
  position: relative;
  transition: background var(--t-fast);
}
.switch__track::after {
  content: ''; position: absolute;
  width: 16px; height: 16px;
  background: var(--surface);
  border-radius: 50%;
  top: 2px; left: 2px;
  transition: transform var(--t-fast);
  box-shadow: var(--sh-xs);
}
.switch input:checked + .switch__track { background: var(--accent); }
.switch input:checked + .switch__track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch__track { box-shadow: var(--ring); }

/* ── BADGES — status pills ──────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: var(--s-1);
  height: 22px; padding: 0 var(--s-2);
  border-radius: var(--r-pill);
  font-size: var(--fs-xs); font-weight: var(--fw-medium);
  line-height: 1;
  white-space: nowrap;
}
.badge::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.badge--good { background: var(--good-soft); color: var(--good-ink); }
.badge--warn { background: var(--warn-soft); color: var(--warn-ink); }
.badge--bad  { background: var(--bad-soft);  color: var(--bad-ink); }
.badge--info { background: var(--info-soft); color: var(--info-ink); }
.badge--accent { background: var(--accent-soft); color: var(--accent-ink); }
.badge--mute   { background: var(--surface-2); color: var(--text-muted); }
.badge--plain  { padding: 0 var(--s-2); }
.badge--plain::before { display: none; }

/* ── METRIC TILE — dashboard ────────────────────────────────────────── */
.metric {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-3);
  padding: var(--s-5);
  display: flex; flex-direction: column; gap: var(--s-2);
}
.metric__label {
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
}
.metric__value {
  font-size: var(--fs-2xl);
  line-height: 1;
  font-weight: var(--fw-semi);
  letter-spacing: var(--tracking-tight);
  font-feature-settings: var(--font-feature-num);
  font-variant-numeric: tabular-nums;
}
.metric__trend {
  font-size: var(--fs-xs);
  color: var(--text-subtle);
}

/* ── TABLE ──────────────────────────────────────────────────────────── */
.tbl-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-3);
  overflow: hidden;
}
.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td {
  text-align: left;
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--border);
}
.tbl th {
  background: var(--surface-2);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  position: sticky; top: 0;
  white-space: nowrap;
}
.tbl tbody tr { transition: background var(--t-fast); cursor: pointer; }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl tbody tr.is-selected { background: var(--accent-soft); }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl td { font-size: var(--fs-base); vertical-align: middle; }
.tbl td.num { text-align: right; font-feature-settings: var(--font-feature-num); font-variant-numeric: tabular-nums; }
.tbl td.center { text-align: center; }

/* Loading state — shimmer rows */
.tbl-shimmer td { padding: var(--s-4); }
.tbl-shimmer .shim {
  height: 12px;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
  border-radius: var(--r-1);
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── EMPTY STATE ────────────────────────────────────────────────────── */
.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center;
  padding: var(--s-9) var(--s-6);
  gap: var(--s-3);
  color: var(--text-muted);
}
.empty__icon {
  width: 48px; height: 48px;
  border-radius: var(--r-3);
  background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-subtle);
}
.empty__title { font-size: var(--fs-md); font-weight: var(--fw-semi); color: var(--text); }
.empty__body  { font-size: var(--fs-sm); max-width: 320px; }
.empty__cta   { margin-top: var(--s-2); }

/* ── TABS — underline only ──────────────────────────────────────────── */
.tabs {
  display: flex; gap: var(--s-5);
  border-bottom: 1px solid var(--border);
}
.tabs__tab {
  padding: var(--s-3) 0;
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  transition: color var(--t-fast), border-color var(--t-fast);
  background: none; border-top: none; border-left: none; border-right: none;
}
.tabs__tab:hover { color: var(--text); }
.tabs__tab.is-active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── BREADCRUMB — Zone → Jamiat → Mauze ─────────────────────────────── */
.crumb {
  display: flex; align-items: center; gap: var(--s-2);
  font-size: var(--fs-sm); color: var(--text-muted);
}
.crumb a { color: var(--text-muted); }
.crumb a:hover { color: var(--text); }
.crumb__sep { color: var(--text-subtle); }
.crumb__last { color: var(--text); font-weight: var(--fw-medium); }

/* ── INLINE COLLAPSIBLE FORM (sub-tab actions, per Moiz pref) ───────── */
.inline-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-3);
  overflow: hidden;
}
.inline-form__head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  cursor: pointer; user-select: none;
  transition: background var(--t-fast);
}
.inline-form__head:hover { background: var(--surface-2); }
.inline-form__head h4 {
  margin: 0; font-size: var(--fs-base); font-weight: var(--fw-medium);
}
.inline-form__caret {
  width: 16px; height: 16px;
  transition: transform var(--t-base);
  color: var(--text-muted);
}
.inline-form.is-open .inline-form__caret { transform: rotate(180deg); }
.inline-form__body {
  display: none;
  padding: var(--s-4); border-top: 1px solid var(--border);
}
.inline-form.is-open .inline-form__body { display: block; }

/* ── MODAL — top-level actions only ─────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(31, 30, 27, 0.45);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: var(--z-modal);
  padding: var(--s-4);
}
.modal {
  background: var(--surface);
  border-radius: var(--r-4);
  box-shadow: var(--sh-lg);
  width: 100%; max-width: 560px;
  display: flex; flex-direction: column;
  max-height: calc(100vh - var(--s-8));
}
.modal__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s-5) var(--s-6);
  border-bottom: 1px solid var(--border);
}
.modal__head h3 { margin: 0; font-size: var(--fs-lg); font-weight: var(--fw-semi); }
.modal__body { padding: var(--s-6); overflow-y: auto; }
.modal__foot {
  display: flex; justify-content: flex-end; gap: var(--s-2);
  padding: var(--s-4) var(--s-6);
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--r-4) var(--r-4);
}

/* ── FILTER CHIPS ───────────────────────────────────────────────────── */
.chips { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.chip {
  display: inline-flex; align-items: center; gap: var(--s-1);
  height: 28px; padding: 0 var(--s-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-pill);
  background: var(--surface);
  font-size: var(--fs-sm); color: var(--text-muted);
  cursor: pointer; transition: all var(--t-fast);
}
.chip:hover { border-color: var(--text-subtle); color: var(--text); }
.chip.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-ink);
}

/* ── DIVIDER ────────────────────────────────────────────────────────── */
.divider { height: 1px; background: var(--border); border: none; margin: var(--s-4) 0; }

/* ── HELPERS ────────────────────────────────────────────────────────── */
.mt-0 { margin-top: 0; }
.mt-2 { margin-top: var(--s-2); }
.mt-4 { margin-top: var(--s-4); }
.mt-6 { margin-top: var(--s-6); }
.mb-2 { margin-bottom: var(--s-2); }
.mb-4 { margin-bottom: var(--s-4); }
.mb-6 { margin-bottom: var(--s-6); }
.gap-2 { gap: var(--s-2); }
.gap-4 { gap: var(--s-4); }
.gap-6 { gap: var(--s-6); }
