/*
 * Musagh main stylesheet.
 * Colour values are copied exactly from the original design (src/styles.css).
 * Logical properties (margin-inline, padding-inline, inset-inline) keep RTL and LTR working.
 */

/* ---------- 1. Design tokens ---------- */
:root {
  --panel-padding-block: 1rem;
  --panel-padding-inline: 1.25rem;
  --radius: 0.625rem;
  --background: oklch(0.965 0.014 88.7); /* warm ivory */
  --foreground: oklch(0.262 0.01 39.3);
  --ivory: oklch(0.965 0.014 88.7);
  --panel: oklch(0.985 0.007 84.6);
  --card: oklch(1 0 0);
  --primary: oklch(0.292 0.076 20.7); /* burgundy */
  --primary-hover: oklch(0.344 0.086 19.8);
  --primary-foreground: oklch(0.965 0.014 88.7);
  --secondary: oklch(0.945 0.013 82.4);
  --secondary-foreground: oklch(0.292 0.076 20.7);
  --muted: oklch(0.945 0.013 82.4);
  --muted-foreground: oklch(0.545 0.017 57.4);
  --accent: oklch(0.929 0.03 80.7);
  --champagne: oklch(0.887 0.046 84.6);
  --gold: oklch(0.652 0.086 80.4);
  --gold-soft: oklch(0.94 0.035 84);
  --destructive: oklch(0.537 0.15 32.6);
  --danger-soft: oklch(0.95 0.03 35);
  --success: oklch(0.479 0.078 161.1);
  --success-soft: oklch(0.95 0.03 160);
  --warning: oklch(0.6 0.12 70);
  --warning-soft: oklch(0.955 0.045 85);
  --info: oklch(0.462 0.071 255.5);
  --info-soft: oklch(0.95 0.02 250);
  --border: oklch(0.901 0.016 73.7);
  --input: oklch(0.88 0.018 73.7);
  --ring: oklch(0.652 0.086 80.4);
  --sidebar: oklch(0.292 0.076 20.7);
  --sidebar-foreground: oklch(0.929 0.03 80.7);
  --sidebar-muted: oklch(0.75 0.04 60);
  --sidebar-accent: oklch(0.238 0.056 18.9);
  --sidebar-border: oklch(0.38 0.07 20);
  --shadow-panel: 0 1px 2px oklch(0.262 0.01 39.3 / 0.04), 0 1px 1px oklch(0.262 0.01 39.3 / 0.03);
  --shadow-raised: 0 8px 24px -12px oklch(0.238 0.056 18.9 / 0.25);

  --font-latin: "Inter", "IBM Plex Sans Arabic", ui-sans-serif, system-ui, sans-serif;
  --font-arabic: "IBM Plex Sans Arabic", "Inter", ui-sans-serif, system-ui, sans-serif;
}

/* ---------- 2. Base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  border-color: var(--border);
}

html {
  font-family: var(--font-latin);
  -webkit-font-smoothing: antialiased;
}

html[lang="ar"] {
  font-family: var(--font-arabic);
}

body {
  margin: 0;
  background-color: var(--background);
  color: var(--foreground);
  font-size: 0.9375rem;
  line-height: 1.5;
}

h1, h2, h3 {
  margin: 0;
  letter-spacing: -0.01em;
}

p, ul {
  margin: 0;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

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

/* Tabular numbers for amounts, weights and quantities */
.num {
  font-variant-numeric: tabular-nums lining-nums;
}

/* Left-to-right fragment (codes, emails, amounts) inside Arabic text */
.ltr {
  direction: ltr;
  unicode-bidi: isolate;
}

.muted-text {
  color: var(--muted-foreground);
}

/* ---------- 3. Shared components ---------- */
.panel {
  background-color: var(--card);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 2px);
  box-shadow: var(--shadow-panel);
  padding-block: var(--panel-padding-block);
  padding-inline: var(--panel-padding-inline);
  min-inline-size: 0;
}

/* Plain content cards need an inset too. Special table/card layouts below retain their own padding. */
.panel:has(> .data-table) { overflow-x: auto; }
.panel:has(> .empty-state:only-child) { padding: 0; } /* Empty states already supply their own inset. */
.panel > .form-grid + .note { margin-block-start: 1rem; }
.employee-operation { display: grid; gap: 0.75rem; align-content: start; }
:where(.form-label, .employee-operation > label):has(> .form-input) {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.logo {
  display: block;
  aspect-ratio: 1300 / 420;
  width: auto;
  object-fit: contain;
  user-select: none;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  height: 2.25rem;
  padding: 0 1rem;
  border: 0;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}

.button svg {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
}

.button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.button-primary {
  background-color: var(--primary);
  color: var(--primary-foreground);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.05);
}

.button-primary:hover:not(:disabled) {
  background-color: var(--primary-hover);
}

.button-ghost {
  background: transparent;
}

.button-ghost:hover {
  background-color: var(--secondary);
  color: var(--secondary-foreground);
}

.button-small {
  height: 2rem;
  padding: 0 0.75rem;
  border-radius: calc(var(--radius) - 2px);
  font-size: 0.75rem;
  gap: 0.375rem;
}

.button-touch {
  height: 2.75rem;
  padding: 0 1.25rem;
}

.button-full-width {
  width: 100%;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  min-inline-size: 0;
}

.form-label {
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.5;
}

.form-input {
  width: 100%;
  height: 2.75rem;
  padding-block: 0.5rem;
  padding-inline: 0.75rem;
  min-inline-size: 0;
  border: 1px solid var(--input);
  border-radius: calc(var(--radius) - 2px);
  background-color: var(--card);
  font-size: 1rem;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.05);
}

textarea.form-input { height: auto; min-block-size: 5.5rem; line-height: 1.5; resize: vertical; }
.form-input[type="file"] { height: auto; min-block-size: 2.75rem; }

.form-input:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--ring);
}

.form-input[aria-invalid="true"] {
  border-color: var(--destructive);
}

/* Password field with a show / hide (eye) button (src/views/password_field.php).
   The password itself is always left-to-right; the button sits at the end of the field in the
   page direction: on the right in English, on the left in Arabic. */
.password-field { position: relative; }

.password-field .form-input { padding-right: 3rem; }

.password-toggle {
  position: absolute;
  top: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;          /* 44 px touch target */
  height: 2.75rem;
  padding: 0;
  border: 0;
  border-radius: calc(var(--radius) - 2px);
  background: transparent;
  color: var(--muted-foreground);
  cursor: pointer;
}

.password-toggle:hover,
.password-toggle.is-visible { color: var(--primary); }

.password-toggle:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--ring);
}

.password-toggle svg { width: 1.125rem; height: 1.125rem; }
.password-toggle .password-toggle-hide,
.password-toggle.is-visible .password-toggle-show { display: none; }
.password-toggle.is-visible .password-toggle-hide { display: block; }

.password-toggle[hidden] { display: none; }

[dir="rtl"] .password-field .form-input { padding-right: 0.75rem; padding-left: 3rem; }
[dir="rtl"] .password-toggle { right: auto; left: 0; }

.field-error {
  font-size: 0.75rem;
  color: var(--destructive);
}

.field-error:empty {
  display: none;
}

/* Gold dashed information note */
.note {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border: 1px dashed oklch(0.652 0.086 80.4 / 0.5);
  border-radius: var(--radius);
  background-color: oklch(0.94 0.035 84 / 0.6);
  font-size: 0.75rem;
  color: oklch(0.262 0.01 39.3 / 0.8);
}

.note svg {
  width: 0.875rem;
  height: 0.875rem;
  margin-top: 0.125rem;
  flex-shrink: 0;
  color: var(--gold);
}

.note[hidden] {
  display: none;
}

/* ---------- 4. Login page ---------- */
.login-page {
  display: flex;
  min-height: 100vh;
}

.login-brand-side {
  display: none; /* Shown on large screens only */
  width: 42%;
  max-width: 560px;
  flex-direction: column;
  justify-content: space-between;
  padding: 2.5rem;
  background-color: var(--primary);
  color: var(--primary-foreground);
}

.login-brand-side .logo {
  height: 4rem;
  align-self: flex-start;
}

.login-slogan {
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.375;
  color: var(--champagne);
}

.login-benefits {
  margin-top: 1rem;
  padding: 0;
  list-style: none;
  font-size: 0.875rem;
  color: oklch(0.965 0.014 88.7 / 0.8);
}

.login-benefits li + li {
  margin-top: 0.5rem;
}

.login-copyright {
  font-size: 0.75rem;
  color: oklch(0.965 0.014 88.7 / 0.6);
}

.login-main {
  display: flex;
  flex: 1;
  flex-direction: column;
}

.login-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
}

.login-mobile-logo {
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  background-color: var(--primary);
}

.login-mobile-logo .logo {
  height: 2.25rem;
}

.login-content {
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: center;
  width: 100%;
  max-width: 460px;
  margin-inline: auto;
  padding: 0 1.25rem 2.5rem;
}

.login-title {
  font-size: 1.5rem;
  font-weight: 600;
}

.login-subtitle {
  margin-top: 0.25rem;
  font-size: 0.875rem;
  color: var(--muted-foreground);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1.5rem;
}

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.small-link {
  font-size: 0.75rem;
}

.login-footer-text {
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted-foreground);
}

@media (min-width: 640px) {
  .login-top-bar {
    padding-inline: 2rem;
  }
}

@media (min-width: 1024px) {
  .login-brand-side {
    display: flex;
  }

  .login-mobile-logo {
    display: none;
  }
}

/* ---------- 5. Centered card pages (activation, forgot password, no access) ---------- */
/* Same layout as the original AuthFrame component */
.auth-frame {
  display: flex;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 1rem;
}

.auth-frame-inner {
  width: 100%;
  max-width: 420px;
}

.auth-frame-wide {
  max-width: 560px;
}

.auth-frame-logo {
  width: fit-content;
  margin: 0 auto 1.5rem;
  padding: 0.75rem 1.25rem;
  border-radius: calc(var(--radius) + 2px);
  background-color: var(--primary);
}

.auth-frame-logo .logo {
  height: 2.75rem;
}

.auth-frame-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.5rem;
}

.auth-frame-title {
  font-size: 1.125rem;
  font-weight: 600;
}

.auth-frame-footer {
  font-size: 0.875rem;
}

.eyebrow {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted-foreground);
}

/* ---------- 6. Small helpers ---------- */
.small-text { font-size: 0.75rem; }
.nowrap { white-space: nowrap; }
.strong-text { font-weight: 600; }
.gold-text { color: var(--gold); }
.danger-text { color: var(--destructive); }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  inset-inline-start: 1rem;
  top: -3rem;
  z-index: 100;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  background: var(--primary);
  color: var(--primary-foreground);
}

.skip-link:focus { top: 1rem; }

.icon {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
}

/* More button styles */
.button-outline {
  border: 1px solid var(--input);
  background-color: var(--card);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.05);
}

.button-outline:hover:not(:disabled) {
  background-color: var(--secondary);
  color: var(--secondary-foreground);
}

.button-icon {
  width: 2.25rem;
  padding: 0;
}

a.button:hover { text-decoration: none; }

/* ---------- 7. App layout: sidebar + top bar ---------- */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  width: 248px;
  height: 100vh;
  flex-shrink: 0;
  background-color: var(--sidebar);
  color: var(--sidebar-foreground);
  transition: width 0.2s;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  height: 72px;
  padding: 0 1.25rem;
  border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-logo .logo-full { height: 2.75rem; }

