/**
 * Modern Minimal Persian Office Automation Design System
 * IRANSansX Typography & RTL Layout Architecture
 */

:root {
  --primary: #1e3a8a;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --primary-dark: #172554;
  --primary-rgb: 30, 58, 138;

  --accent: #2563eb;
  --accent-light: #dbeafe;

  --bg-page: #f8fafc;
  --surface: #ffffff;
  --surface-alt: #f1f5f9;
  --surface-hover: #f8fafc;

  --border: #e2e8f0;
  --border-subtle: #f1f5f9;
  --border-focus: #3b82f6;

  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;
  --text-inverse: #ffffff;

  --success: #059669;
  --success-bg: #ecfdf5;
  --success-border: #a7f3d0;

  --warning: #d97706;
  --warning-bg: #fffbeb;
  --warning-border: #fde68a;

  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --danger-border: #fecaca;

  --purple: #7c3aed;
  --purple-bg: #f5f3ff;
  --purple-border: #ddd6fe;

  --shadow-xs: 0 1px 2px 0 rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 1px 3px 0 rgba(15, 23, 42, 0.08), 0 1px 2px -1px rgba(15, 23, 42, 0.08);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.07), 0 2px 4px -2px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -4px rgba(15, 23, 42, 0.04);
  --shadow-xl: 0 20px 25px -5px rgba(15, 23, 42, 0.1), 0 8px 10px -6px rgba(15, 23, 42, 0.04);

  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;

  --sidebar-width: 260px;
  --header-height: 64px;
  --transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

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

html {
  font-family: 'IRANSansX', 'Vazirmatn', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Tahoma, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  direction: rtl;
  text-align: right;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background-color: var(--bg-page);
  color: var(--text-main);
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* Typography Scale */
h1, h2, h3, h4, h5, h6 {
  color: var(--text-main);
  font-weight: 700;
  line-height: 1.35;
}

h1 { font-size: 1.75rem; font-weight: 800; }
h2 { font-size: 1.4rem; font-weight: 700; }
h3 { font-size: 1.15rem; font-weight: 600; }
h4 { font-size: 1rem; font-weight: 600; }

p {
  color: var(--text-muted);
  font-weight: 400;
  margin-bottom: 0.5rem;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: var(--transition);
}

a:hover {
  color: var(--primary);
}

/* App Layout */
.app-container {
  display: flex;
  min-height: 100vh;
  position: relative;
}

/* Sidebar */
.app-sidebar {
  width: var(--sidebar-width);
  background-color: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  right: 0;
  z-index: 40;
  transition: transform 0.25s ease;
}

.sidebar-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
}

.sidebar-logo-icon {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 8px rgba(30, 58, 138, 0.2);
}

.sidebar-brand-text {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.2;
}

.brand-subtitle {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--text-muted);
}

.sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.sidebar-action-btn {
  width: 100%;
  padding: 0.75rem 1rem;
  background-color: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(30, 58, 138, 0.15);
  transition: var(--transition);
  text-decoration: none;
}

.sidebar-action-btn:hover {
  background-color: var(--primary-hover);
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(30, 58, 138, 0.25);
}

.nav-group-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-subtle);
  padding: 0 0.75rem 0.5rem;
  letter-spacing: 0.05em;
}

.nav-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.nav-item-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.625rem 0.75rem;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.9rem;
  transition: var(--transition);
  position: relative;
}

.nav-item-link:hover {
  background-color: var(--surface-alt);
  color: var(--primary);
}

.nav-item-link.active {
  background-color: var(--primary-light);
  color: var(--primary);
  font-weight: 700;
}

.nav-item-link.active::before {
  content: '';
  position: absolute;
  right: 0;
  top: 15%;
  bottom: 15%;
  width: 3px;
  background-color: var(--primary);
  border-radius: 4px 0 0 4px;
}

.nav-item-content {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.nav-badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-full);
  background-color: var(--surface-alt);
  color: var(--text-muted);
  min-width: 22px;
  text-align: center;
}

.nav-item-link.active .nav-badge {
  background-color: var(--primary);
  color: #fff;
}

.nav-badge.danger {
  background-color: var(--danger-bg);
  color: var(--danger);
  border: 1px solid var(--danger-border);
}

