:root {
  --ink: #17201b;
  --muted: #667085;
  --line: #e6e9ef;
  --panel: #ffffff;
  --bg: #f6f7f9;
  --accent: #0f766e;
  --danger: #b42318;
  --warning: #b54708;
  --success: #027a48;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Tahoma, Arial, sans-serif;
}

.navbar-brand {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
}

.brand-logo {
  width: 32px;
  height: 32px;
  object-fit: contain;
  border-radius: 6px;
}

.nav-link {
  border-radius: 6px;
  color: #344054;
  font-weight: 600;
}

.nav-link:hover {
  background: #eef8f6;
  color: var(--accent);
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.page-head h1 {
  font-size: clamp(1.45rem, 2vw, 2rem);
  margin: 0;
  font-weight: 800;
}

.page-head p {
  margin: .35rem 0 0;
  color: var(--muted);
}

.month-filter {
  display: flex;
  gap: .5rem;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: .85rem;
}

.metric-card,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
}

.metric-card {
  padding: 1rem;
  min-height: 104px;
}

.metric-card span {
  display: block;
  color: var(--muted);
  font-size: .88rem;
}

.metric-card strong {
  display: block;
  margin-top: .6rem;
  font-size: 1.28rem;
  overflow-wrap: anywhere;
}

.metric-card em {
  color: var(--accent);
  font-style: normal;
  font-weight: 700;
}

.panel {
  padding: 1rem;
}