.sidebar-logo .logo-symbol {
  display: none;
  width: 2.25rem;
  height: 2.25rem;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 0.5rem;
}

.sidebar-nav ul {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  height: 2.5rem;
  padding: 0 0.75rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  color: oklch(0.929 0.03 80.7 / 0.85);
  transition: background-color 0.15s, color 0.15s;
}

.sidebar-link:hover {
  background-color: var(--sidebar-accent);
  color: var(--ivory);
  text-decoration: none;
}

.sidebar-link.is-current {
  background-color: var(--champagne);
  color: oklch(0.238 0.056 18.9);
  font-weight: 500;
}

.sidebar-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.sidebar-label {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.sidebar-footer {
  padding: 0.5rem;
  border-top: 1px solid var(--sidebar-border);
}

.sidebar-collapse-button {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  height: 2.25rem;
  padding: 0 0.75rem;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--sidebar-muted);
  font-size: 0.875rem;
  cursor: pointer;
}

.sidebar-collapse-button:hover {
  background-color: var(--sidebar-accent);
  color: var(--ivory);
}

/* The arrow points the way the sidebar will move (same rule as the original app) */
[dir="ltr"] .collapse-icon { transform: scaleX(-1); }
[dir="ltr"] .sidebar-collapsed .collapse-icon { transform: none; }
[dir="rtl"] .sidebar-collapsed .collapse-icon { transform: scaleX(-1); }

/* Collapsed sidebar (desktop) */
.sidebar-collapsed .sidebar { width: 72px; }
.sidebar-collapsed .sidebar-logo { justify-content: center; padding: 0 0.5rem; }
.sidebar-collapsed .sidebar-logo .logo-full { display: none; }
.sidebar-collapsed .sidebar-logo .logo-symbol { display: block; }
.sidebar-collapsed .sidebar-link,
.sidebar-collapsed .sidebar-collapse-button { justify-content: center; padding: 0; }
.sidebar-collapsed .sidebar-label { display: none; }

.sidebar-backdrop { display: none; }

.app-main {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  height: 3.5rem;
  padding: 0 1.25rem;
  border-bottom: 1px solid var(--border);
  background-color: oklch(0.985 0.007 84.6 / 0.95);
  backdrop-filter: blur(4px);
}

.menu-button { display: none; }

.topbar-title {
  min-width: 0;
  flex: 1;
}

.topbar-page,
.topbar-subtitle {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.topbar-page {
  font-size: 0.9375rem;
  font-weight: 600;
}

.topbar-subtitle {
  font-size: 0.75rem;
  color: var(--muted-foreground);
}

.branch-select,
.branch-chip {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  height: 2.25rem;
  padding: 0 0.625rem;
  border: 1px solid var(--input);
  border-radius: var(--radius);
  background-color: var(--card);
  font-size: 0.875rem;
}

.branch-select svg,
.branch-chip svg {
  width: 1rem;
  height: 1rem;
  color: var(--muted-foreground);
}

.branch-select select {
  min-width: 120px;
  border: 0;
  background: transparent;
  font: inherit;
  cursor: pointer;
}

.language-button { height: 2.25rem; }

/* Account menu (uses <details>, no JavaScript needed to open it) */
.account-menu { position: relative; }

.account-menu summary {
  height: 2.25rem;
  padding: 0 0.5rem;
  list-style: none;
}

.account-menu summary::-webkit-details-marker { display: none; }

.avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 999px;
  background-color: var(--primary);
  color: var(--primary-foreground);
}

.account-name {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.account-menu-panel {
  position: absolute;
  inset-inline-end: 0;
  top: calc(100% + 0.25rem);
  z-index: 40;
  width: 16rem;
  padding: 0.25rem;
  box-shadow: var(--shadow-raised);
}

.account-menu-header {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.account-menu-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.5rem 0.75rem;
  border: 0;
  border-radius: calc(var(--radius) - 2px);
  background: transparent;
  font-size: 0.875rem;
  text-align: start;
  cursor: pointer;
}

.account-menu-item:hover { background-color: var(--secondary); }

.page-content {
  width: 100%;
  max-width: 1440px;
  flex: 1;
  margin-inline: auto;
  padding: 1.25rem 1.75rem;
}

/* Tablets and phones: the sidebar slides in from the start side */
@media (max-width: 1023px) {
  .sidebar,
  .sidebar-collapsed .sidebar {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    z-index: 50;
    width: 260px;
    transform: translateX(-100%);
    transition: transform 0.2s;
  }

  [dir="rtl"] .sidebar { transform: translateX(100%); }

  .menu-open .sidebar { transform: none; }

  /* Always show the full sidebar inside the slide-in menu */
  .sidebar-collapsed .sidebar-logo { justify-content: flex-start; padding: 0 1.25rem; }
  .sidebar-collapsed .sidebar-logo .logo-full { display: block; }
  .sidebar-collapsed .sidebar-logo .logo-symbol { display: none; }
  .sidebar-collapsed .sidebar-link { justify-content: flex-start; padding: 0 0.75rem; }
  .sidebar-collapsed .sidebar-label { display: inline; }
  .sidebar-footer { display: none; }

  .menu-open .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 45;
    display: block;
    background: rgb(0 0 0 / 0.4);
  }

  .menu-button { display: inline-flex; }

  .page-content { padding: 1.25rem; }
}

@media (max-width: 767px) {
  .account-name { display: none; }
  .branch-chip { display: none; }
  /* Keep room for the page title: compact branch selector without its icon */
  .branch-select { padding: 0 0.375rem; }
  .branch-select svg { display: none; }
  .branch-select select { min-width: 0; max-width: 7.5rem; }
  .topbar { padding: 0 0.75rem; }
  .page-content { padding: 1.25rem 0.75rem; }
}

/* ---------- 8. Page building blocks ---------- */
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.page-header-text { min-width: 0; }

.page-title {
  font-size: 1.25rem;
  font-weight: 600;
}

.page-description {
  margin-top: 0.125rem;
  font-size: 0.875rem;
  color: var(--muted-foreground);
}

.page-header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.section { margin-top: 1.5rem; }

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.section-title {
  font-size: 0.9375rem;
  font-weight: 600;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 1rem;
}

.stat { padding: 1rem; }

.stat-label {
  font-size: 0.75rem;
  color: var(--muted-foreground);
}

.stat-value {
  margin-top: 0.25rem;
  font-size: 1.125rem;
  font-weight: 600;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 2.5rem 1.5rem;
  text-align: center;
}

.empty-state-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 999px;
  background-color: var(--secondary);
  color: var(--muted-foreground);
}

.empty-state-icon svg { width: 1.25rem; height: 1.25rem; }
.empty-state-title { font-weight: 500; }

.empty-state-text {
  max-width: 24rem;
  font-size: 0.875rem;
  color: var(--muted-foreground);
}

/* Badges (same colours as the original StatusBadge) */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.125rem 0.625rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-success { background-color: var(--success-soft); color: var(--success); }
.badge-warning { background-color: var(--warning-soft); color: var(--warning); }
.badge-info    { background-color: var(--info-soft);    color: var(--info); }
.badge-danger  { background-color: var(--danger-soft);  color: var(--destructive); }
.badge-neutral { background-color: var(--muted);        color: var(--muted-foreground); }
.badge-gold    { background-color: var(--gold-soft);    color: var(--gold); }

/* Tables */
.table-wrapper {
  overflow-x: auto;
  padding: 0;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table th {
  padding: 0.625rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background-color: oklch(0.945 0.013 82.4 / 0.5);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted-foreground);
  text-align: start;
  white-space: nowrap;
}

.data-table td {
  padding: 0.625rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  overflow-wrap: anywhere;
}

.data-table tbody tr:last-child td { border-bottom: 0; }

/* Details list (label / value) */
.details-panel { padding: 1rem 1.25rem; }

.details-list {
  display: grid;
  gap: 0.75rem;
  margin: 0;
}

.details-list > div {
  display: grid;
  grid-template-columns: minmax(0, 10rem) minmax(0, 1fr);
  gap: 1rem;
}

.details-list dt, .details-list dd { min-inline-size: 0; overflow-wrap: anywhere; }

.details-list dt { color: var(--muted-foreground); font-size: 0.875rem; }
.details-list dd { margin: 0; }

/* Cards (branches) */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 440px), 1fr));
  gap: 1rem;
}

.branch-card {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem;
}

.branch-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
}

.branch-card-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.branch-account-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.branch-account-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.branch-account-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.permission-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}

/* Switches (checkbox styled as a toggle) */
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.375rem 0.625rem;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 2px);
  font-size: 0.75rem;
  cursor: pointer;
}

.switch {
  position: relative;
  width: 2.25rem;
  height: 1.25rem;
  flex-shrink: 0;
  margin: 0;
  border-radius: 999px;
  background-color: var(--input);
  appearance: none;
  cursor: pointer;
  transition: background-color 0.15s;
}

.switch::after {
  position: absolute;
  top: 2px;
  inset-inline-start: 2px;
  width: 1rem;
  height: 1rem;
  border-radius: 999px;
  background-color: white;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.2);
  content: "";
  transition: inset-inline-start 0.15s;
}

.switch:checked { background-color: var(--primary); }
.switch:checked::after { inset-inline-start: calc(100% - 1rem - 2px); }

.form-input-small { height: 2.25rem; padding-block: 0.375rem; font-size: 0.875rem; }
.form-input[readonly] { background-color: var(--muted); color: var(--muted-foreground); }
select.form-input { cursor: pointer; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}
.form-grid > * { min-inline-size: 0; }

.form-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.form-section-title {
  margin: 0.5rem 0 0;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--primary);
}

@media (max-width: 640px) {
  :root { --panel-padding-inline: 1rem; }
  .form-grid,
  .form-grid-3,
  .permission-grid { grid-template-columns: 1fr; }
  .details-list > div { grid-template-columns: 1fr; gap: 0.125rem; }
}

/* Dialogs (<dialog> element) */
.dialog {
  width: min(32rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 2px);
  background-color: var(--card);
  color: var(--foreground);
  box-shadow: var(--shadow-raised);
}

.dialog-wide { width: min(46rem, calc(100vw - 2rem)); }

.dialog::backdrop { background: rgb(0 0 0 / 0.45); }

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem 0.5rem;
}

.dialog-title {
  font-size: 1.0625rem;
  font-weight: 600;
}

.dialog-body {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.5rem 1.25rem;
}

.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.75rem 1.25rem 1rem;
}
.dialog > form > .field-error:not(:empty) { margin-inline: var(--panel-padding-inline); }

.development-link {
  margin: 0.375rem 0;
  word-break: break-all;
  font-family: ui-monospace, monospace;
  font-size: 0.6875rem;
}

/* Toast messages */
.toast-area {
  position: fixed;
  top: 1rem;
  left: 50%;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  transform: translateX(-50%);
}

.toast {
  max-width: min(26rem, calc(100vw - 2rem));
  padding: 0.625rem 1rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-raised);
  font-size: 0.875rem;
}

.toast-success { background-color: var(--success-soft); color: var(--success); border: 1px solid var(--success); }
.toast-error   { background-color: var(--danger-soft);  color: var(--destructive); border: 1px solid var(--destructive); }

/* ---------- 9. Stage 4: settings, gold rate, inventory, labels ---------- */
.form-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

