/* VALID - Tahakom Hardware Verification & Validation Platform
   Design tokens follow tahakom.com: plum brand colour, teal accent, light surfaces.
   Layout uses CSS logical properties so RTL (Arabic) works without a second stylesheet. */

@font-face {
  font-family: "IBM Plex Sans Arabic";
  src: url("../fonts/IBMPlexSansArabic-Regular.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Sans Arabic";
  src: url("../fonts/IBMPlexSansArabic-Medium.ttf") format("truetype");
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Sans Arabic";
  src: url("../fonts/IBMPlexSansArabic-SemiBold.ttf") format("truetype");
  font-weight: 600;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Sans Arabic";
  src: url("../fonts/IBMPlexSansArabic-Bold.ttf") format("truetype");
  font-weight: 700;
  font-display: swap;
}

:root {
  --plum-900: #602650;
  --plum-800: #692053;
  --plum-700: #6b005c;
  --plum-100: #f3e8f1;
  --plum-50: #faf5f9;
  --teal-500: #25c7bc;
  --teal-600: #1aa89e;
  --teal-100: #d9f5f2;
  --grey-900: #212529;
  --grey-700: #4c4e55;
  --grey-600: #6c757d;
  --grey-400: #c9cdd2;
  --grey-300: #dee2e6;
  --grey-200: #e9ecef;
  --grey-100: #f1f3f4;
  --surface: #f6f8f7;
  --white: #ffffff;
  --success: #198754;
  --success-bg: #d9f0e3;
  --danger: #c0392b;
  --danger-bg: #f8dcd8;
  --warning: #b7791f;
  --warning-bg: #fdf0d5;
  --info: #1769aa;
  --info-bg: #dbeafe;
  --radius: 6px;
  --radius-sm: 4px;
  --shadow: 0 1px 2px rgba(33, 37, 41, 0.06), 0 1px 6px rgba(33, 37, 41, 0.05);
  --font: "IBM Plex Sans Arabic", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --nav-height: 64px;
}

* { box-sizing: border-box; }
html { font-size: 16px; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--grey-900);
  background: var(--surface);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--plum-900); text-decoration: none; }
