:root {
  --bg: #f2f5f4;
  --bg-alt: #eaf0ee;
  --card: #ffffff;
  --primary: #1e6b52;
  --primary-light: #279470;
  --primary-dark: #123d2f;
  --accent: #d99a3c;
  --text: #1b2422;
  --muted: #667370;
  --border: #e3e8e6;
  --danger: #b3423a;
  --danger-bg: #fbeceb;
  --success-bg: #eaf5ef;
  --success: #1e6b52;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(18, 61, 47, 0.06), 0 1px 1px rgba(18, 61, 47, 0.04);
  --shadow-md: 0 6px 20px rgba(18, 61, 47, 0.09), 0 2px 6px rgba(18, 61, 47, 0.06);
  --shadow-lg: 0 16px 40px rgba(18, 61, 47, 0.14);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: "Segoe UI", "Noto Sans Arabic", Tahoma, sans-serif;
  background: var(--bg);
  background-image:
    radial-gradient(circle at 100% 0%, rgba(30, 107, 82, 0.06), transparent 45%),
    radial-gradient(circle at 0% 100%, rgba(217, 154, 60, 0.05), transparent 40%);
  background-attachment: fixed;
  color: var(--text);
  direction: rtl;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; transition: color .15s ease; }
a:hover { color: var(--primary-dark); text-decoration: underline; }