.form-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.form-field-switch { justify-content: flex-end; }

.read-only-value {
  padding: 0.625rem 0.75rem;
  border-radius: calc(var(--radius) - 2px);
  background-color: var(--muted);
  font-size: 0.875rem;
}

.success-note {
  border-color: oklch(0.479 0.078 161.1 / 0.5);
  background-color: var(--success-soft);
}

.success-note svg { color: var(--success); }

.branch-note { margin-bottom: 1rem; }
.code-text { font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; font-size: 0.8125rem; direction: ltr; unicode-bidi: isolate; }

/* Settings page */
.settings-layout {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  gap: 1rem;
  align-items: start;
}

.settings-form { padding: 1.25rem; }

.settings-side {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Gold rate panel */
.gold-rate-panel {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem;
}

.gold-rate-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
}

.gold-rate-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.gold-rate-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(6.5rem, 1fr));
  gap: 0.5rem;
}

.gold-rate-tile {
  padding: 0.625rem;
  border-radius: var(--radius);
  background-color: var(--gold-soft);
  text-align: center;
}

.gold-rate-karat { font-size: 0.75rem; font-weight: 600; color: var(--gold); }
.gold-rate-value { font-size: 1.0625rem; font-weight: 600; }
.gold-rate-source { line-height: 1.6; }
.gold-rate-updated { margin: 0; font-weight: 600; }

/* Gold Prices page */
.gold-prices-layout {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  gap: 1rem;
  align-items: start;
}

.gold-calculator { padding: 1rem; }

.gold-calculator-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.gold-calculator-form .form-field { flex: 1; min-width: 8rem; }

/* Price breakdown */
.price-example { padding: 1rem; }

.price-breakdown {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  margin: 0.75rem 0;
}

.price-breakdown div {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.375rem 1rem;
  font-size: 0.875rem;
}

.price-breakdown dt { color: var(--muted-foreground); }
.price-breakdown dd { margin: 0; }

.price-total {
  padding-top: 0.375rem;
  border-top: 1px solid var(--border);
  font-weight: 600;
}

.price-total dt { color: var(--foreground) !important; }

/* Shop manager dashboard (overview.php) and activity log (activity.php).
   Only the theme tokens above are used: no new colours, no gradients. */
.dashboard-stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 1rem;
}

.stat-card {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 1rem;
}

.stat-card-icon {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: var(--radius);
  background-color: var(--primary);
  color: var(--champagne);
}

.stat-card-icon svg { width: 1.25rem; height: 1.25rem; }
.stat-card-body { min-width: 0; }

.stat-card-value {
  margin-top: 0.125rem;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--primary);
  overflow-wrap: anywhere;
}

.stat-card-unit {
  margin-inline-start: 0.25rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted-foreground);
}

.stat-card-hint {
  margin-top: 0.125rem;
  font-size: 0.75rem;
  color: var(--muted-foreground);
}

.stat-card-hint-success { color: var(--success); }
.stat-card-hint-warning { color: var(--warning); }
.stat-card-hint-danger { color: var(--destructive); }

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  gap: 1rem;
  align-items: start;
}

.dashboard-column {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

.dashboard-panel { padding: 1rem; }
.dashboard-panel .section-title-row { margin-bottom: 0.5rem; }
.dashboard-panel .table-wrapper { border: 1px solid var(--border); box-shadow: none; }

.dashboard-filter {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.dashboard-filter .form-input { width: auto; }
.dashboard-filter { flex-wrap: wrap; justify-content: flex-end; }
.dashboard-filter .filter-date { display: flex; align-items: center; gap: 0.375rem; }
.dashboard-filter .filter-date[hidden] { display: none; }

.karat-bars {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.karat-bar-row {
  display: grid;
  grid-template-columns: 3rem minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.8125rem;
}

.karat-bar-label { font-weight: 600; color: var(--gold); }

.karat-bar-track {
  height: 0.5rem;
  overflow: hidden;
  border-radius: 999px;
  background-color: var(--gold-soft);
}

.karat-bar-fill {
  height: 100%;
  border-radius: 999px;
  background-color: var(--gold);
}

.karat-bar-value { color: var(--muted-foreground); white-space: nowrap; }

.summary-line {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  font-size: 0.8125rem;
  color: var(--muted-foreground);
}

.activity-feed {
  margin: 0;
  padding: 0;
  list-style: none;
}

.activity-feed-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.625rem 0;
  border-bottom: 1px solid var(--border);
}

.activity-feed-item:last-child { border-bottom: 0; }

.activity-feed-dot {
  flex-shrink: 0;
  width: 0.5rem;
  height: 0.5rem;
  margin-top: 0.4rem;
  border-radius: 999px;
  background-color: var(--gold);
}

.activity-feed-text { min-width: 0; font-size: 0.8125rem; }
.activity-feed-meta { font-size: 0.75rem; color: var(--muted-foreground); }

.quick-actions {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.5rem;
}

.quick-actions .button { justify-content: flex-start; }

.activity-filters .form-field { margin: 0; }
.activity-filters .filter-date { display: flex; align-items: center; gap: 0.375rem; }
.activity-filters .filter-date .form-input { width: auto; }
.activity-details { max-width: 28rem; overflow-wrap: anywhere; }

@media (max-width: 1100px) {
  .dashboard-grid { grid-template-columns: 1fr; }
}

/* Inventory reports (reports.php). Theme tokens only; no gradients.
   Bar charts: one series = one colour (burgundy), 14px bars grown from the line start with a
   4px rounded end, the value at the tip in text colours. */
.report-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  align-items: start;
}

.report-scope { margin: 0.75rem 0 0; line-height: 1.7; }
.report-print-title { display: none; }
.report-section .table-wrapper { margin-top: 0.75rem; }

.report-section .data-table tfoot th,
.report-section .data-table tfoot td {
  border-top: 1px solid var(--border);
  font-weight: 600;
}

.report-section .data-table th[scope="row"] { font-weight: 500; text-align: start; }

.bar-chart { margin: 0.5rem 0 0; }

.bar-chart-title {
  margin-bottom: 0.5rem;
  font-size: 0.75rem;
  color: var(--muted-foreground);
}

.bar-chart-rows {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.bar-chart-row {
  display: grid;
  grid-template-columns: minmax(5rem, 10rem) minmax(0, 1fr);
  align-items: center;
  gap: 0.75rem;
  font-size: 0.8125rem;
}

.bar-chart-label {
  overflow: hidden;
  color: var(--foreground);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-chart-track { padding-inline-end: 6.5rem; }   /* room for the value at the longest bar's tip */

.bar-chart-scale {
  position: relative;
  display: block;
  height: 14px;
}

.bar-chart-bar {
  position: absolute;
  inset-block: 0;
  inset-inline-start: 0;
  width: calc(var(--bar-percent) * 1%);
  border-start-end-radius: 4px;
  border-end-end-radius: 4px;
  background-color: var(--primary);
  print-color-adjust: exact;
  -webkit-print-color-adjust: exact;
}

.bar-chart-value {
  position: absolute;
  top: 50%;
  inset-inline-start: calc(var(--bar-percent) * 1%);
  padding-inline-start: 0.375rem;
  color: var(--muted-foreground);
  white-space: nowrap;
  transform: translateY(-50%);
}

.bar-chart-row:hover .bar-chart-bar { background-color: var(--primary-hover); }

@media (max-width: 1100px) {
  .report-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .bar-chart-row { grid-template-columns: minmax(4rem, 6rem) minmax(0, 1fr); gap: 0.5rem; }
  .report-filters .form-input { flex: 1 1 45%; }
}

@media print {
  .report-print-title { display: block; margin: 0 0 0.25rem; font-size: 1.125rem; font-weight: 600; }
  .report-grid { grid-template-columns: 1fr; }
  .report-section,
  .dashboard-stats .stat-card { break-inside: avoid; box-shadow: none; }
  .report-section .table-wrapper { overflow: visible; }
}

/* Report tabs and inventory movements (reports-movements.php). Theme tokens only; no gradients. */
.report-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.report-tab {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  margin-bottom: -1px;
  padding: 0.5rem 1rem;
  border-bottom: 2px solid transparent;
  color: var(--muted-foreground);
  text-decoration: none;
}

.report-tab:hover { color: var(--primary); }
.report-tab.is-current { border-bottom-color: var(--primary); color: var(--primary); }
.report-tab-label { font-size: 0.875rem; font-weight: 600; }
.report-tab-hint { font-size: 0.6875rem; color: var(--muted-foreground); }

.note-warning {
  border-style: solid;
  border-color: var(--warning);
  background-color: var(--warning-soft);
  color: var(--foreground);
}

.note-warning svg { color: var(--warning); }

.column-chart { margin: 0.5rem 0 0; }
.column-chart-scale { margin-bottom: 0.25rem; }

.column-chart-plot {
  display: grid;
  grid-template-columns: repeat(var(--columns), minmax(0, 1fr));
  align-items: end;
  gap: 2px;
  height: 160px;
  margin: 0;
  padding: 0;
  border-bottom: 1px solid var(--border);
  list-style: none;
}

.column-chart-column {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  height: 100%;
}

.column-chart-bar {
  width: 100%;
  max-width: 24px;
  height: calc(var(--column-percent) * 1%);
  border-radius: 4px 4px 0 0;
  background-color: var(--primary);
  print-color-adjust: exact;
  -webkit-print-color-adjust: exact;
}

.column-chart-column:hover .column-chart-bar { background-color: var(--primary-hover); }

.column-chart-axis {
  display: grid;
  grid-template-columns: repeat(var(--columns), minmax(0, 1fr));
  gap: 2px;
  margin-top: 0.25rem;
}

.column-chart-tick {
  overflow: visible;
  font-size: 0.6875rem;
  color: var(--muted-foreground);
  text-align: center;
  white-space: nowrap;
}

.report-details { margin-top: 0.75rem; }
.report-details summary { cursor: pointer; font-size: 0.8125rem; color: var(--primary); }

.coverage-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: 0.75rem 0 0;
  padding: 0;
  list-style: none;
}

.coverage-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}

.coverage-item .badge { flex-shrink: 0; gap: 0.25rem; min-width: 6.5rem; justify-content: center; }
.coverage-item .badge svg { width: 0.75rem; height: 0.75rem; }
.coverage-item p { margin: 0.125rem 0 0; }

@media (max-width: 640px) {
  .report-tab { flex: 1; padding: 0.5rem; }
  .column-chart-plot { height: 120px; }
  .coverage-item { flex-direction: column; gap: 0.25rem; }
}

@media print {
  .report-details > *:not(summary) { display: block; }
  .report-details summary { display: none; }
}

@media (max-width: 640px) {
  .dashboard-stats { grid-template-columns: 1fr; }
  .dashboard-filter { width: 100%; }
  .dashboard-filter .form-input { flex: 1; }
  .dashboard-filter .filter-date { width: 100%; }
  .activity-filters .filter-date { width: 100%; }
  .activity-filters .filter-date .form-input { flex: 1; }
}

/* Approvals (approvals.php) and the pending count in the sidebar. Theme tokens only; no gradients. */
.sidebar-badge {
  margin-inline-start: auto;
  min-width: 1.375rem;
  padding: 0.0625rem 0.375rem;
  border-radius: 999px;
  background-color: var(--gold);
  color: var(--primary);
  font-size: 0.6875rem;
  font-weight: 700;
  text-align: center;
}

.sidebar-collapsed .sidebar-badge { display: none; }

.approval-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 22rem), 1fr));
  gap: 1rem;
  margin-top: 0.75rem;
}