a:hover { color: var(--plum-700); text-decoration: underline; }
h1, h2, h3, h4 { color: var(--plum-900); margin: 0 0 .5rem; line-height: 1.25; font-weight: 600; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
h4 { font-size: 1rem; color: var(--grey-900); }
p { margin: 0 0 .75rem; }
small, .small { font-size: .85rem; }
.muted { color: var(--grey-600); }
code { background: var(--grey-100); padding: .1em .35em; border-radius: var(--radius-sm); font-size: .9em; }
hr { border: 0; border-top: 1px solid var(--grey-300); margin: 1.25rem 0; }

/* --- Layout ------------------------------------------------------------------------------ */

.topbar {
  background: var(--white);
  border-bottom: 1px solid var(--grey-300);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1rem;
  height: var(--nav-height);
  display: flex;
  align-items: center;
  gap: 1.5rem;
}
.brand { display: flex; align-items: center; gap: .75rem; color: var(--plum-900); text-decoration: none; min-width: 0; }
.brand:hover { text-decoration: none; }
.brand img, .brand svg { height: 40px; width: auto; flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; font-size: .8rem; color: var(--grey-600); }
.topbar-actions { display: flex; align-items: center; gap: .5rem; margin-inline-start: auto; }
.topbar-actions .user-name { font-size: .9rem; color: var(--grey-700); white-space: nowrap; }
.topbar .nav-toggle { display: none; }
.navbar { border-top: 1px solid var(--grey-200); background: var(--white); }
.nav { max-width: 1280px; margin: 0 auto; padding: 0 .5rem; display: flex; gap: .15rem; flex-wrap: wrap; }
.nav a {
  padding: .6rem .8rem;
  color: var(--grey-700);
  font-weight: 500;
  font-size: .95rem;
  white-space: nowrap;
  border-bottom: 3px solid transparent;
}
.nav a:hover { color: var(--plum-900); text-decoration: none; border-bottom-color: var(--plum-100); }
.nav a.active { color: var(--plum-900); border-bottom-color: var(--plum-900); }

.hero {
  background: linear-gradient(120deg, var(--plum-900), var(--plum-800) 70%, #7a2a63);
  color: var(--white);
  padding: 2rem 0;
}
.hero h1, .hero h2 { color: var(--white); }
.hero .muted { color: rgba(255, 255, 255, .8); }
.hero .accent { color: var(--teal-500); }

main.container, .container {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}
main { flex: 1; }
.container-narrow { max-width: 860px; }

.footer {
  background: var(--plum-800);
  color: rgba(255, 255, 255, .85);
  padding: 1.25rem 1rem;
  font-size: .85rem;
}
.footer-inner { max-width: 1280px; margin: 0 auto; display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.footer a { color: var(--teal-500); }

/* --- Page header ------------------------------------------------------------------------- */

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head h1 { margin-bottom: .15rem; }
.page-head .actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.breadcrumb { font-size: .85rem; color: var(--grey-600); margin-bottom: .5rem; }
.breadcrumb a { color: var(--grey-600); }
.breadcrumb span::before { content: "/"; margin: 0 .4rem; color: var(--grey-400); }

/* --- Cards and grids --------------------------------------------------------------------- */

.card {
  background: var(--white);
  border: 1px solid var(--grey-300);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.card-title { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .75rem; }
.card-title h2, .card-title h3 { margin: 0; }
.card.flat { box-shadow: none; }
.card.accent { border-inline-start: 4px solid var(--teal-500); }
.card.plum { border-inline-start: 4px solid var(--plum-900); }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stack > * + * { margin-top: 1rem; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }

.stat { background: var(--white); border: 1px solid var(--grey-300); border-radius: var(--radius); padding: 1rem 1.25rem; }
.stat .value { font-size: 1.9rem; font-weight: 600; color: var(--plum-900); line-height: 1.1; }
.stat .label { font-size: .85rem; color: var(--grey-600); }

.tile {
  display: block;
  background: var(--white);
  border: 1px solid var(--grey-300);
  border-top: 4px solid var(--plum-900);
  border-radius: var(--radius);
  padding: 1.25rem;
  color: inherit;
  transition: transform .12s ease, box-shadow .12s ease;
}
.tile:hover { text-decoration: none; transform: translateY(-2px); box-shadow: var(--shadow); color: inherit; }
.tile .tile-code { font-size: .75rem; letter-spacing: .1em; text-transform: uppercase; color: var(--teal-600); font-weight: 600; }
.tile h3 { margin: .25rem 0 .5rem; }
.tile.domain-II { border-top-color: var(--teal-500); }
.tile.domain-III { border-top-color: var(--grey-700); }

/* --- Buttons ----------------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem 1rem;
  border-radius: 5px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 500;
  font-size: .95rem;
  cursor: pointer;
  line-height: 1.2;
  background: var(--grey-700);
  color: var(--white);
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; filter: brightness(1.08); color: var(--white); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--plum-900); }
.btn-primary:hover { background: var(--plum-700); }
.btn-accent { background: var(--teal-600); }
.btn-outline { background: transparent; color: var(--plum-900); border-color: var(--plum-900); }
.btn-outline:hover { background: var(--plum-50); color: var(--plum-900); }
.btn-ghost { background: transparent; color: var(--grey-700); border-color: var(--grey-300); }
.btn-ghost:hover { background: var(--grey-100); color: var(--grey-900); }
.btn-danger { background: var(--danger); }
.btn-sm { padding: .3rem .65rem; font-size: .85rem; }
.btn-lg { padding: .7rem 1.4rem; font-size: 1.05rem; }
.btn-block { width: 100%; justify-content: center; }
form.inline { display: inline; }

/* --- Forms ------------------------------------------------------------------------------- */

.field { margin-bottom: 1rem; }
.field label, .label { display: block; font-weight: 500; margin-bottom: .3rem; font-size: .92rem; }
.field .hint { font-size: .8rem; color: var(--grey-600); margin-top: .25rem; }
input[type="text"], input[type="email"], input[type="password"], input[type="date"], input[type="number"],
input[type="search"], input[type="file"], select, textarea {
  width: 100%;
  padding: .5rem .65rem;
  border: 1px solid var(--grey-400);
  border-radius: var(--radius-sm);
  font: inherit;
  background: var(--white);
  color: var(--grey-900);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--teal-500); outline-offset: 1px; border-color: var(--teal-600); }
textarea { min-height: 96px; resize: vertical; }
textarea.tall { min-height: 220px; }
textarea.code { font-family: Consolas, "Courier New", monospace; font-size: .9rem; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1.25rem; }
.form-grid .span-2 { grid-column: span 2; }
.form-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1rem; flex-wrap: wrap; }
.check { display: flex; align-items: center; gap: .5rem; font-weight: 400; }
.check input { width: auto; }
fieldset { border: 1px solid var(--grey-300); border-radius: var(--radius); padding: 1rem 1.25rem; margin: 0 0 1rem; }
legend { font-weight: 600; color: var(--plum-900); padding: 0 .4rem; }
.required::after { content: " *"; color: var(--danger); }

.choice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .75rem; }
.choice {
  border: 1px solid var(--grey-300);
  border-radius: var(--radius);
  padding: .75rem;
  background: var(--white);
}
.choice label { font-weight: 600; font-size: .85rem; color: var(--grey-700); text-transform: uppercase; letter-spacing: .04em; }

/* --- Tables ------------------------------------------------------------------------------ */

.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; background: var(--white); font-size: .93rem; }
.table th, .table td { padding: .6rem .75rem; border-bottom: 1px solid var(--grey-300); text-align: start; vertical-align: top; }
.table th { background: var(--grey-100); font-weight: 600; color: var(--grey-700); font-size: .85rem; letter-spacing: .02em; }
.table tr:hover td { background: var(--plum-50); }
.table td.actions, .table th.actions { text-align: end; white-space: nowrap; }
.table .num { text-align: end; font-variant-numeric: tabular-nums; }
.table-compact th, .table-compact td { padding: .35rem .5rem; }

