/* AMC ERP theme: design tokens and shared component classes.
   Spec: docs/blueprints/01_UI_MOBILE_PWA_AND_SECURITY.md sections 3.1 and 3.2.
   Light tokens plus the dark block. No page-specific rules here. */

:root {
  /* surfaces */
  --amc-sidebar:        #0F172A;
  --amc-sidebar-hover:  #1E293B;
  --amc-sidebar-text:   #94A3B8;
  --amc-sidebar-active: #FFFFFF;
  --amc-bg:             #F8FAFC;
  --amc-card:           #FFFFFF;
  --amc-border:         #E2E8F0;
  --amc-text:           #0F172A;
  --amc-text-muted:     #64748B;
  /* accents */
  --amc-primary:        #1D4ED8;
  --amc-primary-hover:  #1E40AF;
  --amc-primary-soft:   #DBEAFE;
  --amc-success:        #059669;
  --amc-success-soft:   #D1FAE5;
  --amc-warning:        #D97706;
  --amc-warning-soft:   #FEF3C7;
  --amc-danger:         #DC2626;
  --amc-danger-soft:    #FEE2E2;
  /* shape */
  --amc-radius-sm: 6px;  --amc-radius: 10px;  --amc-radius-lg: 14px;
  --amc-shadow-1: 0 1px 2px rgba(15,23,42,.06);
  --amc-shadow-2: 0 4px 16px rgba(15,23,42,.08);
  --amc-shadow-3: 0 16px 40px rgba(15,23,42,.18);
  /* spacing scale */
  --amc-1: 4px; --amc-2: 8px; --amc-3: 12px; --amc-4: 16px; --amc-5: 24px; --amc-6: 32px;
  /* layout (navbar stays 66px until every page is on the theme) */
  --amc-navbar-h: 66px;  --amc-sidebar-w: 260px;  --amc-sidebar-fold-w: 66px;  --amc-bottombar-h: 60px;
  /* type */
  --amc-font: 'Inter', 'Roboto', system-ui, sans-serif;
  --amc-font-ar: 'IBM Plex Sans Arabic', 'Cairo', 'Tahoma', sans-serif;
  --amc-fs-xs: 12px; --amc-fs-sm: 13px; --amc-fs: 14px; --amc-fs-lg: 16px; --amc-fs-xl: 20px; --amc-fs-kpi: 28px;
}

/* Dark theme (Obsidian). The data-theme attribute is set before first paint by head_meta.php. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --amc-sidebar: #020617;  --amc-sidebar-hover: #0F172A;
  --amc-bg: #0B1120;  --amc-card: #111827;  --amc-border: #1F2937;
  --amc-text: #E5E7EB;  --amc-text-muted: #9CA3AF;
  --amc-primary: #3B82F6;  --amc-primary-hover: #60A5FA;  --amc-primary-soft: #1E3A8A;
  --amc-success: #10B981;  --amc-success-soft: #064E3B;
  --amc-warning-soft: #78350F;  --amc-danger-soft: #7F1D1D;
  --amc-shadow-1: 0 1px 2px rgba(0,0,0,.5);  --amc-shadow-2: 0 4px 16px rgba(0,0,0,.5);
}

/* ── Card ───────────────────────────────────────────────────────────────── */
.amc-card {
  background: var(--amc-card);
  border: 1px solid var(--amc-border);
  border-radius: var(--amc-radius);
  box-shadow: var(--amc-shadow-1);
  color: var(--amc-text);
}
.amc-card-header {
  padding: var(--amc-3) var(--amc-4);
  border-block-end: 1px solid var(--amc-border);
  font-weight: 600;
}
.amc-card-body { padding: var(--amc-4); }

/* ── KPI card ───────────────────────────────────────────────────────────── */
.amc-kpi {
  background: var(--amc-card);
  border: 1px solid var(--amc-border);
  border-radius: var(--amc-radius);
  box-shadow: var(--amc-shadow-1);
  padding: var(--amc-4);
  color: var(--amc-text);
}
.amc-kpi-label { font-size: var(--amc-fs-sm); color: var(--amc-text-muted); }
.amc-kpi-value {
  font-size: var(--amc-fs-kpi);
  font-weight: 700;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}
