@import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@400;500;700&display=swap');

:root {
  --font:       'Tajawal', sans-serif;
  --bg:         #F5F4F0;
  --bg-card:    #FFFFFF;
  --bg-side:    #1A1A2E;
  --text:       #1C1C1C;
  --text-2:     #5A5A6E;
  --text-3:     #9696A8;
  --primary:    #2563EB;
  --primary-dk: #1D4ED8;
  --primary-lt: #EFF6FF;
  --success:    #16A34A;
  --success-lt: #F0FDF4;
  --warning:    #D97706;
  --warning-lt: #FFFBEB;
  --danger:     #DC2626;
  --danger-lt:  #FEF2F2;
  --info:       #0891B2;
  --info-lt:    #ECFEFF;
  --border:     #E4E3DE;
  --border-2:   #CCCBC4;
  --radius:     10px;
  --radius-lg:  14px;
  --shadow:     0 1px 3px rgba(0,0,0,.08);
  --shadow-md:  0 4px 12px rgba(0,0,0,.10);
  --sidebar-w:  240px;
  --header-h:   60px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; direction: rtl; }
body { font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.6; min-height: 100vh; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }
img { max-width: 100%; }

/* Layout */
.layout { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-side);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; right: 0;
  height: 100vh;
  z-index: 300;
  overflow-y: auto;
  transition: transform .2s ease;
}
.sidebar-brand { padding: 20px 18px 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar-brand h1 { font-size: 1.05rem; font-weight: 700; color: #fff; }
.sidebar-brand span { display: block; font-size: .7rem; color: rgba(255,255,255,.4); margin-top: 2px; }
.sidebar-nav { padding: 8px 0; flex: 1; }
.nav-section { font-size: .66rem; font-weight: 600; color: rgba(255,255,255,.3); letter-spacing: .08em; padding: 14px 18px 5px; text-transform: uppercase; }
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 18px;
  color: rgba(255,255,255,.6);
  font-size: .92rem;
  text-decoration: none;
  transition: background .15s, color .15s;
  position: relative;
}
.nav-link:hover { background: rgba(255,255,255,.07); color: #fff; text-decoration: none; }
.nav-link.active { background: rgba(37,99,235,.22); color: #fff; font-weight: 500; }
.nav-link.active::before { content:''; position:absolute; right:0; top:0; width:3px; height:100%; background:var(--primary); border-radius:3px 0 0 3px; }
.nav-link svg { width: 17px; height: 17px; flex-shrink: 0; }
.sidebar-footer { padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-footer a { display:flex; align-items:center; gap:8px; color:rgba(255,255,255,.45); font-size:.82rem; }
.sidebar-footer a:hover { color: var(--danger); text-decoration:none; }

/* Main */
.main-wrap { flex: 1; margin-right: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }

/* Header */
.top-bar {
  height: var(--header-h);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 22px;
  position: sticky; top: 0; z-index: 100;
}
.top-bar .page-ttl { font-size: .95rem; font-weight: 600; }
.top-bar .top-date { font-size: .78rem; color: var(--text-3); }
.menu-btn { display: none; background: none; border: none; cursor: pointer; padding: 6px; color: var(--text-2); }
.menu-btn svg { width: 22px; height: 22px; display: block; }

/* Page */
.page { padding: 22px; flex: 1; }

/* Card */
.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); margin-bottom: 18px; }
.card-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; }
.card-title { font-size: .9rem; font-weight: 600; }
.card-body { padding: 18px; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px 18px; box-shadow: var(--shadow); }
.stat-lbl { font-size: .75rem; color: var(--text-3); font-weight: 500; margin-bottom: 5px; }
.stat-val { font-size: 1.4rem; font-weight: 700; line-height: 1.2; }
.stat-sub { font-size: .73rem; color: var(--text-3); margin-top: 3px; }
.stat.s-danger  { border-right: 3px solid var(--danger);  }
.stat.s-warning { border-right: 3px solid var(--warning); }
.stat.s-success { border-right: 3px solid var(--success); }
.stat.s-info    { border-right: 3px solid var(--info);    }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 15px; border-radius: var(--radius);
  font-size: .84rem; font-weight: 500; cursor: pointer;
  border: 1px solid transparent;
  transition: .15s; white-space: nowrap; text-decoration: none;
}
.btn:hover { text-decoration: none; filter: brightness(.93); }
.btn svg { width: 15px; height: 15px; flex-shrink: 0; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-danger  { background: var(--danger);  color: #fff; border-color: var(--danger);  }
.btn-warning { background: var(--warning); color: #fff; border-color: var(--warning); }
.btn-outline { background: transparent; color: var(--text-2); border-color: var(--border-2); }
.btn-outline:hover { background: var(--bg); }
.btn-ghost  { background: transparent; color: var(--text-2); border-color: transparent; }
.btn-ghost:hover { background: var(--bg); }
.btn-sm { padding: 5px 10px; font-size: .78rem; }
.btn-xs { padding: 3px 7px; font-size: .72rem; }

/* Forms */
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: .8rem; font-weight: 500; color: var(--text-2); margin-bottom: 4px; }
.req { color: var(--danger); }
.form-control {
  display: block; width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border-2); border-radius: var(--radius);
  background: var(--bg-card); color: var(--text); font-size: .92rem;
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none; appearance: none;
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.form-control::placeholder { color: var(--text-3); }
textarea.form-control { resize: vertical; min-height: 76px; }
select.form-control { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239696A8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: left 10px center; padding-left: 30px; }
.form-row   { display: grid; grid-template-columns: 1fr 1fr;     gap: 13px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 13px; }
.form-hint  { font-size: .73rem; color: var(--text-3); margin-top: 3px; }

/* Table */
.tbl-wrap { overflow-x: auto; }
table.dtbl { width: 100%; border-collapse: collapse; font-size: .92rem; }
.dtbl thead tr { background: var(--bg); }
.dtbl th { padding: 10px 13px; text-align: right; font-weight: 600; color: var(--text-2); font-size: .76rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
.dtbl td { padding: 10px 13px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.dtbl tbody tr:last-child td { border-bottom: none; }
.dtbl tbody tr:hover { background: #FAFAF8; }
.acts { display: flex; gap: 4px; }

/* Badge */
.badge { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 20px; font-size: .71rem; font-weight: 600; white-space: nowrap; }
.b-success { background: var(--success-lt); color: var(--success); }
.b-danger  { background: var(--danger-lt);  color: var(--danger);  }
.b-warning { background: var(--warning-lt); color: var(--warning); }
.b-info    { background: var(--info-lt);    color: var(--info);    }
.b-gray    { background: #F1F1EF;           color: var(--text-2);  }

/* Alert */
.alert { padding: 11px 15px; border-radius: var(--radius); font-size: .92rem; margin-bottom: 14px; display: flex; align-items: center; gap: 9px; }
.alert svg { width: 17px; height: 17px; flex-shrink: 0; }
.alert-success { background: var(--success-lt); color: var(--success); border: 1px solid #BBF7D0; }
.alert-danger  { background: var(--danger-lt);  color: var(--danger);  border: 1px solid #FECACA; }
.alert-warning { background: var(--warning-lt); color: var(--warning); border: 1px solid #FDE68A; }
.alert-info    { background: var(--info-lt);    color: var(--info);    border: 1px solid #A5F3FC; }

/* Filter bar */
.filter-bar { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 12px 15px; margin-bottom: 14px; display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.filter-bar .form-group { margin-bottom: 0; min-width: 130px; }
.filter-bar .form-control { font-size: .82rem; padding: 6px 9px; }

/* Pagination */
.pager { display: flex; align-items: center; gap: 4px; justify-content: center; padding: 14px; }
.pager a, .pager span { display: inline-flex; align-items: center; justify-content: center; min-width: 32px; height: 32px; border-radius: 7px; font-size: .8rem; border: 1px solid var(--border); background: var(--bg-card); color: var(--text-2); cursor: pointer; text-decoration: none; padding: 0 6px; }
.pager a:hover { background: var(--bg); text-decoration: none; }
.pager .cur { background: var(--primary); color: #fff; border-color: var(--primary); }
.pager .dis { opacity: .4; pointer-events: none; }

/* Modal */
.modal-bg { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 500; align-items: center; justify-content: center; padding: 14px; }
.modal-bg.show { display: flex; }
.modal { background: var(--bg-card); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto; animation: mIn .17s ease; }
.modal-lg { max-width: 740px; }
@keyframes mIn { from { opacity:0; transform:translateY(-10px); } to { opacity:1; transform:none; } }
.modal-head { padding: 15px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { font-size: .92rem; font-weight: 600; }
.modal-x { background: none; border: none; cursor: pointer; color: var(--text-3); padding: 3px; border-radius: 6px; display: flex; line-height: 1; font-size: 1.2rem; }
.modal-x:hover { color: var(--danger); background: var(--danger-lt); }
.modal-body { padding: 18px; }
.modal-foot { padding: 13px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* Today alert */
.today-alert { background: var(--danger); color: #fff; border-radius: var(--radius-lg); padding: 14px 18px; margin-bottom: 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.today-alert h3 { font-size: .88rem; font-weight: 600; margin-bottom: 2px; }
.today-alert .big { font-size: 1.7rem; font-weight: 700; }

/* Invoice items */
.inv-items { width: 100%; border-collapse: collapse; }
.inv-items th { background: var(--bg); padding: 7px 9px; font-size: .76rem; font-weight: 600; color: var(--text-2); text-align: right; border: 1px solid var(--border); }
.inv-items td { padding: 4px 5px; border: 1px solid var(--border); vertical-align: middle; }
.inv-total td { padding: 8px 9px; font-weight: 600; background: var(--bg); }

/* Grid helpers */
.g2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.g3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* Sidebar overlay */
.sb-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 290; }
.sb-overlay.show { display: block; }

/* Print */
@media print {
  .sidebar, .top-bar, .no-print { display: none !important; }
  .main-wrap { margin-right: 0 !important; }
  .page { padding: 0 !important; }
  .card { box-shadow: none !important; }
  body { background: #fff; font-size: 13px; }
}

/* Responsive */
@media (max-width: 900px) {
  .sidebar { transform: translateX(100%); }
  .sidebar.open { transform: translateX(0); }
  .main-wrap { margin-right: 0; }
  .menu-btn { display: flex; }
}
@media (max-width: 640px) {
  .page { padding: 13px; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .card-head { flex-direction: column; align-items: flex-start; }
  .filter-bar { flex-direction: column; }
  .filter-bar .form-group { width: 100%; min-width: unset; }
}
@media (max-width: 380px) {
  .stats { grid-template-columns: 1fr; }
}

/* Utilities */
.tc { text-align: center; }
.tr { text-align: right; }
.tl { text-align: left; }
.text-danger  { color: var(--danger);  }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-muted   { color: var(--text-3);  }
.fw6 { font-weight: 600; }
.fw7 { font-weight: 700; }
.mt1 { margin-top: 8px;  }
.mt2 { margin-top: 16px; }
.mb1 { margin-bottom: 8px;  }
.mb2 { margin-bottom: 16px; }
.df  { display: flex; }
.ac  { align-items: center; }
.gap1 { gap: 8px; }
.gap2 { gap: 14px; }
.jb  { justify-content: space-between; }
.w100 { width: 100%; }

/* ===== PRINT STYLES ===== */
@media print {
  .sidebar, .top-bar, .no-print,
  .filter-bar, .pager, .acts,
  .btn, button { display: none !important; }
  .main-wrap { margin-right: 0 !important; }
  .page { padding: 0 !important; }
  .card { box-shadow: none !important; border: 1px solid #ccc !important; margin-bottom: 10px !important; }
  body { background: #fff; font-size: 13px; }
  .dtbl th, .dtbl td { padding: 7px 10px !important; font-size: 12px; }
  .dtbl thead tr { background: #f0f0f0 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .badge { border: 1px solid #999 !important; background: transparent !important; color: #000 !important; }
  .print-title { display: block !important; }
  h1.print-title { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
  .print-meta { display: block !important; font-size: 11px; color: #666; margin-bottom: 14px; }
  .stat { border: 1px solid #ddd !important; }
}
.print-title { display: none; }
.print-meta  { display: none; }

/* Print button style */
.btn-print {
  background: #fff;
  color: var(--text-2);
  border: 1px solid var(--border-2);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius);
  font-size: .84rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
}
.btn-print:hover { background: var(--bg); text-decoration: none; }
.btn-print svg { width: 15px; height: 15px; }
