/* ==========================================================================
   ARAK SERVICE CENTER — DESIGN SYSTEM COMPONENT PRIMITIVES
   Consumes ONLY design tokens from tokens.css.
   Distinct structural geometry per theme:
     - [data-theme="neo-light"]  (نيو فاتح)  -> Brutalist thick borders + hard offset shadows
     - [data-theme="neo-dark"]   (نيو غامق)  -> Quiet dense flat hairline rows
     - [data-theme="odoo"]       (أودو)      -> Odoo 18 form-view, breadcrumbs & arrow statusbar
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.5;
  background-color: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* Scope root helper so side-by-side preview frames work independently */
.ds-scope {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.5;
  background-color: var(--bg);
  color: var(--text);
}

/* Monospace Numbers & Serials (always LTR isolated inside RTL) */
.ds-mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  direction: ltr;
  unicode-bidi: isolate;
}

.ds-muted {
  color: var(--muted);
}

/* ==========================================================================
   1. THEME SWITCHER BAR (نيو فاتح | نيو غامق | أودو)
   ========================================================================== */
.ds-switcher {
  display: inline-grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
  background: var(--surface);
  border: var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.ds-switcher-btn {
  appearance: none;
  border: 0;
  border-inline-end: var(--border);
  background: transparent;
  color: var(--muted);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 600;
  min-height: 40px;
  padding: 6px 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 120ms ease, color 120ms ease;
}

.ds-switcher-btn:last-child {
  border-inline-end: 0;
}

.ds-switcher-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.ds-switcher-btn[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 700;
}

/* ==========================================================================
   1B. THEME DROPDOWN SELECTOR (Icon Trigger + Menu)
   ========================================================================== */
.ds-theme-dropdown {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}

.ds-theme-trigger {
  appearance: none;
  width: 36px;
  height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--btn-sec-bg);
  color: var(--btn-sec-fg);
  border: var(--btn-sec-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-btn);
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease, transform 80ms ease;
}

.ds-theme-trigger:hover {
  background: var(--btn-sec-hover);
  color: var(--text);
}

.ds-theme-trigger:active {
  transform: translate(var(--btn-active-shift), var(--btn-active-shift));
  box-shadow: var(--shadow-btn-active);
}

.ds-theme-trigger[aria-expanded="true"] {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}

.ds-theme-menu {
  position: absolute;
  top: calc(100% + 8px);
  inset-inline-end: 0;
  min-width: 184px;
  padding: 6px;
  background: var(--surface);
  border: var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  z-index: calc(var(--z-header) + 15);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ds-theme-menu-label {
  padding: 4px 10px 6px;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--muted);
  border-bottom: var(--divider);
  margin-bottom: 4px;
}

.ds-theme-option {
  appearance: none;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 600;
  padding: 9px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: start;
  white-space: nowrap;
  transition: background-color 120ms ease, color 120ms ease;
}

.ds-theme-option:hover {
  background: var(--surface-hover);
}

.ds-theme-option[aria-checked="true"] {
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 700;
}

.ds-theme-option-main {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.ds-theme-check {
  opacity: 0;
  flex-shrink: 0;
}

.ds-theme-option[aria-checked="true"] .ds-theme-check {
  opacity: 1;
}

/* ==========================================================================
   2. HEADER & ODOO BREADCRUMB STRIP
   ========================================================================== */
.ds-app-header {
  background: var(--surface);
  border-bottom: var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

[data-theme="neo-light"] .ds-app-header {
  background: var(--bg);
}

.ds-breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-base);
  font-weight: var(--heading-weight);
  color: var(--text);
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  line-height: 1.3;
}

.ds-breadcrumb-parent {
  display: none;
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
}

.ds-breadcrumb-sep {
  display: none;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}

/* Odoo-native displays true breadcrumb hierarchy on wider screens */
@media (min-width: 640px) {
  [data-theme="odoo"] .ds-breadcrumb-parent,
  [data-theme="odoo"] .ds-breadcrumb-sep {
    display: inline;
  }
}

[data-theme="odoo"] .ds-breadcrumb-parent {
  color: var(--accent);
}

/* ==========================================================================
   3. SURFACE / PANEL (Distinct per theme — no nested rounded card soup)
   ========================================================================== */
