/* INSIDE audit tool and admin panel. Builds on styles.css tokens and components. */

.app { display: flex; flex-direction: column; min-height: 100vh; }
.app main { flex: 1; }
.inline-form { display: inline; margin: 0; }

/* ---------- header / footer ---------- */
.app-header { background: var(--white); border-block-end: 1px solid var(--line); }
.app-header__inner { display: flex; align-items: center; gap: var(--space-4); min-height: 4.25rem; flex-wrap: wrap; padding-block: 0.5rem; }
.app-header .brand img { height: 40px; width: auto; }
.app-header__title { color: var(--muted); font-weight: 600; font-size: 0.95rem; padding-inline-start: var(--space-4); border-inline-start: 1px solid var(--line); }
.app-header__actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-inline-start: auto; align-items: center; }
.app-footer { padding-block: var(--space-5); color: var(--muted); font-size: 0.85rem; border-block-start: 1px solid var(--line); background: var(--stone-200); }
@media (max-width: 599.98px) { .app-header__title { display: none; } }

/* ---------- code entry / login ---------- */
.code-entry { display: grid; place-items: center; padding-block: clamp(2.5rem, 6vw, 5rem); }
.code-card { width: 100%; max-width: 32rem; }
.code-card h1 { font-size: var(--fs-700); margin-block-end: var(--space-3); }
.code-card .lead { margin-block-end: var(--space-5); font-size: 1.05rem; }
.code-input { font-size: 1.9rem; letter-spacing: 0.5em; text-align: center; font-weight: 600; font-family: var(--font-sans); padding-inline-start: 0.5em; }
.code-submit { width: 100%; margin-block-start: var(--space-5); }
.code-note { margin-block-start: var(--space-5); color: var(--muted); font-size: 0.9rem; }
.alert p { margin: 0; }
.alert__title { font-family: var(--font-sans); font-size: 1rem; color: inherit; margin-block-end: 0.3rem; }
:lang(ar) .alert__title { font-family: var(--font-ar); }

/* ---------- sticky progress bar ---------- */
.audit-bar { position: sticky; top: 0; z-index: 30; background: rgba(255, 255, 255, 0.96); border-block-end: 1px solid var(--line); backdrop-filter: blur(8px); }
.audit-bar__inner { display: flex; align-items: center; gap: var(--space-4); min-height: 3.75rem; flex-wrap: wrap; }
.audit-bar__progress { flex: 1; min-width: 12rem; display: grid; gap: 0.35rem; }
.audit-bar__label { font-size: 0.9rem; font-weight: 600; color: var(--navy); }
.audit-bar__status { font-size: 0.85rem; color: var(--success); min-width: 5rem; }
.meter { display: block; height: 8px; border-radius: 99px; background: var(--stone-200); overflow: hidden; }
.meter__fill { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--navy), var(--teal), var(--gold)); transition: width 0.3s; }
[dir="rtl"] .meter__fill { background: linear-gradient(-90deg, var(--navy), var(--teal), var(--gold)); }
.meter--lg { height: 12px; }

/* ---------- layout ---------- */
.audit-layout { display: grid; gap: var(--space-6); padding-block: var(--space-6) var(--space-8); }
@media (min-width: 1000px) { .audit-layout { grid-template-columns: 17rem 1fr; align-items: start; } }
.audit-layout > * { min-width: 0; }
.audit-nav ol { list-style: none; display: grid; gap: 0.25rem; }
@media (min-width: 1000px) { .audit-nav { position: sticky; top: 5rem; max-height: calc(100vh - 6rem); overflow-y: auto; } }
@media (max-width: 999.98px) {
  .audit-nav ol { display: flex; overflow-x: auto; gap: 0.4rem; padding-block-end: 0.4rem; }
  .audit-nav li { flex: none; }
  .audit-nav__link > span:nth-child(2) { display: none; }
}
.audit-nav__link {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.55rem 0.7rem; border-radius: var(--radius-sm);
  color: var(--ink); text-decoration: none; font-size: 0.9rem; line-height: 1.3;
  border: 1px solid transparent;
}
.audit-nav__link:hover { background: var(--white); border-color: var(--line); color: var(--navy); }
.audit-nav__link[aria-current] { background: var(--white); border-color: var(--navy); color: var(--navy); font-weight: 600; box-shadow: var(--shadow-sm); }
.audit-nav__num { display: grid; place-items: center; flex: none; width: 1.7rem; height: 1.7rem; border-radius: 50%; background: var(--navy-100); color: var(--navy); font-size: 0.78rem; font-weight: 700; }
.audit-nav__count { margin-inline-start: auto; white-space: nowrap; font-size: 0.75rem; color: var(--muted); font-weight: 600; direction: ltr; }
.audit-nav__count.is-done { color: var(--success); }
.audit-nav__count.is-done::after { content: " ✓"; }

