@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700;800&display=swap');

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

:root {
  --sidebar-w: 240px;
  --primary:   #1a3c5e;
  --primary-d: #122a43;
  --accent:    #e67e22;
  --accent-d:  #cf6d17;
  --success:   #27ae60;
  --danger:    #e74c3c;
  --warning:   #f39c12;
  --info:      #2980b9;
  --bg:        #f0f2f5;
  --card:      #ffffff;
  --text:      #1a1a2e;
  --muted:     #6c757d;
  --border:    #dee2e6;
  --sidebar-bg:#1a3c5e;
  --sidebar-tx:#c8d8e8;
  --sidebar-ac:#e67e22;
}

body { font-family: 'Cairo', sans-serif; background: var(--bg); color: var(--text); direction: rtl; }

/* ── SIDEBAR ── */
.sidebar {
  position: fixed; top: 0; right: 0;
  width: var(--sidebar-w); height: 100vh;
  background: var(--sidebar-bg);
  display: flex; flex-direction: column;
  z-index: 100; overflow-y: auto;
}
.sidebar-logo {
  padding: 22px 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex; align-items: center; gap: 12px;
}
.sidebar-logo .logo-icon {
  width: 42px; height: 42px; background: var(--accent);
  border-radius: 10px; display: flex; align-items: center; justify-content: center;
  font-size: 20px; color: #fff; font-weight: 800; flex-shrink: 0;
}
.sidebar-logo .logo-text { color: #fff; font-size: 14px; font-weight: 700; line-height: 1.3; }
.sidebar-logo .logo-text span { display: block; font-size: 11px; font-weight: 400; color: var(--sidebar-tx); }

.sidebar-nav { flex: 1; padding: 12px 0; }
.nav-section { padding: 16px 20px 6px; font-size: 10px; font-weight: 700; color: rgba(200,216,232,.45); letter-spacing: .08em; text-transform: uppercase; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 20px; color: var(--sidebar-tx);
  text-decoration: none; font-size: 14px; font-weight: 500;
  transition: background .15s, color .15s;
  border-right: 3px solid transparent;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: rgba(230,126,34,.15); color: var(--accent); border-right-color: var(--accent); font-weight: 700; }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-footer { padding: 16px 20px; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-footer a { display: flex; align-items: center; gap: 10px; color: var(--sidebar-tx); font-size: 13px; text-decoration: none; }
.sidebar-footer a:hover { color: #fff; }

/* ── MAIN LAYOUT ── */
.main { margin-right: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }

/* ── TOPBAR ── */
.topbar {
  background: #fff; padding: 0 28px;
  height: 62px; display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.topbar-title { font-size: 18px; font-weight: 700; color: var(--primary); }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.topbar-user { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.topbar-avatar { width: 34px; height: 34px; background: var(--primary); border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 13px; font-weight: 700; }

/* ── PAGE CONTENT ── */
.page-content { flex: 1; padding: 28px; }

/* ── STAT CARDS ── */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; margin-bottom: 28px; }
.stat-card { background: var(--card); border-radius: 14px; padding: 22px 24px; display: flex; align-items: center; gap: 18px; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
.stat-icon { width: 52px; height: 52px; border-radius: 12px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.stat-icon svg { width: 26px; height: 26px; }
.stat-icon.blue   { background: rgba(26,60,94,.1);  color: var(--primary); }
.stat-icon.orange { background: rgba(230,126,34,.1); color: var(--accent); }
.stat-icon.green  { background: rgba(39,174,96,.1);  color: var(--success); }
.stat-icon.red    { background: rgba(231,76,60,.1);   color: var(--danger); }
.stat-icon.purple { background: rgba(142,68,173,.1); color: #8e44ad; }
.stat-num { font-size: 28px; font-weight: 800; line-height: 1; color: var(--text); }
.stat-label { font-size: 13px; color: var(--muted); margin-top: 4px; }

/* ── CARDS ── */
.card { background: var(--card); border-radius: 14px; box-shadow: 0 1px 4px rgba(0,0,0,.06); overflow: hidden; margin-bottom: 24px; }
.card-header { padding: 16px 22px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-header h3 { font-size: 15px; font-weight: 700; color: var(--primary); }
.card-body { padding: 22px; }

/* ── TABLES ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th { background: #f8f9fa; padding: 11px 14px; font-weight: 700; color: var(--primary); text-align: right; border-bottom: 2px solid var(--border); white-space: nowrap; }
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover { background: #fafbfc; }
tbody tr:last-child td { border-bottom: none; }

/* ── BADGES ── */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 700; }
.badge-success { background: rgba(39,174,96,.12); color: var(--success); }
.badge-warning { background: rgba(243,156,18,.12); color: var(--warning); }
.badge-danger  { background: rgba(231,76,60,.12);  color: var(--danger); }
.badge-info    { background: rgba(41,128,185,.12);  color: var(--info); }
.badge-primary { background: rgba(26,60,94,.12);   color: var(--primary); }

/* ── BUTTONS ── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 18px; border-radius: 8px; font-size: 13px; font-weight: 700; cursor: pointer; border: none; text-decoration: none; transition: all .18s; font-family: 'Cairo', sans-serif; }
.btn svg { width: 15px; height: 15px; }
.btn-primary  { background: var(--primary);  color: #fff; }
.btn-primary:hover  { background: var(--primary-d); }
.btn-accent   { background: var(--accent);   color: #fff; }
.btn-accent:hover   { background: var(--accent-d); }
.btn-success  { background: var(--success);  color: #fff; }
.btn-danger   { background: var(--danger);   color: #fff; }
.btn-sm       { padding: 5px 12px; font-size: 12px; }
.btn-outline  { background: transparent; border: 1.5px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }

/* ── FORMS ── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-full { grid-column: 1 / -1; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 13px; font-weight: 700; color: var(--primary); }
.form-group input, .form-group select, .form-group textarea {
  padding: 9px 12px; border: 1.5px solid var(--border); border-radius: 8px;
  font-size: 14px; font-family: 'Cairo', sans-serif; color: var(--text);
  background: #fff; transition: border-color .15s;
  direction: rtl;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none; border-color: var(--primary);
}
.form-group textarea { resize: vertical; min-height: 80px; }
.form-actions { margin-top: 20px; display: flex; gap: 10px; }

/* ── MODAL ── */
.modal-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 200; align-items: center; justify-content: center; }
.modal-backdrop.open { display: flex; }
.modal { background: #fff; border-radius: 16px; width: 90%; max-width: 640px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal-lg { max-width: 900px; }
.modal-header { padding: 18px 24px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-header h4 { font-size: 16px; font-weight: 700; color: var(--primary); }
.modal-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }

/* ── FLASH ── */
.flash { padding: 12px 18px; border-radius: 10px; margin-bottom: 20px; font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 10px; }
.flash-success { background: rgba(39,174,96,.1); color: var(--success); border: 1px solid rgba(39,174,96,.25); }
.flash-danger  { background: rgba(231,76,60,.1); color: var(--danger);  border: 1px solid rgba(231,76,60,.25); }

/* ── SEARCH BAR ── */
.search-bar { display: flex; gap: 10px; margin-bottom: 18px; align-items: center; flex-wrap: wrap; }
.search-bar input, .search-bar select { padding: 8px 12px; border: 1.5px solid var(--border); border-radius: 8px; font-family: 'Cairo', sans-serif; font-size: 13px; min-width: 180px; }

/* ── ORDER ITEMS TABLE ── */
.items-table { width: 100%; border-collapse: collapse; margin-top: 12px; }
.items-table th { padding: 9px 10px; background: #f8f9fa; font-size: 12px; font-weight: 700; color: var(--primary); border-bottom: 2px solid var(--border); }
.items-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.items-table input, .items-table select { border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px; font-family: 'Cairo', sans-serif; font-size: 13px; width: 100%; }
.items-total { text-align: left; padding: 12px 10px; font-size: 15px; font-weight: 800; color: var(--primary); }

/* ── PAGE HEADER ── */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.page-header h2 { font-size: 20px; font-weight: 800; color: var(--primary); }

/* ── DETAILS VIEW ── */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.detail-row { display: flex; flex-direction: column; gap: 4px; }
.detail-label { font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--muted); letter-spacing: .05em; }
.detail-value { font-size: 15px; font-weight: 600; color: var(--text); }

/* ── EMPTY STATE ── */
.empty-state { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty-state svg { width: 52px; height: 52px; margin-bottom: 14px; opacity: .35; }

/* ── REPORTS CHARTS AREA ── */
.report-period { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 20px; }
.period-btn { padding: 7px 18px; border-radius: 20px; border: 1.5px solid var(--border); background: #fff; font-family: 'Cairo', sans-serif; font-size: 13px; font-weight: 600; cursor: pointer; color: var(--muted); }
.period-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ── LOGIN ── */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, var(--primary) 0%, #0d2035 100%); }
.login-card { background: #fff; border-radius: 20px; padding: 40px; width: 100%; max-width: 400px; box-shadow: 0 24px 60px rgba(0,0,0,.3); }
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo .icon { width: 64px; height: 64px; background: var(--accent); border-radius: 16px; display: inline-flex; align-items: center; justify-content: center; font-size: 28px; color: #fff; font-weight: 900; margin-bottom: 12px; }
.login-logo h1 { font-size: 20px; font-weight: 800; color: var(--primary); }

/* ── LANGUAGE PILL ── */
.lang-pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 12px; border-radius: 20px; font-size: 12px; font-weight: 700;
  background: rgba(26,60,94,.08); color: var(--primary); text-decoration: none;
  border: 1.5px solid var(--border); transition: all .15s;
}
.lang-pill:hover { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ── WA BUTTON ── */
.btn-wa { background: #25d366; color: #fff; }
.btn-wa:hover { background: #1ebe5d; }
.btn-wa svg { width: 15px; height: 15px; }

/* ── LTR (English) overrides ── */
[dir="ltr"] .sidebar { left: 0; right: auto; }
[dir="ltr"] .main { margin-left: var(--sidebar-w); margin-right: 0; }
[dir="ltr"] .nav-item { border-right: none; border-left: 3px solid transparent; }
[dir="ltr"] .nav-item.active { border-left-color: var(--accent); border-right-color: transparent; }
[dir="ltr"] thead th { text-align: left; }
[dir="ltr"] .form-group input,
[dir="ltr"] .form-group select,
[dir="ltr"] .form-group textarea { direction: ltr; }
[dir="ltr"] .items-total { text-align: right; }
[dir="ltr"] .sidebar-logo { flex-direction: row; }
[dir="ltr"] .topbar-right { flex-direction: row-reverse; }
[dir="ltr"] .loc-sidebar { border-radius: 0; box-shadow: -1px 0 0 var(--border); }

/* ── PRINT ── */
.print-only { display: none; }

@media print {
  .no-print, .sidebar, .topbar, .flash, .btn, .modal-backdrop,
  .page-header .btn, .card-header .btn, .search-bar,
  .report-period, .form-actions, .modal-footer { display: none !important; }
  .main { margin: 0 !important; }
  .page-content { padding: 0 !important; }
  .card { box-shadow: none !important; border: 1px solid #ccc !important; margin-bottom: 12px !important; }
  .card-header { background: #f8f9fa !important; }
  body { font-size: 12px; color: #000; }
  a { color: #000; text-decoration: none; }
  .badge { border: 1px solid #ccc; }
  .print-only { display: block !important; }
  @page { margin: 15mm; size: A4; }
}

.print-invoice {
  border: 2px solid var(--primary);
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 20px;
}
.print-shop-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 2px solid var(--primary);
}
.print-shop-name { font-size: 22px; font-weight: 800; color: var(--primary); }
.print-shop-tag  { font-size: 13px; color: var(--muted); margin-top: 2px; }
.print-shop-logo { width: 56px; height: 56px; background: var(--primary); border-radius: 12px; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 20px; font-weight: 900; }
.print-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px; font-size: 13px; }
.print-meta-row { display: flex; gap: 6px; }
.print-meta-label { font-weight: 700; color: var(--primary); min-width: 80px; }
.print-footer { text-align: center; margin-top: 20px; padding-top: 12px; border-top: 1px solid #ddd; color: var(--muted); font-size: 13px; }

/* ── PHOTO UPLOAD DROP ZONE ── */
.photo-drop-zone {
  border: 2px dashed var(--border); border-radius: 12px; padding: 30px 20px;
  text-align: center; cursor: pointer; transition: all .2s; user-select: none;
}
.photo-drop-zone:hover, .photo-drop-zone.drag-over, .photo-drop-zone.has-files {
  border-color: var(--primary); background: rgba(26,60,94,.04);
}
.photo-drop-icon { font-size: 34px; margin-bottom: 10px; }
.photo-drop-text { font-weight: 700; font-size: 14px; color: var(--text); margin-bottom: 4px; }
.photo-drop-hint { font-size: 12px; color: var(--muted); }
.photo-preview-grid { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.photo-thumb-wrap { width: 88px; }
.photo-thumb-pre  { width: 88px; height: 88px; object-fit: cover; border-radius: 8px; border: 2px solid var(--border); display: block; }
.photo-thumb-name { font-size: 10px; color: var(--muted); margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: center; }

/* ── PHOTO GALLERY ── */
.photo-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.gallery-item  { position: relative; line-height: 0; }
.gallery-thumb {
  width: 100%; height: 110px; object-fit: cover; border-radius: 8px; display: block;
  cursor: pointer; border: 2px solid var(--border); transition: all .18s;
}
.gallery-thumb:hover { border-color: var(--primary); transform: scale(1.03); }
.gallery-del-form { position: absolute; top: 4px; inset-inline-end: 4px; }
.gallery-del-btn {
  background: rgba(0,0,0,.65); color: #fff; border: none; border-radius: 50%;
  width: 22px; height: 22px; cursor: pointer; font-size: 15px; line-height: 22px;
  text-align: center; opacity: 0; transition: opacity .15s; padding: 0; display: block;
}
.gallery-item:hover .gallery-del-btn { opacity: 1; }

/* ── LIGHTBOX ── */
#lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.93); z-index: 9999; display: none; align-items: center; justify-content: center; }
#lightbox.open { display: flex; }
#lightboxImg { max-width: 90vw; max-height: 90vh; object-fit: contain; border-radius: 8px; box-shadow: 0 0 40px rgba(0,0,0,.5); }
.lb-btn {
  position: fixed; background: rgba(255,255,255,.18); border: none; color: #fff;
  font-size: 26px; width: 46px; height: 46px; border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: background .2s;
  line-height: 1;
}
.lb-btn:hover { background: rgba(255,255,255,.35); }
.lb-prev  { top: 50%; left: 16px;  transform: translateY(-50%); }
.lb-next  { top: 50%; right: 16px; transform: translateY(-50%); }
.lb-close { top: 16px; right: 16px; }

/* ── LIVE SEARCH DROPDOWN ── */
.sdrop {
  position: absolute; top: calc(100% + 4px);
  inset-inline-start: 0; inset-inline-end: 0;
  background: var(--card); border: 1.5px solid var(--border);
  border-radius: 12px; box-shadow: 0 8px 32px rgba(0,0,0,.13);
  max-height: 320px; overflow-y: auto; z-index: 999;
  display: none;
}
.sdrop.open { display: block; }
.sdrop-item {
  padding: 10px 16px; cursor: pointer;
  border-bottom: 1px solid var(--border); transition: background .13s;
}
.sdrop-item:last-child { border-bottom: none; }
.sdrop-item:hover { background: #f0f2f5; }
.sdrop-name { font-weight: 700; font-size: 14px; color: var(--primary); }
.sdrop-sub  { font-size: 12px; color: var(--muted); margin-top: 2px; }
.sdrop-empty { padding: 14px 16px; color: var(--muted); font-size: 13px; text-align: center; }

/* ── RESPONSIVE ── */
@media (max-width: 900px) {
  .sidebar { transform: translateX(100%); transition: transform .3s; }
  [dir="rtl"] .sidebar { transform: translateX(100%); }
  [dir="ltr"] .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-right: 0; margin-left: 0; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}
