:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --primary: #1a2433;
  --primary-hover: #111827;
  --accent: #c58940;
  --accent-light: #fdf6ec;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --success: #15803d;
  --success-bg: #dcfce7;
  --warning: #b45309;
  --warning-bg: #fef3c7;
  --danger: #b91c1c;
  --danger-bg: #fee2e2;
  --radius: 12px;
  --shadow: 0 4px 16px rgba(17, 24, 39, 0.05);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: "Cairo", sans-serif;
}

body {
  background-color: var(--bg);
  color: var(--text);
  direction: rtl;
  line-height: 1.6;
}

body.tablet-mode input,
body.tablet-mode select,
body.tablet-mode .btn {
  padding: 0.9rem 1.15rem;
  font-size: 1.05rem;
}

body.tablet-mode .nav-item {
  padding: 0.9rem 1.1rem;
  font-size: 1.05rem;
}

.hidden {
  display: none !important;
}

.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: radial-gradient(circle at top right, #2b3a4f 0%, #111827 100%);
}

.login-card {
  background: var(--surface);
  width: 100%;
  max-width: 420px;
  padding: 2.3rem;
  border-radius: 16px;
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.35);
  text-align: center;
}

.brand-badge {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  padding: 0.25rem 1rem;
  border-radius: 999px;
  font-size: 0.85rem;
  margin-bottom: 0.75rem;
}

.login-card h1 {
  font-size: 1.45rem;
  color: var(--primary);
  margin-bottom: 0.25rem;
}

.login-card .subtitle {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

.login-card .form-group {
  text-align: right;
}

.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 270px;
  background: var(--primary);
  color: #fff;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform 0.25s ease;
}

.sidebar-header {
  padding: 1.25rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo-title {
  display: block;
  font-weight: 800;
  font-size: 1.2rem;
  color: #fff;
}

.logo-sub {
  font-size: 0.76rem;
  color: #9ca3af;
}

.user-card {
  padding: 0.9rem 1.25rem;
  background: rgba(255, 255, 255, 0.04);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.user-name {
  font-weight: 700;
  margin-bottom: 0.35rem;
}

.user-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.badge-gold {
  background: rgba(197, 137, 64, 0.25);
  color: #fbbf24;
  border: 1px solid rgba(251, 191, 36, 0.35);
}

.badge-glass {
  background: rgba(255, 255, 255, 0.1);
  color: #e5e7eb;
}

.nav-menu {
  flex: 1;
  padding: 0.75rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.22rem;
  overflow-y: auto;
}

.nav-group-label {
  font-size: 0.72rem;
  font-weight: 800;
  color: #9ca3af;
  margin: 0.65rem 0.5rem 0.2rem;
  letter-spacing: 0.3px;
}

.nav-item {
  background: transparent;
  border: none;
  color: #d1d5db;
  text-align: right;
  padding: 0.6rem 0.95rem;
  border-radius: 9px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: all 0.2s;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.nav-item.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 12px rgba(197, 137, 64, 0.35);
}

.nav-badge {
  background: #ef4444;
  color: #fff;
  border-radius: 999px;
  padding: 0.08rem 0.48rem;
  font-size: 0.74rem;
  font-weight: 800;
}

.sidebar-footer {
  padding: 0.9rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.btn-outline-light {
  background: transparent;
  color: #e5e7eb;
  border: 1px solid rgba(255, 255, 255, 0.25);
}

.btn-outline-light:hover {
  background: rgba(255, 255, 255, 0.08);
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  background: var(--surface);
  padding: 0.9rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.topbar h2 {
  font-size: 1.2rem;
  color: var(--primary);
}

.content-body {
  padding: 1.4rem;
  max-width: 1460px;
  width: 100%;
  margin: 0 auto;
}

.quick-actions-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-bottom: 1.25rem;
}

.smart-alerts {
  background: var(--warning-bg);
  border: 1px solid #fcd34d;
  color: #92400e;
  padding: 0.8rem 1.1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.9rem;
  font-weight: 700;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.alert-pill {
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid #f59e0b;
  color: #92400e;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
}

.alert-pill:hover {
  background: #fff;
}

.price-alerts {
  background: #eff6ff;
  border: 1px solid #93c5fd;
  color: #1e40af;
  padding: 0.8rem 1.1rem;
  border-radius: var(--radius);
  margin-bottom: 1.1rem;
  font-size: 0.9rem;
  font-weight: 700;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
}

.page-section {
  display: none;
}

.page-section.active {
  display: block;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.35rem;
  margin-bottom: 1.35rem;
  border: 1px solid var(--border);
}

.card-header {
  margin-bottom: 1.1rem;
  padding-bottom: 0.8rem;
  border-bottom: 1px solid var(--border);
}

.card-header h3 {
  font-size: 1.06rem;
  color: var(--primary);
}

.form-section-box {
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
}

.section-subtitle {
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 0.75rem;
}

.hint-text {
  font-size: 0.8rem;
  color: var(--muted);
}

.flex-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(205px, 1fr));
  gap: 1rem;
  margin-bottom: 1.35rem;
}

.stat-card {
  background: var(--surface);
  padding: 1.15rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-right: 4px solid var(--primary);
}

.stat-card.warn { border-right-color: var(--warning); }
.stat-card.danger { border-right-color: var(--danger); }
.stat-card.success { border-right-color: var(--success); }

.stat-label {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 600;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text);
  margin-top: 0.25rem;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(430px, 1fr));
  gap: 1.3rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(225px, 1fr));
  gap: 0.95rem;
}

