/* ============================================
   Nexa Warehouse ERP - Common Styles
   RTL Support + Persian Fonts + Responsive
   ============================================ */

/* Import Vazirmatn Font for Persian */
@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@100;200;300;400;500;600;700;800;900&display=swap');

/* CSS Variables */
:root {
  --primary-color: #3b82f6;
  --primary-dark: #2563eb;
  --primary-light: #60a5fa;
  --secondary-color: #1e40af;
  --success-color: #10b981;
  --danger-color: #ef4444;
  --warning-color: #f59e0b;
  --info-color: #06b6d4;
  
  --bg-primary: #f1f5f9;
  --bg-secondary: #ffffff;
  --bg-sidebar: #1e293b;
  --bg-sidebar-hover: #334155;
  --bg-sidebar-active: #3b82f6;
  
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --text-light: #94a3b8;
  --text-white: #ffffff;
  
  --border-color: #e2e8f0;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1);
  
  --sidebar-width: 260px;
  --header-height: 64px;
  --border-radius: 12px;
  --transition: all 0.3s ease;
}

/* Reset & Base */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Vazirmatn', Tahoma, Arial, sans-serif;
  direction: rtl;
  text-align: right;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.7;
  min-height: 100vh;
  overflow-x: hidden;
}

/* RTL Specific */
[dir="rtl"] .flex-row {
  flex-direction: row-reverse;
}

/* Link Styles */
a {
  text-decoration: none;
  color: inherit;
  transition: var(--transition);
}

/* Button Base */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 24px;
  border: none;
  border-radius: 8px;
  font-family: 'Vazirmatn', Tahoma, sans-serif;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
  color: var(--text-white);
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--primary-dark), var(--secondary-color));
}

.btn-success {
  background: linear-gradient(135deg, var(--success-color), #059669);
  color: var(--text-white);
}

.btn-danger {
  background: linear-gradient(135deg, var(--danger-color), #dc2626);
  color: var(--text-white);
}

.btn-outline {
  background: transparent;
  border: 2px solid var(--border-color);
  color: var(--text-primary);
}

.btn-outline:hover {
  border-color: var(--primary-color);
  color: var(--primary-color);
}

.btn-sm {
  padding: 6px 16px;
  font-size: 12px;
}

.btn-lg {
  padding: 14px 32px;
  font-size: 16px;
}

.btn-block {
  width: 100%;
}

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 8px;
}

/* Input Styles */
.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
}

.form-input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  font-family: 'Vazirmatn', Tahoma, sans-serif;
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-secondary);
  transition: var(--transition);
  direction: rtl;
}

.form-input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

.form-input::placeholder {
  color: var(--text-light);
}

.form-input.error {
  border-color: var(--danger-color);
}

.form-input.error:focus {
  box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.1);
}

.form-error {
  color: var(--danger-color);
  font-size: 12px;
  margin-top: 4px;
  display: none;
}

.form-error.show {
  display: block;
}

/* Card Component */
.card {
  background: var(--bg-secondary);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-sm);
  padding: 24px;
  transition: var(--transition);
}

.card:hover {
  box-shadow: var(--shadow-md);
}

.card-header {
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
}

.card-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.card-body {
  padding: 0;
}

/* Badge Component */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}

.badge-success {
  background: #d1fae5;
  color: #065f46;
}

.badge-danger {
  background: #fee2e2;
  color: #991b1b;
}

.badge-warning {
  background: #fef3c7;
  color: #92400e;
}

.badge-info {
  background: #cffafe;
  color: #155e75;
}

.badge-primary {
  background: #dbeafe;
  color: #1e40af;
}

/* Alert Component */
#alertContainer {
  position: fixed;
  top: 80px;
  right: 20px;
  left: 20px;
  z-index: 12000;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
}

.alert {
  padding: 16px 20px;
  border-radius: 8px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 500px;
  pointer-events: auto;
  box-shadow: var(--shadow-lg);
  animation: alertSlideIn 0.3s ease;
}

/* .alert sets display:flex, which (being an author rule) beats the UA default [hidden] {
   display: none } at equal specificity. Any .alert toggled via the `hidden` attribute — e.g.
   sales-invoice.html's #viewTaxError/#viewRejectionBlock — stayed visibly on screen even
   though JS had correctly set element.hidden = true. This restores hidden's actual meaning. */
.alert[hidden] {
  display: none;
}

@keyframes alertSlideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.alert-success {
  background: #d1fae5;
  color: #065f46;
  border-right: 4px solid var(--success-color);
}

