/* ============================================================
   styles.css - Custom UI Styles & @media Print Layouts
   Accounting & Warehouse Management System
   ============================================================ */

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

:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #eef2ff;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --slate-50: #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --slate-900: #0f172a;
  --bg-body: #f1f5f9;
  --bg-card: #ffffff;
  --bg-input: #ffffff;
  --bg-topbar: #ffffff;
  --bg-table-header: #f8fafc;
  --bg-table-row-hover: #f8fafc;
  --bg-modal: #ffffff;
  --bg-autocomplete: #ffffff;
  --bg-toggle: #f1f5f9;
  --text-primary: #1e293b;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --border-light: #f1f5f9;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 8px 24px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.15);
  --bg-sidebar: #0f172a;
  --sidebar-width: 260px;
  --header-height: 64px;
}

[data-theme="dark"] {
  --primary: #818cf8;
  --primary-dark: #6366f1;
  --primary-light: #1e1b4b;
  --success: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;
  --slate-50: #0f172a;
  --slate-100: #1e293b;
  --slate-200: #334155;
  --slate-300: #475569;
  --slate-400: #64748b;
  --slate-500: #94a3b8;
  --slate-600: #cbd5e1;
  --slate-700: #e2e8f0;
  --slate-800: #f1f5f9;
  --slate-900: #f8fafc;
  --bg-body: #0f172a;
  --bg-card: #1e293b;
  --bg-input: #334155;
  --bg-topbar: #1e293b;
  --bg-table-header: #1e293b;
  --bg-table-row-hover: #1e293b;
  --bg-modal: #1e293b;
  --bg-autocomplete: #1e293b;
  --bg-toggle: #334155;
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --border-color: #334155;
  --border-light: #1e293b;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 8px 24px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
  --bg-sidebar: #020617;
}

[data-theme="electric"] {
  --primary: #0096ff;
  --primary-dark: #0070cc;
  --primary-light: rgba(0, 150, 255, 0.08);
  --success: #00d4a1;
  --warning: #ffb800;
  --danger: #ff4d6a;
  --slate-50: #0a0e27;
  --slate-100: #0d1b3e;
  --slate-200: #122456;
  --slate-300: #1a3370;
  --slate-400: #2a4a8a;
  --slate-500: #4a6aaa;
  --slate-600: #7a9acc;
  --slate-700: #a0bef0;
  --slate-800: #d0e0ff;
  --slate-900: #e8f0fe;
  --bg-body: #070b1e;
  --bg-card: #0d1b3e;
  --bg-input: #0a1535;
  --bg-topbar: #0d1b3e;
  --bg-table-header: #0d1b3e;
  --bg-table-row-hover: #122456;
  --bg-modal: #0d1b3e;
  --bg-autocomplete: #0d1b3e;
  --bg-toggle: #122456;
  --text-primary: #e8f0fe;
  --text-secondary: #a0bef0;
  --text-muted: #6a8ac0;
  --border-color: rgba(0, 150, 255, 0.15);
  --border-light: rgba(0, 150, 255, 0.08);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.6), 0 0 40px rgba(0, 150, 255, 0.08);
  --bg-sidebar: #050919;
}

/* Muted backgrounds for readonly fields and table footers (dark mode aware) */
.bg-slate-50-dark {
  background: #f8fafc;
}
.form-input[readonly],
.form-input:read-only {
  background: #f8fafc;
}
[data-theme="dark"] .bg-slate-50-dark {
  background: #1e293b;
}
[data-theme="dark"] .form-input[readonly],
[data-theme="dark"] .form-input:read-only {
  background: #1e293b;
  color: #f1f5f9;
}
[data-theme="electric"] .bg-slate-50-dark {
  background: #0d1b3e;
}
[data-theme="electric"] .form-input[readonly],
[data-theme="electric"] .form-input:read-only {
  background: #0d1b3e;
  color: #e8f0fe;
}

html, body {
  max-width: 100vw;
  overflow-x: hidden;
}

body {
  font-family: 'Tajawal', 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg-body);
  color: var(--text-primary);
  direction: rtl;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--slate-200); }