.full-width {
  grid-column: 1 / -1;
}

.divider {
  border: none;
  border-top: 1px dashed var(--border);
  margin: 1.1rem 0;
}

.form-group {
  margin-bottom: 0.3rem;
}

.form-group label {
  display: block;
  font-size: 0.86rem;
  font-weight: 700;
  margin-bottom: 0.28rem;
  color: #374151;
}

.input-with-btn {
  display: flex;
  gap: 0.4rem;
}

input, select, textarea {
  width: 100%;
  padding: 0.58rem 0.76rem;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 0.91rem;
  background: #fff;
  color: var(--text);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(197, 137, 64, 0.16);
}

.readonly-highlight {
  background: var(--accent-light);
  font-weight: 800;
  color: var(--primary);
  border-color: #e5c9a3;
}

.calc-preview {
  display: block;
  margin-top: 0.28rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--primary);
}

.calc-preview.error {
  color: var(--danger);
}

.filters-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.filters-row input, .filters-row select {
  width: auto;
  min-width: 160px;
}

.form-actions {
  display: flex;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.btn {
  padding: 0.6rem 1.15rem;
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 700;
  font-size: 0.89rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-sm {
  padding: 0.36rem 0.72rem;
  font-size: 0.81rem;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--accent);
  color: #fff;
}

.btn-secondary:hover:not(:disabled) {
  opacity: 0.92;
}

.btn-success {
  background: var(--success);
  color: #fff;
}

.btn-outline {
  background: transparent;
  border-color: #cbd5e1;
  color: var(--text);
}

.btn-outline:hover:not(:disabled) {
  background: #f1f5f9;
}

.btn-danger-outline {
  background: transparent;
  border-color: #fca5a5;
  color: var(--danger);
}

.btn-danger-outline:hover:not(:disabled) {
  background: var(--danger-bg);
}

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-weight: 800;
  cursor: pointer;
  text-decoration: underline;
  font-size: 0.9rem;
}

.table-responsive {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

th, td {
  padding: 0.68rem 0.75rem;
  text-align: right;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  background: #f8fafc;
  font-weight: 700;
  color: var(--primary);
}

tr:hover td {
  background: #f9fafb;
}

tr.reversed-row td {
  opacity: 0.55;
  text-decoration: line-through;
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.58rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
}

.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: #dbeafe; color: #1d4ed8; }
.badge-neutral { background: #e5e7eb; color: #374151; }

.units-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.unit-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 0.5rem;
  align-items: center;
}

.users-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 1.15rem;
}

.employee-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.15rem;
  background: #fcfcfd;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03);
}

.emp-meta-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  font-size: 0.78rem;
  color: var(--muted);
  background: #f1f5f9;
  padding: 0.45rem 0.7rem;
  border-radius: 7px;
  margin: 0.55rem 0;
}

.perms-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.4rem;
  margin: 0.65rem 0;
  padding: 0.65rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.perm-check {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.81rem;
  cursor: pointer;
}

.perm-check input {
  width: auto;
}

.report-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1rem;
  font-weight: 700;
  color: var(--primary);
}

.alert {
  padding: 0.75rem;
  border-radius: 8px;
  margin-top: 1rem;
  font-size: 0.88rem;
  font-weight: 600;
}

.alert-danger {
  background: var(--danger-bg);
  color: var(--danger);
}

.scroll-top-btn {
  position: fixed;
  bottom: 1.4rem;
  right: 1.4rem;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  font-size: 1.2rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
  z-index: 900;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 2000;
}

.modal-box {
  background: var(--surface);
  width: 100%;
  max-width: 920px;
  border-radius: 14px;
  padding: 1.45rem;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}

.modal-header {
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.75rem;
  margin-bottom: 1rem;
}

.modal-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.mini-stat {
  background: #f8fafc;
  padding: 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.toast-container {
  position: fixed;
  bottom: 1.25rem;
  left: 1.25rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  background: #1f2937;
  color: #fff;
  padding: 0.8rem 1.2rem;
  border-radius: 9px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.22);
  font-size: 0.9rem;
  font-weight: 600;
}

.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

.mobile-only {
  display: none;
}

.icon-btn {
  background: transparent;
  border: none;
  font-size: 1.35rem;
  cursor: pointer;
  color: inherit;
}

@media (max-width: 860px) {
  .mobile-only { display: inline-block; }
  .hide-mobile { display: none; }
  .sidebar {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    transform: translateX(100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .grid-2 {
    grid-template-columns: 1fr;
  }
  .users-cards-grid {
    grid-template-columns: 1fr;
  }
}

@media print {
  .sidebar, .topbar, .btn, .filters-row, .print-col, .scroll-top-btn {
    display: none !important;
  }
  .main-content, .content-body {
    padding: 0 !important;
    margin: 0 !important;
  }
}