.approval-card {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem;
}

.approval-card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.875rem;
}

.approval-details {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  margin: 0;
  font-size: 0.8125rem;
}

.approval-details div {
  display: grid;
  grid-template-columns: minmax(6.5rem, 9rem) minmax(0, 1fr);
  gap: 0.5rem;
}

.approval-details dt { color: var(--muted-foreground); }
.approval-details dd { margin: 0; overflow-wrap: anywhere; }

.approval-form {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.approval-form textarea { height: auto; padding-block: 0.5rem; resize: vertical; }
.approval-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.approval-reject { color: var(--destructive); border-color: var(--destructive); }

.approval-outcomes {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  margin: 0;
  padding: 0;
  border: 0;
  font-size: 0.8125rem;
}

.approval-outcomes label { display: flex; align-items: flex-start; gap: 0.5rem; }

.approval-decision {
  margin: 0;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  color: var(--muted-foreground);
  line-height: 1.7;
}

.approval-reason-text { color: var(--foreground); }

@media (max-width: 640px) {
  .approval-details div { grid-template-columns: 1fr; gap: 0.125rem; }
}

/* Inventory list */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
  padding: 0.75rem;
}

.filter-bar .form-input { width: auto; }
.filter-search { flex: 1; min-width: 14rem; }
.filter-search .form-input { width: 100%; }

.selection-bar {
  position: sticky;
  top: 4rem;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  background-color: var(--primary);
  color: var(--primary-foreground);
}

.selection-bar[hidden] { display: none; }
.selection-bar .button-primary { background-color: var(--champagne); color: var(--primary); }

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.pagination-links {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.item-thumb {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background-color: var(--gold-soft);
  color: var(--gold);
}

.item-thumb img { width: 100%; height: 100%; object-fit: cover; }
.item-thumb svg { width: 40%; height: 40%; }

/* Quick entry and import */
.shared-details,
.import-form { margin-bottom: 1rem; padding: 1rem; }

.import-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.import-row .form-input { flex: 1; min-width: 16rem; padding-top: 0.5rem; }
.import-help { margin-top: 0.75rem; font-size: 0.875rem; }
.import-help summary { cursor: pointer; color: var(--primary); }

.review-panel { padding: 1rem; }
.review-table-wrapper { margin-top: 0.5rem; border: 1px solid var(--border); border-radius: var(--radius); }
.review-table td { padding: 0.375rem; }
.review-table .form-input { min-width: 6.5rem; }
.review-table select.form-input { min-width: 6rem; }
.row-number { color: var(--muted-foreground); text-align: center; }
.review-empty { padding: 1rem; text-align: center; }

.row-has-error { background-color: var(--danger-soft); }

.row-errors-line td {
  padding: 0.25rem 0.75rem 0.5rem;
  background-color: var(--danger-soft);
  font-size: 0.75rem;
  color: var(--destructive);
}

/* Item page */
.item-layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.item-photo-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem;
}

.photo-form { display: flex; flex-direction: column; gap: 0.5rem; inline-size: 100%; text-align: center; }
.photo-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.375rem; }
.photo-actions .button { padding-inline: 0.375rem; gap: 0.25rem; }
.photo-actions .file-button:has(input:disabled) { opacity: 0.5; cursor: wait; }
.item-photo-panel .item-thumb { max-inline-size: 100%; }
.file-button { cursor: pointer; }

.item-barcode {
  width: 100%;
  text-align: center;
}

.item-barcode .barcode { width: 100%; height: 50px; }

.item-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.item-title-row > .section-title { min-inline-size: 0; overflow-wrap: anywhere; }

.history-panel { grid-column: 2 / -1; padding: 1rem; }

.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0.75rem 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.875rem;
}

.history-list li { display: flex; flex-wrap: wrap; gap: 0.75rem; }
.item-history-list li { padding-block: 0.75rem; border-bottom: 1px solid var(--border); }
.item-history-list li:last-child { border-bottom: 0; }
.item-history-details { flex-basis: 100%; margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }

/* Barcode labels (about 50 x 25 mm each) */
.label-sheet {
  display: grid;
  grid-template-columns: repeat(auto-fill, 50mm);
  gap: 4mm;
}

.item-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 50mm;
  height: 25mm;
  padding: 1.5mm 2mm;
  overflow: hidden;
  border: 1px dashed var(--input);
  border-radius: 2mm;
  background: #fff;
  color: #000;
  break-inside: avoid;
}

.item-label-shop { font-size: 6.5pt; font-weight: 600; white-space: nowrap; }
.item-label .barcode { width: 100%; height: 10mm; }
.item-label-code { font-family: ui-monospace, monospace; font-size: 8pt; font-weight: 600; direction: ltr; }
.item-label-details { font-size: 6.5pt; }

@media (max-width: 1100px) {
  .settings-layout,
  .gold-prices-layout,
  .item-layout { grid-template-columns: 1fr; }
  .history-panel { grid-column: auto; }
  .form-grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .gold-rate-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid-4 { grid-template-columns: 1fr; }
}

/* ---------- 10. Print ---------- */
@media print {
  @page {
    size: A4;
    margin: 12mm;
  }

  body {
    background: white !important;
  }

  .no-print,
  .page-header,
  .toast-area,
  .skip-link {
    display: none !important;
  }

  .page-content { padding: 0; }
  .item-label { border-color: transparent; }
}

/* ---------- 10. Stage 4 fixes: cost warnings, item editing ---------- */

/* An unusual purchase cost: a warning (amber), not an error (red) */
.review-table .form-input.has-warning { border-color: var(--warning); background-color: var(--warning-soft); }

.row-warning-line td {
  padding: 0.25rem 0.75rem 0.5rem;
  background-color: var(--warning-soft);
  font-size: 0.75rem;
  color: var(--warning);
}

/* Results being reloaded by the filters */
#inventory-results[aria-busy="true"] { opacity: 0.6; transition: opacity 0.15s; }

/* Edit item page: the details that cannot be changed */
.edit-fixed-details { margin-bottom: 1rem; }

/* ---------- MUSAGH AI Assistant (insights.php). Theme tokens only; no gradients. ----------
   Every rule is scoped to .ai-page. Desktop: header, then the sidebar ("New chat" and suggested
   questions, 280px) on the LEFT and the chat on the RIGHT in both languages. Messages are placed
   physically: the user on the right, the assistant on the left. */
.ai-page {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  max-width: 1200px;
  height: calc(100dvh - 7.5rem);
  min-height: 34rem;
  margin-inline: auto;
}

/* ----- Header: icon + one title group, aligned to the reading direction ----- */
.ai-page .ai-page-header { display: flex; align-items: center; gap: 0.875rem; text-align: start; }
.ai-page .ai-page-heading { display: flex; flex: 1; flex-direction: column; gap: 0.25rem; min-width: 0; }
.ai-page .ai-title-group { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.25rem 0.75rem; }
.ai-page .ai-title { margin: 0; font-size: 1.5rem; font-weight: 700; line-height: 1.25; color: var(--primary); }
.ai-page .ai-title-alt {
  padding: 0.125rem 0.625rem;
  border: 1px solid var(--champagne);
  border-radius: 999px;
  background-color: var(--gold-soft);
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
}
.ai-page .ai-page-text { margin: 0; font-size: 0.875rem; line-height: 1.6; color: var(--muted-foreground); }

.ai-page .ai-mark {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 3.25rem;
  height: 3.25rem;
  border-radius: 0.875rem;
  background-color: var(--primary);
  color: var(--champagne);
}

.ai-page .ai-mark svg { width: 1.625rem; height: 1.625rem; }
.ai-page .ai-mark-large { width: 4rem; height: 4rem; border-radius: 1rem; }
.ai-page .ai-mark-large svg { width: 2rem; height: 2rem; }

/* ----- Two columns; the sidebar is on the left in both directions ----- */
.ai-page .ai-layout {
  display: grid;
  flex: 1;
  grid-template-columns: minmax(0, 1fr) 280px;
  grid-template-areas: "main side";   /* Arabic (RTL): the first column is on the right */
  gap: 1.25rem;
  min-height: 0;
}

[dir="ltr"] .ai-page .ai-layout {
  grid-template-columns: 280px minmax(0, 1fr);
  grid-template-areas: "side main";   /* English (LTR): the sidebar stays on the left */
}

/* Thin, quiet scrollbars where something scrolls */
.ai-page .ai-chat-scroll,
.ai-page .ai-side { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
.ai-page .ai-chat-scroll::-webkit-scrollbar,
.ai-page .ai-side::-webkit-scrollbar { width: 6px; }
.ai-page .ai-chat-scroll::-webkit-scrollbar-thumb,
.ai-page .ai-side::-webkit-scrollbar-thumb { border-radius: 999px; background-color: var(--border); }
.ai-page .ai-chat-scroll::-webkit-scrollbar-track,
.ai-page .ai-side::-webkit-scrollbar-track { background: transparent; }

/* ----- Sidebar: fills the column height and scrolls as a whole, so nothing is clipped ----- */
.ai-page .ai-side {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  grid-area: side;
  min-width: 0;
  min-height: 0;
  max-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background-color: var(--card);
  box-shadow: var(--shadow-panel);
}

.ai-page .ai-side > * { flex-shrink: 0; }
.ai-page .ai-new-chat { width: 100%; height: 2.5rem; }

.ai-page .ai-side-title { display: flex; align-items: center; gap: 0.5rem; margin: 0; font-size: 0.9375rem; font-weight: 600; line-height: 1.4; color: var(--primary); }
.ai-page .ai-side-title svg { flex-shrink: 0; width: 1.125rem; height: 1.125rem; color: var(--gold); }

.ai-page .ai-side-list { display: flex; flex-direction: column; gap: 0.5rem; margin: 0; padding: 2px; list-style: none; }
.ai-page .ai-side-list li { min-width: 0; }

.ai-page .ai-side-question {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  width: 100%;
  min-width: 0;
  padding: 0.6875rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background-color: var(--panel);
  color: var(--foreground);
  font: inherit;
  font-size: 0.8125rem;
  line-height: 1.5;
  text-align: start;
  white-space: normal;
  overflow-wrap: anywhere;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
}

.ai-page .ai-side-question > span { flex: 1; min-width: 0; }
.ai-page .ai-side-question svg { flex-shrink: 0; width: 1.125rem; height: 1.125rem; margin-top: 0.0625rem; color: var(--gold); }
.ai-page .ai-side-question:hover { border-color: var(--gold); background-color: var(--gold-soft); }
.ai-page .ai-side-question:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--ring); }

.ai-page .ai-side-more {
  display: inline-flex;
  align-self: flex-start;
  align-items: center;
  gap: 0.25rem;
  margin-top: -0.25rem;
  padding: 0.25rem 0.125rem;
  border: 0;
  border-radius: 0.375rem;
  background: none;
  color: var(--primary);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
}

.ai-page .ai-side-more:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--ring); }
.ai-page .ai-side-more svg { width: 1rem; height: 1rem; transition: transform 0.15s; }
.ai-page .ai-side-more[aria-expanded="true"] svg { transform: rotate(180deg); }
.ai-page .ai-side-note { margin: auto 0 0; padding-top: 0.875rem; border-top: 1px solid var(--border); font-size: 0.75rem; line-height: 1.65; color: var(--muted-foreground); }