::-webkit-scrollbar-thumb { background: var(--slate-400); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--slate-500); }

/* ===== Login Screen ===== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0a0e27 0%, #0d1b3e 50%, #122456 100%);
  position: relative;
  overflow: hidden;
}

.login-page::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(ellipse at 30% 50%, rgba(0, 150, 255, 0.15) 0%, transparent 60%),
              radial-gradient(ellipse at 70% 50%, rgba(0, 200, 255, 0.1) 0%, transparent 60%);
  animation: loginGlow 8s ease-in-out infinite alternate;
}

@keyframes loginGlow {
  0% { transform: translate(0, 0) rotate(0deg); }
  100% { transform: translate(-5%, 5%) rotate(3deg); }
}

.login-card {
  position: relative;
  z-index: 1;
  background: rgba(13, 27, 62, 0.95);
  backdrop-filter: blur(20px);
  border-radius: 24px;
  padding: 48px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.5), 0 0 40px rgba(0, 150, 255, 0.1);
  border: 1px solid rgba(0, 150, 255, 0.15);
  animation: slideUp 0.6s ease-out;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo .icon {
  width: 64px;
  height: 64px;
  background: linear-gradient(135deg, #0096ff, #00d4ff);
  border-radius: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  color: white;
  margin-bottom: 16px;
  box-shadow: 0 8px 24px rgba(0, 150, 255, 0.4);
}

.login-logo h1 {
  font-size: 22px;
  font-weight: 700;
  color: #e8f0fe;
  margin-bottom: 4px;
}

.login-logo p {
  font-size: 13px;
  color: rgba(160, 190, 240, 0.7);
}

.login-input {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid rgba(0, 150, 255, 0.2);
  border-radius: 12px;
  font-size: 14px;
  font-family: inherit;
  background: rgba(10, 20, 50, 0.6);
  color: #e8f0fe;
  transition: all 0.2s;
  text-align: right;
}

.login-input::placeholder {
  color: rgba(160, 190, 240, 0.4);
}

.login-input:focus {
  outline: none;
  border-color: #0096ff;
  box-shadow: 0 0 0 4px rgba(0, 150, 255, 0.15);
  background: rgba(10, 20, 50, 0.8);
}

.login-btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  background: linear-gradient(135deg, #0096ff, #00d4ff);
  color: white;
  cursor: pointer;
  transition: all 0.3s;
  position: relative;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0, 150, 255, 0.3);
}

.login-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 150, 255, 0.5);
}

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

/* ===== Dashboard Layout ===== */
.dashboard {
  display: flex;
  min-height: 100vh;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

.sidebar {
  position: fixed;
  top: 0;
  right: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-sidebar, #0f172a);
  color: white;
  z-index: 50;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  text-align: center;
}

.sidebar-header h2 {
  font-size: 16px;
  font-weight: 700;
  color: white;
}

.sidebar-header p {
  font-size: 11px;
  color: var(--slate-400);
  margin-top: 2px;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--slate-300);
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 2px;
  position: relative;
  user-select: none;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: white;
}

.nav-item.active {
  background: rgba(79, 70, 229, 0.2);
  color: #818cf8;
}

.nav-item.active::before {
  content: '';
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 24px;
  background: var(--primary);
  border-radius: 0 3px 3px 0;
}

.nav-item .nav-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.06);
}

.nav-item.active .nav-icon {
  background: rgba(79, 70, 229, 0.3);
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 12px;
}

.user-avatar {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), #818cf8);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

.user-details { flex: 1; min-width: 0; }
.user-details .name { font-size: 13px; font-weight: 600; color: white; }
.user-details .role { font-size: 11px; color: var(--slate-400); }

.logout-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all 0.2s;
  flex-shrink: 0;
}

.logout-btn:hover {
  background: rgba(239, 68, 68, 0.25);
}

/* ===== Main Content ===== */
.main-content {
  margin-right: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  width: calc(100% - var(--sidebar-width));
  max-width: calc(100% - var(--sidebar-width));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--bg-topbar);
  border-bottom: 1px solid var(--border-color);
  padding: 0 24px;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

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

