:root {
  --bg-page: #f8fafc;
  --bg-surface: #ffffff;
  --bg-subtle: #f1f5f9;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --emerald-600: #059669;
  --emerald-700: #047857;
  --emerald-50: #ecfdf5;
  --emerald-100: #d1fae5;
  --emerald-800: #065f46;
  --amber-50: #fffbeb;
  --amber-800: #92400e;
  --rose-50: #fff1f2;
  --rose-700: #be123c;
  --sky-50: #f0f9ff;
  --sky-700: #0369a1;
  --radius-md: 0.75rem;
  --radius-lg: 1rem;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 10px 25px -5px rgba(15, 23, 42, 0.12);
}

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

html {
  font-size: 16px;
}

body {
  margin: 0;
  font-family: "Cairo", "Segoe UI", Tahoma, Arial, sans-serif;
  background-color: var(--bg-page);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.bidi-ltr {
  direction: ltr;
  unicode-bidi: isolate;
  display: inline-block;
  font-variant-numeric: tabular-nums;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 3px solid #059669;
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* Header */
.app-header {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 30;
  box-shadow: var(--shadow-sm);
}

.header-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  max-width: 1280px;
  margin: 0 auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-mark {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.75rem;
  background: var(--emerald-600);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.25rem;
  flex-shrink: 0;
}

.brand-title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.brand-sub {
  margin: 0;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.625rem;
}

/* Mode Banner */
.mode-banner {
  background: #fef3c7;
  color: #78350f;
  border-bottom: 1px solid #fde68a;
  padding: 0.5rem 1rem;
  font-size: 0.9375rem;
  font-weight: 600;
  text-align: center;
}

.stale-banner {
  background: var(--rose-50);
  color: var(--rose-700);
  border: 1px solid #fecdd3;
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

/* Navigation Tabs */
.nav-tabs {
  display: flex;
  gap: 0.375rem;
  overflow-x: auto;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 1.5rem;
}

.nav-tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 700;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  white-space: nowrap;
  min-height: 44px;
}

.nav-tab:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
}

.nav-tab[aria-selected="true"] {
  background: var(--emerald-50);
  color: var(--emerald-800);
  border-color: #a7f3d0;
}

/* Cards & Grids */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
}

.card-title {
  margin: 0 0 0.75rem 0;
  font-size: 1.0625rem;
  font-weight: 800;
  color: var(--text-primary);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

.grid-3 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

.grid-4 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 640px) {
  .grid-2 { grid-template-columns: repeat(2, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 1024px) {
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
  .grid-4 { grid-template-columns: repeat(4, 1fr); }
}

.kpi-label {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin: 0;
}

.kpi-value {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text-primary);
  margin: 0.375rem 0;
}

.kpi-sub {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin: 0;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 700;
  padding: 0.5rem 1rem;
  min-height: 44px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--emerald-600);
  color: #ffffff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--emerald-700);
}

.btn-secondary {
  background: var(--bg-subtle);
  color: var(--text-primary);
  border-color: var(--border-color);
}
.btn-secondary:hover:not(:disabled) {
  background: #e2e8f0;
}

.btn-danger {
  background: var(--rose-50);
  color: var(--rose-700);
  border-color: #fecdd3;
}
.btn-danger:hover:not(:disabled) {
  background: #ffe4e6;
}

.btn-sm {
  min-height: 36px;
  padding: 0.35rem 0.75rem;
  font-size: 0.875rem;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.625rem;
  border-radius: 9999px;
  font-size: 0.8125rem;
  font-weight: 700;
  white-space: nowrap;
}

.badge-emerald { background: var(--emerald-100); color: var(--emerald-800); }
.badge-amber { background: var(--amber-50); color: var(--amber-800); border: 1px solid #fde68a; }
.badge-rose { background: var(--rose-50); color: var(--rose-700); border: 1px solid #fecdd3; }
.badge-sky { background: var(--sky-50); color: var(--sky-700); border: 1px solid #bae6fd; }
.badge-slate { background: var(--bg-subtle); color: var(--text-secondary); }

/* Forms */
.form-group {
  margin-bottom: 0.875rem;
}

.form-label {
  display: block;
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.form-control {
  width: 100%;
  min-height: 44px;
  padding: 0.5rem 0.75rem;
  font-family: inherit;
  font-size: 1rem;
  color: var(--text-primary);
  background: var(--bg-surface);
  border: 1px solid #cbd5e1;
  border-radius: var(--radius-md);
}

/* Tables vs Mobile Cards */
.table-wrap {
  overflow-x: auto;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: right;
  font-size: 0.9375rem;
}

table.data-table th {
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-weight: 700;
  padding: 0.75rem;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

table.data-table td {
  padding: 0.75rem;
  border-bottom: 1px solid var(--border-color);
  vertical-align: top;
}

.desktop-only { display: none; }
.mobile-only { display: block; }

@media (min-width: 768px) {
  .desktop-only { display: block; }
  .mobile-only { display: none; }
}

.mobile-order-card {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  margin-bottom: 0.75rem;
  background: var(--bg-surface);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-backdrop.hidden,
.hidden {
  display: none !important;
}

.modal-dialog {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  max-width: 680px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.5rem;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.75rem;
  margin-bottom: 1rem;
}

/* Toast / Inline Feedback */
.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 1.25rem;
  z-index: 60;
  max-width: 420px;
  padding: 0.875rem 1rem;
  border-radius: var(--radius-md);
  font-weight: 700;
  box-shadow: var(--shadow-lg);
}
.toast-success { background: #065f46; color: #fff; }
.toast-error { background: #9f1239; color: #fff; }

/* Auth Card */
.auth-wrap {
  max-width: 460px;
  margin: 3rem auto;
  padding: 0 1rem;
}

/* Simulator Phone */
.phone-shell {
  background: #0f172a;
  color: #f8fafc;
  border-radius: 1.75rem;
  padding: 1rem;
  border: 3px solid #334155;
  max-width: 380px;
}

.wa-chat {
  background: #0b141a;
  border-radius: 1rem;
  padding: 0.875rem;
  margin-top: 0.5rem;
}

.wa-bubble {
  background: #202c33;
  color: #f1f5f9;
  border-radius: 0.75rem;
  padding: 0.75rem;
  border-right: 4px solid var(--emerald-600);
  margin-bottom: 0.75rem;
  white-space: pre-line;
  font-size: 0.9375rem;
}

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

.timeline-item {
  border-right: 2px solid var(--emerald-600);
  padding: 0.375rem 0.75rem 0.375rem 0;
  margin-bottom: 0.5rem;
  font-size: 0.9375rem;
}

.stack-sm > * + * { margin-top: 0.5rem; }
.stack-md > * + * { margin-top: 1rem; }
.stack-lg > * + * { margin-top: 1.5rem; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; }
.flex-gap { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