.ds-surface {
  background: var(--surface);
  border: var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: var(--card-pad);
}

[data-theme="neo-dark"] .ds-surface {
  background: var(--surface);
}

[data-theme="odoo"] .ds-surface {
  background: var(--surface);
}

.ds-section-title {
  margin: 0 0 10px 0;
  font-size: var(--text-sm);
  font-weight: var(--heading-weight);
  color: var(--muted);
  letter-spacing: 0.01em;
}

[data-theme="neo-light"] .ds-section-title {
  color: var(--text);
  text-transform: none;
}

[data-theme="odoo"] .ds-section-title {
  color: var(--accent);
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 6px;
  margin-bottom: 12px;
}

/* ==========================================================================
   4. BUTTONS (One primary CTA pinned at bottom + secondary/danger utilities)
   ========================================================================== */
.ds-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--btn-height);
  padding: 0 18px;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: 700;
  line-height: 1.2;
  border-radius: var(--radius);
  cursor: pointer;
  user-select: none;
  text-decoration: none;
  transition: transform 80ms ease, background-color 120ms ease, border-color 120ms ease;
}

.ds-btn-full {
  width: 100%;
}

.ds-btn-primary {
  background: var(--accent);
  color: var(--accent-fg);
  border: var(--border);
  box-shadow: var(--shadow-btn);
}

[data-theme="neo-dark"] .ds-btn-primary,
[data-theme="odoo"] .ds-btn-primary {
  border-color: var(--accent);
}

.ds-btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.ds-btn-primary:active:not(:disabled) {
  transform: translate(var(--btn-active-shift), var(--btn-active-shift));
  box-shadow: var(--shadow-btn-active);
}

.ds-btn-secondary {
  background: var(--btn-sec-bg);
  color: var(--btn-sec-fg);
  border: var(--btn-sec-border);
  box-shadow: var(--shadow-btn);
}

.ds-btn-secondary:hover:not(:disabled) {
  background: var(--btn-sec-hover);
}

.ds-btn-secondary:active:not(:disabled) {
  transform: translate(var(--btn-active-shift), var(--btn-active-shift));
  box-shadow: var(--shadow-btn-active);
}

.ds-btn-danger {
  background: var(--status-danger-bg);
  color: var(--status-danger-fg);
  border: var(--border-width) solid var(--status-danger-border);
  box-shadow: var(--shadow-btn);
}

.ds-btn:disabled {
  opacity: 0.48;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

/* Pinned Bottom Primary CTA Container */
.ds-pinned-action {
  background: var(--bg);
  border-top: var(--divider);
  padding: 10px 16px;
}

[data-theme="odoo"] .ds-pinned-action {
  background: var(--surface);
}

/* ==========================================================================
   5. INPUTS & SELECTS (Theme-distinct form architecture)
   ========================================================================== */
.ds-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Odoo 18 Form-View Horizontal Label+Field Layout on wider forms or compact rows */
[data-theme="odoo"] .ds-field-odoo-inline {
  flex-direction: row;
  align-items: center;
  gap: 12px;
}

[data-theme="odoo"] .ds-field-odoo-inline .ds-label {
  flex: 0 0 118px;
  border-inline-end: 1px solid var(--border-subtle);
  padding-inline-end: 10px;
  color: var(--text);
  font-size: var(--text-sm);
}

.ds-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--label-weight);
  color: var(--muted);
}

[data-theme="neo-light"] .ds-label {
  color: var(--text);
}

.ds-input,
.ds-select {
  width: 100%;
  min-height: var(--input-height);
  padding: 8px var(--input-px);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  color: var(--text);
  background: var(--input-bg);
  border: var(--input-border);
  border-bottom: var(--input-border-bottom);
  border-radius: var(--input-radius);
  box-shadow: var(--shadow-input);
  outline: none;
  transition: border-color 120ms ease, background-color 120ms ease;
}

.ds-input::placeholder {
  color: var(--muted);
}

.ds-input:focus,
.ds-select:focus {
  border-color: var(--input-focus-border);
  outline: var(--input-focus-outline);
  outline-offset: 0;
}