.topbar-title span {
  color: var(--text-muted);
  font-weight: 400;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.server-ip {
  font-size: 12px;
  color: var(--text-muted);
  direction: ltr;
  white-space: nowrap;
}

.menu-toggle {
  display: none;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 10px;
  background: var(--bg-toggle);
  cursor: pointer;
  font-size: 20px;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}

.theme-toggle {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 10px;
  background: var(--bg-toggle);
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.theme-toggle:hover {
  background: var(--border-color);
}

/* ===== المستخدمون المتصلون حالياً ===== */
.online-users-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.online-users-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 40px;
  padding: 0 14px;
  border: none;
  border-radius: 10px;
  background: var(--bg-toggle);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.online-users-btn:hover {
  background: var(--border-color);
}

.pulse-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #22c55e;
  animation: onlinePulse 2s infinite;
  flex-shrink: 0;
}

@keyframes onlinePulse {
  0%   { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.55); }
  70%  { box-shadow: 0 0 0 7px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

.online-users-dropdown {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  min-width: 270px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
  display: none;
  z-index: 70;
  overflow: hidden;
}

.online-users-dropdown.open {
  display: block;
}

.dropdown-header {
  padding: 11px 15px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-table-header);
}

.dropdown-body {
  max-height: 300px;
  overflow-y: auto;
}

.online-user-item,
.online-now-card-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 15px;
  border-bottom: 1px solid var(--border-light);
}

.dropdown-body .online-user-item:last-child {
  border-bottom: none;
}

.online-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.online-avatar-lg {
  width: 40px;
  height: 40px;
  font-size: 16px;
}

.online-user-info {
  flex: 1;
  min-width: 0;
}

.online-user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.online-user-meta {
  font-size: 11px;
  color: var(--text-muted);
}

.you-tag {
  color: #22c55e;
  font-size: 10px;
  font-weight: 700;
}

.status-dot-sm {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2);
  flex-shrink: 0;
}

.online-now-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}

.online-now-card-item {
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--bg-table-header);
}

.user-badge-online,
.user-badge-offline {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.user-badge-online {
  color: #16a34a;
  background: rgba(34, 197, 94, 0.12);
}

.user-badge-offline {
  color: var(--text-muted);
  background: var(--bg-toggle);
}

.page-content {
  padding: 24px;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

/* ===== Cards & Containers ===== */
.card {
  background: var(--bg-card);
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  width: 100%;
  max-width: 100%;
}

.card-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
}

.card-header h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}

.card-body {
  padding: 14px;
}

/* ===== Form Elements ===== */
.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border-color);
  border-radius: 10px;
  font-size: 13px;
  font-family: inherit;
  background: var(--bg-input);
  transition: all 0.2s;
  text-align: right;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

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

.form-select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 12px center;
  padding-left: 32px;
}

.form-input-sm {
  padding: 5px 8px;
  font-size: 12px;
}

.flex-1 {
  flex: 1;
}

#invDiscountValue {
  min-width: 120px;
  padding: 8px 12px;
  font-size: 14px;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover { box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3); }

.btn-success {
  background: var(--success);
  color: white;
}
.btn-success:hover { box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3); }

.btn-warning {
  background: var(--warning);
  color: white;
}
.btn-warning:hover { box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3); }

.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-danger:hover { box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3); }

.btn-sm {
  padding: 6px 14px;
  font-size: 12px;
  border-radius: 8px;
}

.btn-xs {
  padding: 4px 10px;
  font-size: 11px;
  border-radius: 6px;
}

.btn-outline {
  background: transparent;
  border: 1.5px solid var(--border-color);
  color: var(--text-secondary);
}
.btn-outline:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

/* ===== Tables ===== */
.table-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  width: 100%;
  max-width: 100%;
}

/* Horizontal scrollbar at the TOP of tables (mirrors the table scroll) */
.table-top-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  width: 100%;
  height: 8px;
  margin-bottom: 2px;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}
.table-top-scroll::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
.table-top-scroll::-webkit-scrollbar-track {
  background: var(--slate-200);
}
.table-top-scroll::-webkit-scrollbar-thumb {
  background: var(--slate-400);
  border-radius: 3px;
}
.table-top-scroll::-webkit-scrollbar-thumb:hover {
  background: var(--slate-500);
}
.table-top-scroll > div {
  height: 1px;
}

