/*
 * Tarteeb — base styles shared by every page (panel, sign-in, platform).
 * The visual language of the team's existing panel (warm cream background,
 * white cards, brown accent, pill tabs, 12px radius, Segoe UI / system font),
 * generalised: no brand, tokens for light AND dark, logical properties so the
 * same rules work left-to-right (English) and right-to-left (Arabic).
 * No inline styles anywhere (CSP style-src 'self').
 */

:root {
  color-scheme: light;
  --bg: #f6f4ef;
  --card: #ffffff;
  --card-2: #fcfbf8;
  --sand: #efe9df;
  --sand-2: #e5ddcf;
  --ink: #2b2620;
  --muted: #655e51;
  --line: #e2dccf;
  --line-strong: #cfc6b5;
  --accent: #8d6a4a;
  --accent-dark: #6f5238;
  --accent-ink: #ffffff;
  --accent-soft: #f3ebdd;
  --green: #256a41;
  --green-bg: #e5f3ea;
  --red: #a93a2a;
  --red-bg: #fbe9e6;
  --amber: #7f5608;
  --amber-bg: #fcf1d8;
  --blue: #245f9e;
  --blue-bg: #e7f0fa;
  --wa: #1b7a4b;
  --focus: #2f6fb3;
  --shadow: 0 3px 10px rgba(40, 30, 20, 0.07);
  --shadow-lg: 0 12px 40px rgba(40, 30, 20, 0.22);
  --radius: 12px;
  --radius-sm: 8px;
  --hdr-h: 60px;
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --font-ar: "Segoe UI", Tahoma, "Noto Sans Arabic", "Geeza Pro", system-ui, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "SFMono-Regular", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #16130f;
    --card: #211d18;
    --card-2: #1c1914;
    --sand: #2e2821;
    --sand-2: #3a332a;
    --ink: #eee8dd;
    --muted: #b6ad9e;
    --line: #3a332a;
    --line-strong: #544a3d;
    --accent: #d2a57a;
    --accent-dark: #e2bb94;
    --accent-ink: #1b150f;
    --accent-soft: #3a2e22;
    --green: #86d3a4;
    --green-bg: #173424;
    --red: #f3a293;
    --red-bg: #3d1e19;
    --amber: #eec77a;
    --amber-bg: #3a2d12;
    --blue: #9cc4ef;
    --blue-bg: #182a3d;
    --wa: #6fd6a0;
    --focus: #8fbcf0;
    --shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.6);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #16130f;
  --card: #211d18;
  --card-2: #1c1914;
  --sand: #2e2821;
  --sand-2: #3a332a;
  --ink: #eee8dd;
  --muted: #b6ad9e;
  --line: #3a332a;
  --line-strong: #544a3d;
  --accent: #d2a57a;
  --accent-dark: #e2bb94;
  --accent-ink: #1b150f;
  --accent-soft: #3a2e22;
  --green: #86d3a4;
  --green-bg: #173424;
  --red: #f3a293;
  --red-bg: #3d1e19;
  --amber: #eec77a;
  --amber-bg: #3a2d12;
  --blue: #9cc4ef;
  --blue-bg: #182a3d;
  --wa: #6fd6a0;
  --focus: #8fbcf0;
  --shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.6);
}

/* ------------------------------------------------------------ reset --- */
*,
*::before,
*::after {
  box-sizing: border-box;
}
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--ink);
}
html[lang="ar"] body {
  font-family: var(--font-ar);
}
h1,
h2,
h3,
h4,
p,
ul,
ol,
dl,
figure {
  margin: 0;
}
h1 {
  font-size: 19px;
  font-weight: 700;
}
h2 {
  font-size: 16px;
  font-weight: 700;
}
h3 {
  font-size: 14px;
  font-weight: 700;
}
a {
  color: var(--accent-dark);
}
img {
  max-width: 100%;
}
button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}
[hidden] {
  display: none !important;
}
.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
.skip {
  position: absolute;
  inset-inline-start: 8px;
  top: -60px;
  z-index: 1000;
  background: var(--card);
  color: var(--ink);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}