.amc-kpi-delta { font-size: var(--amc-fs-xs); color: var(--amc-text-muted); }
.amc-kpi-spark { display: block; margin-block-start: var(--amc-2); max-width: 100%; }

/* ── Table (.amc-table-cards stacks to cards under 768px) ───────────────── */
.amc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--amc-fs);
  color: var(--amc-text);
}
.amc-table th,
.amc-table td {
  padding: var(--amc-2) var(--amc-3);
  border-block-end: 1px solid var(--amc-border);
  text-align: start;
}
.amc-table th {
  font-size: var(--amc-fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--amc-text-muted);
}
@media (max-width: 767px) {
  .amc-table-cards thead { display: none; }
  .amc-table-cards,
  .amc-table-cards tbody,
  .amc-table-cards tr,
  .amc-table-cards td { display: block; width: 100%; }
  .amc-table-cards tr {
    margin-block-end: var(--amc-3);
    border: 1px solid var(--amc-border);
    border-radius: var(--amc-radius);
    background: var(--amc-card);
  }
  .amc-table-cards td {
    display: flex;
    justify-content: space-between;
    gap: var(--amc-3);
    border-block-end: 0;
  }
  .amc-table-cards td[data-label]::before {
    content: attr(data-label);
    color: var(--amc-text-muted);
    font-size: var(--amc-fs-xs);
  }
}

/* ── Status pill ────────────────────────────────────────────────────────── */
.amc-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--amc-1);
  padding: 2px var(--amc-2);
  border-radius: 999px;
  font-size: var(--amc-fs-xs);
  font-weight: 600;
  line-height: 1.5;
  background: var(--amc-primary-soft);
  color: var(--amc-primary);
}
.amc-pill--ok   { background: var(--amc-success-soft); color: var(--amc-success); }
.amc-pill--warn { background: var(--amc-warning-soft); color: var(--amc-warning); }
.amc-pill--bad  { background: var(--amc-danger-soft);  color: var(--amc-danger); }
.amc-pill--idle { background: var(--amc-border);       color: var(--amc-text-muted); }