/* --- Badges and alerts ------------------------------------------------------------------- */

.badge {
  display: inline-block;
  padding: .15rem .55rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .03em;
  text-transform: uppercase;
  background: var(--grey-200);
  color: var(--grey-700);
  white-space: nowrap;
}
.badge-plum { background: var(--plum-100); color: var(--plum-900); }
.badge-teal { background: var(--teal-100); color: var(--teal-600); }
.badge-success, .badge-pass, .badge-released, .badge-completed, .badge-approved, .badge-qualified { background: var(--success-bg); color: var(--success); }
.badge-danger, .badge-fail, .badge-not_qualified { background: var(--danger-bg); color: var(--danger); }
.badge-warning, .badge-blocked, .badge-draft, .badge-in_progress, .badge-conditionally_qualified { background: var(--warning-bg); color: var(--warning); }
.badge-info, .badge-public { background: var(--info-bg); color: var(--info); }
.badge-na, .badge-pending, .badge-archived, .badge-open { background: var(--grey-200); color: var(--grey-600); }
.badge-restricted { background: var(--plum-100); color: var(--plum-900); }
.badge-mandatory { background: var(--plum-900); color: var(--white); }
.badge-recommended { background: var(--teal-100); color: var(--teal-600); }
.badge-optional { background: var(--grey-200); color: var(--grey-600); }
.badge-domain-I { background: var(--plum-100); color: var(--plum-900); }
.badge-domain-II { background: var(--teal-100); color: var(--teal-600); }
.badge-domain-III { background: var(--grey-200); color: var(--grey-700); }