.skip:focus {
  top: 8px;
}
.ltr {
  direction: ltr;
  unicode-bidi: isolate;
}
bdi,
.bidi {
  unicode-bidi: isolate;
}
.mono {
  font-family: var(--mono);
  font-size: 0.93em;
}
.muted,
.hint {
  color: var(--muted);
}
.hint {
  font-size: 13px;
  line-height: 1.5;
}
.nowrap {
  white-space: nowrap;
}
.pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.grow {
  flex: 1 1 auto;
}
.row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.row.tight {
  gap: 6px;
}
.row.end {
  justify-content: flex-end;
}
.stack {
  display: grid;
  gap: 12px;
}
.stack.tight {
  gap: 6px;
}
.spacer {
  flex: 1 1 auto;
}
/* directional glyphs (arrows) point the other way in Arabic */
[dir="rtl"] .flip {
  display: inline-block;
  transform: scaleX(-1);
}

/* ----------------------------------------------------------- cards --- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 18px;
}
.card > h2,
.card-head {
  margin-bottom: 12px;
}
.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.card-head h2 {
  margin: 0;
}
.card.danger-edge {
  border-color: var(--red);
}
.card.accent-edge {
  border-inline-start: 5px solid var(--accent);
}
.sub {
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
}

/* --------------------------------------------------------- buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  background: var(--accent);
  color: var(--accent-ink);
  text-decoration: none;
  white-space: nowrap;
  min-height: 38px;
}
.btn:hover {
  background: var(--accent-dark);
}
.btn.secondary {
  background: var(--sand);
  color: var(--ink);
  border-color: var(--line);
}
.btn.secondary:hover {
  background: var(--sand-2);
}
.btn.danger {
  background: var(--red);
  color: #fff;
}
:root[data-theme="dark"] .btn.danger {
  color: #1b0f0c;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .btn.danger {
    color: #1b0f0c;
  }
}
.btn.danger:hover {
  filter: brightness(1.08);
}
.btn.ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}
.btn.ghost:hover {
  background: var(--sand);
}
.btn.ok {
  background: var(--green);
  color: #fff;
}
:root[data-theme="dark"] .btn.ok {
  color: #0d1f14;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .btn.ok {
    color: #0d1f14;
  }
}
.btn.sm {
  padding: 5px 11px;
  font-size: 13px;
  min-height: 30px;
  border-radius: 8px;
}
.btn.xs {
  padding: 2px 8px;
  font-size: 12px;
  min-height: 24px;
  border-radius: 7px;
}
.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
}
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
}
.icon-btn:hover {
  background: var(--sand);
}
a.icon-btn,
a.btn {
  text-decoration: none;
}
.icon-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.linklike {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent-dark);
  text-decoration: underline;
  cursor: pointer;
  font: inherit;
}

/* spinner inside a busy button: same box, nothing jumps */
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.is-busy {
  position: relative !important;
  color: transparent !important;
  cursor: progress !important;
}
.is-busy > * {
  visibility: hidden;
}
.is-busy::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 15px;
  height: 15px;
  margin: -8px 0 0 -8px;
  border: 2px solid var(--accent-ink);
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
.btn.secondary.is-busy::after,
.btn.ghost.is-busy::after,
.icon-btn.is-busy::after,
.chip.is-busy::after {
  border-color: var(--muted);
  border-right-color: transparent;
}
button.is-busy:disabled {
  opacity: 1;
}