.table-container table {
  min-width: 500px;
}

/* Sales list table - compact */
#salesListTable th,
#salesListTable td {
  padding: 6px 8px;
  font-size: 12px;
  white-space: nowrap;
}

/* General data table styles for overflow control */
.table-container table th,
.table-container table td {
  white-space: nowrap;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  table-layout: auto;
}

thead th {
  background: var(--bg-table-header);
  padding: 10px 14px;
  text-align: right;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border-color);
  white-space: nowrap;
}

tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}

tbody tr:hover {
  background: var(--bg-table-row-hover);
}

/* ===== Stats Cards ===== */
.stat-card {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 20px;
  border: 1px solid var(--border-color);
  transition: all 0.3s;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-card .stat-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  margin-bottom: 12px;
}

.stat-card .stat-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.stat-card .stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  margin-top: 4px;
}

/* ===== Invoice Table Styles ===== */
/* Invoice items table - fixed layout fills full screen width */
#invoiceItemsTable {
  table-layout: fixed;
  width: 100%;
}

#purchaseItemsTable,
#quickPurchaseItemsTable {
  table-layout: fixed;
}

#invoiceItemsTable th,
#invoiceItemsTable td,
#purchaseItemsTable th,
#purchaseItemsTable td,
#quickPurchaseItemsTable th,
#quickPurchaseItemsTable td {
  padding: 8px 6px;
  font-size: 13px;
}

#invoiceItemsTable td,
#purchaseItemsTable td,
#quickPurchaseItemsTable td {
  vertical-align: top;
}

#invoiceItemsTable input,
#invoiceItemsTable select,
#purchaseItemsTable input,
#purchaseItemsTable select,
#quickPurchaseItemsTable input,
#quickPurchaseItemsTable select {
  font-size: 13px !important;
  padding: 6px 8px !important;
  min-width: 0 !important;
  width: 100% !important;
  box-sizing: border-box !important;
}

.item-zero-stock {
  border: 2px solid #dc2626 !important;
  color: #dc2626 !important;
  background-color: #fef2f2 !important;
}

.invoice-grid-header {
  background: var(--bg-table-header);
  display: grid;
  gap: 1px;
  background: var(--border-color);
  border-radius: 10px 10px 0 0;
  overflow: hidden;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 0;
}

.invoice-grid-header > div {
  padding: 10px 12px;
  background: var(--bg-table-header);
  text-align: center;
}

.invoice-row {
  display: grid;
  gap: 1px;
  background: var(--border-color);
  border-bottom: 1px solid var(--border-color);
}

.invoice-row > div {
  padding: 8px 8px;
  background: var(--bg-card);
  text-align: center;
}

.invoice-row-remove,
.invoice-row-add {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  line-height: 1;
  border-radius: 4px;
  transition: all 0.2s;
}

.invoice-row-remove {
  color: var(--danger);
}

.invoice-row-add {
  color: var(--primary);
}

.invoice-row-remove:hover {
  background: #fef2f2;
}

.invoice-row-add:hover {
  background: #d1fae5;
}

.purchase-row-remove,
.purchase-row-add {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  line-height: 1;
  border-radius: 4px;
  transition: all 0.2s;
}

.purchase-row-remove:hover {
  background: #fef2f2;
}

.purchase-row-add:hover {
  background: #d1fae5;
}

/* ===== Stats Grid ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
  width: 100%;
}

/* ===== Tab Content ===== */
.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== Section Toggle ===== */
.section-toggle {
  display: flex;
  gap: 8px;
  background: var(--bg-toggle);
  padding: 4px;
  border-radius: 12px;
  width: fit-content;
  flex-wrap: wrap;
}

.section-toggle .toggle-btn {
  padding: 8px 18px;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  background: transparent;
  color: var(--text-secondary);
  transition: all 0.2s;
}

.section-toggle .toggle-btn.active {
  background: var(--bg-card);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: var(--bg-modal);
  border-radius: 20px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.3s ease;
}