/* ── Buttons (36px desktop, 44px touch) ─────────────────────────────────── */
.amc-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--amc-2);
  min-height: 36px;
  padding: 0 var(--amc-4);
  border: 1px solid var(--amc-border);
  border-radius: var(--amc-radius-sm);
  background: var(--amc-card);
  color: var(--amc-text);
  font-family: inherit;
  font-size: var(--amc-fs);
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, border-color .15s, color .15s;
}
.amc-btn:hover { background: var(--amc-bg); text-decoration: none; }
.amc-btn--primary { background: var(--amc-primary); border-color: var(--amc-primary); color: #fff; }
.amc-btn--primary:hover { background: var(--amc-primary-hover); border-color: var(--amc-primary-hover); }
.amc-btn--success { background: var(--amc-success); border-color: var(--amc-success); color: #fff; }
.amc-btn--success:hover { filter: brightness(.92); background: var(--amc-success); }
.amc-btn--danger { background: var(--amc-danger); border-color: var(--amc-danger); color: #fff; }
.amc-btn--danger:hover { filter: brightness(.92); background: var(--amc-danger); }
.amc-btn--ghost { background: transparent; border-color: transparent; color: var(--amc-text-muted); }
.amc-btn--ghost:hover { background: var(--amc-primary-soft); color: var(--amc-primary); }
.amc-btn--icon { padding: 0; width: 36px; }
@media (pointer: coarse) {
  .amc-btn { min-height: 44px; }
  .amc-btn--icon { width: 44px; }
}

/* ── Form controls ──────────────────────────────────────────────────────── */
.amc-field { display: flex; flex-direction: column; gap: var(--amc-1); }
.amc-label { font-size: var(--amc-fs-sm); font-weight: 500; color: var(--amc-text-muted); }
.amc-input,
.amc-select {
  width: 100%;
  min-height: 36px;
  padding: 0 var(--amc-3);
  border: 1px solid var(--amc-border);
  border-radius: var(--amc-radius-sm);
  background: var(--amc-card);
  color: var(--amc-text);
  font-family: inherit;
  font-size: var(--amc-fs);
}
.amc-input:focus,
.amc-select:focus {
  outline: 2px solid var(--amc-primary);
  outline-offset: 0;
  border-color: var(--amc-primary);
}
@media (pointer: coarse) {
  .amc-input,
  .amc-select { min-height: 44px; }
}

/* ── Drawer (slides in from the inline-end side) ────────────────────────── */
.amc-drawer {
  position: fixed;
  inset-block: 0;
  inset-inline-end: 0;
  width: min(420px, 100vw);
  background: var(--amc-card);
  color: var(--amc-text);
  box-shadow: var(--amc-shadow-3);
  z-index: 1060;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform .25s ease;
}
:root[dir="rtl"] .amc-drawer,
html[dir="rtl"] .amc-drawer { transform: translateX(-100%); }
.amc-drawer.is-open,
:root[dir="rtl"] .amc-drawer.is-open,
html[dir="rtl"] .amc-drawer.is-open { transform: translateX(0); }
.amc-drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.45);
  z-index: 1055;
  display: none;
}
.amc-drawer.is-open + .amc-drawer-backdrop,
.amc-drawer-backdrop.is-open { display: block; }

/* ── Modal and command palette ──────────────────────────────────────────── */
.amc-modal {
  position: fixed;
  inset: 0;
  z-index: 1070;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 12vh var(--amc-4) var(--amc-4);
  background: rgba(15,23,42,.45);
}
.amc-modal.is-open { display: flex; }
.amc-palette {
  width: min(640px, 100%);
  max-height: 70vh;
  overflow-y: auto;
  background: var(--amc-card);
  color: var(--amc-text);
  border: 1px solid var(--amc-border);
  border-radius: var(--amc-radius-lg);
  box-shadow: var(--amc-shadow-3);
}

/* Command palette parts (markup in includes/header.php, behaviour in assets/js/amc-shell.js) */
.amc-palette-head {
  position: sticky;
  inset-block-start: 0;
  display: flex;
  align-items: center;
  gap: var(--amc-3);
  padding: var(--amc-3) var(--amc-4);
  background: var(--amc-card);
  border-block-end: 1px solid var(--amc-border);
  color: var(--amc-text-muted);
}
.amc-palette-input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--amc-text);
  font: inherit;
  font-size: var(--amc-fs-lg);
}
.amc-palette-input::placeholder { color: var(--amc-text-muted); }
.amc-palette-close {
  border: 1px solid var(--amc-border);
  border-radius: var(--amc-radius-sm);
  background: transparent;
  color: var(--amc-text-muted);
  font: inherit;
  font-size: var(--amc-fs-xs);
  padding: 2px 6px;
  cursor: pointer;
}
.amc-palette-group {
  padding: var(--amc-2) var(--amc-4) var(--amc-1);
  font-size: var(--amc-fs-xs);
  font-weight: 600;
  color: var(--amc-text-muted);
}
.amc-palette-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--amc-2) var(--amc-4);
  border-inline-start: 3px solid transparent;
  color: var(--amc-text);
  text-decoration: none;
  cursor: pointer;
}
.amc-palette-item:hover,
.amc-palette-item.is-active {
  background: var(--amc-primary-soft);
  border-inline-start-color: var(--amc-primary);
  color: var(--amc-text);
  text-decoration: none;
}
.amc-palette-title { font-size: var(--amc-fs); overflow-wrap: anywhere; }
.amc-palette-sub { font-size: var(--amc-fs-xs); color: var(--amc-text-muted); overflow-wrap: anywhere; }
.amc-palette-item.is-active .amc-palette-sub { color: inherit; opacity: .85; }
.amc-palette-status {
  padding: var(--amc-3) var(--amc-4);
  font-size: var(--amc-fs-sm);
  color: var(--amc-text-muted);
}
.amc-palette-status:empty { display: none; }
.navbar-icon-btn.amc-search-btn {
  width: auto;
  gap: var(--amc-2);
  padding-inline: var(--amc-3);
  border: 1px solid var(--amc-border);
  border-radius: var(--amc-radius-sm);
  font-size: var(--amc-fs-sm);
}
.amc-search-hint { font-size: var(--amc-fs-xs); }
@media (max-width: 767px) {
  .amc-search-hint { display: none; }
  .navbar-icon-btn.amc-search-btn { min-width: 44px; min-height: 44px; justify-content: center; }
}

