/* deJournal - mobile-first UI */
:root {
  --p: #0f766e; --p-dark: #115e59; --p-light: #ccfbf1;
  --acc: #f59e0b; --bg: #f1f5f9; --card: #ffffff;
  --txt: #0f172a; --mut: #64748b; --line: #e2e8f0;
  --danger: #dc2626; --ok: #16a34a;
  --r: 14px; --sh: 0 1px 3px rgba(15, 23, 42, .08), 0 4px 14px rgba(15, 23, 42, .06);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Noto Sans", "Noto Sans Arabic", sans-serif;
  background: var(--bg); color: var(--txt); font-size: 15px; line-height: 1.45;
}
[dir="rtl"] body { font-family: "Segoe UI", system-ui, "Noto Naskh Arabic", Tahoma, sans-serif; }
h1, h2, h3 { margin: .2em 0 .4em; font-weight: 700; }
a { color: var(--p); text-decoration: none; }
button { font: inherit; cursor: pointer; }
input, select, textarea {
  font: inherit; width: 100%; padding: 10px 12px; border: 1.5px solid var(--line);
  border-radius: 10px; background: #fff; color: var(--txt); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--p); }
label { display: block; font-size: 13px; color: var(--mut); margin: 10px 0 4px; font-weight: 600; }

.splash { height: 100vh; display: flex; flex-direction: column; gap: 12px; align-items: center; justify-content: center; color: var(--p); font-weight: 700; }
.splash-logo { width: 64px; height: 64px; border-radius: 18px; background: var(--p); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 26px; }

/* layout */
.wrap { max-width: 1080px; margin: 0 auto; padding: 14px; padding-bottom: 84px; }
.topbar {
  position: sticky; top: 0; z-index: 30; background: var(--p); color: #fff;
  padding: 10px 14px; display: flex; align-items: center; gap: 10px; box-shadow: var(--sh);
}
.topbar .tb-title { font-weight: 700; flex: 1; min-width: 0; }
.topbar .tb-title small { display: block; font-weight: 400; opacity: .85; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .icon-btn { background: rgba(255,255,255,.14); color: #fff; border: none; border-radius: 10px; padding: 8px 10px; font-size: 14px; }
.topbar .icon-btn:active { background: rgba(255,255,255,.3); }
.badge-sync { font-size: 11px; background: var(--acc); color: #78350f; border-radius: 999px; padding: 2px 8px; font-weight: 700; }

.card { background: var(--card); border-radius: var(--r); box-shadow: var(--sh); padding: 16px; margin-bottom: 14px; }
.card h2 { font-size: 17px; margin-top: 0; }
.muted { color: var(--mut); font-size: 13px; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1.5px solid var(--line); background: #fff; color: var(--txt);
  border-radius: 12px; padding: 11px 16px; font-weight: 600; text-decoration: none;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--p); border-color: var(--p); color: #fff; }
.btn.dark { background: var(--p-dark); border-color: var(--p-dark); color: #fff; }
.btn.danger { background: #fff; border-color: var(--danger); color: var(--danger); }
.btn.block { width: 100%; }
.btn.big { padding: 14px 18px; font-size: 16px; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn-row { display: flex; gap: 10px; margin-top: 14px; }
.btn-row .btn { flex: 1; }

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1.5px solid var(--line); background: #fff; border-radius: 999px; padding: 9px 14px; font-weight: 600; font-size: 14px; }
.chip.on { background: var(--p); border-color: var(--p); color: #fff; }

/* school grid */
.schools-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; margin-top: 12px; }
.school-card { background: #fff; border: 2px solid var(--line); border-radius: var(--r); padding: 16px 10px; text-align: center; cursor: pointer; }
.school-card:active, .school-card.on { border-color: var(--p); background: var(--p-light); }
.school-card img, .school-card .ph-logo { width: 56px; height: 56px; border-radius: 12px; object-fit: contain; background: var(--bg); }
.ph-logo { display: inline-flex; align-items: center; justify-content: center; font-weight: 800; color: var(--p); font-size: 20px; }

/* class grid 3x4 */
.class-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.class-card {
  background: #fff; border: 2px solid var(--line); border-radius: var(--r); padding: 14px 8px;
  text-align: center; cursor: pointer; position: relative; min-height: 86px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.class-card:active { border-color: var(--p); background: var(--p-light); }
.class-card b { font-size: 15px; }
.class-card small { color: var(--mut); font-size: 11.5px; }
.class-card .dot { position: absolute; top: 8px; right: 8px; width: 9px; height: 9px; border-radius: 50%; background: var(--ok); }

/* step indicator */
.steps { display: flex; gap: 6px; margin: 4px 0 12px; }
.steps span { flex: 1; height: 5px; border-radius: 3px; background: var(--line); }
.steps span.on { background: var(--p); }

/* slider jam pelajaran */
.slider-wrap { position: relative; height: 320px; border-radius: var(--r); background: #fff; box-shadow: var(--sh); overflow: hidden; }
.slider-center { position: absolute; top: 50%; left: 8px; right: 8px; transform: translateY(-50%); height: 64px; border: 2px dashed var(--p); border-radius: 12px; pointer-events: none; z-index: 2; }
.slider { height: 100%; overflow-y: auto; scroll-snap-type: y mandatory; scrollbar-width: none; }
.slider::-webkit-scrollbar { display: none; }
.slider .spacer { height: 128px; scroll-snap-align: center; }
.p-item { height: 64px; scroll-snap-align: center; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--mut); transition: color .15s; cursor: pointer; }
.p-item b { font-size: 16px; color: inherit; }
.p-item.sel { color: var(--p); font-weight: 800; }
.slider-time { position: absolute; bottom: 8px; left: 0; right: 0; text-align: center; font-size: 12px; color: var(--p); font-weight: 700; z-index: 3; }

/* attendance */
.att-row { display: flex; align-items: center; gap: 8px; padding: 10px 4px; border-bottom: 1px solid var(--line); }
.att-row:last-child { border-bottom: none; }
.att-info { flex: 1; min-width: 0; }
.att-info b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att-info small { color: var(--mut); font-size: 12px; }
.att-btns { display: flex; gap: 6px; align-items: center; }
.att-btns button { width: 42px; height: 38px; border-radius: 10px; border: 2px solid var(--line); background: #fff; font-weight: 800; font-size: 14px; }
.att-btns .h.on { background: var(--ok); border-color: var(--ok); color: #fff; }
.att-btns .i.on { background: var(--acc); border-color: var(--acc); color: #78350f; }
.att-reason { font-size: 11px; color: var(--acc); font-weight: 700; max-width: 64px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att-summary { display: flex; gap: 10px; margin-bottom: 8px; }
.att-summary .sum { flex: 1; background: #fff; border-radius: 12px; box-shadow: var(--sh); padding: 10px; text-align: center; }
.att-summary .sum b { font-size: 22px; display: block; }
.att-summary .sum.ok b { color: var(--ok); }
.att-summary .sum.warn b { color: var(--acc); }

/* modal & toast */
.modal-back { position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal { background: #fff; border-radius: 18px 18px 0 0; width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto; padding: 18px; animation: up .18s ease; }
@keyframes up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
.modal h3 { margin-top: 0; }
.toasts { position: fixed; top: 12px; left: 0; right: 0; z-index: 99; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { background: #0f172a; color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 13.5px; box-shadow: var(--sh); max-width: 90%; }
.toast.ok { background: var(--ok); }
.toast.err { background: var(--danger); }

/* keypad */
.pin-dots { display: flex; gap: 14px; justify-content: center; margin: 18px 0; }
.pin-dots span { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--p); }
.pin-dots span.f { background: var(--p); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; max-width: 320px; margin: 0 auto; }
.keypad button { height: 58px; border-radius: 14px; border: none; background: #fff; box-shadow: var(--sh); font-size: 22px; font-weight: 700; }
.keypad button:active { background: var(--p-light); }
.keypad button.ctl { font-size: 15px; color: var(--p); }

/* admin layout */
.admin-body { display: flex; min-height: 100vh; }
.side {
  width: 220px; background: #0f172a; color: #cbd5e1; padding: 14px 8px; position: sticky; top: 0;
  height: 100vh; overflow-y: auto; flex-shrink: 0; display: none;
}
.side .brand { color: #fff; font-weight: 800; padding: 8px 10px 14px; font-size: 17px; }
.side a { display: block; color: inherit; padding: 9px 12px; border-radius: 10px; margin: 2px 0; font-size: 14px; }
.side a.on, .side a:hover { background: #1e293b; color: #fff; }
.main { flex: 1; padding: 16px; min-width: 0; }
@media (min-width: 900px) {
  .side { display: block; }
  .admin-top { display: none !important; }
  .wrap { padding-bottom: 20px; }
}
.admin-top { position: sticky; top: 0; z-index: 30; background: var(--p); color: #fff; padding: 10px 14px; display: flex; align-items: center; gap: 10px; box-shadow: var(--sh); }
.tabs { display: flex; gap: 8px; overflow-x: auto; padding: 10px 0; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { flex-shrink: 0; border: 1.5px solid var(--line); background: #fff; border-radius: 999px; padding: 7px 14px; font-size: 13px; font-weight: 600; color: var(--txt); }
.tabs a.on { background: var(--p); color: #fff; border-color: var(--p); }

/* tables */
.tbl-wrap { overflow-x: auto; background: #fff; border-radius: var(--r); box-shadow: var(--sh); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 480px; }
.tbl th, .tbl td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
[dir="rtl"] .tbl th, [dir="rtl"] .tbl td { text-align: right; }
.tbl th { background: #f8fafc; color: var(--mut); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; position: sticky; top: 0; }
.tbl tr:last-child td { border-bottom: none; }
.tbl .actions { display: flex; gap: 6px; }
.tbl .actions button { border: none; background: var(--bg); border-radius: 8px; padding: 5px 9px; font-size: 12px; font-weight: 700; }
.tbl .actions button.del { color: var(--danger); }
.tag { display: inline-block; border-radius: 999px; padding: 2px 9px; font-size: 11.5px; font-weight: 700; }
.tag.ok { background: #dcfce7; color: #166534; }
.tag.warn { background: #fef3c7; color: #92400e; }
.tag.off { background: #e2e8f0; color: #475569; }

/* stats */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 700px) { .stat-grid { grid-template-columns: repeat(4, 1fr); } }
.stat { background: #fff; border-radius: var(--r); box-shadow: var(--sh); padding: 14px; }
.stat b { font-size: 26px; display: block; color: var(--p); }
.stat span { color: var(--mut); font-size: 12.5px; }

/* forms */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.form-grid .full { grid-column: 1 / -1; }
.search-row { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.search-row input, .search-row select { width: auto; flex: 1; min-width: 130px; }

/* journal list */
.j-item { background: #fff; border-radius: var(--r); box-shadow: var(--sh); padding: 13px 15px; margin-bottom: 10px; cursor: pointer; display: flex; gap: 10px; align-items: center; }
.j-date { background: var(--p-light); color: var(--p-dark); border-radius: 10px; padding: 6px 10px; text-align: center; font-weight: 800; min-width: 52px; }
.j-date small { display: block; font-weight: 600; font-size: 10.5px; }
.j-info { flex: 1; min-width: 0; }
.j-info b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* print */
.print-doc { background: #fff; max-width: 800px; margin: 0 auto; padding: 24px; }
.print-head { display: flex; gap: 14px; align-items: center; border-bottom: 3px double #333; padding-bottom: 10px; margin-bottom: 12px; }
.print-head img { width: 60px; height: 60px; object-fit: contain; }
@media print {
  body { background: #fff; }
  .no-print { display: none !important; }
  .print-doc { padding: 0; }
  table.tbl { min-width: 0; }
  .tbl th { position: static; }
}
.center { text-align: center; }
.right { text-align: right; }
.mt { margin-top: 14px; }
.flex { display: flex; gap: 10px; align-items: center; }
.grow { flex: 1; }
