/* MENA Commerce Admin Panel — Minimal RTL stylesheet */
:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --border: #e1e4e8;
  --primary: #1a56db;
  --primary-dark: #1240a8;
  --text: #1f2937;
  --text-muted: #6b7280;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --radius: 6px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

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

body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; }

/* Nav */
.admin-nav {
  display: flex; align-items: center; gap: 4px;
  background: var(--text); color: #fff;
  padding: 0 20px; height: 52px;
}
.nav-brand { font-weight: 700; font-size: 15px; }
.admin-nav a { color: rgba(255,255,255,0.8); text-decoration: none; padding: 6px 12px; border-radius: var(--radius); font-size: 13px; }
.admin-nav a:hover, .admin-nav a.active { background: rgba(255,255,255,0.15); color: #fff; }
.nav-spacer { flex: 1; }
.nav-user { font-size: 12px; color: rgba(255,255,255,0.6); margin-left: 12px; }
.nav-logout { font-size: 12px; }

/* Main */
.admin-main { max-width: 1200px; margin: 0 auto; padding: 24px 20px; }

/* Login page */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-box { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 36px; width: 340px; }
.login-box h1 { font-size: 20px; margin-bottom: 24px; text-align: center; }
.login-box label { display: block; margin-bottom: 16px; font-size: 13px; color: var(--text-muted); }
.login-box input { display: block; width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px; }
.login-box button { width: 100%; padding: 10px; background: var(--primary); color: #fff; border: none; border-radius: var(--radius); font-size: 14px; cursor: pointer; margin-top: 8px; }
.login-box button:hover { background: var(--primary-dark); }
.error-msg { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; border-radius: var(--radius); padding: 8px 12px; margin-bottom: 16px; font-size: 13px; }

/* Page header */
.page-header { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-header h2 { font-size: 18px; flex: 1; }
.page-hint { color: var(--text-muted); font-size: 13px; }

/* Badge */
.badge { display: inline-block; background: var(--primary); color: #fff; border-radius: 20px; padding: 2px 8px; font-size: 12px; font-weight: 600; margin-right: 6px; }

/* Filter bar */
.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; }
.filter-bar select, .filter-bar input[type="date"] {
  padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 13px; background: var(--surface);
}
.filter-bar button { padding: 6px 16px; background: var(--primary); color: #fff; border: none; border-radius: var(--radius); font-size: 13px; cursor: pointer; }

/* Table */
.data-table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }
.data-table th { background: #f8f9fa; font-weight: 600; font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; padding: 10px 14px; text-align: right; border-bottom: 1px solid var(--border); }
.data-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #f8f9fa; }
.data-table code { font-family: 'Courier New', monospace; font-size: 12px; background: #f3f4f6; padding: 2px 6px; border-radius: 4px; }
.truncate { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.empty { text-align: center; color: var(--text-muted); padding: 32px; }

/* Buttons */
.btn-sm { display: inline-block; padding: 4px 12px; background: var(--primary); color: #fff; text-decoration: none; border-radius: var(--radius); font-size: 12px; }
.btn-sm:hover { background: var(--primary-dark); }

/* Status badges */
.status-badge { display: inline-block; padding: 3px 8px; border-radius: 12px; font-size: 12px; font-weight: 600; }
.status-new          { background: #dbeafe; color: #1e40af; }
.status-sent_to_crm  { background: #e0f2fe; color: #0369a1; }
.status-crm_failed   { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.status-contacted    { background: #fef9c3; color: #854d0e; }
.status-unconfirmed  { background: #ffedd5; color: #9a3412; }
.status-confirmed    { background: #dcfce7; color: #166534; }
.status-shipped      { background: #e0e7ff; color: #3730a3; }
.status-delivered    { background: #d1fae5; color: #065f46; }
.status-returned     { background: #fee2e2; color: #991b1b; }
.status-cancelled    { background: #f3f4f6; color: #6b7280; }

/* Detail grid */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
@media (max-width: 700px) { .detail-grid { grid-template-columns: 1fr; } }

.detail-card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 20px; margin-bottom: 16px; }
.detail-card h3 { font-size: 14px; font-weight: 600; margin-bottom: 14px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.action-card { border-color: var(--primary); }

dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
dt { font-weight: 600; font-size: 12px; color: var(--text-muted); align-self: center; }
dd { font-size: 13px; }

/* Action buttons */
.action-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-action { padding: 8px 18px; border: none; border-radius: var(--radius); font-size: 13px; cursor: pointer; font-weight: 600; }
.btn-confirmed   { background: #dcfce7; color: #166534; }
.btn-shipped     { background: #e0e7ff; color: #3730a3; }
.btn-delivered   { background: #d1fae5; color: #065f46; }
.btn-cancelled   { background: #fee2e2; color: #991b1b; }
.btn-contacted   { background: #fef9c3; color: #854d0e; }
.btn-unconfirmed { background: #ffedd5; color: #9a3412; }
.btn-returned    { background: #fee2e2; color: #991b1b; }
.btn-action:hover { filter: brightness(0.92); }

/* CRM Failed banner */
.crm-failed-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  background: #fef2f2; border: 1px solid #fecaca; border-radius: 8px; padding: 14px 18px;
}
.crm-failed-msg { display: flex; flex-direction: column; gap: 4px; }
.crm-failed-msg strong { font-size: 14px; color: #991b1b; }
.crm-failed-msg span { font-size: 13px; color: #7f1d1d; }

/* Retry CRM button */
.btn-retry {
  padding: 8px 18px; background: #dc2626; color: #fff; border: none;
  border-radius: var(--radius); font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn-retry:hover { background: #b91c1c; }
.retry-hint { font-size: 12px; color: var(--text-muted); font-style: italic; }

/* Success message */
.success-msg {
  background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0;
  border-radius: var(--radius); padding: 8px 12px; font-size: 13px;
}

/* crm_failed rows in the table — subtle left-border highlight */
tr.row-crm-failed td { border-right: 3px solid #dc2626; }

@media (max-width: 600px) {
  .crm-failed-banner { flex-direction: column; align-items: flex-start; }
  .btn-retry { width: 100%; text-align: center; }
}

/* Pagination */
.pagination { display: flex; align-items: center; gap: 12px; margin-top: 16px; justify-content: center; }
.pagination a { color: var(--primary); text-decoration: none; font-size: 13px; }
.pagination span { font-size: 13px; color: var(--text-muted); }

/* Mobile table scroll — prevents horizontal page overflow */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 8px; }
.table-wrap .data-table { border-radius: 0; }

/* Mobile nav — collapse to wrap on small screens */
@media (max-width: 600px) {
  .admin-nav { flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 2px; }
  .nav-spacer { display: none; }
  .admin-main { padding: 16px 12px; }
  .detail-grid { grid-template-columns: 1fr; }
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-bar select, .filter-bar input { width: 100%; }
}

/* Error page */
.error-page { text-align: center; padding: 60px 20px; }
.error-page h2 { font-size: 20px; margin-bottom: 12px; color: var(--danger); }
.error-page p  { color: var(--text-muted); margin-bottom: 24px; }

/* Nav brand RTL: space separates brand from nav links on its left in RTL flow */
.nav-brand { margin-inline-end: 24px; }

/* ── Dashboard ────────────────────────────────────────────────────────────── */

/* KPI cards */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
@media (max-width: 800px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }

.kpi-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 18px 20px;
}
.kpi-card.kpi-good { border-top: 3px solid var(--success); }
.kpi-card.kpi-best { border-top: 3px solid #0891b2; }
.kpi-value { font-size: 32px; font-weight: 700; line-height: 1; margin-bottom: 6px; }
.kpi-label { font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 8px; }
.kpi-sub   { font-size: 11px; color: var(--text-muted); direction: ltr; }
.kpi-link  { font-size: 12px; color: var(--primary); text-decoration: none; }
.kpi-link:hover { text-decoration: underline; }

/* Revenue */
.revenue-grid { display: flex; gap: 32px; flex-wrap: wrap; }
.revenue-item { min-width: 140px; }
.revenue-currency { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 8px; }
.revenue-row { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 4px; }
.rev-label { font-size: 12px; color: var(--text-muted); }
.rev-value { font-size: 14px; font-weight: 600; }
.rev-delivered { color: var(--success); }

/* Two-column layout */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
@media (max-width: 700px) { .two-col { grid-template-columns: 1fr; } }

/* Country bars */
.country-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.country-code { font-size: 12px; font-weight: 700; width: 28px; direction: ltr; text-align: left; flex-shrink: 0; }
.country-bar-wrap { flex: 1; background: var(--bg); border-radius: 4px; height: 10px; overflow: hidden; }
.country-bar { background: var(--primary); height: 100%; border-radius: 4px; min-width: 4px; }
.country-count { font-size: 12px; color: var(--text-muted); width: 24px; text-align: left; direction: ltr; flex-shrink: 0; }

/* CAPI health */
.capi-ok   { color: var(--success); font-weight: 600; }
.capi-fail { color: var(--danger);  font-weight: 600; }

/* Hourly bar chart */
.hour-chart { display: flex; align-items: flex-end; gap: 2px; height: 90px; padding-bottom: 18px; }
.hour-bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; gap: 2px; }
.hour-bar       { width: 100%; background: var(--primary); border-radius: 2px 2px 0 0; opacity: 0.75; }
.hour-bar-empty { background: var(--border); opacity: 1; }
.hour-label       { font-size: 9px; color: var(--text-muted); direction: ltr; }
.hour-label-empty { height: 14px; }

/* Stale-order warning */
.alert-warning {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: #fffbeb; border: 1px solid #fde68a; border-radius: 8px; padding: 12px 16px;
}
.alert-warning strong { font-size: 13px; color: #92400e; flex-shrink: 0; }
.alert-warning span   { font-size: 13px; color: #78350f; flex: 1; }
.btn-sm-inline { font-size: 12px; color: var(--primary); text-decoration: none; white-space: nowrap; }
@media (max-width: 600px) { .alert-warning { flex-direction: column; align-items: flex-start; } }

/* ── CRM Retry Queue panel ─────────────────────────────────────────────────── */
.retry-queue-stats { display: flex; gap: 28px; flex-wrap: wrap; margin-top: 4px; }
.rq-stat { min-width: 120px; }
.rq-value { font-size: 28px; font-weight: 700; line-height: 1; margin-bottom: 4px; }
.rq-pending { color: var(--warning); }
.rq-maxed   { color: var(--danger); }
.rq-label   { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.rq-sub     { font-size: 11px; color: var(--text-muted); direction: ltr; margin-top: 2px; }
.rq-time    { font-size: 13px; color: var(--text); }
.retry-queue-migration {
  font-size: 13px; color: var(--warning);
  background: #fffbeb; border: 1px solid #fde68a;
  border-radius: var(--radius); padding: 10px 14px;
}
.retry-queue-migration code { font-size: 12px; direction: ltr; display: inline-block; }

/* ── Order detail: retry meta info ─────────────────────────────────────────── */
.retry-meta {
  display: flex; flex-wrap: wrap; gap: 16px;
  margin-top: 8px; padding-top: 8px;
  border-top: 1px solid rgba(220,38,38,0.2);
  font-size: 12px; color: #7f1d1d;
}
.retry-meta strong { color: #991b1b; }
.retry-error-msg   { font-family: 'Courier New', monospace; font-size: 11px; word-break: break-all; }
