/* ============================================================
   نظام الصيدليات الزراعية - ملف التنسيقات
   ============================================================ */

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

:root {
  --primary: #16a34a;
  --primary-dark: #15803d;
  --primary-light: #dcfce7;
  --secondary: #0ea5e9;
  --danger: #dc2626;
  --warning: #f59e0b;
  --bg: #f3f6f4;
  --surface: #ffffff;
  --text: #1f2937;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 4px 12px rgba(0,0,0,0.08);
  --radius: 12px;
  --radius-sm: 8px;
}

html, body {
  font-family: "Segoe UI", "Tahoma", "Arial", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  direction: rtl;
  font-size: 15px;
  line-height: 1.5;
}

/* ============================================================
   إدارة الشاشات
============================================================ */
.screen { display: none; }
.screen.active { display: block; }

/* ============================================================
   شاشات المصادقة
============================================================ */
.auth-wrap {
  min-height: 100vh;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #16a34a 0%, #0ea5e9 100%);
}
.auth-wrap.active { display: flex; }

.auth-card {
  width: 100%;
  max-width: 460px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
}

.auth-brand { text-align: center; margin-bottom: 24px; }
.brand-logo {
  width: 64px; height: 64px;
  background: var(--primary-light);
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  margin-bottom: 12px;
}
.auth-brand h1 { font-size: 22px; color: var(--primary-dark); }
.auth-sub { font-size: 13px; color: var(--text-muted); margin-top: 6px; }

.tabs {
  display: flex;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 24px;
}
.tab-btn {
  flex: 1;
  padding: 10px;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  font-family: inherit;
}
.tab-btn.active {
  background: var(--surface);
  color: var(--primary-dark);
  box-shadow: var(--shadow-sm);
}

.auth-form { display: none; }
.auth-form.active { display: block; }

.auth-form label,
.card-form label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  margin-top: 12px;
  color: var(--text);
}

input[type="text"], input[type="email"], input[type="password"],
input[type="tel"], input[type="number"], input[type="date"],
select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color .2s, box-shadow .2s;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
input[readonly] { background: #f9fafb; color: var(--text-muted); }

.password-wrap { position: relative; }
.password-wrap input { padding-left: 44px; }
.eye-btn {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 18px;
  padding: 4px 8px;
}

.auth-extra { text-align: center; margin-top: 16px; }
.link-btn {
  background: transparent;
  border: none;
  color: var(--primary-dark);
  cursor: pointer;
  text-decoration: underline;
  font-size: 13px;
  font-family: inherit;
}

.hint {
  font-size: 13px;
  color: var(--text-muted);
  background: var(--primary-light);
  padding: 10px;
  border-radius: var(--radius-sm);
  margin-top: 12px;
}
.hint strong { color: var(--primary-dark); letter-spacing: 2px; }

/* ============================================================
   الأزرار
============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  transition: transform .1s, opacity .2s, background .2s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--secondary); color: #fff; }
.btn-secondary:hover { opacity: .9; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .9; }
.btn-ghost { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,0.4); }
.btn-ghost:hover { background: rgba(255,255,255,0.1); }
.btn-block { width: 100%; margin-top: 18px; }
.btn-sm { padding: 6px 10px; font-size: 12px; }

.icon-btn {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  padding: 6px 10px;
}

.file-label { cursor: pointer; }

/* ============================================================
   الواجهة الرئيسية
============================================================ */
.app-header {
  background: var(--primary-dark);
  color: #fff;
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-sm);
}
.header-right {
  display: flex;
  align-items: center;
  gap: 14px;
}
.pharmacy-identity {
  display: flex;
  align-items: center;
  gap: 10px;
}
.pharmacy-identity img {
  width: 42px;
  height: 42px;
  object-fit: cover;
  border-radius: 50%;
  background: #fff;
  display: none;
}
.pharmacy-identity img[src] { display: block; }
.pharmacy-identity h2 { font-size: 17px; }
.pharmacy-identity small { font-size: 12px; opacity: 0.85; }

.app-body { display: flex; min-height: calc(100vh - 66px); }

.sidebar {
  width: 220px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 16px 10px;
  flex-shrink: 0;
}
.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.nav-btn {
  text-align: right;
  padding: 10px 14px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  font-family: inherit;
  transition: background .2s;
}
.nav-btn:hover { background: var(--bg); }
.nav-btn.active {
  background: var(--primary-light);
  color: var(--primary-dark);
}

.app-main {
  flex: 1;
  padding: 22px;
  overflow-x: auto;
}

.view { display: none; }
.view.active { display: block; }

.view-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 10px;
}
.view-title {
  font-size: 20px;
  color: var(--primary-dark);
  border-bottom: 3px solid var(--primary);
  padding-bottom: 6px;
  display: inline-block;
}
.sub-title {
  font-size: 16px;
  color: var(--text);
  margin: 18px 0 10px;
}

/* ============================================================
   النماذج بطاقة
============================================================ */
.card-form {
  background: var(--surface);
  padding: 18px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
}
.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.grid-2 .full { grid-column: 1 / -1; }

.logo-preview-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
}
.logo-preview-wrap img {
  width: 64px; height: 64px;
  object-fit: cover;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  display: none;
}
.logo-preview-wrap img[src] { display: block; }

.actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.sep { border: none; border-top: 1px dashed var(--border); margin: 18px 0; }

