/* ===================================================
   نظام تسجيل الزيارات — Professional Design
   =================================================== */
@import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@300;400;500;700;800&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Colors */
  --primary:        #1a6b3c;
  --primary-light:  #22875e;
  --primary-dark:   #134d2c;
  --primary-glow:   rgba(26,107,60,.15);

  --blue:   #2563eb;
  --green:  #16a34a;
  --orange: #ea580c;
  --purple: #7c3aed;
  --red:    #dc2626;

  --bg:       #f0f2f7;
  --surface:  #ffffff;
  --border:   #e2e8f0;
  --text:     #0f172a;
  --text-2:   #475569;
  --text-3:   #94a3b8;

  /* Layout */
  --sidebar-w: 260px;
  --topbar-h:  60px;
  --radius-sm: 8px;
  --radius:    14px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 4px rgba(0,0,0,.06);
  --shadow:    0 4px 20px rgba(0,0,0,.08);
  --shadow-lg: 0 8px 40px rgba(0,0,0,.12);
}

html, body {
  height: 100%;
  font-family: 'Tajawal', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  direction: rtl;
}

/* ============================
   SIDEBAR
   ============================ */
.sidebar {
  position: fixed;
  top: 0; right: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: linear-gradient(160deg, #0f2c1c 0%, #1a4a2e 60%, #1e5c38 100%);
  display: flex;
  flex-direction: column;
  z-index: 200;
  transition: transform .3s ease;
  box-shadow: -4px 0 20px rgba(0,0,0,.25);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: .8rem;
  padding: 1.4rem 1.2rem;
  border-bottom: 1px solid rgba(255,255,255,.1);
}

.logo-icon { font-size: 2rem; }

.logo-title {
  display: block;
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.2;
}
.logo-sub {
  display: block;
  color: rgba(255,255,255,.6);
  font-size: .72rem;
  margin-top: .1rem;
}
.logo-sub2 {
  display: block;
  color: rgba(255,255,255,.38);
  font-size: .65rem;
  margin-top: .1rem;
}

.sidebar-nav {
  flex: 1;
  padding: 1rem .8rem;
  display: flex;
  flex-direction: column;
  gap: .3rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .7rem 1rem;
  border-radius: var(--radius-sm);
  background: transparent;
  border: none;
  color: rgba(255,255,255,.65);
  cursor: pointer;
  font-size: .93rem;
  font-family: inherit;
  font-weight: 500;
  transition: all .2s;
  width: 100%;
  text-align: right;
}
.nav-item:hover {
  background: rgba(255,255,255,.1);
  color: #fff;
}
.nav-item.active {
  background: rgba(255,255,255,.18);
  color: #fff;
  font-weight: 700;
  box-shadow: inset 3px 0 0 #5df4a0;
}

.nav-icon { font-size: 1.1rem; }

.sidebar-footer {
  padding: 1rem 1.2rem;
  border-top: 1px solid rgba(255,255,255,.1);
  text-align: center;
}
.live-clock {
  font-size: 1.6rem;
  font-weight: 700;
  color: #5df4a0;
  letter-spacing: 3px;
  font-variant-numeric: tabular-nums;
}
.live-date {
  font-size: .75rem;
  color: rgba(255,255,255,.5);
  margin-top: .3rem;
}

/* ============================
   MAIN WRAPPER
   ============================ */
.main-wrapper {
  margin-right: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin .3s;
}

/* ============================
   TOPBAR
   ============================ */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.menu-toggle {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--text-2);
  display: none;
  padding: .3rem .55rem;
  line-height: 1;
  flex-shrink: 0;
}