.modal-lg { max-width: 720px; }

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  padding: 18px 20px;
  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;
}

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: var(--slate-200);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--text-muted);
  transition: all 0.2s;
}

.modal-close:hover {
  background: var(--slate-300);
}

.modal-body {
  padding: 20px;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-start;
  gap: 8px;
}

/* ===== Badge ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #dbeafe; color: #1e40af; }

/* ===== Text colors ===== */
.text-green-600 { color: #16a34a !important; }
.text-red-600 { color: #dc2626 !important; }

/* ===== Cash box rows ===== */
tr.cash-row-in td { background: rgba(22, 163, 74, 0.07); }
tr.cash-row-out td { background: rgba(220, 38, 38, 0.07); }

/* ===== Autocomplete ===== */
.autocomplete-wrap {
  position: relative;
}

.autocomplete-list {
  position: absolute;
  top: 100%;
  right: 0;
  left: 0;
  background: var(--bg-autocomplete);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  z-index: 10;
  max-height: 180px;
  overflow-y: auto;
  display: none;
}

.autocomplete-list.open { display: block; }

.autocomplete-item {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid var(--border-light);
  transition: background 0.15s;
}

.autocomplete-item:hover, .autocomplete-item.active {
  background: var(--primary-light);
}

.autocomplete-item:last-child { border-bottom: none; }

.autocomplete-item small {
  display: block;
  font-size: 11px;
  color: var(--slate-400);
}

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

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

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

/* ===== Notifications / Toasts ===== */
.toast-container {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 12px 24px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  animation: toastIn 0.3s ease;
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  direction: rtl;
}

.toast-success { background: #065f46; color: white; }
.toast-error { background: #991b1b; color: white; }
.toast-info { background: #1e40af; color: white; }

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

/* ===== Responsive ===== */

/* Medium screens / small laptops - narrower sidebar */
@media (max-width: 1200px) {
  :root {
    --sidebar-width: 220px;
  }

  .stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 12px;
  }

  #invoiceItemsTable th,
  #invoiceItemsTable td,
  #purchaseItemsTable th,
  #purchaseItemsTable td,
  #quickPurchaseItemsTable th,
  #quickPurchaseItemsTable td {
    font-size: 12px !important;
    padding: 6px 4px !important;
  }
}

/* Tablets */
@media (max-width: 992px) {
  :root {
    --sidebar-width: 200px;
  }

  .stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
  }

  .card-body {
    padding: 14px;
  }

  .page-content {
    padding: 16px;
  }
}

/* Mobile */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(260px);
    --sidebar-width: 260px;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-content {
    margin-right: 0;
    width: 100%;
    max-width: 100%;
  }

  .menu-toggle {
    display: flex;
  }

  .online-label {
    display: none;
  }

  .online-users-btn {
    padding: 0 10px;
  }

  .page-content {
    padding: 12px;
  }

  .stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 8px;
  }

  .stat-card {
    padding: 14px;
  }

  .stat-card .stat-value {
    font-size: 18px;
  }

  .login-card {
    margin: 16px;
    padding: 32px 24px;
  }

  .card-body {
    padding: 12px;
  }

  .section-toggle .toggle-btn {
    font-size: 11px;
    padding: 6px 12px;
  }

  #invoiceItemsTable th,
  #invoiceItemsTable td,
  #purchaseItemsTable th,
  #purchaseItemsTable td,
  #quickPurchaseItemsTable th,
  #quickPurchaseItemsTable td {
    font-size: 11px !important;
    padding: 4px 3px !important;
  }
}