.audit-panel { background: var(--white); border: 1px solid var(--stone-200); border-radius: var(--radius-lg); padding: clamp(1.25rem, 1rem + 2vw, 2.5rem); box-shadow: var(--shadow-sm); }
.audit-panel h1, .audit-panel > h2 { font-size: var(--fs-700); margin-block-end: var(--space-3); }
.audit-panel .lead { font-size: 1.02rem; }
.audit-pager { display: flex; justify-content: space-between; gap: var(--space-3); margin-block-start: var(--space-6); padding-block-start: var(--space-5); border-block-start: 1px solid var(--stone-200); flex-wrap: wrap; }

/* ---------- rating scale legend ---------- */
.scale { display: grid; gap: 0.5rem; }
.scale__row { display: grid; gap: 0.25rem 1rem; padding: 0.8rem 1rem; border-radius: var(--radius); background: var(--stone); }
@media (min-width: 720px) { .scale__row { grid-template-columns: 15rem 1fr; align-items: center; } }
.scale dt { font-weight: 600; color: var(--navy); display: flex; align-items: center; gap: 0.6rem; }
.scale dd { margin: 0; color: var(--muted); font-size: 0.92rem; }

.pill { display: inline-grid; place-items: center; min-width: 2rem; height: 2rem; padding-inline: 0.5rem; border-radius: 99px; font-weight: 700; font-size: 0.85rem; background: var(--stone-200); color: var(--ink); }
.pill--1 { background: #FBE4E1; color: #8A1C12; }
.pill--2 { background: #FCEBD3; color: #7A4A06; }
.pill--3 { background: var(--teal-100); color: var(--teal-700); }
.pill--4 { background: var(--success-100); color: var(--success); }
.pill--NA { background: var(--stone-200); color: var(--muted); }

/* ---------- standards ---------- */
.std-list { display: grid; gap: 0.75rem; margin-block-start: var(--space-6); }
.std { margin: 0; padding: 1rem 1.15rem; border: 1px solid var(--stone-200); border-radius: var(--radius); background: var(--white); transition: border-color 0.2s, box-shadow 0.2s; }
.std:not(.std--empty) { border-color: var(--stone-300); background: #FCFBF8; }
.std--flag { border-color: var(--error); box-shadow: 0 0 0 3px var(--error-100); }
.std legend { display: flex; gap: 0.75rem; padding: 0; float: left; width: 100%; margin-block-end: 0.75rem; font-weight: 500; color: var(--ink); line-height: 1.5; }
[dir="rtl"] .std legend { float: right; }
.std legend + * { clear: both; }
.std__id { flex: none; min-width: 2.6rem; color: var(--teal-700); font-weight: 700; direction: ltr; }
.std__ratings { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.rate { position: relative; cursor: pointer; }
.rate input { position: absolute; opacity: 0; width: 100%; height: 100%; inset: 0; margin: 0; cursor: pointer; }
.rate span {
  display: grid; place-items: center; min-width: 3rem; height: 2.6rem; padding-inline: 0.75rem;
  border: 1.5px solid #8F92A8; border-radius: var(--radius-sm); background: var(--white);
  font-weight: 700; color: var(--navy); transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.rate:hover span { border-color: var(--navy); }
.rate input:focus-visible + span { outline: 3px solid var(--teal-700); outline-offset: 2px; }
.rate input:checked + span { color: var(--white); border-color: transparent; }
.rate--1 input:checked + span { background: #B42318; }
.rate--2 input:checked + span { background: #B56B06; }
.rate--3 input:checked + span { background: var(--teal-700); }
.rate--4 input:checked + span { background: var(--success); }
.rate--NA input:checked + span { background: #5D6076; }
.std__notes { margin-block-start: 0.6rem; }
.std__notes summary { cursor: pointer; color: var(--teal-700); font-size: 0.88rem; font-weight: 600; width: max-content; }
.std__notes textarea { margin-block-start: 0.5rem; min-height: 4rem; }

/* ---------- report ---------- */
.report-wrap { padding-block: var(--space-6) var(--space-8); }
.report-actions { display: flex; flex-wrap: wrap; gap: var(--space-3); margin-block: var(--space-5); }
.report { background: var(--white); border: 1px solid var(--stone-200); border-radius: var(--radius-lg); padding: clamp(1.25rem, 1rem + 2.5vw, 3rem); box-shadow: var(--shadow-sm); display: grid; gap: var(--space-7); }
.report h2 { font-size: var(--fs-600); margin-block-end: var(--space-4); }
.report__head { display: grid; gap: var(--space-5); align-items: start; }
@media (min-width: 800px) { .report__head { grid-template-columns: auto 1fr; } }
.report__logo { width: 10rem; height: auto; }
.report__head h1 { font-size: var(--fs-700); }
.report__meta { display: grid; gap: 0.5rem 1.5rem; margin-block-start: var(--space-4); }
@media (min-width: 640px) { .report__meta { grid-template-columns: repeat(2, 1fr); } }
.report__meta dt { font-size: 0.78rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
:lang(ar) .report__meta dt { text-transform: none; letter-spacing: 0; font-size: 0.88rem; }
.report__meta dd { margin: 0; font-weight: 600; color: var(--navy); }
.report__note { margin-block-start: var(--space-3); color: var(--muted); font-size: 0.88rem; }

.score-hero { display: grid; gap: var(--space-5); padding: clamp(1.25rem, 1rem + 2vw, 2rem); border-radius: var(--radius-lg); background: var(--navy); color: #DADCF0; }
@media (min-width: 800px) { .score-hero { grid-template-columns: 1fr 1.2fr; align-items: center; } }
.score-hero h2 { color: #BFC3E6; font-family: var(--font-sans); font-size: 0.9rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.1em; margin: 0; }
:lang(ar) .score-hero h2 { font-family: var(--font-ar); text-transform: none; letter-spacing: 0; font-size: 1rem; }
.score-hero__num p { margin-block: 0.4rem 0.8rem; }
.score-hero__num strong { font-family: var(--font-serif); font-size: clamp(3rem, 2rem + 4vw, 4.5rem); color: var(--white); line-height: 1; }
.score-hero .meter { background: rgba(255, 255, 255, 0.15); }
.score-band { font-size: 1.5rem; font-weight: 700; color: var(--white); margin-block-end: 0.4rem; }
.score-hero.tone--urgent .score-band { color: #FFB4AB; }
.score-hero.tone--developing .score-band { color: #F6D58A; }
.score-hero.tone--strong .score-band { color: #9BE0B8; }

.table-wrap { overflow-x: auto; border: 1px solid var(--stone-200); border-radius: var(--radius); }
.score-table, .ans-table, .admin-table { width: 100%; border-collapse: collapse; font-size: 0.93rem; }
.score-table th, .score-table td, .ans-table th, .ans-table td, .admin-table th, .admin-table td { padding: 0.75rem 0.9rem; text-align: start; border-block-end: 1px solid var(--stone-200); vertical-align: top; }
.score-table thead th, .ans-table thead th, .admin-table thead th { background: var(--stone); color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
:lang(ar) .score-table thead th, :lang(ar) .ans-table thead th { text-transform: none; letter-spacing: 0; font-size: 0.88rem; }
.score-table tbody th { font-weight: 600; color: var(--navy); }
.num { font-variant-numeric: tabular-nums; font-weight: 700; }
.dom-num { display: inline-grid; place-items: center; width: 1.6rem; height: 1.6rem; border-radius: 50%; background: var(--navy-100); font-size: 0.75rem; margin-inline-end: 0.4rem; }
.bar { display: inline-block; vertical-align: middle; width: 5rem; height: 7px; border-radius: 9px; background: var(--stone-200); overflow: hidden; margin-inline-end: 0.4rem; }
.bar span { display: block; height: 100%; border-radius: 9px; background: var(--muted); }
.tone--urgent .bar span { background: #B42318; }
.tone--developing .bar span { background: var(--gold); }
.tone--strong .bar span { background: var(--success); }
.tag { display: inline-block; padding: 0.2rem 0.6rem; border-radius: 99px; font-size: 0.8rem; font-weight: 600; background: var(--stone-200); white-space: nowrap; }
.tone--urgent .tag { background: #FBE4E1; color: #8A1C12; }
.tone--developing .tag { background: var(--gold-100); color: #6B4F08; }
.tone--strong .tag { background: var(--success-100); color: var(--success); }

.priority-list, .guide { list-style: none; display: grid; gap: 0.6rem; }
.priority-list li, .guide li { display: grid; gap: 0.2rem; padding: 0.85rem 1rem; border-radius: var(--radius); background: var(--stone); border-inline-start: 5px solid var(--muted); }
.priority-list li span:last-child, .guide li span:last-child { color: var(--muted); font-size: 0.92rem; }
.guide li { grid-template-columns: 7.5rem 9rem 1fr; align-items: center; }
@media (max-width: 719.98px) { .guide li { grid-template-columns: 1fr; } }
.guide__range { font-weight: 700; font-variant-numeric: tabular-nums; }
.tone--urgent.priority-list li, .priority-list li.tone--urgent, .guide li.tone--urgent { border-color: #B42318; }
.priority-list li.tone--developing, .guide li.tone--developing { border-color: var(--gold); }
.guide li.tone--strong { border-color: var(--success); }
.ans-domain { font-size: 1.15rem; margin-block: var(--space-5) var(--space-3); }

/* ---------- admin ---------- */
.admin { padding-block: var(--space-6) var(--space-8); display: grid; gap: var(--space-6); }
.admin-top { display: grid; gap: var(--space-5); }
@media (min-width: 960px) { .admin-top { grid-template-columns: 1.6fr 1fr; align-items: start; } }
.admin-top h1 { font-size: var(--fs-600); }
.gen-form { display: grid; gap: var(--space-4); }
@media (min-width: 640px) { .gen-form { grid-template-columns: 1fr auto; align-items: end; } }
.new-code { margin-block-start: var(--space-5); padding: var(--space-5); border-radius: var(--radius); background: var(--navy-050); border: 1.5px dashed var(--navy); text-align: center; }
.new-code__label { color: var(--muted); font-weight: 600; }
.new-code__code { font-size: 2.8rem; font-weight: 700; letter-spacing: 0.3em; color: var(--navy); font-variant-numeric: tabular-nums; padding-inline-start: 0.3em; }
.new-code__meta { color: var(--muted); font-size: 0.9rem; margin-block-end: var(--space-4); }
.copy-row { display: flex; gap: var(--space-2); }
.copy-row .input { min-height: 2.5rem; font-size: 0.88rem; direction: ltr; }
.admin-stats { list-style: none; display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-3); }
.admin-stats li { padding: 1.1rem 1.25rem; border-radius: var(--radius); background: var(--white); border: 1px solid var(--stone-200); box-shadow: var(--shadow-sm); }
.admin-stats strong { display: block; font-family: var(--font-serif); font-size: 2rem; color: var(--navy); line-height: 1.1; }
.admin-stats span { color: var(--muted); font-size: 0.9rem; }
.admin-list { background: var(--white); border: 1px solid var(--stone-200); border-radius: var(--radius-lg); padding: clamp(1rem, 0.8rem + 1.5vw, 2rem); }
.admin-list__head { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); flex-wrap: wrap; margin-block-end: var(--space-4); }
.admin-list__head h2 { font-size: var(--fs-600); }
.admin-table td small { color: var(--muted); }
.code-cell { font-weight: 700; font-size: 1.05rem; letter-spacing: 0.08em; color: var(--navy); }
.status { display: inline-block; padding: 0.2rem 0.6rem; border-radius: 99px; font-size: 0.8rem; font-weight: 600; white-space: nowrap; }
.status--unused { background: var(--stone-200); color: var(--muted); }
.status--in_progress { background: var(--gold-100); color: #6B4F08; }
.status--submitted { background: var(--success-100); color: var(--success); }
.status--expired, .status--revoked { background: #FBE4E1; color: #8A1C12; }
.row-actions { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; }
.row-actions .btn--sm, .more summary { min-height: 2.1rem; padding: 0.35rem 0.8rem; font-size: 0.85rem; }
.more { position: relative; }
.more summary { list-style: none; }
.more summary::-webkit-details-marker { display: none; }
.more__menu { position: absolute; inset-inline-end: 0; top: calc(100% + 4px); z-index: 10; min-width: 13rem; padding: 0.35rem; background: var(--white); border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); }
.more__item { display: block; width: 100%; padding: 0.55rem 0.75rem; border: 0; background: none; text-align: start; font: inherit; font-size: 0.9rem; color: var(--ink); border-radius: 6px; cursor: pointer; }
.more__item:hover { background: var(--stone); }
.more__item--danger { color: var(--error); }
.empty { color: var(--muted); padding: var(--space-5) 0; }

/* ---------- print (Save as PDF) ---------- */
@media print {
  .app-header, .app-footer, .no-print, .audit-bar, .skip-link { display: none !important; }
  body { background: #fff; }
  .report { border: 0; box-shadow: none; padding: 0; gap: 1.5rem; }
  .score-hero { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .table-wrap { overflow: visible; border: 0; }
  .score-table tr, .ans-table tr, .guide li, .priority-list li { break-inside: avoid; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ---------- phone fixes ---------- */
.admin > *, .admin-top > *, .gen-form > * { min-width: 0; }
@media (max-width: 599.98px) {
  .std__ratings { display: grid; grid-template-columns: repeat(5, 1fr); }
  .rate span { min-width: 0; padding-inline: 0.25rem; }
  .std { padding: 0.9rem; }
  .std legend { gap: 0.5rem; }
  .copy-row { flex-direction: column; }
  .new-code__code { font-size: 2.2rem; }
  .app-header__actions .btn--sm { min-height: 2.25rem; padding: 0.35rem 0.8rem; font-size: 0.85rem; }
}
