/* Shared tokens and components for every page (landing, chat, admin).
   Logical properties (inline-start/end) so Arabic flips without extra rules. */

@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400..700&family=IBM+Plex+Sans+Arabic:wght@400;500;600;700&display=swap");

:root {
  color-scheme: light dark;
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --surface-3: #e9ecf1;
  --text: #0b1220;
  --muted: #576074;
  --border: #e3e6eb;
  --border-strong: #cfd4dc;
  --primary: #0b1220; /* ink: main buttons */
  --on-primary: #ffffff;
  --accent: #ea580c; /* orange: highlights, never body text on white */
  --accent-soft: #fff1e8;
  --accent-ink: #9a3412; /* orange that passes 4.5:1 as text */
  --me: #0b1220; /* technician's own bubbles */
  --on-me: #ffffff;
  --danger: #b42318;
  --danger-surface: #fef3f2;
  --success: #067647;
  --ring: #2563eb;
  --scrim: rgb(11 18 32 / 0.55);
  --shadow-sm: 0 1px 2px rgb(11 18 32 / 0.06), 0 1px 1px rgb(11 18 32 / 0.04);
  --shadow-md: 0 4px 12px -2px rgb(11 18 32 / 0.08), 0 2px 4px -2px rgb(11 18 32 / 0.05);
  --shadow-lg: 0 24px 48px -12px rgb(11 18 32 / 0.18), 0 8px 16px -8px rgb(11 18 32 / 0.08);
  --radius: 16px;
  --radius-sm: 10px;
  --radius-lg: 24px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
  --space-8: 32px;
  --tap: 44px;
  --fast: 150ms;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --font: "Inter", "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Arabic", Tahoma, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0f1a;
    --surface: #111827;
    --surface-2: #172033;
    --surface-3: #1f2a40;
    --text: #f3f5f8;
    --muted: #a4adbd;
    --border: #232e43;
    --border-strong: #33405a;
    --primary: #f3f5f8;
    --on-primary: #0b1220;
    --accent: #fb7a32;
    --accent-soft: #2a1a10;
    --accent-ink: #fdba8c;
    --me: #2b3a55;
    --on-me: #ffffff;
    --danger: #fda29b;
    --danger-surface: #2b1414;
    --success: #6ce9a6;
    --ring: #60a5fa;
    --scrim: rgb(0 0 0 / 0.65);
    --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4);
    --shadow-md: 0 4px 12px -2px rgb(0 0 0 / 0.5);
    --shadow-lg: 0 24px 48px -12px rgb(0 0 0 / 0.6);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 var(--font);
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}
html[lang="ar"] body { line-height: 1.7; }

[hidden] { display: none !important; }

.icon {
  width: 24px;
  height: 24px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-sm { width: 18px; height: 18px; }
[dir="rtl"] .icon-flip { transform: scaleX(-1); }

:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }

/* Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--tap);
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 999px;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.005em;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color var(--fast), border-color var(--fast), box-shadow var(--fast), opacity var(--fast);
}
.btn:active { opacity: 0.85; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--on-primary); box-shadow: var(--shadow-sm); }
.btn-primary:hover { box-shadow: var(--shadow-md); opacity: 0.92; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.btn-secondary:hover { background: var(--surface-2); }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: var(--tap);
  height: var(--tap);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background-color var(--fast);
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:active { opacity: 0.7; }
.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--tap);
  padding: 6px var(--space-4);
  border: 1px solid var(--border-strong);
  border-radius: 22px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  text-align: start;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background-color var(--fast), border-color var(--fast);
}
.chip:hover { border-color: var(--text); }
.chip:active { opacity: 0.8; }

/* Brand mark: a page with a highlighted line; does not depend on the product name. */
/* Used as <svg class="mark"><use href="#i-mark"/></svg>; colours reach the symbol through custom properties. */
.mark { width: 28px; height: 28px; flex: none; --mark-bg: var(--text); --mark-page: var(--surface); --mark-hl: var(--accent); --mark-line: var(--border-strong); }

/* Top bar (chat, admin) */

.bar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 60px;
  padding: 0 var(--space-4);
  padding-top: env(safe-area-inset-top);
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: inline-flex; align-items: center; gap: 10px; min-height: var(--tap); color: inherit; text-decoration: none; font-weight: 700; font-size: 17px; letter-spacing: -0.02em; }

/* Forms */

.field { display: grid; gap: 6px; margin-bottom: var(--space-4); }
.field > label, .field > .label { font-weight: 600; font-size: 14px; }
.hint { color: var(--muted); font-size: 14px; font-weight: 400; }
.input {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--fast), box-shadow var(--fast);
}
.input::placeholder { color: color-mix(in srgb, var(--muted) 80%, transparent); }
.input:hover { border-color: var(--muted); }
.input:focus { outline: none; border-color: var(--ring); box-shadow: 0 0 0 4px color-mix(in srgb, var(--ring) 18%, transparent); }
.input[aria-invalid="true"] { border-color: var(--danger); }
.input[aria-invalid="true"]:focus { box-shadow: 0 0 0 4px color-mix(in srgb, var(--danger) 18%, transparent); }
.field-error { margin: 0; color: var(--danger); font-size: 14px; font-weight: 500; }
.field-error:empty { display: none; }

/* Dialogs (native <dialog>: showModal traps focus and closes on Escape) */

dialog {
  width: min(520px, calc(100vw - 2 * var(--space-4)));
  max-height: calc(100dvh - 2 * var(--space-4));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}
dialog[open] { animation: dialog-in 240ms var(--ease-out); }
dialog::backdrop { background: var(--scrim); backdrop-filter: blur(2px); }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
.dialog-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding-block: var(--space-4) var(--space-2);
  padding-inline: var(--space-6) var(--space-3);
}
.dialog-head h2 { flex: 1; margin: 0; font-size: 19px; letter-spacing: -0.015em; min-width: 0; }
.dialog-body { padding: var(--space-2) var(--space-6) var(--space-6); }
.dialog-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-top: var(--space-2); }

.progress {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}
.progress > span { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--accent); transition: width 400ms var(--ease-out); }

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