.sidebar-footer {
  padding: 0.85rem 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.user-mini-profile {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  overflow: hidden;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  font-weight: 700;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.user-mini-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.user-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role-tag {
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Main Content Area */
.app-main {
  flex: 1;
  margin-right: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-right 0.25s ease;
}

/* Top Header */
.app-header {
  height: var(--header-height);
  background-color: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 30;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.header-toggle-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.5rem;
  border-radius: var(--radius-md);
}

.header-toggle-btn:hover {
  background-color: var(--surface-alt);
  color: var(--text-main);
}

.header-page-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.header-date-badge {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  background-color: var(--surface-alt);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
}

.header-icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 0.5rem;
  border-radius: var(--radius-full);
  cursor: pointer;
  position: relative;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-icon-btn:hover {
  background-color: var(--surface-alt);
  color: var(--primary);
}

.btn-indicator {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background-color: var(--danger);
  border: 2px solid var(--surface);
}

.header-logout-btn {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--danger);
  background-color: var(--danger-bg);
  border: 1px solid var(--danger-border);
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-md);
  text-decoration: none;
  transition: var(--transition);
}

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

/* Page Content Body */
.page-content {
  flex: 1;
  padding: 1.5rem;
}

/* Cards */
.card {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  transition: var(--transition);
  overflow: hidden;
}

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

.card-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title {
  font-size: 1.05rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.card-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.card-body {
  padding: 1.5rem;
}

.card-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  background-color: var(--surface-alt);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.55rem 1.15rem;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

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

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

.btn-outline {
  background-color: transparent;
  color: var(--text-main);
  border-color: var(--border);
}

.btn-outline:hover:not(:disabled) {
  background-color: var(--surface-alt);
  border-color: var(--text-subtle);
}

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

.btn-danger:hover:not(:disabled) {
  background-color: #b91c1c;
  border-color: #b91c1c;
  color: #fff;
}

.btn-success {
  background-color: var(--success);
  color: #fff;
  border-color: var(--success);
}

.btn-success:hover:not(:disabled) {
  background-color: #047857;
  color: #fff;
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
}

.btn-icon-only {
  padding: 0.5rem;
  border-radius: var(--radius-md);
}

/* Forms & Inputs */
.form-group {
  margin-bottom: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.form-label .required {
  color: var(--danger);
}

.form-control, .form-select {
  width: 100%;
  padding: 0.6rem 0.85rem;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-main);
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  outline: none;
  transition: var(--transition);
}

.form-control:focus, .form-select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.form-control::placeholder {
  color: var(--text-subtle);
  font-weight: 400;
}

.form-textarea {
  min-height: 100px;
  resize: vertical;
}

.form-helper {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 400;
}

/* Badges & Chips */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: var(--radius-full);
  line-height: 1;
}

.badge-blue { background-color: var(--primary-light); color: var(--primary); border: 1px solid #bfdbfe; }
.badge-emerald, .badge-success { background-color: var(--success-bg); color: var(--success); border: 1px solid var(--success-border); }
.badge-amber, .badge-warning { background-color: var(--warning-bg); color: var(--warning); border: 1px solid var(--warning-border); }
.badge-danger, .badge-rose { background-color: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger-border); }
.badge-purple { background-color: var(--purple-bg); color: var(--purple); border: 1px solid var(--purple-border); }
.badge-slate { background-color: var(--surface-alt); color: var(--text-muted); border: 1px solid var(--border); }

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.modal-backdrop.show {
  opacity: 1;
  visibility: visible;
}

.modal-container {
  background-color: var(--surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  border: 1px solid var(--border);
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  transform: scale(0.95);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-backdrop.show .modal-container {
  transform: scale(1);
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.modal-close-btn {
  background: none;
  border: none;
  color: var(--text-subtle);
  cursor: pointer;
  padding: 0.4rem;
  border-radius: var(--radius-md);
  transition: var(--transition);
}

.modal-close-btn:hover {
  background-color: var(--surface-alt);
  color: var(--text-main);
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  background-color: var(--surface-alt);
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* Toast Notification Container */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  left: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  min-width: 320px;
  max-width: 440px;
  background-color: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  padding: 0.85rem 1.15rem;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  transform: translateX(-100%);
  opacity: 0;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
}

.toast.show {
  transform: translateX(0);
  opacity: 1;
}

.toast-icon {
  flex-shrink: 0;
  margin-top: 0.15rem;
}

.toast-content {
  flex: 1;
}

.toast-title {
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 0.15rem;
}

.toast-message {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.4;
  margin: 0;
}

.toast-close {
  background: none;
  border: none;
  color: var(--text-subtle);
  cursor: pointer;
  padding: 0.2rem;
}

.toast-success { border-right: 4px solid var(--success); }
.toast-success .toast-icon { color: var(--success); }
.toast-error { border-right: 4px solid var(--danger); }
.toast-error .toast-icon { color: var(--danger); }
.toast-warning { border-right: 4px solid var(--warning); }
.toast-warning .toast-icon { color: var(--warning); }
.toast-info { border-right: 4px solid var(--accent); }
.toast-info .toast-icon { color: var(--accent); }

/* Skeleton Loading Animation */
.skeleton {
  background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s infinite;
  border-radius: var(--radius-xs);
}

@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Responsive adjustments */
@media (max-width: 992px) {
  .app-sidebar {
    transform: translateX(100%);
  }
  .app-sidebar.open {
    transform: translateX(0);
  }
  .app-main {
    margin-right: 0;
  }
  .header-toggle-btn {
    display: flex;
  }
}