/* ── Edara sync pill (header; states from api/edara_status.php) ─────────── */
.amc-edara-pill { display: inline-flex; align-items: center; margin-inline-end: 10px; }
.amc-edara-link {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--amc-2);
  padding-block: var(--amc-1);
  padding-inline: var(--amc-3);
  border: 1px solid var(--amc-border);
  border-radius: 999px;
  font-size: var(--amc-fs-xs);
  color: var(--amc-text);
  text-decoration: none;
  white-space: nowrap;
}
.amc-edara-link:hover { background: var(--amc-bg); color: var(--amc-text); text-decoration: none; }
.amc-edara-dot { inline-size: 8px; block-size: 8px; border-radius: 50%; background: var(--amc-text-muted); flex: none; }
.amc-edara-pill.is-ok .amc-edara-dot { background: var(--amc-success); }
.amc-edara-pill.is-warn .amc-edara-dot { background: var(--amc-warning); }
.amc-edara-pill.is-warn .amc-edara-link { background: var(--amc-warning-soft); }
.amc-edara-pill.is-bad .amc-edara-dot { background: var(--amc-danger); }
.amc-edara-pill.is-bad .amc-edara-link { background: var(--amc-danger-soft); }
@media (max-width: 767px) {
  /* phones: dot only (44px target); the text stays for screen readers */
  .amc-edara-link { min-inline-size: 44px; min-block-size: 44px; justify-content: center; padding-inline: 0; border-radius: var(--amc-radius-sm); }
  .amc-edara-text { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}

/* ── Mobile bottom bar ──────────────────────────────────────────────────── */
.amc-bottombar {
  position: fixed;
  inset-inline: 0;
  inset-block-end: 0;
  height: var(--amc-bottombar-h);
  display: none;
  align-items: center;
  justify-content: space-around;
  background: var(--amc-card);
  border-block-start: 1px solid var(--amc-border);
  box-shadow: var(--amc-shadow-2);
  z-index: 1040;
}
@media (max-width: 767px) {
  .amc-bottombar { display: flex; }
}

/* ── Numbers ────────────────────────────────────────────────────────────── */
.num { font-variant-numeric: tabular-nums; text-align: end; }
.ltr-num {
  font-variant-numeric: tabular-nums;
  direction: ltr;
  unicode-bidi: isolate;
}

/* ── Arabic type (pages print lang="ar" only when they are RTL ready) ──── */
html[lang="ar"] body,
html[lang="ar"] .site-navbar { font-family: var(--amc-font-ar); }

/* ── Print is always light ──────────────────────────────────────────────── */
@media print {
  :root,
  :root[data-theme="dark"] {
    color-scheme: light;
    --amc-sidebar:        #0F172A;
    --amc-sidebar-hover:  #1E293B;
    --amc-bg:             #F8FAFC;
    --amc-card:           #FFFFFF;
    --amc-border:         #E2E8F0;
    --amc-text:           #0F172A;
    --amc-text-muted:     #64748B;
    --amc-primary:        #1D4ED8;
    --amc-primary-hover:  #1E40AF;
    --amc-primary-soft:   #DBEAFE;
    --amc-success:        #059669;
    --amc-success-soft:   #D1FAE5;
    --amc-warning-soft:   #FEF3C7;
    --amc-danger-soft:    #FEE2E2;
    --amc-shadow-1: 0 1px 2px rgba(15,23,42,.06);
    --amc-shadow-2: 0 4px 16px rgba(15,23,42,.08);
  }
}

/* ── Header on phones: keep the user avatar on screen (the 44px pill and search targets left no room) ─────────── */
@media (max-width: 575px) {
  .site-navbar .navbar-container { padding-inline: 8px; }
  .site-navbar .navbar-toolbar-right { gap: 0; min-width: 0; }
  .site-navbar .navbar-toolbar-right .navbar-user-toggle { padding: 4px 4px; }
  .site-navbar .navbar-toolbar-right .navbar-icon-btn:not(.amc-search-btn):not(#amcThemeToggle) { display: none; }   /* the bell is a placeholder with no action yet */
  .site-navbar .navbar-toolbar-right .amc-edara-pill { margin-inline-end: 4px; }
}