/* ---------- Top navigation ---------- */
.topbar {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  color: #fff;
  padding: 14px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: var(--shadow-md);
}
.topbar .brand {
  font-weight: 700;
  font-size: 17px;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.topbar nav {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  background: rgba(255,255,255,0.08);
  padding: 4px;
  border-radius: 999px;
}
.topbar nav a {
  color: #dbeee5;
  font-size: 13.5px;
  padding: 8px 16px;
  border-radius: 999px;
  transition: background .15s ease, color .15s ease;
  white-space: nowrap;
}
.topbar nav a:hover { color: #fff; text-decoration: none; background: rgba(255,255,255,0.12); }
.topbar nav a.active { background: #fff; color: var(--primary-dark); font-weight: 600; }
.topbar .user {
  font-size: 13px;
  color: #cfe5db;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.topbar .user .avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: rgba(255,255,255,0.18);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #fff;
}
.topbar .user a { color: #f3d9d6; }

.container { max-width: 1180px; margin: 28px auto 60px; padding: 0 20px; animation: fadeIn .25s ease; }
.container.container-wide { max-width: 1680px; }

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

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .2s ease;
}
.card h2 { margin-top: 0; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.card h3 { font-size: 14px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }

.stat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}
.stat::before {
  content: "";
  position: absolute; inset-inline-start: 0; top: 0; bottom: 0; width: 4px;
  background: linear-gradient(var(--primary), var(--accent));
}
.stat .num { font-size: 30px; font-weight: 800; color: var(--primary-dark); font-variant-numeric: tabular-nums; }
.stat .label { color: var(--muted); font-size: 12.5px; margin-top: 6px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background .15s ease, transform .1s ease, box-shadow .15s ease;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; box-shadow: var(--shadow-md); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.secondary { background: #fff; color: var(--primary); border: 1px solid var(--border); box-shadow: none; }
.btn.secondary:hover { background: var(--success-bg); border-color: var(--primary-light); }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); box-shadow: none; }
.btn.ghost:hover { background: var(--bg-alt); color: var(--text); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

/* ---------- Forms ---------- */
input[type=text], input[type=password], input[type=file], input[type=search], select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-top: 6px;
  margin-bottom: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  transition: border-color .15s ease, box-shadow .15s ease;
}
input[type=text]:focus, input[type=password]:focus, input[type=search]:focus, select:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(30, 107, 82, 0.15);
}
input[type=file] { padding: 8px; cursor: pointer; }

label { font-size: 13.5px; font-weight: 600; color: var(--text); }

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card { width: 380px; box-shadow: var(--shadow-lg); }
.login-card h1 { font-size: 21px; text-align: center; margin-bottom: 4px; }
.login-card p.sub { text-align: center; color: var(--muted); font-size: 13px; margin-top: 0; margin-bottom: 22px; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; table-layout: auto; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: right; word-break: break-word; }
th {
  background: var(--bg-alt);
  color: var(--primary-dark);
  position: sticky;
  top: 0;
  font-weight: 700;
  font-size: 12.5px;
  z-index: 1;
  box-shadow: 0 1px 0 var(--border);
}
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { background: #e2ebe7; }
th.sortable .arrow { display: inline-block; width: 12px; opacity: .4; font-size: 11px; }
th.sortable.sort-asc .arrow, th.sortable.sort-desc .arrow { opacity: 1; color: var(--accent); }
tbody tr { transition: background .1s ease; }
tbody tr:nth-child(even) { background: #fbfcfc; }
tbody tr:hover { background: #eef6f2; }
tbody tr.row-hidden { display: none; }
.table-wrap { max-height: 640px; overflow-y: auto; overflow-x: hidden; border: 1px solid var(--border); border-radius: var(--radius-sm); }

/* Dense mode for wide data tables (report) — smaller type/padding so more columns fit without horizontal scroll */
#reportTable { table-layout: fixed; }
#reportTable th, #reportTable td { padding: 8px 8px; font-size: 12.5px; }
#reportTable th { font-size: 11.5px; line-height: 1.3; }
#reportTable td[data-label="ناوی کتێب"] { text-align: right; }

/* Below this width, 12 columns can't fit side by side — switch to a stacked card per row instead of scrolling */
@media (max-width: 900px) {
  .table-wrap { max-height: none; overflow: visible; border: none; }
  #reportTable, #reportTable thead, #reportTable tbody, #reportTable tr, #reportTable th, #reportTable td {
    display: block;
  }
  #reportTable thead { position: absolute; inset-inline-start: -9999px; }
  #reportTable tbody tr {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 10px;
    padding: 6px 10px;
    background: var(--card);
    box-shadow: var(--shadow-sm);
  }
  #reportTable tbody tr:nth-child(even) { background: var(--card); }
  #reportTable td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 7px 2px;
    border-bottom: 1px dashed var(--border);
    text-align: end;
  }
  #reportTable td:last-child { border-bottom: none; }
  #reportTable td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--muted);
    font-size: 12px;
    flex-shrink: 0;
  }
}

/* ---------- Filter bar ---------- */
.filter-bar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 4px;
}
.filter-bar .field { min-width: 200px; flex: 1; }
.filter-bar .field.grow-2 { flex-grow: 2; min-width: 240px; }
.filter-bar .field label { display: block; margin-bottom: 0; }
.search-input-wrap { position: relative; }
.search-input-wrap input { padding-inline-start: 34px; margin-bottom: 0; }
.search-input-wrap .icon {
  position: absolute; inset-inline-start: 10px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: 14px; pointer-events: none;
}
.field-actions { display: flex; align-items: center; }

/* ---------- Alerts / badges ---------- */
.alert { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.alert.success { background: var(--success-bg); color: var(--success); border: 1px solid #bfe2d1; }
.alert.error { background: var(--danger-bg); color: var(--danger); border: 1px solid #f0c6c2; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 4px 12px; border-radius: 999px; font-size: 12px; background: var(--bg-alt); color: var(--primary-dark); font-weight: 600; }
.badge.accent { background: #fbeed9; color: #8a5a13; }
.badge.muted { background: #eef1f0; color: var(--muted); }

.text-muted { color: var(--muted); }
.mb-0 { margin-bottom: 0; }
.flex { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.right { text-align: left; font-variant-numeric: tabular-nums; }

.empty-state { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty-state .icon { font-size: 34px; margin-bottom: 10px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c7d4cf; border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: #aebfb8; }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .topbar { flex-direction: column; align-items: stretch; gap: 10px; padding: 12px 16px; }
  .topbar nav { justify-content: center; }
  .topbar .user { justify-content: center; }
  .container { margin: 16px auto 40px; padding: 0 12px; }
  .card { padding: 16px; }
  .filter-bar .field { min-width: 100%; }
}
