/* ===== أساسيات ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
  font-family: 'Cairo', Tahoma, sans-serif;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  color: #333;
  min-height: 100vh;
  padding: 24px 16px;
  line-height: 1.6;
}

.container {
  background: #fff;
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px;
  border-radius: 20px;
  box-shadow: 0 10px 30px rgba(0,0,0,.08);
}
.container.narrow { max-width: 900px; }
.container.form-page { max-width: 1000px; }

h2 {
  text-align: center; color: #1a202c; font-size: 26px; font-weight: 700;
  margin-bottom: 26px; position: relative; padding-bottom: 12px;
}
h2::after {
  content: ''; position: absolute; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 60px; height: 3px; background: #007bff; border-radius: 2px;
}
h3 { text-align: center; color: #333; margin-bottom: 14px; }

a { color: #007bff; }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  gap: 10px; flex-wrap: wrap; margin-bottom: 18px;
}
.topbar .who { font-size: 14px; color: #4a5568; }

/* ===== أزرار ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border: 0; border-radius: 10px; cursor: pointer;
  font-family: inherit; font-size: 15px; font-weight: 600; text-decoration: none;
  color: #fff; background: #007bff; transition: filter .15s, transform .15s;
}
.btn:hover { filter: brightness(.92); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 3px solid #7ab8ff; outline-offset: 2px;
}
.btn-success   { background: #28a745; }
.btn-warning   { background: #ffc107; color: #333; }
.btn-danger    { background: #dc3545; }
.btn-secondary { background: #6c757d; }
.btn-info      { background: #17a2b8; }
.btn-sm        { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn-block     { width: 100%; }

form.inline { display: inline; }

/* ===== رسائل ===== */
.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 18px; font-weight: 600; }
.alert-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.alert-danger  { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
.alert-warning { background: #fff3cd; color: #856404; border: 1px solid #ffeeba; }
.alert-info    { background: #e8f4fd; color: #0c5460; border: 1px solid #bbe2f8; }
.alert ul { padding-right: 20px; font-weight: 400; }

/* ===== نماذج ===== */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 20px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full-width { grid-column: 1 / -1; }
label { font-weight: 600; font-size: 14px; color: #2d3748; }
input[type=text], input[type=number], input[type=date], input[type=password], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid #cbd5e0; border-radius: 8px;
  font-family: inherit; font-size: 15px; background: #fff;
}
.note { font-size: 12px; color: #718096; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.check input { width: auto; }

.row-item { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.row-item input { flex: 1; min-width: 0; }
.badge-num {
  background: #e2e8f0; color: #4a5568; border-radius: 6px; padding: 2px 8px;
  font-size: 12px; font-weight: 700; flex: none;
}
.btn-remove {
  background: #fee2e2; color: #b91c1c; border: 0; border-radius: 8px;
  width: 34px; height: 34px; cursor: pointer; flex: none; font-size: 14px;
}
.btn-remove:hover { background: #dc3545; color: #fff; }
.btn-add {
  background: #e6f4ea; color: #1e7e34; border: 1px dashed #28a745; border-radius: 8px;
  padding: 8px 12px; cursor: pointer; font-family: inherit; font-weight: 600; width: 100%;
}
.btn-add:hover { background: #28a745; color: #fff; }
.actions-container { grid-column: 1 / -1; display: flex; gap: 12px; flex-wrap: wrap; margin-top: 6px; }
.actions-container .btn-submit { flex: 1; min-width: 220px; padding: 14px; font-size: 17px; }

/* ===== جداول ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; margin-top: 12px; min-width: 760px; }
th, td { border: 1px solid #e2e8f0; padding: 10px; text-align: center; }
th { background: #007bff; color: #fff; font-weight: 600; }
tr:nth-child(even) td { background: #f9fafb; }
td.right, th.right { text-align: right; }
.action-btns { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.muted { color: #777; }
.pos { color: #0056b3; font-weight: 700; }
.neg { color: #c62828; font-weight: 700; }
.money { color: #16a34a; font-weight: 700; }

.filter-form {
  background: #eef2f7; padding: 14px; border-radius: 12px; margin-bottom: 18px;
  display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap;
}
.filter-form .form-group { min-width: 160px; }

.total-box {
  background: #eef2f7; border: 1px solid #cbd5e1; padding: 14px 18px; border-radius: 12px;
  font-size: 1.15rem; font-weight: 700; margin-top: 18px;
  display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
}
.total-box span { color: #16a34a; }

.pagination { display: flex; gap: 8px; justify-content: center; align-items: center; margin-top: 16px; flex-wrap: wrap; }

.alerts-box { background: #e8f4fd; border: 1px solid #bbe2f8; color: #0c5460; padding: 14px; border-radius: 12px; margin-bottom: 18px; }
.alerts-box ul { padding-right: 20px; margin-top: 6px; }

.print-only { display: none; }

/* ===== الشاشة الرئيسية ===== */
body.dash { display: flex; justify-content: center; align-items: center; }
.dash-card {
  background: #fff; padding: 40px 30px; border-radius: 20px; width: 100%; max-width: 480px;
  box-shadow: 0 10px 30px rgba(0,0,0,.08); text-align: center;
}
.dash-card .who { margin-bottom: 20px; font-size: 14px; color: #4a5568; }
.menu { display: flex; flex-direction: column; gap: 16px; }
.menu a {
  display: flex; align-items: center; gap: 15px; padding: 16px 20px;
  background: #fff; color: #4a5568; border: 2px solid #e2e8f0; border-radius: 12px;
  font-size: 16px; font-weight: 600; text-decoration: none; transition: all .25s;
}
.menu a i { font-size: 20px; width: 35px; text-align: center; }
.menu a:hover { transform: translateY(-3px); box-shadow: 0 6px 20px rgba(0,0,0,.06); }
.menu .m-blue i { color: #007bff; }   .menu .m-blue:hover { border-color: #007bff; background: #f0f7ff; color: #007bff; }
.menu .m-green i { color: #28a745; }  .menu .m-green:hover { border-color: #28a745; background: #f0fdf4; color: #28a745; }
.menu .m-amber i { color: #d97706; }  .menu .m-amber:hover { border-color: #d97706; background: #fffbeb; color: #d97706; }
.menu .m-purple i { color: #6f42c1; } .menu .m-purple:hover { border-color: #6f42c1; background: #f6f1fd; color: #6f42c1; }
.menu .m-red i { color: #dc3545; }    .menu .m-red:hover { border-color: #dc3545; background: #fef2f2; color: #dc3545; }

/* ===== تسجيل الدخول ===== */
body.auth { display: flex; justify-content: center; align-items: center; }
.auth-card {
  background: #fff; padding: 36px 30px; border-radius: 20px; width: 100%; max-width: 420px;
  box-shadow: 0 10px 30px rgba(0,0,0,.08);
}
.auth-card .form-group { margin-bottom: 16px; }

/* ===== الفاتورة ===== */
.invoice { max-width: 800px; }
.inv-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.inv-head h1 { font-size: 24px; color: #1a202c; }
.inv-meta { font-size: 14px; color: #4a5568; line-height: 1.9; }
.inv-section { margin-top: 22px; }
.inv-section h4 { margin-bottom: 6px; color: #1a202c; }
.inv-table { min-width: 0; }
.inv-table td.right { text-align: right; }
.inv-total td { font-weight: 700; font-size: 1.1rem; background: #eef2f7 !important; }

/* ===== الطباعة ===== */
@media print {
  body { background: #fff; padding: 0; font-size: 12px; }
  .container, .dash-card { box-shadow: none; padding: 0; max-width: 100%; }
  .no-print, .filter-form, .pagination, .col-actions { display: none !important; }
  .print-only { display: block; }
  table { min-width: 0; font-size: 11px; }
  th, td { padding: 5px !important; }
  th { background: #eee !important; color: #000 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .total-box { background: transparent; border: 1px solid #000; page-break-inside: avoid; }
}

/* ===== الصلاحيات ===== */
.pill { display: inline-block; padding: 2px 12px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.pill-admin  { background: #e3eefa; color: #154a85; }
.pill-viewer { background: #e6f4ea; color: #1e7e34; }

/* ===== صورة الفاتورة ===== */
.img-preview, .current-image img, .inv-image img {
  display: block; max-width: 100%; max-height: 260px; border-radius: 10px; border: 1px solid #e2e8f0; margin-top: 8px;
}
.current-image { display: flex; flex-direction: column; gap: 8px; margin-bottom: 6px; }
.inv-image img { max-height: 420px; margin: 8px auto 0; }
input[type=file] { padding: 8px; border: 1px dashed #cbd5e0; border-radius: 8px; background: #f9fafb; width: 100%; font-family: inherit; }
@media print { .inv-image img { max-height: 9cm; } }

/* ===== صور متعددة ===== */
.preview-grid, .thumbs { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }
.preview-grid .img-preview { height: 90px; width: auto; max-width: 100%; margin-top: 0; }
.thumb { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 13px; font-weight: 400; }
.thumb img { height: 90px; width: auto; max-width: 100%; border-radius: 8px; border: 1px solid #e2e8f0; }
.inv-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); gap: 12px; }
.inv-gallery img { display: block; width: 100%; height: auto; max-height: 70vh; object-fit: contain; background: #f1f5f9; border-radius: 10px; border: 1px solid #e2e8f0; }
@media print { .inv-gallery { grid-template-columns: repeat(2, 1fr); } .inv-gallery img { max-height: 9cm; } }

/* ===== منع تجاوز الصور لعرض الصفحة + تحسين الجوال ===== */
img { max-width: 100%; height: auto; }
.inv-gallery a { display: block; min-width: 0; }
@media (max-width: 600px) {
  body { padding: 12px 8px; }
  .container { padding: 18px 14px; border-radius: 14px; }
  .inv-gallery { grid-template-columns: 1fr; }
}