/* ============================================================
   الإحصائيات
============================================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--surface);
  padding: 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border-right: 4px solid var(--primary);
}
.stat-warn { border-right-color: var(--warning); }
.stat-danger { border-right-color: var(--danger); }
.stat-label { font-size: 13px; color: var(--text-muted); }
.stat-value { font-size: 24px; font-weight: 700; margin-top: 6px; color: var(--text); }

/* ============================================================
   الجداول
============================================================ */
.table-wrap {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.data-table thead {
  background: var(--primary-light);
  color: var(--primary-dark);
}
.data-table th, .data-table td {
  padding: 10px 12px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table tbody tr:hover { background: #fafafa; }
.data-table .empty {
  text-align: center;
  padding: 30px;
  color: var(--text-muted);
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge-ok { background: var(--primary-light); color: var(--primary-dark); }
.badge-warn { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }

/* ============================================================
   التقرير
============================================================ */
.report-area {
  background: var(--surface);
  padding: 18px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.report-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.report-summary .stat-card { border-right-width: 4px; }

/* ============================================================
   Toast
============================================================ */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  background: var(--text);
  color: #fff;
  padding: 12px 22px;
  border-radius: 999px;
  font-size: 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: all .3s;
  z-index: 9999;
  max-width: 90%;
  text-align: center;
}
.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}
.toast.success { background: var(--primary); }
.toast.error { background: var(--danger); }
.toast.warn { background: var(--warning); color: #fff; }

/* ============================================================
   Responsive
============================================================ */
@media (max-width: 800px) {
  .sidebar {
    position: fixed;
    inset: 66px 0 0 auto;
    right: 0;
    height: calc(100vh - 66px);
    width: 220px;
    transform: translateX(100%);
    transition: transform .3s;
    z-index: 50;
    box-shadow: -4px 0 12px rgba(0,0,0,0.1);
  }
  .sidebar.open { transform: translateX(0); }
  .app-main { padding: 16px; }
  .stat-value { font-size: 20px; }
  .view-title { font-size: 18px; }
}

@media (min-width: 801px) {
  #sidebar-toggle { display: none; }
}

/* ============================================================
   الطباعة
============================================================ */
.print-only { display: none; }

@media print {
  body * { visibility: hidden; }
  #print-area, #print-area * { visibility: visible; }
  #print-area {
    display: block !important;
    position: absolute;
    inset: 0;
    width: 100%;
    padding: 20px;
    background: #fff;
    color: #000;
  }
  .no-print { display: none !important; }

  #print-area .print-header {
    display: flex;
    align-items: center;
    gap: 14px;
    border-bottom: 2px solid #000;
    padding-bottom: 10px;
    margin-bottom: 16px;
  }
  #print-area .print-header img {
    width: 70px; height: 70px;
    object-fit: cover;
    border-radius: 6px;
  }
  #print-area h2 { font-size: 20px; margin-bottom: 4px; }
  #print-area .print-meta { font-size: 12px; color: #333; }
  #print-area table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 14px;
    font-size: 12px;
  }
  #print-area th, #print-area td {
    border: 1px solid #555;
    padding: 6px 8px;
    text-align: right;
  }
  #print-area thead { background: #eee; }
  #print-area .print-footer {
    margin-top: 30px;
    display: flex;
    justify-content: space-between;
    font-size: 12px;
  }
  #print-area .print-note {
    font-size: 11px;
    color: #555;
    margin-top: 20px;
    border-top: 1px dashed #999;
    padding-top: 8px;
  }
  #print-area .totals-row {
    background: #f5f5f5;
    font-weight: bold;
  }
}

/* ============================================================
   منتقي التاريخ العربي المخصص
============================================================ */
.ar-date-wrap { position: relative; }
.ar-date-display {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-align: right;
}
.ar-date-display:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.ar-date-popup {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 1000;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
  min-width: 280px;
  user-select: none;
}
.ar-date-popup[hidden] { display: none; }
.ar-date-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  gap: 6px;
}
.ar-date-title {
  flex: 1;
  text-align: center;
  font-weight: 600;
  font-size: 14px;
  color: var(--primary-dark);
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  font-family: inherit;
}
.ar-date-title:hover { background: var(--primary-light); }
.ar-nav {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 32px;
  height: 32px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
}
.ar-nav:hover { background: var(--primary-light); border-color: var(--primary); }
.ar-date-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  margin-bottom: 4px;
}
.ar-date-wd {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  padding: 6px 0;
  font-weight: 600;
}
.ar-date-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}
.ar-date-cell {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  font-size: 13px;
  padding: 8px 0;
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
  text-align: center;
}
.ar-date-cell:hover:not(:disabled) {
  background: var(--primary-light);
  border-color: var(--primary);
}
.ar-date-cell.empty {
  cursor: default;
  visibility: hidden;
}
.ar-date-cell.today {
  font-weight: 700;
  color: var(--primary-dark);
  border-color: var(--primary);
}
.ar-date-cell.selected {
  background: var(--primary);
  color: #fff;
  font-weight: 700;
}
.ar-date-cell.selected:hover { background: var(--primary-dark); }
.ar-month-grid, .ar-year-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 4px 0;
}
.ar-month-cell, .ar-year-cell {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 6px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
}
.ar-month-cell:hover, .ar-year-cell:hover {
  background: var(--primary-light);
  border-color: var(--primary);
}
.ar-month-cell.selected, .ar-year-cell.selected {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  font-weight: 700;
}
.ar-date-foot {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
.ar-foot-btn {
  flex: 1;
  padding: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  color: var(--text);
}
.ar-foot-btn:hover {
  background: var(--primary-light);
  border-color: var(--primary);
}

