/* ================================================================
   ZATCA E-Invoicing System — Main Stylesheet
   RTL Arabic-first, modern UI
================================================================ */

/* ── Variables ─────────────────────────────────────────────── */
:root {
  --primary:     #1a5276;
  --primary-lt:  #2471a3;
  --primary-bg:  #eaf2f8;
  --accent:      #e67e22;
  --success:     #27ae60;
  --danger:      #e74c3c;
  --warning:     #f39c12;
  --info:        #2980b9;
  --text:        #2c3e50;
  --text-muted:  #7f8c8d;
  --border:      #dce1e7;
  --bg:          #f5f7fa;
  --card-bg:     #ffffff;
  --sidebar-w:   260px;
  --topbar-h:    60px;
  --radius:      8px;
  --shadow:      0 2px 8px rgba(0,0,0,.08);
  --shadow-lg:   0 4px 20px rgba(0,0,0,.12);
  --transition:  .2s ease;
}

/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body {
  font-family: 'Segoe UI', 'Arial', 'Tahoma', sans-serif;
  background: var(--bg);
  color: var(--text);
  direction: rtl;
  line-height: 1.6;
  min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-lt); }
img { max-width: 100%; }
ul, ol { list-style: none; }

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: var(--primary);
  color: #fff;
  display: flex;
  flex-direction: column;
  z-index: 1000;
  overflow-y: auto;
  transition: transform var(--transition);
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,.15);
  flex-shrink: 0;
}
.logo-mark { font-size: 24px; }
.logo-text { flex: 1; }
.logo-title { display: block; font-size: 16px; font-weight: 700; }
.logo-sub   { display: block; font-size: 10px; opacity: .7; }
.sidebar-toggle { display: none; background: none; border: none; color: #fff; font-size: 18px; cursor: pointer; }

.nav-list { padding: 10px 0; flex: 1; }
.nav-section-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: .5;
  padding: 14px 18px 4px;
  font-weight: 600;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  color: rgba(255,255,255,.85);
  font-size: 13.5px;
  transition: all var(--transition);
  border-right: 3px solid transparent;
}
.nav-link:hover,
.nav-link.active {
  background: rgba(255,255,255,.12);
  color: #fff;
  border-right-color: var(--accent);
}
.nav-icon { font-size: 16px; }

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-top: 1px solid rgba(255,255,255,.15);
  flex-shrink: 0;
}
.user-info { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.user-avatar {
  width: 34px; height: 34px;
  background: var(--accent);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; flex-shrink: 0;
}
.user-name  { font-size: 12px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role  { font-size: 10px; color: rgba(255,255,255,.6); }
.btn-logout { color: rgba(255,255,255,.7); font-size: 18px; transition: color var(--transition); }
.btn-logout:hover { color: var(--danger); }

/* ── Overlay ───────────────────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 999;
}

/* ── Main Wrapper ──────────────────────────────────────────── */
.main-wrapper {
  margin-right: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Top Bar ───────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}
.topbar-menu-btn {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
}
.topbar-menu-btn span { display: block; width: 22px; height: 2px; background: var(--text); border-radius: 2px; }
.topbar-title { font-size: 16px; font-weight: 700; color: var(--primary); flex: 1; }
.topbar-actions { display: flex; gap: 8px; }

/* ── Page Content ──────────────────────────────────────────── */
.page-content { padding: 24px; flex: 1; }

/* ── Flash Messages ────────────────────────────────────────── */
.flash-message {
  margin: 0 24px;
  padding: 12px 16px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 500;
  animation: slideDown .3s ease;
}
@keyframes slideDown { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
.flash-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.flash-error   { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
.flash-warning { background: #fff3cd; color: #856404; border: 1px solid #ffeeba; }
.flash-info    { background: #d1ecf1; color: #0c5460; border: 1px solid #bee5eb; }
.flash-close   { margin-right: auto; background: none; border: none; cursor: pointer; font-size: 16px; opacity: .6; }
.flash-close:hover { opacity: 1; }

/* ── Cards ─────────────────────────────────────────────────── */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 10px;
}
.card-title { font-size: 15px; font-weight: 700; color: var(--primary); }
.card-body  { padding: 20px; }

/* ── Stats Grid ────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 14px;
  border-right: 4px solid var(--primary);
}
.stat-card.accent { border-right-color: var(--accent); }
.stat-card.success { border-right-color: var(--success); }
.stat-card.danger  { border-right-color: var(--danger); }
.stat-card.warning { border-right-color: var(--warning); }
.stat-icon { font-size: 28px; }
.stat-value { font-size: 22px; font-weight: 800; color: var(--primary); }
.stat-label { font-size: 12px; color: var(--text-muted); }

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.1); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-accent  { background: var(--accent); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger  { background: var(--danger);  color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-info    { background: var(--info);    color: #fff; }
.btn-outline { background: transparent; color: var(--primary); border: 2px solid var(--primary); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }
.btn-block { display: flex; width: 100%; justify-content: center; }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

/* ── Tables ────────────────────────────────────────────────── */
.table-responsive { overflow-x: auto; }
table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table thead th {
  background: #f0f4f8;
  padding: 12px 14px;
  text-align: right;
  font-weight: 700;
  color: var(--primary);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
.data-table tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.data-table tbody tr:hover { background: var(--primary-bg); }
.data-table .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.data-table .num { text-align: center; font-family: monospace; }

/* ── Badges ────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.badge-secondary { background: #e2e3e5; color: #383d41; }
.badge-success   { background: #d4edda; color: #155724; }
.badge-danger    { background: #f8d7da; color: #721c24; }
.badge-warning   { background: #fff3cd; color: #856404; }
.badge-info      { background: #d1ecf1; color: #0c5460; }
.badge-primary   { background: var(--primary-bg); color: var(--primary); }

/* ── Forms ─────────────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; }
label .req { color: var(--danger); }
.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: var(--card-bg);
  transition: border-color var(--transition), box-shadow var(--transition);
  direction: inherit;
}
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,82,118,.12);
}
.form-control.is-invalid { border-color: var(--danger); }
.invalid-feedback { color: var(--danger); font-size: 11px; margin-top: 4px; }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }

/* ── Invoice Form Specific ─────────────────────────────────── */
.invoice-items-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.invoice-items-table th {
  background: #f0f4f8;
  padding: 9px 8px;
  text-align: center;
  font-weight: 700;
  color: var(--primary);
  border: 1px solid var(--border);
}
.invoice-items-table td {
  padding: 6px 5px;
  border: 1px solid var(--border);
  vertical-align: middle;
}
.invoice-items-table .form-control { padding: 6px 8px; font-size: 12px; }
.invoice-total-box {
  background: var(--primary-bg);
  border: 2px solid var(--primary);
  border-radius: var(--radius);
  padding: 16px 20px;
  min-width: 280px;
}
.total-row { display: flex; justify-content: space-between; padding: 5px 0; font-size: 13px; }
.total-row.grand { border-top: 2px solid var(--primary); margin-top: 6px; padding-top: 8px; font-weight: 800; font-size: 16px; color: var(--primary); }
.total-value { font-family: monospace; font-weight: 700; }

/* ── Pagination ────────────────────────────────────────────── */
.pagination {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-top: 20px;
  flex-wrap: wrap;
}
.pagination a, .pagination span {
  padding: 7px 13px;
  border-radius: var(--radius);
  font-size: 13px;
  border: 1.5px solid var(--border);
  color: var(--primary);
  background: var(--card-bg);
  transition: all var(--transition);
}
.pagination a:hover     { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination span.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination span.dots   { border: none; background: none; color: var(--text-muted); }

/* ── Filter Bar ────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 18px;
}
.filter-bar .form-group { margin-bottom: 0; }
.filter-bar .form-control { min-width: 160px; }

/* ── Empty State ───────────────────────────────────────────── */
.empty-state { text-align: center; padding: 50px 20px; }
.empty-state .empty-icon { font-size: 48px; margin-bottom: 14px; opacity: .4; }
.empty-state h3 { color: var(--text-muted); margin-bottom: 8px; }
.empty-state p  { color: var(--text-muted); font-size: 13px; }

/* ── Section Headers ───────────────────────────────────────── */
.section-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--primary);
  border-right: 4px solid var(--accent);
  padding-right: 10px;
  margin-bottom: 16px;
}

/* ── Tabs ──────────────────────────────────────────────────── */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin-bottom: 20px; flex-wrap: wrap; }
.tab-btn {
  padding: 9px 18px;
  background: none;
  border: none;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  transition: all var(--transition);
  font-family: inherit;
}
.tab-btn:hover  { color: var(--primary); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ── Modals ────────────────────────────────────────────────── */
.modal-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 2000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-width: 560px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 15px; font-weight: 700; color: var(--primary); }
.modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-muted); }
.modal-body   { padding: 20px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }

/* ── Alerts ────────────────────────────────────────────────── */
.alert { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; font-size: 13px; }
.alert-info    { background: #d1ecf1; color: #0c5460; border: 1px solid #bee5eb; }
.alert-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.alert-warning { background: #fff3cd; color: #856404; border: 1px solid #ffeeba; }
.alert-danger  { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }

/* ── Login Page ────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary) 0%, #0d3b5e 100%);
  padding: 20px;
}
.login-card {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo .logo-big { font-size: 48px; }
.login-logo h2 { color: var(--primary); font-size: 20px; margin-top: 8px; }
.login-logo p  { color: var(--text-muted); font-size: 12px; }

/* ── Loading Spinner ───────────────────────────────────────── */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 900px) {
  .sidebar {
    transform: translateX(100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-toggle { display: block; }
  .sidebar-overlay.open { display: block; }
  .main-wrapper { margin-right: 0; }
  .topbar-menu-btn { display: flex; }
  .page-content { padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .filter-bar { flex-direction: column; }
  .filter-bar .form-control { min-width: 100%; }
  .topbar-actions { display: none; }
}

/* ── Utilities ─────────────────────────────────────────────── */
.d-flex       { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-10 { gap: 10px; }
.gap-16 { gap: 16px; }
.mb-0  { margin-bottom: 0 !important; }
.mb-10 { margin-bottom: 10px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.mt-16 { margin-top: 16px; }
.text-muted  { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-center { text-align: center; }
.text-right  { text-align: right; }
.font-mono   { font-family: monospace; }
.fw-bold     { font-weight: 700; }
.small       { font-size: 12px; }
.w-100       { width: 100%; }
.hidden      { display: none !important; }