/* ----- Chat column: the thread scrolls, the composer stays at the bottom ----- */
.ai-page .ai-main { display: flex; flex-direction: column; grid-area: main; gap: 0.75rem; min-width: 0; min-height: 0; }

.ai-page .ai-chat-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background-color: var(--panel);
  box-shadow: var(--shadow-panel);
  scroll-behavior: smooth;
}

.ai-page .ai-thread {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  max-width: 850px;
  min-height: 100%;
  margin-inline: auto;
  padding: 1.5rem 1.25rem;
}

.ai-page .ai-row { display: flex; align-items: flex-start; gap: 0.75rem; }
.ai-page .assistant-message { display: flex; flex-direction: column; gap: 0.3125rem; font-size: 0.9375rem; }

/* The user's question: on the right, avatar outermost */
.ai-page .assistant-message-user { align-self: flex-end; align-items: flex-end; max-width: 78%; }
.ai-page .assistant-message-user .ai-row { flex-direction: row-reverse; }
[dir="rtl"] .ai-page .assistant-message-user { align-self: flex-start; align-items: flex-start; }
[dir="rtl"] .ai-page .assistant-message-user .ai-row { flex-direction: row; }

.ai-page .assistant-message-user .ai-bubble {
  padding: 0.6875rem 1rem;
  border-radius: 1rem;
  border-top-right-radius: 0.25rem;
  background-color: var(--primary);
  color: var(--primary-foreground);
  overflow-wrap: anywhere;
}

.ai-page .assistant-message-user .assistant-time { padding-inline: 3rem; }

/* The assistant's answer: on the left, avatar outermost */
.ai-page .assistant-message-assistant { align-self: flex-start; width: 100%; }
[dir="rtl"] .ai-page .assistant-message-assistant { align-self: flex-end; }
[dir="rtl"] .ai-page .assistant-message-assistant .ai-row { flex-direction: row-reverse; }

.ai-page .ai-user-avatar,
.ai-page .ai-bot-avatar {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 999px;
}

.ai-page .ai-user-avatar { background-color: var(--primary); color: var(--primary-foreground); }
.ai-page .ai-bot-avatar { border: 1px solid var(--champagne); background-color: var(--gold-soft); color: var(--primary); }
.ai-page .ai-user-avatar svg,
.ai-page .ai-bot-avatar svg { width: 1.125rem; height: 1.125rem; }

.ai-page .assistant-text { margin: 0; line-height: 1.7; }
.ai-page .assistant-time { font-size: 0.6875rem; color: var(--muted-foreground); }

.ai-page .ai-card {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 0.875rem;
  min-width: 0;
  max-width: 680px;
  padding: 1rem 1.125rem 0.625rem;
  border: 1px solid var(--border);
  border-radius: 1rem;
  border-top-left-radius: 0.25rem;
  background-color: var(--card);
  box-shadow: var(--shadow-panel);
  overflow-wrap: anywhere;
}

/* ----- Key numbers: one card each, label on top, the number large with its unit beside it ----- */
.ai-page .ai-highlights { display: grid; gap: 0.625rem; }
.ai-page .ai-highlights-many { grid-template-columns: repeat(auto-fit, minmax(min(100%, 11.5rem), 1fr)); }

.ai-page .ai-highlight {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  min-width: 0;
  padding: 0.875rem 1rem;
  border: 1px solid var(--champagne);
  border-inline-start: 3px solid var(--gold);
  border-radius: 0.75rem;
  background-color: var(--gold-soft);
}

.ai-page .ai-highlight-label {
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: 0.01em;
  color: var(--muted-foreground);
}

.ai-page .ai-highlight-figure { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.25rem 0.5rem; }
.ai-page .ai-highlight-number { font-size: 1.875rem; font-weight: 700; line-height: 1.1; color: var(--primary); font-variant-numeric: tabular-nums; }
.ai-page .ai-highlights-many .ai-highlight-number { font-size: 1.5rem; }
.ai-page .ai-highlight-unit {
  padding: 0.0625rem 0.5rem;
  border-radius: 999px;
  background-color: var(--card);
  color: var(--primary);
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1.5;
}

.ai-page .ai-caption { margin: -0.25rem 0 0; font-size: 0.8125rem; line-height: 1.6; color: var(--muted-foreground); }
.ai-page .ai-link { align-self: flex-start; font-size: 0.8125rem; font-weight: 500; color: var(--primary); }

/* "More details": opens in place, nothing is clipped */
.ai-page .ai-details { border: 1px solid var(--border); border-radius: 0.75rem; background-color: var(--panel); }

.ai-page .ai-details summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5625rem 0.875rem;
  color: var(--primary);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}

.ai-page .ai-details summary::-webkit-details-marker { display: none; }
.ai-page .ai-details summary svg { flex-shrink: 0; width: 1rem; height: 1rem; }
.ai-page .ai-details-chevron { margin-inline-start: auto; transition: transform 0.15s; }
.ai-page .ai-details[open] .ai-details-chevron { transform: rotate(180deg); }
.ai-page .ai-details summary:focus-visible { outline: none; border-radius: 0.75rem; box-shadow: 0 0 0 2px var(--ring); }
.ai-page .ai-details[open] summary { border-bottom: 1px solid var(--border); }
.ai-page .ai-details-body { padding: 0.25rem 0.875rem 0.75rem; }

.ai-page .assistant-figures { display: flex; flex-direction: column; margin: 0; }

.ai-page .assistant-figures div {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.25rem 1rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.8125rem;
}

.ai-page .assistant-figures div:last-child { border-bottom: 0; }
.ai-page .assistant-figures dt { color: var(--muted-foreground); }
.ai-page .assistant-figures dd { margin: 0; font-weight: 600; color: var(--foreground); }

.ai-page .assistant-note { display: flex; align-items: flex-start; gap: 0.375rem; margin: 0.5rem 0 0; font-size: 0.75rem; line-height: 1.6; color: var(--muted-foreground); }
.ai-page .assistant-note svg { flex-shrink: 0; width: 0.875rem; height: 0.875rem; margin-top: 0.1875rem; color: var(--gold); }
.ai-page .ai-sources-title { margin: 0.75rem 0 0.25rem; font-size: 0.75rem; font-weight: 600; color: var(--muted-foreground); }
.ai-page .assistant-sources { margin: 0; padding-inline-start: 1rem; font-size: 0.75rem; line-height: 1.6; color: var(--muted-foreground); }

.ai-page .ai-card-footer { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-top: -0.25rem; padding-top: 0.375rem; border-top: 1px solid var(--border); }

.ai-page .ai-icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.875rem;
  height: 1.875rem;
  border: 0;
  border-radius: 0.5rem;
  background: transparent;
  color: var(--muted-foreground);
  cursor: pointer;
}

.ai-page .ai-icon-button:hover { background-color: var(--muted); color: var(--primary); }
.ai-page .ai-icon-button:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--ring); }
.ai-page .ai-icon-button svg { width: 1rem; height: 1rem; }

.ai-page .assistant-suggestions { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.ai-page .ai-chip {
  padding: 0.375rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background-color: var(--card);
  color: var(--primary);
  font: inherit;
  font-size: 0.8125rem;
  line-height: 1.45;
  text-align: start;
  cursor: pointer;
}

.ai-page .ai-chip:hover { border-color: var(--gold); background-color: var(--gold-soft); }
.ai-page .ai-chip:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--ring); }

/* Empty conversation */
.ai-page .ai-welcome {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 2rem 1rem;
  text-align: center;
}

.ai-page .ai-welcome-title { margin: 0.75rem 0 0; font-size: 1.375rem; font-weight: 700; line-height: 1.3; color: var(--primary); }
.ai-page .ai-welcome-text { max-width: 30rem; margin: 0; font-size: 0.9375rem; line-height: 1.7; color: var(--muted-foreground); }

/* "Typing" while the answer is on its way (on the assistant's side) */
.ai-page .ai-typing { display: flex; align-self: flex-start; align-items: flex-start; gap: 0.75rem; }
[dir="rtl"] .ai-page .ai-typing { flex-direction: row-reverse; align-self: flex-end; }

.ai-page .ai-typing .ai-bubble {
  display: flex;
  gap: 0.25rem;
  padding: 0.875rem 1rem;
  border: 1px solid var(--border);
  border-radius: 1rem;
  border-top-left-radius: 0.25rem;
  background-color: var(--card);
}

.ai-page .ai-typing .ai-bubble span { width: 0.375rem; height: 0.375rem; border-radius: 999px; background-color: var(--gold); animation: ai-typing 1.2s infinite ease-in-out; }
.ai-page .ai-typing .ai-bubble span:nth-child(2) { animation-delay: 0.15s; }
.ai-page .ai-typing .ai-bubble span:nth-child(3) { animation-delay: 0.3s; }

@keyframes ai-typing {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

/* ----- Composer, at the bottom of the chat column ----- */
.ai-page .ai-composer { flex-shrink: 0; }

.ai-page .ai-composer-box {
  display: flex;
  align-items: flex-end;
  gap: 0.625rem;
  max-width: 850px;
  margin-inline: auto;
  padding: 0.5rem;
  padding-inline-start: 1.125rem;
  border: 1px solid var(--input);
  border-radius: 1.25rem;
  background-color: var(--card);
  box-shadow: var(--shadow-raised);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.ai-page .ai-composer-box:focus-within { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }

.ai-page .ai-composer-input {
  flex: 1;
  min-width: 0;
  min-height: 1.5rem;
  max-height: 160px;
  padding: 0.625rem 0;
  border: 0;
  background: transparent;
  color: var(--foreground);
  font: inherit;
  font-size: 0.9375rem;
  line-height: 1.55;
  resize: none;
}

.ai-page .ai-composer-input::placeholder { color: var(--muted-foreground); }
.ai-page .ai-composer-input:focus { outline: none; }

.ai-page .ai-send {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  border: 0;
  border-radius: 999px;
  background-color: var(--primary);
  color: var(--primary-foreground);
  cursor: pointer;
  transition: background-color 0.15s, opacity 0.15s;
}

.ai-page .ai-send:hover:not(:disabled) { background-color: var(--primary-hover); }
.ai-page .ai-send:disabled { opacity: 0.35; cursor: default; }
.ai-page .ai-send:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--ring); }
.ai-page .ai-send svg { width: 1.125rem; height: 1.125rem; }
[dir="rtl"] .ai-page .ai-send svg { transform: scaleX(-1); }   /* The paper plane points towards the reading direction */

.ai-page .ai-composer-meta {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  max-width: 850px;
  margin: 0.375rem auto 0;
  padding-inline: 0.75rem;
  font-size: 0.6875rem;
  color: var(--muted-foreground);
}

.ai-page .ai-composer .field-error { max-width: 850px; margin-inline: auto; padding-inline: 0.75rem; }

/* ----- Tablet: narrower sidebar, still on the left ----- */
@media (max-width: 1100px) {
  .ai-page .ai-layout { grid-template-columns: minmax(0, 1fr) 240px; }
  [dir="ltr"] .ai-page .ai-layout { grid-template-columns: 240px minmax(0, 1fr); }
}

