/* ==========================================================================
   VetPharm Pro - Modern Cloud Accounting CSS (Hesabfa-Inspired Architecture)
   Clean, Professional, Medical-Grade RTL Design System
   ========================================================================== */

:root {
  --primary: #0284c7;         /* Sky / Medical Blue */
  --primary-dark: #0369a1;
  --primary-light: #e0f2fe;
  --accent: #10b981;          /* Emerald Success */
  --accent-light: #d1fae5;
  --warning: #f59e0b;         /* Amber Warning */
  --warning-light: #fef3c7;
  --danger: #ef4444;          /* Red Danger / Overdue */
  --danger-light: #fee2e2;
  --purple: #8b5cf6;          /* B2B Network */
  --purple-light: #ede9fe;

  --bg-app: #f8fafc;          /* Light Slate Canvas */
  --bg-surface: #ffffff;
  --bg-subtle: #f1f5f9;
  
  --text-main: #0f172a;       /* Slate 900 */
  --text-muted: #64748b;      /* Slate 500 */
  --text-light: #94a3b8;
  
  --border-color: #e2e8f0;
  --border-focus: #38bdf8;
  
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.07), 0 2px 4px -2px rgb(0 0 0 / 0.07);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.05);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Vazirmatn', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

body {
  background-color: var(--bg-app);
  color: var(--text-main);
  direction: rtl;
  text-align: right;
  font-size: 14px;
  line-height: 1.5;
  overflow-x: hidden;
}

/* App Container Layout */
.pharmacy-layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar Navigation */
.sidebar {
  width: 260px;
  background: #0f172a; /* Slate 900 */
  color: #f8fafc;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-left: 1px solid #1e293b;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-header {
  padding: 20px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid #1e293b;
  background: #090e1a;
}

.sidebar-logo-icon {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, #0284c7, #10b981);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 4px 12px rgba(2, 132, 199, 0.3);
}

.sidebar-title h2 {
  font-size: 16px;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: -0.3px;
}

.sidebar-title span {
  font-size: 11px;
  color: #38bdf8;
  font-weight: 500;
  display: block;
}

.nav-section-title {
  font-size: 11px;
  font-weight: 700;
  color: #64748b;
  padding: 16px 18px 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.sidebar-nav {
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  color: #94a3b8;
  text-decoration: none;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 13.5px;
  transition: all 0.2s ease;
  cursor: pointer;
  border: 1px solid transparent;
}

.nav-link:hover {
  background: #1e293b;
  color: #ffffff;
}

.nav-link.active {
  background: linear-gradient(90deg, rgba(2, 132, 199, 0.25), transparent);
  color: #38bdf8;
  border-right: 3px solid #38bdf8;
  font-weight: 600;
}

.nav-link svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.85;
}

.nav-badge {
  margin-right: auto;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 12px;
  font-weight: 700;
}