[data-theme="odoo"] .ds-input:focus,
[data-theme="odoo"] .ds-select:focus {
  border-bottom: 2px solid var(--input-focus-border);
  padding-bottom: 7px;
}

.ds-input.ds-input-error {
  border-color: var(--status-danger-fg);
  border-bottom-color: var(--status-danger-fg);
}

.ds-field-hint {
  font-size: var(--text-xs);
  color: var(--muted);
}

.ds-field-error {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--status-danger-fg);
}

/* Custom Select Wrapper with Geometric SVG Chevron */
.ds-select-wrap {
  position: relative;
  width: 100%;
}

.ds-select {
  appearance: none;
  -webkit-appearance: none;
  padding-inline-end: 38px;
  cursor: pointer;
}

.ds-select-chevron {
  position: absolute;
  top: 50%;
  inset-inline-end: 12px;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--muted);
  pointer-events: none;
}

[data-theme="neo-light"] .ds-select-chevron {
  color: var(--text);
}

[data-theme="odoo"] .ds-select-chevron {
  inset-inline-end: 4px;
}

/* ==========================================================================
   6. LIST ROWS & KEY-VALUE FINANCIAL LISTS
   - Separated individual cards across all 3 themes using theme tokens
   ========================================================================== */
.ds-list {
  display: flex;
  flex-direction: column;
  gap: var(--row-gap);
}

.ds-list-header {
  display: none;
}

[data-theme="odoo"] .ds-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px var(--row-px);
  background: var(--surface-subtle);
  border: var(--border);
  border-radius: var(--radius);
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--muted);
}

.ds-list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--touch-min);
  padding: var(--row-py) var(--row-px);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  text-align: start;
  text-decoration: none;
  border: var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  transition: background-color 100ms ease, border-color 100ms ease;
}

.ds-list-row--interactive {
  cursor: pointer;
}

.ds-list-row--interactive:hover {
  background: var(--surface-hover);
}