.alert-danger {
  background: #fee2e2;
  color: #991b1b;
  border-right: 4px solid var(--danger-color);
}

.alert-warning {
  background: #fef3c7;
  color: #92400e;
  border-right: 4px solid var(--warning-color);
}

.alert-info {
  background: #cffafe;
  color: #155e75;
  border-right: 4px solid var(--info-color);
}

/* Loading Spinner */
.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border-color);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.spinner-sm {
  width: 24px;
  height: 24px;
  border-width: 3px;
}

.spinner-lg {
  width: 56px;
  height: 56px;
  border-width: 5px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Loading Overlay */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

/* Toast Notification */
.toast-container {
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 14px 20px;
  border-radius: 8px;
  color: var(--text-white);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: slideInLeft 0.3s ease, fadeOut 0.3s ease 2.7s;
  min-width: 280px;
  direction: rtl;
}

.toast-success { background: var(--success-color); }
.toast-error { background: var(--danger-color); }
.toast-warning { background: var(--warning-color); }
.toast-info { background: var(--info-color); }

@keyframes slideInLeft {
  from { transform: translateX(-100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* Table Styles */
.table-container {
  overflow-x: auto;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  padding: 12px 16px;
  text-align: right;
  border-bottom: 1px solid var(--border-color);
}

.table th {
  background: #f8fafc;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
}

.table td {
  color: var(--text-secondary);
}

.table tbody tr:hover {
  background: #f8fafc;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-secondary);
}

.empty-state-icon {
  font-size: 64px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
}

.empty-state-text {
  font-size: 14px;
}

/* ============================================
   Shared Modal (mobile-safe)
   .modal-content uses a flex column so .modal-header
   and .modal-footer never scroll away — only
   .modal-body scrolls. Pages may still override
   .modal-content max-width / .modal-footer alignment.
   ============================================ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal.show {
  display: flex;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  max-height: 90dvh;
  overflow: hidden;
  animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(-20px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  line-height: 1;
  transition: var(--transition);
}

.modal-close:hover {
  background: var(--bg-primary);
  color: var(--text-primary);
}

.modal-body {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 24px;
}

.modal-footer {
  flex: 0 0 auto;
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  background: #f8fafc;
}

@media (max-width: 768px) {
  .modal {
    padding: 0;
  }

  .modal-content {
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100vh;
    max-height: 100dvh;
    margin: 0;
    border-radius: 0;
  }

  .modal-body {
    padding: 16px;
  }

  .modal-footer {
    padding: 12px 16px;
    flex-direction: column;
  }

  .modal-footer .btn {
    width: 100%;
  }
}

/* Responsive Utilities */
@media (max-width: 768px) {
  :root {
    --border-radius: 8px;
  }
  
  .card {
    padding: 16px;
  }
  
  .btn {
    padding: 8px 16px;
    font-size: 13px;
  }
}

/* Print Styles */
@media print {
  .no-print {
    display: none !important;
  }
  
  body {
    background: white;
  }
}
/* Prevent body scroll while mobile sidebar is open */
body.sidebar-open {
  overflow: hidden;
}

.tree-cell{
display:flex;
align-items:center;
gap:6px;
}

.tree-line{
width:16px;
border-left:1px solid #ccc;
height:14px;
margin-right:4px;
}

.toggle-btn{
cursor:pointer;
font-size:12px;
width:14px;
display:inline-block;
}

.tree-text{
user-select:none;
}

.level-1{margin-right:18px}
.level-2{margin-right:36px}
.level-3{margin-right:54px}
.level-4{margin-right:72px}

/* ============================================
   Outline button variants

   These were referenced by markup (btn-outline-primary / btn-outline-danger on
   the invoice row actions) but never defined, so every action button rendered
   with the same neutral base style. Defining them matters most for the
   irreversible ones: a void must not look like an edit.
   ============================================ */
.btn-outline-primary,
.btn-outline-warning,
.btn-outline-danger {
  background: transparent;
  border: 1px solid currentColor;
}

.btn-outline-primary {
  color: var(--primary-color);
}

.btn-outline-warning {
  color: var(--warning-color);
}

.btn-outline-danger {
  color: var(--danger-color);
}

.btn-outline-primary:hover {
  background: var(--primary-color);
  color: #fff;
}

.btn-outline-warning:hover {
  background: var(--warning-color);
  color: #fff;
}

.btn-outline-danger:hover {
  background: var(--danger-color);
  color: #fff;
}