.nav-badge.danger { background: var(--danger); color: white; }
.nav-badge.warning { background: var(--warning); color: #000; }
.nav-badge.purple { background: var(--purple); color: white; }

/* Main Content Area */
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Top Navigation Bar */
.topbar {
  height: 64px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 90;
  box-shadow: var(--shadow-sm);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.pharmacy-badge-info {
  display: flex;
  flex-direction: column;
}

.pharmacy-badge-info .ph-name {
  font-weight: 700;
  font-size: 14px;
  color: var(--text-main);
}

.pharmacy-badge-info .ph-meta {
  font-size: 11.5px;
  color: var(--text-muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn svg { width: 16px; height: 16px; }

.btn-primary {
  background-color: var(--primary);
  color: white;
  box-shadow: 0 2px 4px rgba(2, 132, 199, 0.25);
}
.btn-primary:hover { background-color: var(--primary-dark); }

.btn-success {
  background-color: var(--accent);
  color: white;
  box-shadow: 0 2px 4px rgba(16, 185, 129, 0.25);
}
.btn-success:hover { background-color: #059669; }

.btn-outline {
  background: transparent;
  border-color: var(--border-color);
  color: var(--text-main);
}
.btn-outline:hover {
  background: var(--bg-subtle);
  border-color: #cbd5e1;
}

.btn-danger {
  background-color: var(--danger);
  color: white;
}
.btn-danger:hover { background-color: #dc2626; }

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

/* Page Body Container */
.content-body {
  padding: 24px;
  flex: 1;
}

/* Tab Panels */
.tab-pane {
  display: none;
}
.tab-pane.active {
  display: block;
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: translateY(0); }
}

/* KPI Summary Cards Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.kpi-info h3 {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.kpi-info .kpi-value {
  font-size: 22px;
  font-weight: 800;
  color: var(--text-main);
}

.kpi-info .kpi-sub {
  font-size: 11px;
  color: var(--text-light);
  margin-top: 4px;
}

.kpi-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.kpi-icon.blue { background: var(--primary-light); color: var(--primary); }
.kpi-icon.green { background: var(--accent-light); color: var(--accent); }
.kpi-icon.amber { background: var(--warning-light); color: var(--warning); }
.kpi-icon.red { background: var(--danger-light); color: var(--danger); }
.kpi-icon.purple { background: var(--purple-light); color: var(--purple); }

/* Data Tables & Panels */
.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
  overflow: hidden;
}

.panel-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.panel-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.search-input-wrap {
  position: relative;
  width: 240px;
}

.search-input-wrap input {
  width: 100%;
  padding: 7px 32px 7px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 13px;
  outline: none;
  background: var(--bg-subtle);
  transition: border-color 0.2s;
}

.search-input-wrap input:focus {
  border-color: var(--primary);
  background: white;
}

.search-input-wrap svg {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  color: var(--text-muted);
}

.select-filter {
  padding: 7px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 13px;
  outline: none;
  background: white;
  cursor: pointer;
}

/* Table Style */
.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: right;
  font-size: 13px;
}

.data-table th {
  background: #f8fafc;
  padding: 12px 16px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-main);
  vertical-align: middle;
}

.data-table tbody tr:hover {
  background-color: #f8fafc;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-success { background: var(--accent-light); color: #065f46; }
.badge-warning { background: var(--warning-light); color: #92400e; }
.badge-danger { background: var(--danger-light); color: #991b1b; }
.badge-info { background: var(--primary-light); color: #0369a1; }
.badge-purple { background: var(--purple-light); color: #5b21b6; }
.badge-gray { background: #e2e8f0; color: #475569; }

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-overlay.active {
  display: flex;
}

.modal-card {
  background: white;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 780px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: modalPop 0.2s ease-out;
}

.modal-card.modal-lg {
  max-width: 950px;
}

@keyframes modalPop {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

.modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
}

.btn-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-sm);
}
.btn-close:hover { background: var(--bg-subtle); color: var(--danger); }

.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  background: #f8fafc;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* Forms & Inputs */
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-main);
}

.form-group input,
.form-group select,
.form-group textarea {
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 13px;
  outline: none;
  background: white;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15);
}

.form-group .field-hint {
  font-size: 11px;
  color: var(--text-muted);
}

/* Invoicing Table inside Form */
.invoice-items-table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0 16px;
}

.invoice-items-table th {
  background: #f1f5f9;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  border: 1px solid var(--border-color);
}

.invoice-items-table td {
  padding: 8px 10px;
  border: 1px solid var(--border-color);
  vertical-align: middle;
}

.invoice-items-table input,
.invoice-items-table select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #cbd5e1;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
}

.invoice-summary-box {
  background: #f8fafc;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 320px;
  margin-right: auto;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
}

.summary-row.total {
  font-size: 15px;
  font-weight: 800;
  border-top: 1px dashed var(--border-color);
  padding-top: 8px;
  color: var(--primary-dark);
}

/* Toast Notification */
.toast-container {
  position: fixed;
  bottom: 24px;
  left: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 9999;
}

.toast {
  background: #1e293b;
  color: white;
  padding: 12px 18px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideUp 0.2s ease-out;
  border-right: 4px solid var(--primary);
}

.toast.success { border-right-color: var(--accent); }
.toast.danger { border-right-color: var(--danger); }
.toast.warning { border-right-color: var(--warning); }

@keyframes slideUp {
  from { transform: translateY(10px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Hamburger & Sidebar Controls */
.btn-hamburger {
  display: none;
  background: none;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  color: var(--text-main);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.btn-hamburger:hover {
  background: var(--bg-subtle);
}

.btn-sidebar-close {
  display: none;
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 18px;
  cursor: pointer;
  margin-right: auto;
  padding: 4px 8px;
  line-height: 1;
}

.btn-sidebar-close:hover {
  color: white;
}

/* Mobile Sidebar Backdrop */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(2px);
  z-index: 1000;
}

.sidebar-backdrop.active {
  display: block;
}

/* Permission Matrix Component */
.permission-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  background: white;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color 0.2s, background-color 0.2s;
}

.permission-item:hover {
  border-color: var(--primary);
  background: #f0f9ff;
}

.permission-item input[type="checkbox"] {
  margin-top: 3px;
  accent-color: var(--primary);
  cursor: pointer;
  width: 16px;
  height: 16px;
}

.permission-item div strong {
  display: block;
  font-size: 13px;
  color: #0f172a;
}

.permission-item div small {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Responsive & Mobile Layout */
@media (max-width: 1024px) {
  .topbar-actions {
    flex-wrap: wrap;
  }
}

@media (max-width: 768px) {
  .btn-hamburger {
    display: flex;
  }

  .btn-sidebar-close {
    display: block;
  }

  .sidebar {
    position: fixed;
    top: 0;
    right: -280px;
    width: 270px;
    height: 100vh;
    z-index: 1001;
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: -4px 0 20px rgba(0,0,0,0.25);
  }

  .sidebar.open {
    right: 0;
  }

  .main-wrapper {
    width: 100%;
    min-width: 0;
  }

  .topbar {
    padding: 12px 14px;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .pharmacy-badge-info .ph-meta {
    display: none;
  }

  .topbar-actions {
    display: flex;
    overflow-x: auto;
    padding-bottom: 6px;
    gap: 6px;
    -webkit-overflow-scrolling: touch;
  }

  .topbar-actions .btn {
    white-space: nowrap;
    font-size: 12px;
    padding: 6px 10px;
    flex-shrink: 0;
  }

  .content-body {
    padding: 14px;
  }

  .kpi-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .panel-header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .panel-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .panel-actions .search-input-wrap,
  .panel-actions .select-filter,
  .panel-actions .btn {
    width: 100%;
  }

  .modal-card {
    margin: 10px;
    width: calc(100% - 20px) !important;
    max-width: 100% !important;
    max-height: 92vh;
  }

  .form-row {
    flex-direction: column;
    gap: 10px;
  }

  .invoice-summary-box {
    max-width: 100%;
    margin-right: 0;
  }

  .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* Print Invoice & Voucher Styling */
@media print {
  body {
    background: white !important;
    color: black !important;
  }
  .sidebar, .topbar, .panel-actions, .btn, .nav-section-title, .sidebar-backdrop {
    display: none !important;
  }
  .main-wrapper, .content-body {
    padding: 0 !important;
    margin: 0 !important;
  }
  .print-only {
    display: block !important;
  }
}