.ds-list-row-main {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ds-list-row-title {
  font-size: var(--text-base);
  font-weight: var(--heading-weight);
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ds-list-row-sub {
  font-size: var(--text-sm);
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.ds-list-row-end {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

/* Key-Value Financial Breakdown Sheet (matches mockup card) */
.ds-kv-card {
  background: var(--surface);
  border: var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.ds-kv-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: var(--divider);
  font-size: var(--text-base);
}

.ds-kv-row:last-child {
  border-bottom: 0;
}

.ds-kv-label {
  color: var(--muted);
  font-weight: 500;
}

.ds-kv-value {
  color: var(--text);
  font-weight: 600;
}

.ds-total-card {
  background: var(--surface);
  border: var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ds-total-label {
  font-size: var(--text-sm);
  color: var(--muted);
  font-weight: 600;
}

.ds-total-amount {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.ds-total-currency {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--muted);
}

/* ==========================================================================
   7. STATUS CHIPS (Real Status Only: green / amber / red / neutral)
   ========================================================================== */
.ds-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  font-size: var(--text-xs);
  font-weight: 700;
  line-height: 1.3;
  border-radius: var(--radius-chip);
  border: var(--border-width) solid transparent;
  white-space: nowrap;
}

/* Subtle dot shown in Linear dark mode for quiet scannability */
.ds-chip-dot {
  display: none;
  width: 6px;
  height: 6px;
  border-radius: 2px;
  background: currentColor;
  flex-shrink: 0;
}

[data-theme="neo-dark"] .ds-chip-dot {
  display: inline-block;
}

.ds-chip--ok {
  background: var(--status-ok-bg);
  color: var(--status-ok-fg);
  border-color: var(--status-ok-border);
}

.ds-chip--warn {
  background: var(--status-warn-bg);
  color: var(--status-warn-fg);
  border-color: var(--status-warn-border);
}

.ds-chip--danger {
  background: var(--status-danger-bg);
  color: var(--status-danger-fg);
  border-color: var(--status-danger-border);
}

.ds-chip--neutral {
  background: var(--status-neutral-bg);
  color: var(--status-neutral-fg);
  border-color: var(--status-neutral-border);
}

.ds-chip--info {
  background: var(--status-info-bg);
  color: var(--status-info-fg);
  border-color: var(--status-info-border);
}

/* ==========================================================================
   8. STAGE TRACKER (4 Segments — Structurally Distinct per Theme)
   - A (neo-light): 4 bold safety-yellow brutalist bars + strong labels
   - B (neo-dark):  4 sleek 4px Linear progress bars + quiet labels
   - C (odoo):      4 Odoo 18 arrow-shaped RTL chevron stages
   ========================================================================== */
.ds-stage-tracker {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  width: 100%;
}

.ds-stage-step {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: start;
  font-family: var(--font-sans);
}

.ds-stage-bar {
  display: block;
  width: 100%;
  height: var(--stage-bar-height);
  background: var(--stage-track-bg);
  border-radius: 2px;
  transition: background-color 120ms ease;
}

[data-theme="neo-light"] .ds-stage-bar {
  border: 1.5px solid var(--border-color);
  border-radius: 2px;
}

.ds-stage-step[data-state="done"] .ds-stage-bar,
.ds-stage-step[data-state="current"] .ds-stage-bar {
  background: var(--stage-active-bg);
}

.ds-stage-label {
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ds-stage-step[data-state="current"] .ds-stage-label {
  color: var(--text);
  font-weight: 700;
}

/* Direction C (Odoo): True Arrow-Shaped RTL Statusbar (o_statusbar_status) */
[data-theme="odoo"] .ds-stage-tracker {
  display: flex;
  gap: 0;
  background: var(--border-color);
  padding: 1px;
  border-radius: var(--radius);
  overflow: hidden;
}

[data-theme="odoo"] .ds-stage-bar {
  display: none;
}

[data-theme="odoo"] .ds-stage-step {
  flex: 1 1 0;
  min-width: 0;
  min-height: var(--stage-bar-height);
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 6px 12px 6px 14px;
  background: var(--surface);
  position: relative;
  /* Middle RTL arrow: notch on right, tip pointing left */
  clip-path: polygon(100% 0, 10px 0, 0 50%, 10px 100%, 100% 100%, calc(100% - 10px) 50%);
  margin-inline-start: -8px;
}

[data-theme="odoo"] .ds-stage-step:first-child {
  /* Rightmost RTL start: flat right edge, arrow tip pointing left */
  clip-path: polygon(100% 0, 10px 0, 0 50%, 10px 100%, 100% 100%);
  margin-inline-start: 0;
  padding-inline-start: 8px;
}

[data-theme="odoo"] .ds-stage-step:last-child {
  /* Leftmost RTL end: notch on right, flat left edge */
  clip-path: polygon(100% 0, 0 0, 0 100%, 100% 100%, calc(100% - 10px) 50%);
  padding-inline-end: 8px;
}

[data-theme="odoo"] .ds-stage-step[data-state="done"] {
  background: var(--stage-done-bg);
}

[data-theme="odoo"] .ds-stage-step[data-state="done"] .ds-stage-label {
  color: var(--stage-done-fg);
  font-weight: 600;
}

[data-theme="odoo"] .ds-stage-step[data-state="current"] {
  background: var(--stage-active-bg);
}

[data-theme="odoo"] .ds-stage-step[data-state="current"] .ds-stage-label {
  color: var(--stage-active-fg);
  font-weight: 700;
}

/* ==========================================================================
   9. BOTTOM TAB BAR (3 Items: المتابعة | الإصلاح | الإعدادات)
   ========================================================================== */
.ds-tabbar {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  background: var(--tabbar-bg);
  border-top: var(--tabbar-border);
  min-height: var(--tabbar-height);
}

.ds-tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--tabbar-fg);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 600;
  min-height: var(--tabbar-height);
  padding: 8px 6px 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  position: relative;
  transition: color 120ms ease;
}

.ds-tab-icon {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: square;
  stroke-linejoin: miter;
}

[data-theme="neo-light"] .ds-tab-icon {
  stroke-width: 2;
}

.ds-tab[aria-selected="true"] {
  color: var(--tabbar-active-fg);
  font-weight: 700;
}

.ds-tab[aria-selected="true"]::before {
  content: '';
  position: absolute;
  top: 0;
  inset-inline: 18%;
  height: var(--tabbar-indicator-h);
  background: var(--tabbar-indicator);
}