/* ----- Small tablet and mobile: one column, suggestions above the chat ----- */
@media (max-width: 900px) {
  .ai-page { height: auto; min-height: 0; }
  .ai-page .ai-layout,
  [dir="ltr"] .ai-page .ai-layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: "side" "main"; }
  .ai-page .ai-side { max-height: none; padding: 0.875rem; gap: 0.75rem; }
  .ai-page .ai-new-chat { width: auto; align-self: flex-start; }
  .ai-page .ai-side-list { flex-direction: row; flex-wrap: wrap; }
  .ai-page .ai-side-list li { flex: 1 1 14rem; }
  .ai-page .ai-side-question { height: 100%; padding: 0.5625rem 0.75rem; }
  .ai-page .ai-side-note { display: none; }
  .ai-page .ai-main { height: calc(100dvh - 9rem); min-height: 26rem; }
}

@media (max-width: 640px) {
  .ai-page { gap: 1rem; }
  .ai-page .ai-title { font-size: 1.25rem; }
  .ai-page .ai-mark { width: 2.75rem; height: 2.75rem; border-radius: 0.75rem; }
  .ai-page .ai-mark svg { width: 1.375rem; height: 1.375rem; }
  .ai-page .ai-page-text { display: none; }
  .ai-page .ai-new-chat { width: 100%; }
  .ai-page .ai-side-list li { flex-basis: 100%; }
  .ai-page .ai-thread { gap: 1rem; padding: 1rem 0.75rem; }
  .ai-page .ai-row { gap: 0.5rem; }
  .ai-page .ai-user-avatar,
  .ai-page .ai-bot-avatar { width: 2rem; height: 2rem; }
  .ai-page .assistant-message-user { max-width: 90%; }
  .ai-page .assistant-message-user .assistant-time { padding-inline: 2.5rem; }
  .ai-page .ai-card { padding: 0.875rem 0.875rem 0.5rem; }
  .ai-page .ai-highlight-number { font-size: 1.625rem; }
  .ai-page .ai-highlights-many .ai-highlight-number { font-size: 1.375rem; }
  .ai-page .ai-composer-meta > span:first-child { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .ai-page .ai-typing .ai-bubble span { animation: none; }
  .ai-page .ai-chat-scroll { scroll-behavior: auto; }
}

/* ---------- 11. Platform administrator: shop actions ---------- */

.row-actions { display: flex; flex-wrap: wrap; gap: 0.375rem; }
.status-reason { max-width: 14rem; margin-top: 0.25rem; overflow-wrap: anywhere; }

.button-danger {
  background-color: var(--destructive);
  border-color: var(--destructive);
  color: #fff;
}
.button-danger:hover { filter: brightness(0.92); }

.form-textarea { min-height: 4.5rem; resize: vertical; font-family: inherit; }

/* ---------- 12. Shared fixes ---------- */

/*
 * The HTML "hidden" attribute must always hide an element. Without this rule, a class that sets
 * "display" (e.g. .dialog-body { display: flex } or .button { display: inline-flex }) wins over it,
 * and elements the scripts hide stay visible.
 */
[hidden] { display: none !important; }

/* Text in the other writing direction inside a sentence (CR numbers, dates in Arabic text) */
.isolate-ltr { direction: ltr; unicode-bidi: isolate; white-space: nowrap; }   /* Never split a code across lines */

/* Coloured variants of .note for messages inside dialogs */
.note-error   { border-color: var(--destructive); background-color: var(--danger-soft); color: var(--destructive); }
.note-success { border-color: var(--success); background-color: var(--success-soft); color: var(--success); }
.note-error svg, .note-success svg { color: inherit; }

/* ---------- 13. Platform administrator: support tickets ---------- */
.ticket-layout { display: grid; grid-template-columns: minmax(0, 24rem) minmax(0, 1fr); gap: 1rem; align-items: start; margin-top: 1rem; }
@media (max-width: 900px) { .ticket-layout { grid-template-columns: 1fr; } }

.conversation { display: flex; flex-direction: column; gap: 0.75rem; margin: 0.75rem 0 1rem; padding: 0; list-style: none; }
.message { padding: 0.625rem 0.875rem; border: 1px solid var(--border); border-radius: var(--radius); }
.message-shop { background-color: var(--card); }
.message-admin { background-color: oklch(0.94 0.035 84 / 0.6); border-color: oklch(0.652 0.086 80.4 / 0.5); }
.message-meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.375rem; margin-bottom: 0.25rem; font-size: 0.8125rem; }
.message-text { margin: 0; white-space: normal; overflow-wrap: anywhere; }

.ticket-conversation { padding: 1rem 1.25rem; }
.reply-form, .status-form { margin-top: 0.75rem; }
.status-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.5rem; padding-top: 0.75rem; border-top: 1px solid var(--border); }
.status-form .form-field { min-width: 12rem; }
/* The ticket details panel is narrow: a smaller label column leaves room for codes and dates */
.ticket-layout .details-list div { grid-template-columns: 6.5rem minmax(0, 1fr); }
.ticket-layout .details-list dd { min-width: 0; overflow-wrap: anywhere; }
/* Codes stay on one line elsewhere, but inside the narrow ticket details they may wrap rather than overflow */
.ticket-layout .details-list .isolate-ltr { white-space: normal; overflow-wrap: anywhere; }   /* Breaks at hyphens first */

/* ---------- 14. Customer display (second monitor or paired device, read-only) ---------- */
/*
   The display wears its shop's colours (Settings -> Shop identity), sent with every answer and applied by
   customer-display.js as --cd-* values (Musagh's burgundy and gold until then): the header, the welcome panel and the
   price panel are in the brand colour with light text on them; the rest is ivory. Always in both languages: each text in
   Arabic with its English below it (.cd-bi: .cd-ar then .cd-en, smaller, at a fixed gap); a value is shown once.
   Shows the price of the item being looked at (for browsing and comparing; scanning sells nothing). No cart total.
   Everything is in this file on purpose: a paired device on the local network may load only main.css. */
body.customer-display {
  --cd-brand: #591a23; --cd-on-brand: #ffffff; --cd-ink: #591a23; --cd-soft: #f2eded; --cd-accent: #c09652;
  --cd-ivory: #fbf8f2; --cd-panel-text: #f8f1e4; --cd-text: #1f1b18; --cd-muted: #6e655d; --cd-line: rgb(31 27 24 / 0.11);
  --cd-on-brand-muted: color-mix(in srgb, var(--cd-on-brand) 80%, var(--cd-brand));
  --cd-card-shadow: 0 1px 2px rgb(31 27 24 / 0.05), 0 14px 34px -20px rgb(31 27 24 / 0.35);
  height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; margin: 0;
  font-family: var(--font-arabic); color: var(--cd-text); background-color: var(--cd-ivory);
}

/* Both languages: the Arabic line, then the English line below it, smaller, at a fixed gap; each keeps its own direction */
.cd-bi { display: inline-flex; flex-direction: column; align-items: flex-start; gap: 0.18em; }
.cd-bi > .cd-ar, .cd-bi > .cd-en { display: block; unicode-bidi: isolate; }
/* At least about 12px where the Arabic is small, always smaller than the Arabic above it */
.cd-bi > .cd-en { font-size: max(0.62em, min(0.75rem, 0.9em)); font-weight: 500; line-height: 1.25; opacity: 0.85; letter-spacing: 0.01em; }
.cd-bi > .cd-en[hidden] { display: none; }
.cd-message .cd-bi { align-items: center; }
/* Side by side: the Arabic on the right and its English on the left, on one level */
.cd-bi.cd-side { flex-direction: row; align-items: baseline; justify-content: center; gap: 0 clamp(1rem, 2.5vw, 2.25rem); }
.cd-bi.cd-side > .cd-en { margin: 0; }

/* Header: the full width in the brand colour; the small logo and the branch in both languages; light text on it */
.cd-header { flex: none; display: flex; align-items: center; gap: clamp(0.875rem, 1.6vw, 1.5rem);
  padding: clamp(0.5rem, 1.2vh, 0.875rem) clamp(1rem, 2.5vw, 2.25rem); background-color: var(--cd-brand); color: var(--cd-on-brand);
  border-bottom: 2px solid color-mix(in srgb, var(--cd-accent) 70%, transparent); transition: background-color 300ms ease; }
.cd-shop-logo { flex: none; display: inline-flex; align-items: center; justify-content: center;
  block-size: clamp(3rem, 7.2vh, 4.25rem); max-inline-size: clamp(7rem, 14vw, 13rem); }