.topbar-school {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: .1rem;
  min-width: 0;
}
.topbar-school-name {
  font-size: .88rem;
  font-weight: 800;
  color: var(--primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-page {
  font-size: .75rem;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-info {
  font-size: .82rem;
  color: var(--text-2);
  background: var(--bg);
  padding: .3rem .8rem;
  border-radius: 99px;
  border: 1px solid var(--border);
}

/* ============================
   PAGES
   ============================ */
.page { display: none; }
.page.active { display: block; }

.page-content {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

/* ============================
   CARDS
   ============================ */
.section-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  overflow: hidden;
}

.card-header {
  padding: 1.2rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, #f8fafc, #fff);
}
.card-title-group {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.card-icon {
  width: 48px; height: 48px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}
.card-icon.green { background: #dcfce7; }
.card-header h2 { font-size: 1.15rem; font-weight: 700; }
.card-header p  { font-size: .82rem; color: var(--text-2); margin-top: .2rem; }

.card-header-mini {
  padding: .9rem 1.2rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
}
.card-header-mini h3 { font-size: .95rem; font-weight: 700; }
.card-header-mini.between { justify-content: space-between; }

/* ============================
   INFO BANNER (تاريخ تلقائي)
   ============================ */
.info-banner {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0;
  margin: 1.2rem 1.5rem .5rem;
  background: linear-gradient(135deg, #f0fdf4, #dcfce7);
  border: 1px solid #bbf7d0;
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.info-item {
  flex: 1;
  min-width: 130px;
  padding: .8rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .25rem;
  text-align: center;
}
.info-label {
  font-size: .72rem;
  color: #166534;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.info-value {
  font-size: .95rem;
  font-weight: 700;
  color: #14532d;
}
.time-badge {
  font-size: 1.2rem;
  letter-spacing: 2px;
  color: var(--primary);
}
.info-divider {
  width: 1px;
  height: 40px;
  background: #bbf7d0;
  align-self: center;
}

/* ============================
   FORM
   ============================ */
form { padding: 0 1.5rem 1.5rem; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
  margin-top: 1.2rem;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: .45rem;
}

.field-label {
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-2);
}
.req { color: var(--red); margin-right: 2px; }

.field-input-wrap {
  display: flex;
  align-items: center;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  transition: border-color .2s, box-shadow .2s;
  overflow: hidden;
}
.field-input-wrap.flex1 { flex: 1; }
.field-input-wrap:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.field-prefix {
  padding: 0 .7rem;
  font-size: .95rem;
  color: var(--text-3);
  flex-shrink: 0;
  background: #f8fafc;
  border-left: 1px solid var(--border);
  height: 100%;
  display: flex;
  align-items: center;
  align-self: stretch;
}

.field-input {
  flex: 1;
  border: none;
  outline: none;
  padding: .6rem .85rem;
  font-size: .92rem;
  font-family: inherit;
  color: var(--text);
  background: transparent;
  direction: rtl;
  min-width: 0;
}
.field-input::placeholder { color: var(--text-3); }

select.field-input { cursor: pointer; }

/* ============================
   SIGNATURE
   ============================ */
.signature-section {
  margin-top: 1.2rem;
}

.signature-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: .5rem;
}
.sig-controls { display: flex; align-items: center; gap: .8rem; }

.sig-status-badge {
  font-size: .78rem;
  background: #dcfce7;
  color: #166534;
  padding: .15rem .6rem;
  border-radius: 99px;
  font-weight: 700;
}

.signature-canvas-wrap {
  position: relative;
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  background: #fafcff;
  overflow: hidden;
  cursor: crosshair;
}
.signature-canvas-wrap:hover { border-color: var(--primary); }

#signatureCanvas {
  display: block;
  width: 100%;
  height: 140px;
  touch-action: none;
}

.sig-hint {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  color: var(--text-3);
  font-size: .88rem;
  pointer-events: none;
  transition: opacity .2s;
}
.sig-hint.hidden { opacity: 0; }

/* ============================
   BUTTONS
   ============================ */
.btn-primary, .btn-outline, .btn-ghost, .btn-danger {
  font-family: inherit;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all .2s;
  padding: .55rem 1.2rem;
  font-size: .88rem;
  border: none;
  white-space: nowrap;
}
.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-light); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(26,107,60,.3); }
.btn-primary.btn-lg { padding: .75rem 2rem; font-size: 1rem; }

.btn-outline {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text-2);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }

.btn-ghost {
  background: none;
  border: none;
  color: var(--primary);
  font-size: .85rem;
  padding: .3rem .6rem;
}
.btn-ghost:hover { background: var(--primary-glow); border-radius: 6px; }

.btn-danger {
  background: #fee2e2;
  color: var(--red);
  border: 1px solid #fecaca;
}
.btn-danger:hover { background: var(--red); color: #fff; }

.form-footer {
  display: flex;
  gap: 1rem;
  justify-content: flex-end;
  margin-top: 1.5rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--border);
}

/* ============================
   STATS
   ============================ */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.2rem 1.4rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: transform .2s, box-shadow .2s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }

.stat-icon { font-size: 2rem; }

.stat-val {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1;
}
.stat-lbl {
  font-size: .78rem;
  color: var(--text-2);
  margin-top: .3rem;
}

.stat-card.blue  .stat-val { color: var(--blue); }
.stat-card.green .stat-val { color: var(--green); }
.stat-card.orange .stat-val { color: var(--orange); }
.stat-card.purple .stat-val { color: var(--purple); }

/* ============================
   CHARTS
   ============================ */
.charts-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1rem;
}

.chart-wrap {
  padding: 1rem;
  height: 240px;
  position: relative;
}

/* ============================
   FILTERS
   ============================ */
.filter-card { padding: 1rem 1.2rem; }
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: .7rem;
  align-items: center;
}

/* ============================
   TABLE
   ============================ */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .85rem;
}
thead tr {
  background: #f8fafc;
  border-bottom: 2px solid var(--border);
}
th {
  padding: .75rem .9rem;
  text-align: right;
  font-weight: 700;
  color: var(--text-2);
  white-space: nowrap;
}
td {
  padding: .7rem .9rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fff8; }

.empty-msg {
  text-align: center;
  padding: 2.5rem !important;
  color: var(--text-3);
  font-size: .9rem;
}

/* Status badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: .22rem .7rem;
  border-radius: 99px;
  font-size: .75rem;
  font-weight: 700;
  gap: .3rem;
}
.badge-in  { background: #dcfce7; color: #166534; }
.badge-out { background: #f1f5f9; color: #475569; }

/* Sig thumbnail */
.sig-thumb {
  width: 72px; height: 32px;
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: zoom-in;
  background: #fff;
}

.action-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  padding: .25rem .4rem;
  border-radius: 6px;
  transition: background .15s;
  color: var(--text-2);
}
.action-btn:hover { background: #fee2e2; color: var(--red); }

/* Report meta */
.report-meta {
  padding: .5rem 1rem;
  font-size: .82rem;
  color: var(--text-2);
  border-bottom: 1px solid var(--border);
  background: #fafafa;
}

/* ============================
   MODAL
   ============================ */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  z-index: 500;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: #fff;
  border-radius: var(--radius);
  padding: 1rem;
  position: relative;
  max-width: 90vw;
}
.modal-box img { max-width: 500px; width: 100%; height: auto; display: block; }
.modal-close {
  position: absolute;
  top: .5rem; left: .5rem;
  background: #f1f5f9;
  border: none;
  border-radius: 50%;
  width: 28px; height: 28px;
  cursor: pointer;
  font-size: .9rem;
  display: flex; align-items: center; justify-content: center;
}

/* ============================
   TOAST
   ============================ */