/* ---------------------------------------------------------- inputs --- */
label,
.label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 4px;
}
input[type="text"],
input[type="search"],
input[type="email"],
input[type="tel"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="time"],
input[type="url"],
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  font-size: 14px;
  background: var(--card);
  color: var(--ink);
  min-height: 38px;
}
textarea {
  resize: vertical;
  line-height: 1.5;
}
input[type="checkbox"],
input[type="radio"] {
  width: 17px;
  height: 17px;
  accent-color: var(--accent);
  margin: 0;
  flex: none;
}
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 0;
  border-color: var(--focus);
}
input[aria-invalid="true"],
select[aria-invalid="true"],
textarea[aria-invalid="true"] {
  border-color: var(--red);
}
.field {
  display: grid;
  gap: 2px;
}
.field .hint {
  margin-top: 3px;
}
.fields {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}
.fields.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.check {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
  margin: 0;
}
.check input {
  margin-top: 2px;
}
.check .hint {
  display: block;
  font-weight: 400;
}
.form-error {
  color: var(--red);
  background: var(--red-bg);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 13.5px;
  margin-top: 10px;
}
.form-ok {
  color: var(--green);
  background: var(--green-bg);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 13.5px;
}
.seg {
  display: inline-flex;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  overflow: hidden;
}
.seg button {
  border: 0;
  background: transparent;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  color: var(--muted);
  min-height: 32px;
}
.seg button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
}

/* ----------------------------------------------------------- chips --- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  background: var(--sand);
  color: var(--ink);
  line-height: 1.6;
}
.chip.green {
  background: var(--green-bg);
  color: var(--green);
}
.chip.red {
  background: var(--red-bg);
  color: var(--red);
}
.chip.amber {
  background: var(--amber-bg);
  color: var(--amber);
}
.chip.blue {
  background: var(--blue-bg);
  color: var(--blue);
}
.chip.muted {
  background: var(--sand);
  color: var(--muted);
  font-weight: 600;
}
.chip.soft {
  font-weight: 600;
}
.pill {
  display: inline-block;
  min-width: 24px;
  text-align: center;
  background: var(--sand);
  border-radius: 999px;
  padding: 1px 10px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--accent-dark);
}
.pill.hot {
  background: var(--red);
  color: #fff;
}
:root[data-theme="dark"] .pill.hot {
  color: #1b0f0c;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .pill.hot {
    color: #1b0f0c;
  }
}
.badge {
  display: inline-block;
  background: var(--red);
  color: #fff;
  border-radius: 10px;
  padding: 0 7px;
  font-size: 11px;
  font-weight: 700;
  margin-inline-start: 6px;
  line-height: 18px;
  min-width: 18px;
  text-align: center;
}
:root[data-theme="dark"] .badge {
  color: #1b0f0c;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .badge {
    color: #1b0f0c;
  }
}

/* ---------------------------------------------------------- tables --- */
.table-wrap {
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--muted);
  text-align: start;
  padding: 8px 10px;
  border-bottom: 2px solid var(--line);
  white-space: nowrap;
}
html[lang="ar"] th {
  text-transform: none;
  letter-spacing: 0;
  font-size: 12.5px;
}
td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  text-align: start;
}
tbody tr:hover td {
  background: var(--card-2);
}

/* ------------------------------------------------------ disclosure --- */
details.fold > summary {
  cursor: pointer;
  list-style: none;
}
details.fold > summary::-webkit-details-marker {
  display: none;
}
.caret {
  display: inline-block;
  transition: transform 0.15s ease;
  color: var(--accent-dark);
  font-size: 12px;
}
[dir="rtl"] .caret {
  transform: scaleX(-1);
}
details[open] > summary .caret {
  transform: rotate(90deg);
}