.cd-shop-logo[hidden] { display: none; }
.cd-shop-logo img { display: block; max-inline-size: 100%; max-block-size: 100%; inline-size: auto; block-size: auto; object-fit: contain; }
/* A logo that does not stand out from the brand colour sits on a plate of the colour that shows it best (customer-display.js) */
.cd-shop-logo.has-plate { padding: 0.3rem 0.625rem; border-radius: 0.625rem; background-color: var(--cd-plate, var(--cd-ivory)); }
.cd-shop { flex: 1; min-width: 0; display: flex; align-items: center; gap: clamp(0.875rem, 1.6vw, 1.5rem); }
.cd-branch-name { min-width: 0; font-size: clamp(0.9375rem, 1.25vw, 1.125rem); line-height: 1.3; color: var(--cd-on-brand-muted); }
.cd-branch-name > span { max-inline-size: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cd-header-actions { flex: none; display: flex; gap: 0.5rem; }
.cd-header-button { display: inline-flex; align-items: center; min-block-size: 2.5rem; padding: 0.3rem 0.875rem;
  font: inherit; font-size: 1rem; font-weight: 500; color: var(--cd-on-brand); background: transparent; cursor: pointer;
  border: 1px solid color-mix(in srgb, var(--cd-on-brand) 40%, transparent); border-radius: 0.5rem; transition: background-color 160ms ease; }
.cd-header-button .cd-bi { align-items: center; }
.cd-header-button:hover { background-color: color-mix(in srgb, var(--cd-on-brand) 12%, transparent); }
.cd-header-button:focus-visible { outline: 2px solid var(--cd-on-brand); outline-offset: 2px; }
.cd-header-button[hidden] { display: none; }

.cd-main { flex: 1; min-height: 0; display: flex; padding: clamp(0.625rem, 1.6vh, 1.25rem) clamp(0.75rem, 1.6vw, 1.5rem); }
.cd-screen { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; gap: 1rem; }
.cd-screen[hidden] { display: none; }
.cd-message { align-items: center; justify-content: center; text-align: center; }
.cd-message h1 { margin: 0; font-size: clamp(1.75rem, 4vw, 3rem); font-weight: 700; line-height: 1.25; color: var(--cd-ink); }
.cd-message p { margin: 0; font-size: clamp(1.0625rem, 1.7vw, 1.375rem); line-height: 1.6; color: var(--cd-muted); max-width: 44rem; text-wrap: balance; }
.cd-warning h1 { color: var(--destructive); }

/* Welcome: on ivory (no panel), centred: the greeting in one row (Arabic on the right, English on the left, balanced),
   then the description: the Arabic line, then the English line, both centred */
.cd-welcome-group { display: flex; flex-direction: column; align-items: center; text-align: center; gap: clamp(1rem, 3vh, 1.75rem);
  max-inline-size: 60rem; animation: cd-enter 600ms cubic-bezier(0.2, 0.7, 0.2, 1) both; }
.cd-welcome-group h1.cd-welcome-title { margin: 0; color: var(--cd-ink); font-size: clamp(2.25rem, min(4.4vw, 7vh), 3.75rem); line-height: 1.2; }
.cd-welcome-group .cd-welcome-title > .cd-en { font-size: 0.86em; font-weight: 600; opacity: 1; letter-spacing: 0; }
.cd-welcome-group p.cd-welcome-text { margin: 0; max-width: none; font-size: clamp(1.125rem, min(1.9vw, 3vh), 1.5rem); color: var(--cd-muted); }
.cd-welcome-group .cd-welcome-text > .cd-en { font-size: 0.86em; }

/* Logo boxes (welcome panel and thank-you): the image never larger than its box, kept whole */
.cd-mark { display: flex; align-items: center; justify-content: center; inline-size: min(240px, 70vw); block-size: 180px; flex: none; }
.cd-mark-logo { display: flex; align-items: center; justify-content: center; box-sizing: border-box; inline-size: 100%; block-size: 100%; }
.cd-mark-logo[hidden] { display: none; }
.cd-mark-logo img { display: block; max-inline-size: 100%; max-block-size: 100%; inline-size: auto; block-size: auto; object-fit: contain; }
.cd-mark-logo.has-plate { padding: 1rem 1.25rem; border-radius: 1rem; background-color: var(--cd-plate, var(--cd-brand)); }
/* No logo at all: the Musagh symbol drawn in the shop's colour (ivory on the welcome panel) */
.cd-mark-symbol { display: block; inline-size: 120px; block-size: 120px; max-block-size: 100%; background-color: var(--cd-brand);
  -webkit-mask: url("/assets/img/brand/musagh-symbol_burgundy.png") center / contain no-repeat;
          mask: url("/assets/img/brand/musagh-symbol_burgundy.png") center / contain no-repeat; }
body.has-brand-logo .cd-mark-symbol { display: none; }

/* Thank-you: centred column on ivory */
.cd-greeting-group { display: flex; flex-direction: column; align-items: center; text-align: center; max-inline-size: 46rem; }
.cd-greeting-group h1 { margin-block-start: 24px; }
.cd-greeting-group .cd-greeting-text { margin-block-start: 1rem; }

/* ---- The item being looked at: details on one side, the price panel (about half) on the other ---- */
.cd-quote { gap: clamp(0.375rem, 1vh, 0.625rem); }
.cd-stage { flex: 1; min-height: 0; display: flex; }
.cd-item { flex: 1; min-width: 0; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: clamp(1rem, 2.4vw, 2.25rem); padding: clamp(0.625rem, min(1.8vw, 2.6vh), 1.75rem); overflow: hidden;
  background-color: #ffffff; border: 1px solid var(--cd-line); border-radius: 1.25rem; box-shadow: var(--cd-card-shadow); }
.cd-item-info { min-width: 0; min-height: 0; display: flex; flex-direction: column; justify-content: center;
  gap: clamp(0.5rem, 1.6vh, 1.25rem); overflow-y: auto; scrollbar-width: none; }
.cd-item-head { display: flex; align-items: center; gap: clamp(1rem, 2vw, 1.75rem); }

/* The piece: whole, never cropped or stretched, about 220-280 px, no heavy frame */
.cd-media { display: flex; align-items: center; justify-content: center; overflow: hidden; color: var(--cd-accent); flex: none; }
.cd-media img { display: block; max-inline-size: 100%; max-block-size: 100%; inline-size: auto; block-size: auto; object-fit: contain; }
.cd-item-media { inline-size: clamp(170px, 23vh, 260px); block-size: clamp(170px, 23vh, 260px); border-radius: 0.875rem; }
.cd-item-media.is-icon { background-color: var(--cd-soft); }
.cd-item-media.is-icon .cd-type-icon { inline-size: 55%; block-size: 55%; }
.cd-type-icon { inline-size: 60%; block-size: 60%; }
.cd-type-icon svg { inline-size: 100%; block-size: 100%; }

.cd-item-title { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: clamp(0.25rem, 0.8vh, 0.625rem); }
/* Type and name: two facing columns, Arabic on the right and English on the left, each pair on one level */
.cd-item-title .cd-side { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: baseline; gap: 0 1.25rem; inline-size: 100%; }
.cd-item-title .cd-side > .cd-en { text-align: left; font-size: 0.82em; }
.cd-item-title .cd-side > .cd-ar { text-align: right; }
.cd-item-title .cd-side > .cd-en[hidden] { display: block; visibility: hidden; }
.cd-item-type { margin: 0; font-size: clamp(1rem, min(1.35vw, 2.2vh), 1.25rem); font-weight: 600; color: var(--cd-ink); }
.cd-item-name { margin: 0; font-size: clamp(1.25rem, min(2.1vw, 3.6vh), 2rem); font-weight: 600; line-height: 1.25; color: var(--cd-text); }
/* At most two lines each (the more specific selector wins over the generic .cd-bi > span display) */
.cd-item-name.cd-bi > span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.cd-item-name > .cd-en { color: var(--cd-muted); opacity: 1; font-weight: 500; }
.cd-item-code { margin: 0; text-align: center; font-size: clamp(0.9375rem, 1.15vw, 1.0625rem); color: var(--cd-muted); letter-spacing: 0.05em; unicode-bidi: isolate; }

/* Light tables: the Arabic name on the right, the value in the middle, the English name on the left; one value per row */
.cd-table { display: flex; flex-direction: column; margin: 0; font-size: clamp(1rem, min(1.4vw, 2.35vh), 1.3125rem); }
.cd-row { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 1rem;
  padding-block: clamp(0.25rem, 0.85vh, 0.7rem); border-bottom: 1px solid var(--cd-line); }
.cd-row:first-child { border-top: 1px solid var(--cd-line); }
.cd-row[hidden] { display: none; }
.cd-row-ar { text-align: right; color: var(--cd-text); }
.cd-row-en { text-align: left; color: var(--cd-muted); font-size: 0.9em; }
.cd-row-value { min-inline-size: 7ch; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; unicode-bidi: isolate; white-space: nowrap; color: var(--cd-text); }
.cd-row-value.is-spec { font-size: 1.1em; }

/* The price: the largest thing on the screen, light and bold on the brand colour; the currency smaller, in both languages */
.cd-price-block { min-width: 0; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: clamp(0.375rem, 1.6vh, 1rem); text-align: center; padding: clamp(1rem, 3vh, 2rem) clamp(0.75rem, 2vw, 1.5rem);
  border-radius: 1.125rem; background-color: var(--cd-brand); color: var(--cd-on-brand); container-type: inline-size; transition: background-color 300ms ease; }
.cd-price-block .cd-bi { align-items: center; }
.cd-price-label { margin: 0; font-size: clamp(1.125rem, 6cqi, 1.75rem); color: var(--cd-on-brand-muted); }
.cd-was { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 0.25rem 1.25rem; font-size: clamp(1rem, 4.5cqi, 1.375rem); }
.cd-was[hidden] { display: none; }
.cd-was-price { color: color-mix(in srgb, var(--cd-on-brand) 70%, var(--cd-brand)); text-decoration-thickness: 2px; unicode-bidi: isolate; font-variant-numeric: tabular-nums; }
.cd-saving { display: inline-flex; align-items: center; gap: 0.5rem; color: var(--cd-on-brand); font-weight: 600; }
.cd-saving-value { unicode-bidi: isolate; font-variant-numeric: tabular-nums; }
.cd-price { margin: 0; display: flex; flex-wrap: nowrap; align-items: center; justify-content: center; gap: 0.625rem; max-width: 100%; overflow: hidden; }
[dir="rtl"] .cd-price { flex-direction: row-reverse; }
.cd-price-amount { font-size: clamp(2.75rem, 19cqi, 8rem); font-weight: 700; line-height: 1.05; white-space: nowrap; font-variant-numeric: tabular-nums; }
.cd-currency { flex: none; font-size: clamp(1.125rem, 5.2cqi, 2rem); font-weight: 600; line-height: 1.1; color: var(--cd-on-brand-muted); white-space: nowrap; }
.cd-currency > .cd-en { font-size: 0.72em; }
.cd-price-note { margin: 0; font-size: clamp(1rem, 4.4cqi, 1.375rem); color: var(--cd-on-brand-muted); }
.cd-price-note > .cd-en { font-size: 0.8em; }

/* Items looked at before: a small, muted strip at the bottom */
.cd-viewed { flex: none; display: flex; align-items: center; gap: 0.75rem; height: clamp(3rem, 7vh, 4.5rem); padding: 0.375rem 0.625rem;
  border-radius: 0.875rem; background-color: rgb(255 255 255 / 0.6); border: 1px solid var(--cd-line); }
.cd-viewed[hidden] { display: none; }
.cd-viewed-title { flex: none; margin: 0; font-size: 0.875rem; font-weight: 500; color: var(--cd-muted); white-space: nowrap; }
.cd-viewed-list { flex: 1; min-width: 0; height: 100%; display: flex; gap: 0.5rem; overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; }
.cd-mini { flex: none; display: flex; align-items: center; gap: 0.5rem; max-width: 19rem; height: 100%; padding: 0.25rem 0.375rem 0.25rem 0.625rem;
  background-color: #ffffff; border: 1px solid var(--cd-line); border-radius: 0.625rem; }
.cd-mini-media { height: 100%; width: auto; aspect-ratio: 1; border-radius: 0.5rem; background-color: var(--cd-soft); }
.cd-mini-media .cd-type-icon { width: 65%; height: 65%; }
.cd-mini-body { min-width: 0; }
.cd-mini-name { max-inline-size: 100%; font-size: 0.875rem; font-weight: 500; line-height: 1.25; }
.cd-mini-name > span { max-inline-size: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cd-mini-meta { display: none; }
.cd-mini-price { flex: none; font-size: 0.9375rem; font-weight: 600; color: var(--cd-ink); white-space: nowrap; }
.cd-money { display: inline-flex; align-items: center; gap: 0.35em; direction: ltr; unicode-bidi: isolate; }
[dir="rtl"] .cd-money { flex-direction: row-reverse; }
.cd-amount { font-variant-numeric: tabular-nums; white-space: nowrap; }
.cd-unit { font-size: 0.68em; font-weight: 500; color: var(--cd-muted); line-height: 1.1; }

/* The notes at the bottom: the Arabic line, then the English line; the time of the price once, readable */
.cd-foot { flex: none; display: flex; justify-content: center; align-items: center; gap: 1.25rem; color: var(--cd-muted); }
.cd-foot-text { align-items: center; font-size: 0.9375rem; }
.cd-foot-text > .cd-en { font-size: 0.86em; }
.cd-updated-time { font-size: 1.125rem; font-weight: 700; color: var(--cd-text); font-variant-numeric: tabular-nums; unicode-bidi: isolate;
  padding-inline-start: 1.25rem; border-inline-start: 1px solid var(--cd-line); }

/* Gentle entry when another item comes (no flashing) */
.cd-enter { animation: cd-enter 380ms cubic-bezier(0.2, 0.7, 0.2, 1) both; }
@keyframes cd-enter { from { opacity: 0; transform: translateY(8px) scale(0.99); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .cd-enter, .cd-welcome-group { animation: none; } }

/* Portrait (iPad upright) or narrow: details first, then the large price */
@media (orientation: portrait), (max-width: 900px) {
  .cd-item { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .cd-item-media { inline-size: clamp(9rem, 26vw, 13rem); block-size: clamp(9rem, 26vw, 13rem); }
  .cd-item-name { font-size: clamp(1.25rem, 4.2vw, 2rem); }
  .cd-shop { flex-direction: column; align-items: flex-start; gap: 0.25rem; }
  .cd-branch-name { padding-inline-start: 0; border-inline-start: 0; }
}
@media (max-width: 560px) {
  .cd-item-head { flex-direction: column; align-items: flex-start; }
  .cd-viewed-title { display: none; }
}

/* Development harness for the customer display */
.dev-display-panel { padding: 1rem 1.25rem; display: flex; flex-direction: column; gap: 0.75rem; margin-top: 1rem; }
.dev-display-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.dev-display-row .form-input { width: auto; min-width: 12rem; }
.dev-display-row .dev-discount { min-width: 7rem; }

/* Sales page (sales.php): clear sections, labels above their fields, payment apart from the cart */
.sale-page { display: flex; flex-direction: column; gap: 1.25rem; }
.sale-page .panel { padding: clamp(1rem, 2.2vw, 1.5rem); }
.sale-page .form-field { display: flex; flex-direction: column; gap: 0.5rem; }
.sale-page .form-label { font-size: 0.9375rem; line-height: 1.4; }
.sale-page .form-grid .form-label { display: flex; flex-direction: column; gap: 0.5rem; }   /* Labels that wrap their field */
.sale-section { display: flex; flex-direction: column; gap: 1rem; }
.sale-section-title { font-size: 1.125rem; font-weight: 600; padding-bottom: 0.75rem; border-bottom: 1px solid var(--border); }
.sale-scan { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.75rem; }
.sale-scan-field { flex: 1 1 18rem; min-width: 0; }
.sale-scan-buttons, .sale-payment-buttons, .sale-device-buttons { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.sale-search-results { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.sale-search-results:empty { display: none; }
.sale-pricing { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.75rem; }
.sale-discount-field { flex: 0 1 14rem; }
.sale-summary { display: flex; flex-direction: column; align-items: flex-start; gap: 0.5rem; padding: 0.875rem 1rem;
  border-radius: calc(var(--radius) - 2px); background-color: var(--muted); }
.sale-total { font-size: 1.125rem; font-weight: 600; }
.sale-total:empty, .sale-approval:empty { display: none; }
.sale-payment { border-top: 3px solid var(--gold); }
.sale-payment .form-grid { gap: 1rem; }
.sale-payment-buttons { justify-content: flex-end; padding-top: 0.25rem; }

/* This tab's customer display controls */
.sale-display-bar { display: flex; flex-direction: column; gap: 1rem; }
.sale-display-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem; }
.sale-display-status { font-size: 0.875rem; color: var(--muted-foreground); }
.sale-display-status[data-status="open"] { color: var(--success); font-weight: 500; }
.sale-display-status[data-status="moved"], .sale-display-status[data-status="duplicate"] { color: var(--warning); }
.sale-display-actions .sale-cancel { margin-inline-start: auto; }

/* Linking another device: QR code and one-time link */
.sale-device { display: flex; flex-wrap: wrap; gap: 1.25rem 1.5rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.sale-device-qr { flex: none; width: 13rem; padding: 0.5rem; background: #ffffff; border: 1px solid var(--border); border-radius: calc(var(--radius) - 2px); }
.sale-device-qr svg { display: block; width: 100%; height: auto; }
.sale-device-body { flex: 1 1 18rem; min-width: 0; display: flex; flex-direction: column; gap: 0.75rem; }
.sale-device-title { font-size: 1.0625rem; font-weight: 600; }
.sale-device-steps { margin: 0; padding-inline-start: 1.25rem; display: grid; gap: 0.25rem; color: var(--muted-foreground); }
.sale-device-field { display: flex; flex-direction: column; gap: 0.5rem; }
.sale-device-copy { display: flex; gap: 0.5rem; }
.sale-device-copy .form-input { flex: 1; min-width: 0; font-size: 0.875rem; }
.sale-device-state { font-weight: 500; }
.sale-device-state[data-phase="ready"] { color: var(--success); }
.sale-device-state[data-phase="expired"], .sale-device-state[data-phase="lan"] { color: var(--warning); }
@media (max-width: 640px) {
  .sale-payment .form-grid-3 { grid-template-columns: minmax(0, 1fr); }
  .sale-device-qr { width: 11rem; }
}

/* Sales cart: select items, remove the selected ones, empty the cart */
.sale-cart-tools { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.5rem; }
.sale-pick-column { width: 2.5rem; }
.sale-page .data-table input[type="checkbox"] { width: 1.125rem; height: 1.125rem; accent-color: var(--primary); cursor: pointer; }

/* Sales: discount of the current item, approval states and action results with meaning colours */
.sale-discount-code { display: inline-block; margin-inline-start: 0.375rem; padding: 0.05rem 0.5rem; border-radius: 999px;
  font-size: 0.8125rem; font-weight: 600; background-color: var(--gold-soft); color: var(--primary); }
.sale-status { margin: 0; padding: 0.625rem 0.875rem; border-radius: calc(var(--radius) - 2px); border: 1px solid transparent; font-weight: 500; }
.sale-status:empty { display: none; }
.sale-status[data-tone="success"] { background-color: var(--success-soft); color: var(--success); border-color: var(--success); }
.sale-status[data-tone="warning"] { background-color: var(--warning-soft); color: oklch(0.45 0.1 70); border-color: var(--warning); }
.sale-status[data-tone="error"] { background-color: var(--danger-soft); color: var(--destructive); border-color: var(--destructive); }
.sale-badge { display: inline-block; padding: 0.05rem 0.45rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; white-space: nowrap; }
.sale-badge[data-tone="warning"] { background-color: var(--warning-soft); color: oklch(0.45 0.1 70); }
.sale-badge[data-tone="error"] { background-color: var(--danger-soft); color: var(--destructive); }
.sale-page .data-table tr.sale-row-current td { background-color: var(--gold-soft); }
.sale-page .data-table tr.sale-row-current td:nth-child(2) { font-weight: 600; }

/* Program updated while the page was open: ask to reload (api.js checkAppVersion) */
.app-update-bar { position: sticky; top: 0; z-index: 200; display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
  gap: 0.5rem 1rem; padding: 0.625rem 1rem; background-color: var(--warning-soft); color: oklch(0.4 0.1 70);
  border-bottom: 2px solid var(--warning); font-weight: 600; text-align: center; }
.sale-status[data-tone="updating"] { background-color: var(--muted); color: var(--muted-foreground); border-color: var(--border); font-weight: 400; }
/* Prices of the last valid answer while the new one is missing (being updated or failed) */
.sale-page .data-table tr.sale-row-stale td:nth-child(n+4) { color: var(--muted-foreground); font-style: italic; background-color: var(--warning-soft); }

/* ---------- Subscription billing (admin pages, manager page, documents) ---------- */
.stat-grid-5 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr)); }
.notice-list { display: grid; gap: 0.5rem; margin-bottom: 1rem; }
.billing-flag { margin: 0; padding: 0.625rem 0.875rem; border-radius: calc(var(--radius) - 2px); border: 1px solid var(--border); font-weight: 500; }
.billing-flag[data-tone="warning"] { background-color: var(--warning-soft); color: oklch(0.4 0.1 70); border-color: var(--warning); }
.billing-flag[data-tone="error"] { background-color: var(--danger-soft); color: var(--destructive); border-color: var(--destructive); }
.billing-flag[data-tone="success"] { background-color: var(--success-soft); color: var(--success); border-color: var(--success); }
.subscription-bar { margin-bottom: 1rem; }
.sale-status[data-tone="pending"] { background-color: var(--info-soft); color: var(--info); border-color: var(--info); }
.text-danger { color: var(--destructive); }
.text-warning { color: oklch(0.45 0.1 70); }
.table-caption { margin: 0.5rem 0; }
.sort-link { color: inherit; text-decoration: none; white-space: nowrap; }
.sort-link:hover, .sort-link:focus-visible { text-decoration: underline; }
.actions-cell > a, .actions-cell > button { margin: 0.125rem; }
.data-table .ltr.num { white-space: nowrap; }
.billing-page { display: grid; gap: 1rem; }
.billing-page .panel { padding: 1.25rem; display: grid; gap: 0.75rem; }
.filter-export { margin-inline-start: auto; }
.subscription-status-bar { display: flex; flex-wrap: wrap; gap: 0.75rem 1.5rem; align-items: center; padding: 0.875rem 1.25rem; margin-bottom: 1rem; }
.tabs { display: flex; flex-wrap: wrap; gap: 0.25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.tab { padding: 0.625rem 1rem; border: 0; border-bottom: 3px solid transparent; background: none; color: var(--muted-foreground); font: inherit; font-weight: 500; cursor: pointer; }
.tab[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--gold); }
.tab:focus-visible { outline: 2px solid var(--ring, var(--primary)); outline-offset: 2px; }
.tab-panel { display: grid; gap: 1rem; }
.tab-panel[hidden] { display: none; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr)); gap: 1rem; }
.detail-card, .tab-panel > .panel, .detail-grid > form.panel, #period-form { padding: 1.25rem; display: flex; flex-direction: column; gap: 0.75rem; }
.subsection-title { font-size: 1rem; font-weight: 600; margin: 0.5rem 0 0; }
.plain-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.feature-list { margin: 0; padding-inline-start: 1.25rem; display: grid; gap: 0.25rem; }
.feature-list.compact { font-size: 0.875rem; }
/* Plan modules (enforced) and the explicit free-period choice: one option per line */
.module-choices { display: grid; gap: 0.375rem; margin-block-start: 0.5rem; }
.module-choices label, .complimentary-fields label { display: flex; align-items: baseline; gap: 0.5rem; }
.complimentary-details { display: grid; gap: 0.375rem; margin-block-start: 0.5rem; }
.complimentary-details[hidden] { display: none; }
.event-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.75rem; }
.event-list li { padding-bottom: 0.75rem; border-bottom: 1px solid var(--border); }
.preview-box { padding: 1rem; border-radius: calc(var(--radius) - 2px); background-color: var(--gold-soft); border: 1px solid var(--gold); }
.sub-row td { background-color: var(--muted); }
fieldset.form-field { border: 0; padding: 0; margin: 0; display: grid; gap: 0.375rem; }
/* Printable subscription invoice / receipt */
.document-page { background: var(--background); padding: 1.5rem; }
.document-actions { display: flex; gap: 0.5rem; justify-content: center; margin-bottom: 1rem; }
.document { max-width: 48rem; margin: 0 auto; padding: 2rem; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); display: grid; gap: 1rem; }
.document-header { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; border-bottom: 2px solid var(--gold); padding-bottom: 1rem; }
.document-logo { height: 3rem; }
.document-company { text-align: end; font-size: 0.875rem; display: grid; gap: 0.125rem; }
.document-title { font-size: 1.375rem; color: var(--primary); margin: 0; }
.document-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: 0.5rem 1.5rem; margin: 0; }
.document-meta dt { color: var(--muted-foreground); font-size: 0.8125rem; }
.document-meta dd { margin: 0; }
.document-total td { font-weight: 700; border-top: 2px solid var(--primary); }
.document-amount { font-size: 1.25rem; }
.document-footer { border-top: 1px solid var(--border); padding-top: 0.75rem; font-size: 0.8125rem; }
@media print {
  .document-page { padding: 0; background: #fff; }
  .document { border: 0; padding: 0; max-width: none; }
}

/* Small muted help text under a form field (e.g. password requirements) */
.form-hint { margin: 0.25rem 0 0; font-size: 0.75rem; line-height: 1.4; color: var(--muted-foreground); }