.toast {
  position: fixed;
  bottom: 1.5rem; left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #1e293b;
  color: #fff;
  padding: .75rem 1.5rem;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  z-index: 999;
  opacity: 0;
  transition: all .3s;
  pointer-events: none;
  box-shadow: var(--shadow-lg);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============================
   PRINT
   ============================ */
.print-header { display: none; }
.print-logo { font-size: 2.5rem; margin-bottom: .5rem; }

@media print {
  .sidebar, .topbar, .filter-card, .stats-row,
  .charts-row, .no-print, .action-btn,
  .btn-primary, .btn-outline, .btn-danger { display: none !important; }

  .main-wrapper { margin-right: 0 !important; }
  .page { display: block !important; }
  #page-register, #page-dashboard { display: none !important; }
  #page-reports { display: block !important; }

  .print-header {
    display: block !important;
    text-align: center;
    padding: 1rem;
    margin-bottom: 1.2rem;
    border-bottom: 3px double #000;
  }
  .print-header h1 { font-size: 1.3rem; font-weight: 800; margin-bottom: .3rem; }
  .print-header h2 { font-size: 1rem; font-weight: 600; color: #333; }
  .print-header p  { color: #666; font-size: .82rem; margin-top: .3rem; }

  body { background: #fff; font-size: 11pt; }
  .section-card { box-shadow: none; border: none; }
  table { font-size: 9pt; }
  th, td { padding: .4rem .5rem !important; }
}

/* ============================
   RESPONSIVE
   ============================ */
/* Sidebar overlay for mobile */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 199;
  backdrop-filter: blur(1px);
}
.sidebar-overlay.visible { display: block; }

body.sidebar-open { overflow: hidden; }

@media (max-width: 768px) {
  /* --- Sidebar --- */
  .sidebar {
    transform: translateX(110%);
    box-shadow: none;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: -6px 0 30px rgba(0,0,0,.35);
  }

  /* --- Main layout --- */
  .main-wrapper { margin-right: 0; }
  .menu-toggle { display: flex; align-items: center; justify-content: center; }

  /* --- Topbar --- */
  .topbar { padding: 0 .9rem; gap: .7rem; }
  .topbar-school-name { font-size: .8rem; }
  .topbar-info { display: none; }

  /* --- Form --- */
  .form-grid { grid-template-columns: 1fr; }
  .page-content { padding: .9rem; gap: .9rem; }
  form { padding: 0 .9rem .9rem; }
  .card-header { padding: 1rem; }
  .card-header-mini { padding: .75rem 1rem; }
  .form-footer { flex-direction: column-reverse; gap: .7rem; }
  .form-footer .btn-primary,
  .form-footer .btn-outline { width: 100%; text-align: center; }

  /* --- Info banner --- */
  .info-banner {
    flex-direction: column;
    margin: .9rem .9rem .4rem;
  }
  .info-divider { display: none; }
  .info-item {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    padding: .6rem .9rem;
    border-bottom: 1px solid #bbf7d0;
  }
  .info-item:last-child { border-bottom: none; }
  .info-label { font-size: .78rem; }
  .info-value { font-size: .9rem; }

  /* --- Signature --- */
  .signature-section { margin-top: 1rem; }
  #signatureCanvas { height: 120px; }

  /* --- Stats --- */
  .stats-row { grid-template-columns: 1fr 1fr; gap: .7rem; }
  .stat-card { padding: 1rem; gap: .75rem; }
  .stat-icon { font-size: 1.6rem; }
  .stat-val { font-size: 1.6rem; }

  /* --- Charts --- */
  .charts-row { grid-template-columns: 1fr; }
  .chart-wrap { height: 200px; }

  /* --- Filters --- */
  .filter-card { padding: .85rem; }
  .filter-row { flex-direction: column; }
  .filter-row .field-input-wrap,
  .filter-row select.field-input,
  .filter-row .btn-outline,
  .filter-row .btn-primary { width: 100%; }

  /* --- Table --- */
  .table-wrap { -webkit-overflow-scrolling: touch; }
  th, td { padding: .6rem .55rem; font-size: .8rem; }
}

@media (max-width: 480px) {
  :root { --topbar-h: 52px; }
  .topbar { padding: 0 .7rem; gap: .5rem; }
  .topbar-school-name { font-size: .73rem; }
  .page-content { padding: .65rem; gap: .65rem; }
  form { padding: 0 .65rem .65rem; }
  .info-banner { margin: .75rem .65rem .3rem; }
  .card-header { padding: .85rem; }
  .card-header h2 { font-size: 1rem; }
  .card-header p { font-size: .76rem; }
  .section-card { border-radius: var(--radius-sm); }
  .stats-row { gap: .5rem; }
  .stat-card { padding: .7rem .8rem; gap: .6rem; }
  .stat-val { font-size: 1.35rem; }
  .stat-icon { font-size: 1.3rem; }
  .stat-lbl { font-size: .7rem; }
  .btn-primary.btn-lg { font-size: .92rem; padding: .7rem 1rem; }
  .filter-card { padding: .65rem; }
  th, td { padding: .5rem .4rem; font-size: .75rem; }
}