/* Very small screens */
@media (max-width: 480px) {
  :root {
    --sidebar-width: 100%;
  }

  .sidebar {
    width: 100%;
    transform: translateX(100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }

  .stat-card .stat-value {
    font-size: 16px;
  }

  .topbar {
    padding: 0 12px;
  }

  .topbar-title {
    font-size: 14px;
  }
}

/* ============================================================
   PRINT STYLES - Professional Invoice Printout
   ============================================================ */
@media print {
  @page {
    size: A4;
    margin: 8mm 10mm;
  }

  body {
    background: white !important;
    color: black !important;
    font-size: 8pt;
    direction: rtl;
    font-family: 'Tajawal', 'Segoe UI', Tahoma, sans-serif;
  }

  .no-print {
    display: none !important;
  }

  .print-only {
    display: block !important;
  }

  /* Hide all dashboard chrome */
  .sidebar, .topbar, .toast-container, .menu-toggle, .modal-overlay,
  .dashboard, .main-content, .page-content, .tab-content,
  .section-toggle, .card, .stats-grid, .stat-card {
    display: none !important;
  }

  /* Show the print area */
  #printArea {
    display: block !important;
    position: absolute;
    top: 0;
    right: 0;
    width: 100%;
    height: auto;
  }

  /* Print Invoice Container */
  .print-invoice {
    width: 100%;
    max-width: 100%;
    padding: 0;
    margin: 0;
  }

  .print-invoice .invoice-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    border-bottom: 2px solid #333;
    padding-bottom: 6px;
    margin-bottom: 8px;
    position: relative;
  }

  .print-invoice .invoice-header .print-logo {
    position: absolute;
    top: 0;
    left: 0;
    max-width: 80px;
    max-height: 80px;
    object-fit: contain;
  }
  .print-invoice .invoice-header .company-info h2 {
    font-size: 14pt;
    font-weight: 700;
    margin: 0 0 2px 0;
  }

  .print-invoice .invoice-header .company-info p {
    font-size: 7pt;
    color: #555;
    margin: 1px 0;
  }

  .print-invoice .invoice-header .invoice-title {
    text-align: left;
    padding-left: 90px;
  }

  .print-invoice .invoice-header .invoice-title h1 {
    font-size: 16pt;
    font-weight: 800;
    margin: 0;
    color: #1e293b;
  }

  .print-invoice .invoice-header .invoice-title p {
    font-size: 9pt;
    color: #555;
    margin: 1px 0;
  }

  .print-invoice .invoice-meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3px 16px;
    margin-bottom: 8px;
    font-size: 9pt;
  }

  .print-invoice .invoice-meta .meta-item {
    display: flex;
    justify-content: space-between;
    padding: 2px 0;
    border-bottom: 1px dashed #ddd;
  }

  .print-invoice .invoice-meta .meta-item .label {
    font-weight: 600;
    color: #555;
  }

  .print-invoice .invoice-meta .meta-item .value {
    font-weight: 500;
  }

  .print-invoice table {
    width: 100%;
    border-collapse: collapse;
    font-size: 9pt;
    margin-bottom: 8px;
    table-layout: fixed;
  }

  .print-invoice table th {
    background: #1e40af !important;
    color: white !important;
    padding: 4px 3px;
    text-align: center;
    font-weight: 700;
    font-size: 9pt;
    white-space: normal;
    overflow: hidden;
    border-bottom: none;
    letter-spacing: 0.3px;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .print-invoice table td {
    padding: 2px 2px;
    text-align: center;
    border-bottom: 1px solid #ddd;
    font-size: 9pt;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .print-invoice table tbody tr:nth-child(even) {
    background: #f8fafc;
  }

  .print-invoice .sales-invoice-table {
    table-layout: fixed;
    width: 100%;
  }

  .print-invoice .sales-invoice-table th,
  .print-invoice .statement-print-table th {
    font-size: 9pt;
    padding: 4px 3px;
  }

  .print-invoice .sales-invoice-table td,
  .print-invoice .statement-print-table td {
    font-size: 9pt;
    padding: 3px 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: normal;
    word-break: break-word;
  }

  .print-invoice .statement-print-table {
    table-layout: auto;
  }

  .print-invoice .statement-print-table td:first-child {
    white-space: nowrap;
  }

  .print-invoice .statement-print-table td:nth-child(2) {
    min-width: 120px;
  }

  .print-invoice table tfoot td {
    font-weight: 600;
    padding: 4px;
    border-top: 2px solid #333;
    background: #f1f5f9;
  }

  /* Explicit column widths for 9-column table (invoice print) */
  .print-invoice .sales-invoice-table { width: 100%; }
  .print-invoice .sales-invoice-table th:nth-child(1),
  .print-invoice .sales-invoice-table td:nth-child(1) { width: 3%; }
  .print-invoice .sales-invoice-table th:nth-child(2),
  .print-invoice .sales-invoice-table td:nth-child(2) { width: 22%; }
  .print-invoice .sales-invoice-table th:nth-child(3),
  .print-invoice .sales-invoice-table td:nth-child(3) { width: 7%; }
  .print-invoice .sales-invoice-table th:nth-child(4),
  .print-invoice .sales-invoice-table td:nth-child(4) { width: 7%; }
  .print-invoice .sales-invoice-table th:nth-child(5),
  .print-invoice .sales-invoice-table td:nth-child(5) { width: 11%; }
  .print-invoice .sales-invoice-table th:nth-child(6),
  .print-invoice .sales-invoice-table td:nth-child(6) { width: 9%; }
  .print-invoice .sales-invoice-table th:nth-child(7),
  .print-invoice .sales-invoice-table td:nth-child(7) { width: 9%; }
  .print-invoice .sales-invoice-table th:nth-child(8),
  .print-invoice .sales-invoice-table td:nth-child(8) { width: 9%; }
  .print-invoice .sales-invoice-table th:nth-child(9),
  .print-invoice .sales-invoice-table td:nth-child(9) { width: 7%; }

  .print-invoice .invoice-summary {
    margin-top: 4px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .print-invoice .invoice-summary .summary-box {
    border: 1px solid #ddd;
    border-radius: 3px;
    padding: 6px;
  }

  .print-invoice .invoice-summary .summary-box h4 {
    font-size: 9pt;
    font-weight: 700;
    margin: 0 0 4px 0;
    border-bottom: 1px solid #ddd;
    padding-bottom: 2px;
  }

  .print-invoice .invoice-summary .summary-row {
    display: flex;
    justify-content: space-between;
    padding: 2px 0;
    font-size: 9pt;
  }

  .print-invoice .invoice-summary .summary-row.total {
    font-weight: 700;
    font-size: 9pt;
    border-top: 2px solid #333;
    padding-top: 4px;
    margin-top: 2px;
  }

  .print-invoice .invoice-footer {
    margin-top: 12px;
    padding-top: 8px;
    border-top: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
    font-size: 7pt;
    color: #666;
  }

  .print-invoice .invoice-footer .signature {
    text-align: center;
  }

  .print-invoice .invoice-bank {
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px solid #ddd;
    font-size: 7pt;
    color: #666;
  }

  .print-invoice .invoice-footer .signature .line {
    width: 100px;
    border-top: 1px solid #333;
    margin-top: 24px;
    padding-top: 3px;
  }

  /* Page break avoidance */
  .print-invoice {
    page-break-after: avoid;
  }

  /* Hide non-print areas */
  #loginPage, .sidebar, .topbar, .toast-container,
  button:not(.print-trigger), .form-input, .form-select,
  .modal-overlay, .invoice-row-remove {
    display: none !important;
  }
}

/* Print trigger button style */
.print-trigger {
  /* Always visible */
}

/* Statement clickable links */
.statement-link {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
  border-bottom: 1px dashed var(--primary-light);
}

.statement-link:hover {
  color: #1d4ed8;
  border-bottom-style: solid;
}

/* ===== Maintenance Mode Overlay ===== */
.maintenance-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(6px);
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.maintenance-box {
  background: var(--bg-card);
  color: var(--text-primary);
  border-radius: 20px;
  width: 100%;
  max-width: 460px;
  padding: 36px 28px;
  text-align: center;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.4);
  animation: modalIn 0.3s ease;
}

.maintenance-icon {
  font-size: 56px;
  line-height: 1;
  margin-bottom: 12px;
}

.maintenance-box h2 {
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 12px;
  color: #dc2626;
}

.maintenance-box p {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.8;
  margin-bottom: 12px;
}

.maintenance-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.maintenance-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 999px;
  background: #dcfce7;
  color: #166534;
}

.maintenance-status-badge.on {
  background: #fee2e2;
  color: #991b1b;
}