/* -------------------------------------------------- toasts / busy --- */
.toasts {
  position: fixed;
  inset-inline: 0;
  bottom: 18px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  padding: 0 12px;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: min(560px, 94vw);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 14px 10px 18px;
  border-radius: 14px;
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.18s ease;
  user-select: text;
}
.toast.leaving {
  opacity: 0;
  transition: opacity 0.2s;
}
.toast-error {
  background: var(--red);
  color: #fff;
}
.toast-ok {
  background: var(--green);
  color: #fff;
}
:root[data-theme="dark"] .toast-error,
:root[data-theme="dark"] .toast-ok {
  color: #120c08;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .toast-error,
  :root:not([data-theme="light"]) .toast-ok {
    color: #120c08;
  }
}
.toast-msg {
  flex: 1;
  white-space: pre-line;
  overflow-wrap: anywhere;
}
.toast-x {
  background: none;
  border: 0;
  color: inherit;
  opacity: 0.8;
  cursor: pointer;
  font-size: 13px;
  padding: 2px 4px;
}
@keyframes toast-in {
  from {
    transform: translateY(8px);
    opacity: 0;
  }
}
.bar {
  position: fixed;
  top: 0;
  inset-inline-start: 0;
  height: 3px;
  width: 0;
  z-index: 400;
  background: linear-gradient(90deg, var(--accent), var(--accent-dark));
  opacity: 0;
  transition: width 0.25s ease, opacity 0.3s ease;
  pointer-events: none;
}
.bar.on {
  opacity: 1;
}
.busy {
  position: fixed;
  inset: 0;
  z-index: 350;
  background: rgba(30, 24, 18, 0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}
.busy-spin {
  width: 46px;
  height: 46px;
  border: 5px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
.busy-msg {
  color: #fff;
  font-weight: 700;
  text-align: center;
  max-width: 80vw;
}

/* ---------------------------------------------------------- dialogs --- */
dialog.modal {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0;
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100vh - 32px);
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
}
dialog.modal-sm {
  width: min(420px, calc(100vw - 24px));
}
dialog.modal-lg {
  width: min(820px, calc(100vw - 24px));
}
dialog.modal::backdrop {
  background: rgba(30, 24, 18, 0.5);
}
.modal-form {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 34px);
}
.modal-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.modal-title {
  flex: 1;
  font-size: 16px;
}
.modal-x {
  width: 32px;
  height: 32px;
}
.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
  display: grid;
  gap: 12px;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 18px 16px;
  border-top: 1px solid var(--line);
}

/* ----------------------------------------------------------- misc --- */
.empty {
  padding: 22px 6px;
  text-align: center;
  color: var(--muted);
}
.kv {
  display: grid;
  grid-template-columns: minmax(110px, max-content) 1fr;
  gap: 6px 14px;
  font-size: 14px;
}
.kv dt {
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
}
.kv dd {
  margin: 0;
  overflow-wrap: anywhere;
}
.codebox {
  font-family: var(--mono);
  font-size: 22px;
  letter-spacing: 4px;
  background: var(--sand);
  border-radius: 10px;
  padding: 10px 16px;
  display: inline-block;
  direction: ltr;
}
.copyline {
  display: flex;
  gap: 8px;
  align-items: center;
}
.copyline input {
  font-family: var(--mono);
  font-size: 13px;
  direction: ltr;
}
.qr {
  width: 220px;
  height: 220px;
  background: #fff;
  border-radius: 10px;
  padding: 8px;
  border: 1px solid var(--line);
}
.meter {
  height: 6px;
  border-radius: 4px;
  background: var(--sand);
  overflow: hidden;
  margin-top: 6px;
}
.meter > i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--red);
  transition: width 0.2s ease, background 0.2s ease;
}
.meter[data-score="2"] > i {
  background: var(--amber);
}
.meter[data-score="3"] > i,
.meter[data-score="4"] > i {
  background: var(--green);
}
.steps {
  margin: 0;
  padding-inline-start: 22px;
  display: grid;
  gap: 6px;
  font-size: 14px;
}
.notice {
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13.5px;
  line-height: 1.5;
  background: var(--amber-bg);
  color: var(--ink);
  border: 1px solid transparent;
}
.notice.red {
  background: var(--red-bg);
}
.notice.green {
  background: var(--green-bg);
}
.notice.blue {
  background: var(--blue-bg);
}
.notice b {
  color: inherit;
}
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
.mt {
  margin-top: 14px;
}
.mb {
  margin-bottom: 12px;
}
.mt-s {
  margin-top: 6px;
}