.alert { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid transparent; }
.alert-info { background: var(--info-bg); color: var(--info); border-color: #bcd4f5; }
.alert-success { background: var(--success-bg); color: var(--success); border-color: #b8e0c8; }
.alert-warning { background: var(--warning-bg); color: var(--warning); border-color: #f1dca6; }
.alert-danger, .alert-error { background: var(--danger-bg); color: var(--danger); border-color: #efb8b1; }
.flashes { max-width: 1280px; margin: 1rem auto 0; padding: 0 1rem; }
.flashes .alert { margin-bottom: .5rem; }

/* --- Prose (rendered markdown) ----------------------------------------------------------- */

.prose { max-width: 80ch; }
.prose h1 { font-size: 1.6rem; margin-top: 1.5rem; }
.prose h2 { font-size: 1.3rem; margin-top: 1.75rem; padding-bottom: .25rem; border-bottom: 1px solid var(--grey-300); }
.prose h3 { font-size: 1.1rem; margin-top: 1.25rem; }
.prose h4 { margin-top: 1rem; }
.prose table { border-collapse: collapse; margin: 1rem 0; font-size: .92rem; width: 100%; }
.prose th, .prose td { border: 1px solid var(--grey-300); padding: .4rem .6rem; text-align: start; }
.prose th { background: var(--grey-100); }
.prose blockquote { margin: 1rem 0; padding: .5rem 1rem; border-inline-start: 4px solid var(--teal-500); background: var(--teal-100); border-radius: var(--radius-sm); }
.prose ul, .prose ol { padding-inline-start: 1.5rem; }
.prose li { margin-bottom: .25rem; }
.prose img { max-width: 100%; }

/* --- Definition lists (test blueprint) --------------------------------------------------- */

.blueprint { display: grid; grid-template-columns: 220px 1fr; gap: .4rem 1rem; }
.blueprint dt { font-weight: 600; color: var(--grey-700); font-size: .9rem; }
.blueprint dd { margin: 0; white-space: pre-line; }
.blueprint ul { margin: 0; padding-inline-start: 1.2rem; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; font-size: .93rem; }
.kv dt { color: var(--grey-600); font-weight: 500; }
.kv dd { margin: 0; }

/* --- Wizard / steps ---------------------------------------------------------------------- */

.steps { display: flex; gap: .5rem; margin-bottom: 1.5rem; counter-reset: step; flex-wrap: wrap; }
.steps .step { display: flex; align-items: center; gap: .5rem; padding: .4rem .8rem; border-radius: 999px; background: var(--white); border: 1px solid var(--grey-300); font-size: .9rem; color: var(--grey-600); }
.steps .step::before { counter-increment: step; content: counter(step); display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--grey-200); font-size: .75rem; font-weight: 600; }
.steps .step.active { border-color: var(--plum-900); color: var(--plum-900); font-weight: 600; }
.steps .step.active::before { background: var(--plum-900); color: var(--white); }
.steps .step.done { color: var(--teal-600); }
.steps .step.done::before { background: var(--teal-500); color: var(--white); content: "\2713"; }

/* --- Test run cards ---------------------------------------------------------------------- */

.run-item { border: 1px solid var(--grey-300); border-radius: var(--radius); background: var(--white); margin-bottom: .75rem; overflow: hidden; }
.run-item summary { cursor: pointer; padding: .75rem 1rem; display: flex; align-items: center; gap: .75rem; list-style: none; }
.run-item summary::-webkit-details-marker { display: none; }
.run-item summary .title { flex: 1; font-weight: 600; }
.run-item .body { padding: 0 1rem 1rem; border-top: 1px solid var(--grey-200); }
.run-item.result-pass { border-inline-start: 4px solid var(--success); }
.run-item.result-fail { border-inline-start: 4px solid var(--danger); }
.run-item.result-blocked { border-inline-start: 4px solid var(--warning); }
.run-item.result-na { border-inline-start: 4px solid var(--grey-400); }
.run-item.result-pending { border-inline-start: 4px solid var(--grey-300); }
.result-picker { display: flex; gap: .4rem; flex-wrap: wrap; }
.result-picker label { display: inline-flex; align-items: center; gap: .3rem; padding: .3rem .7rem; border: 1px solid var(--grey-300); border-radius: 999px; cursor: pointer; font-size: .9rem; background: var(--white); }
.result-picker input { display: none; }
.result-picker input:checked + span { font-weight: 700; }
.result-picker label:has(input:checked) { border-color: var(--plum-900); background: var(--plum-50); }
.result-picker label.pass:has(input:checked) { border-color: var(--success); background: var(--success-bg); color: var(--success); }
.result-picker label.fail:has(input:checked) { border-color: var(--danger); background: var(--danger-bg); color: var(--danger); }
.result-picker label.blocked:has(input:checked) { border-color: var(--warning); background: var(--warning-bg); color: var(--warning); }
.evidence-list { list-style: none; padding: 0; margin: .5rem 0 0; }
.evidence-list li { display: flex; align-items: center; gap: .5rem; padding: .3rem 0; border-bottom: 1px dashed var(--grey-200); font-size: .9rem; }
.progress { height: 10px; background: var(--grey-200); border-radius: 999px; overflow: hidden; display: flex; }
.progress span { display: block; height: 100%; }
.progress .pass { background: var(--success); }
.progress .fail { background: var(--danger); }
.progress .blocked { background: var(--warning); }
.progress .na { background: var(--grey-400); }
.saved-indicator { font-size: .8rem; color: var(--teal-600); }
.htmx-request .saved-indicator { opacity: .5; }

/* --- Misc -------------------------------------------------------------------------------- */

.login-wrap { display: grid; place-items: center; min-height: calc(100vh - var(--nav-height) - 80px); padding: 2rem 1rem; }
.login-card { width: 100%; max-width: 420px; }
.login-brand { text-align: center; margin-bottom: 1.25rem; }
.login-brand svg, .login-brand img { height: 64px; }
.logo-mark { display: inline-block; }
.lang-switch { display: inline-flex; border: 1px solid var(--grey-300); border-radius: 999px; overflow: hidden; }
.lang-switch button { background: var(--white); border: 0; padding: .3rem .7rem; font: inherit; font-size: .85rem; cursor: pointer; color: var(--grey-700); }
.lang-switch button.active { background: var(--plum-900); color: var(--white); }
.text-end { text-align: end; }
.text-center { text-align: center; }
.mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: .5rem; } .mb-2 { margin-bottom: 1rem; }
.w-auto { width: auto; }
.nowrap { white-space: nowrap; }
.empty { padding: 2rem; text-align: center; color: var(--grey-600); border: 1px dashed var(--grey-300); border-radius: var(--radius); background: var(--white); }
.draft-note { font-size: .8rem; color: var(--warning); }
details.collapsible > summary { cursor: pointer; font-weight: 600; color: var(--plum-900); }
.chip-list { display: flex; flex-wrap: wrap; gap: .35rem; }
.chip { background: var(--grey-100); border: 1px solid var(--grey-300); border-radius: 999px; padding: .15rem .6rem; font-size: .8rem; }
.sortable-handle { cursor: grab; color: var(--grey-400); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* --- Responsive -------------------------------------------------------------------------- */

@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .topbar-inner { height: auto; padding: .5rem 1rem; flex-wrap: wrap; gap: .75rem; }
  .brand-text { display: none; }
  .topbar .nav-toggle { display: inline-flex; }
  .topbar-actions { margin-inline-start: 0; width: 100%; justify-content: space-between; }
  .navbar { display: none; }
  .navbar.open { display: block; }
  .nav { flex-direction: column; padding: .25rem 0; }
  .nav a { border-bottom: 0; border-inline-start: 3px solid transparent; padding: .5rem 1rem; }
  .nav a.active { border-inline-start-color: var(--plum-900); background: var(--plum-50); }
  .grid-2, .grid-3, .grid-4, .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .blueprint { grid-template-columns: 1fr; }
  .page-head { flex-direction: column; }
}
@media (max-width: 1100px) {
  .brand-text { display: none; }
}

@media print {
  .topbar, .footer, .actions, .btn, .flashes { display: none !important; }
  body { background: var(--white); }
  .card { box-shadow: none; }
}