.panel h2 {
  font-size: 1rem;
  margin-bottom: 1rem;
  font-weight: 800;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.chart-grid canvas {
  width: 100% !important;
  height: 260px !important;
}

.status-healthy {
  border-color: rgba(2, 122, 72, .35);
  background: #ecfdf3;
}

.status-attention {
  border-color: rgba(181, 71, 8, .35);
  background: #fffaeb;
}

.status-critical {
  border-color: rgba(180, 35, 24, .35);
  background: #fef3f2;
}

.report-box {
  white-space: pre-wrap;
  background: #101828;
  color: #f9fafb;
  border-radius: 8px;
  padding: 1rem;
  line-height: 1.9;
  margin: 0;
}

.settings-logo {
  max-width: 140px;
  max-height: 90px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .5rem;
  background: #fff;
}

.table {
  --bs-table-bg: transparent;
}

.clickable-row { cursor: pointer; }
.clickable-row:hover { background: #eef8f6 !important; }
tr[style*="cursor:pointer"]:hover { background: #eef8f6; }

.form-control,
.form-select,
.btn {
  border-radius: 6px;
}

/* ===== تقويم التاريخ بنمط Google Calendar ===== */
.gdp {
  position: relative;
  display: flex;
  gap: .35rem;
  align-items: stretch;
}

.gdp > .gdp-input {
  flex: 1 1 0;
  width: auto;
  min-width: 0;
}

.gdp-trigger {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  padding: 0;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  border-radius: 6px;
  cursor: pointer;
}

.gdp-trigger:hover,
.gdp-trigger:focus-visible {
  color: var(--accent);
  border-color: var(--accent);
}

.gdp-trigger svg {
  width: 17px;
  height: 17px;
}

.gdp-pop {
  position: absolute;
  top: calc(100% + .35rem);
  inset-inline-start: 0;
  z-index: 1070;
  width: 19.75rem;
  max-width: calc(100vw - 2rem);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 16px 40px rgba(23, 32, 27, .22);
  overflow: hidden;
  display: none;
}

.gdp-pop.is-open { display: block; }

.gdp-head {
  background: var(--accent);
  color: #fff;
  padding: .65rem .9rem .75rem;
}

.gdp-head-label {
  display: block;
  font-size: .72rem;
  opacity: .85;
}

.gdp-head-date {
  display: block;
  font-size: 1.15rem;
  font-weight: 700;
  margin-top: .1rem;
}

.gdp-tools {
  display: flex;
  align-items: center;
  gap: .2rem;
  padding: .45rem .5rem;
  border-bottom: 1px solid var(--line);
}

.gdp-tools .gdp-title {
  flex: 1 1 auto;
  text-align: center;
  font-weight: 700;
  font-size: .92rem;
  white-space: nowrap;
}

.gdp-tools button {
  width: 30px;
  height: 30px;
  border: 0;
  background: transparent;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  cursor: pointer;
}

.gdp-tools button:hover { background: #eef1f4; }
.gdp-tools button svg { width: 16px; height: 16px; }

.gdp-dow,
.gdp-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: .15rem;
  padding-inline: .5rem;
}

.gdp-dow span {
  text-align: center;
  font-size: .68rem;
  font-weight: 700;
  color: var(--muted);
  padding-top: .5rem;
  padding-bottom: .3rem;
}

.gdp-grid {
  padding-bottom: .5rem;
  touch-action: pan-y;
}

.gdp-grid button {
  height: 32px;
  border: 0;
  background: transparent;
  border-radius: 50%;
  font-size: .85rem;
  color: var(--ink);
  cursor: pointer;
}

.gdp-grid button:hover { background: #eef1f4; }

.gdp-grid button.is-today {
  color: var(--accent);
  font-weight: 800;
  box-shadow: inset 0 0 0 1px var(--accent);
}

.gdp-grid button.is-selected {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  box-shadow: none;
}

.gdp-grid .gdp-empty { visibility: hidden; }

/* شبكة الأشهر في حقول الشهر (type=month) */
.gdp-grid.is-months {
  grid-template-columns: repeat(4, 1fr);
  gap: .3rem .25rem;
}

.gdp-grid.is-months button {
  height: 34px;
  border-radius: 8px;
  font-size: .78rem;
  font-weight: 600;
}

.gdp-grid.is-slide-next { animation: gdpSlideNext .18s ease; }
.gdp-grid.is-slide-prev { animation: gdpSlidePrev .18s ease; }

@keyframes gdpSlideNext {
  from { transform: translateX(16px); opacity: .35; }
  to { transform: none; opacity: 1; }
}

@keyframes gdpSlidePrev {
  from { transform: translateX(-16px); opacity: .35; }
  to { transform: none; opacity: 1; }
}

.gdp-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  padding: .45rem .6rem;
  border-top: 1px solid var(--line);
}

.gdp-foot-right {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
}

.gdp-foot .gdp-link {
  border: 0;
  background: transparent;
  padding: .25rem .4rem;
  font-size: .82rem;
  font-weight: 700;
  color: var(--accent);
  border-radius: 6px;
  cursor: pointer;
}

.gdp-foot .gdp-link:hover { background: #eef1f4; }
.gdp-foot .gdp-danger { color: #dc2626; }

.gdp-foot .gdp-ok {
  border: 0;
  background: var(--accent);
  color: #fff;
  font-size: .82rem;
  font-weight: 700;
  padding: .3rem .95rem;
  border-radius: 6px;
  cursor: pointer;
}

.gdp-foot .gdp-ok:hover { filter: brightness(.94); }

/* ===== حقول الأرقام: ملتصقة بالجهة اليمنى، أرقام إنجليزية، بلا أزرار الزيادة/النقص ===== */
input[type="number"],
.num-field {
  direction: ltr;
  text-align: right;
  -moz-appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* ===== صفوف صور الفواتير ===== */
.gallery-day {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--panel);
  font-size: .82rem;
  font-weight: 700;
  color: var(--ink);
  padding: .5rem 0 .35rem;
  margin-top: .5rem;
  border-bottom: 1px solid var(--line);
}

.gallery-day:first-child { margin-top: 0; }

.inv-row {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .7rem .65rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  margin-top: .5rem;
}

.inv-row:hover {
  background: #f9fafb;
  border-color: #d7dce3;
}

.inv-row-icon {
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: #eef1f4;
  color: var(--muted);
}

.inv-row-body {
  flex: 1 1 auto;
  min-width: 0;
}

.inv-row-name {
  font-weight: 700;
  font-size: .9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.inv-row-meta {
  font-size: .76rem;
  color: var(--muted);
  margin-top: .15rem;
}

.inv-row-view { flex: 0 0 auto; }

/* نافذة عرض صورة الفاتورة (مستقلة عن Bootstrap) */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1095;
  display: none;
}

.lightbox.is-open { display: block; }

.lb-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, .78);
}

.lb-dialog {
  position: relative;
  z-index: 1;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.lb-panel {
  width: min(980px, 100%);
  max-height: 94vh;
  display: flex;
  flex-direction: column;
  background: var(--panel, #fff);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .35);
}

.lb-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .6rem .9rem;
  border-bottom: 1px solid var(--line, #e5e7eb);
}

.lb-title {
  font-weight: 700;
  font-size: .95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lb-close {
  border: 0;
  background: transparent;
  color: var(--muted, #6b7280);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 .25rem;
  border-radius: 6px;
}

.lb-close:hover { background: #eef1f4; color: #111827; }

.lb-body {
  flex: 1 1 auto;
  overflow: auto;
  text-align: center;
  background: #f4f6f8;
  padding: .5rem;
}

#lightboxImg {
  max-height: 74vh;
  max-width: 100%;
  object-fit: contain;
}

.lb-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .5rem .9rem;
  border-top: 1px solid var(--line, #e5e7eb);
}

.lb-meta {
  font-size: .78rem;
  color: var(--muted, #6b7280);
}

body.lb-open { overflow: hidden; }

/* زر الرفع الخلفية الفضية */
.btn-silver {
  background: linear-gradient(180deg, #fafbfc 0%, #e8ecf1 45%, #d8dee6 100%);
  border: 1px solid #b6bfc9;
  color: #1f2937;
  font-weight: 700;
  box-shadow: inset 0 1px 0 #fff, 0 1px 2px rgba(16, 24, 40, .08);
}

.btn-silver:hover,
.btn-silver:focus {
  background: linear-gradient(180deg, #ffffff 0%, #eef1f5 45%, #dde3ea 100%);
  border-color: #96a0ac;
  color: #111827;
}

.btn-silver:active {
  background: linear-gradient(180deg, #dfe4ea 0%, #d3d9e1 100%);
  box-shadow: inset 0 2px 4px rgba(16, 24, 40, .15);
}

@media print {
  .navbar, .page-head .btn, .btn-outline-dark, .panel .btn { display: none !important; }
  .page-head .btn-dark { display: none !important; }
  .panel { border: none !important; box-shadow: none !important; padding: 0 !important; }
  .page-head h1 { font-size: 1.4rem; }
  .container-fluid { padding: 0 !important; }
  .table { font-size: 11px; }
  .d-print-block { display: block !important; }
}

@media (max-width: 767px) {
  main.container-fluid {
    padding-inline: .75rem;
  }

  .page-head,
  .month-filter {
    flex-direction: column;
    width: 100%;
  }

  .month-filter .btn,
  .month-filter .form-control {
    width: 100%;
  }

  .metric-card {
    min-height: 92px;
  }
}
