/* ==========================================================================
   RT RW Web — stylesheet utama
   Desain modern, responsive (mobile drawer), dark mode, PWA-friendly
   ========================================================================== */

:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #94a3b8;
  --primary: #0f766e;
  --primary-2: #0d9488;
  --primary-soft: #ccfbf1;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warning: #d97706;
  --warning-soft: #fef3c7;
  --success: #16a34a;
  --success-soft: #dcfce7;
  --info: #2563eb;
  --info-soft: #dbeafe;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .07), 0 4px 14px rgba(15, 23, 42, .05);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, .14);
  --sidebar-w: 264px;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #111a2e;
  --surface-2: #16213a;
  --border: #24314f;
  --text: #e2e8f0;
  --text-2: #94a3b8;
  --text-3: #64748b;
  --primary: #14b8a6;
  --primary-2: #2dd4bf;
  --primary-soft: #0f3d3a;
  --danger: #f87171;
  --danger-soft: #3b1a1a;
  --warning: #fbbf24;
  --warning-soft: #3a2e10;
  --success: #4ade80;
  --success-soft: #14331f;
  --info: #60a5fa;
  --info-soft: #172a44;
  --shadow: 0 1px 3px rgba(0, 0, 0, .35), 0 4px 14px rgba(0, 0, 0, .3);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, .5);
}

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

html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  transition: background .25s, color .25s;
}

a { color: var(--primary-2); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }

/* ============ LOGIN ============ */
.login-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f766e 0%, #0e7490 55%, #1e3a8a 100%);
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 36px 32px;
  animation: rise .4s ease;
}
.login-logo {
  width: 64px; height: 64px;
  border-radius: 16px;
  margin: 0 auto 14px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff; font-size: 22px; font-weight: 800;
}
.login-card h1 { text-align: center; font-size: 22px; margin-bottom: 4px; }
.login-card .sub { text-align: center; color: var(--text-2); font-size: 13px; margin-bottom: 24px; }
.demo-box {
  background: var(--info-soft); border: 1px dashed var(--info);
  color: var(--info); border-radius: var(--radius-sm);
  padding: 10px 12px; font-size: 12.5px; margin-bottom: 18px;
}
.demo-box b { display: block; margin-bottom: 2px; }

/* ============ LAYOUT ============ */
.layout { display: flex; min-height: 100dvh; }
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: fixed; inset: 0 auto 0 0;
  display: flex; flex-direction: column;
  z-index: 50;
  transition: transform .28s ease;
}
.brand {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border);
}
.brand-logo {
  width: 40px; height: 40px; border-radius: 11px; flex: none;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; font-size: 13px;
}
.brand b { display: block; font-size: 15px; line-height: 1.2; }
.brand span { font-size: 11.5px; color: var(--text-3); }

.nav { flex: 1; overflow-y: auto; padding: 10px 10px; }
.nav-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); padding: 14px 10px 6px; font-weight: 700; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: 10px;
  color: var(--text-2); font-weight: 500; font-size: 14px;
  margin-bottom: 2px; border: none; background: none; width: 100%; text-align: left;
  transition: background .15s, color .15s;
}
.nav-item svg { width: 19px; height: 19px; flex: none; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-item .badge-dot { margin-left: auto; }

.sidebar-foot { padding: 14px; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px;
}
.user-chip b { display: block; font-size: 13.5px; line-height: 1.2; }
.user-chip span { font-size: 11.5px; color: var(--text-3); }

.main { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 0 22px; height: 60px;
  display: flex; align-items: center; gap: 14px;
}
.menu-btn { display: none; background: none; border: 1px solid var(--border); border-radius: 9px; padding: 7px 9px; color: var(--text); }
.topbar h2 { font-size: 17px; font-weight: 700; }
.topbar .spacer { flex: 1; }
.icon-btn {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 9px; padding: 8px; color: var(--text-2);
  display: inline-flex; align-items: center; justify-content: center;
  transition: .15s;
}
.icon-btn:hover { color: var(--primary); border-color: var(--primary); }
.icon-btn svg { width: 18px; height: 18px; }

.content { padding: 24px; max-width: 1240px; width: 100%; margin: 0 auto; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h2 { font-size: 20px; }
.page-head p { color: var(--text-2); font-size: 13.5px; margin-top: 2px; }
.page-head .spacer { flex: 1; }

/* ============ OVERLAY ============ */
.overlay {
  position: fixed; inset: 0; background: rgba(2, 6, 23, .5);
  z-index: 49; opacity: 0; pointer-events: none; transition: opacity .25s;
}
.overlay.show { opacity: 1; pointer-events: auto; }

/* ============ CARDS & GRID ============ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card + .card { margin-top: 18px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.card-head h3 { font-size: 15.5px; font-weight: 700; }
.card-head .spacer { flex: 1; }

.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }

.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px;
  display: flex; align-items: flex-start; gap: 14px;
}
.stat-ico {
  width: 44px; height: 44px; border-radius: 12px; flex: none;
  display: flex; align-items: center; justify-content: center;
}
.stat-ico svg { width: 22px; height: 22px; }
.stat-card b { display: block; font-size: 21px; line-height: 1.15; }
.stat-card .lbl { font-size: 12.5px; color: var(--text-2); margin-top: 2px; }
.stat-card .hint { font-size: 11.5px; color: var(--text-3); margin-top: 4px; }
.t-green { background: var(--success-soft); color: var(--success); }
.t-red { background: var(--danger-soft); color: var(--danger); }
.t-blue { background: var(--info-soft); color: var(--info); }
.t-amber { background: var(--warning-soft); color: var(--warning); }
.t-teal { background: var(--primary-soft); color: var(--primary); }

/* ============ TABLES ============ */
.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th {
  text-align: left; padding: 10px 12px;
  color: var(--text-3); font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em;
  border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap;
}
.tbl td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.row-actions { display: inline-flex; gap: 6px; }
.mini-btn {
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 7px; padding: 5px 9px; font-size: 12px; color: var(--text-2);
  display: inline-flex; align-items: center; gap: 5px; transition: .15s;
}
.mini-btn:hover { color: var(--primary); border-color: var(--primary); }
.mini-btn.danger:hover { color: var(--danger); border-color: var(--danger); }

/* ============ BADGES & BUTTONS ============ */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.b-green { background: var(--success-soft); color: var(--success); }
.b-red { background: var(--danger-soft); color: var(--danger); }
.b-amber { background: var(--warning-soft); color: var(--warning); }
.b-blue { background: var(--info-soft); color: var(--info); }
.b-teal { background: var(--primary-soft); color: var(--primary); }
.b-gray { background: var(--surface-2); color: var(--text-3); border: 1px solid var(--border); }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 16px; border-radius: 10px;
  font-size: 14px; font-weight: 600; border: 1px solid transparent;
  transition: filter .15s, transform .05s, background .15s;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-2); }
.btn-outline { background: var(--surface); border-color: var(--border); color: var(--text-2); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.1); }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 8px; }
.btn svg { width: 16px; height: 16px; }

/* ============ FORM ============ */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft);
}
.field textarea { min-height: 96px; resize: vertical; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hint-txt { font-size: 11.5px; color: var(--text-3); margin-top: 5px; }

.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.search-input {
  position: relative; flex: 1; min-width: 200px; max-width: 340px;
}
.search-input svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-3); }
.search-input input {
  width: 100%; padding: 9px 12px 9px 34px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text);
}
.search-input input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

/* ============ MODAL ============ */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(2, 6, 23, .55);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 18px; opacity: 0; pointer-events: none; transition: opacity .2s;
}
.modal-backdrop.show { opacity: 1; pointer-events: auto; }
.modal {
  background: var(--surface); border-radius: 16px;
  width: 100%; max-width: 560px; max-height: 92dvh; overflow-y: auto;
  box-shadow: var(--shadow-lg); padding: 22px;
  transform: translateY(10px) scale(.98); transition: transform .2s;
}
.modal-backdrop.show .modal { transform: none; }
.modal-head { display: flex; align-items: center; margin-bottom: 16px; }
.modal-head h3 { font-size: 17px; flex: 1; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.modal-xl { max-width: 860px; }

/* ============ TOAST ============ */
#toast-root { position: fixed; top: 16px; right: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--surface); border: 1px solid var(--border);
  border-left: 4px solid var(--primary); border-radius: 10px;
  box-shadow: var(--shadow-lg); padding: 12px 16px;
  font-size: 13.5px; min-width: 240px; max-width: 360px;
  display: flex; gap: 10px; align-items: flex-start;
  animation: slide-in .25s ease;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warning); }
.toast .t-ico { font-size: 16px; line-height: 1.3; }

/* ============ FEED / LIST ============ */
.feed-item {
  display: flex; gap: 14px; padding: 16px 0;
  border-bottom: 1px solid var(--border);
}
.feed-item:last-child { border-bottom: none; }
.feed-ico {
  width: 40px; height: 40px; border-radius: 11px; flex: none;
  display: flex; align-items: center; justify-content: center; font-size: 18px;
}
.feed-item h4 { font-size: 14.5px; margin-bottom: 3px; }
.feed-item p { font-size: 13px; color: var(--text-2); }
.feed-meta { display: flex; gap: 10px; align-items: center; margin-top: 6px; font-size: 11.5px; color: var(--text-3); flex-wrap: wrap; }
.feed-body { flex: 1; min-width: 0; }

.pin-flag { color: var(--warning); font-size: 13px; }

/* ============ AGENDA TIMELINE ============ */
.agenda-item {
  display: flex; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--border);
}
.agenda-item:last-child { border-bottom: none; }
.agenda-date {
  flex: none; width: 54px; text-align: center;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 7px 4px;
}
.agenda-date .d { font-size: 18px; font-weight: 800; line-height: 1; color: var(--primary); }
.agenda-date .m { font-size: 10px; text-transform: uppercase; color: var(--text-3); font-weight: 700; }
.agenda-body { flex: 1; }
.agenda-body h4 { font-size: 14px; }

/* ============ DONUT / CHART ============ */
.chart-box { position: relative; display: flex; align-items: center; justify-content: center; }
.donut-center {
  position: absolute; text-align: center;
}
.donut-center b { display: block; font-size: 22px; }
.donut-center span { font-size: 11px; color: var(--text-3); }
.legend { display: flex; flex-direction: column; gap: 7px; margin-top: 12px; }
.legend-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-2); }
.legend-row .sw { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.legend-row .val { margin-left: auto; font-weight: 600; color: var(--text); }

/* ============ PATROL / GATE ============ */
.pos-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 8px;
}
.pos-card .pos-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.pos-card h4 { font-size: 14.5px; }
.pos-card .code { font-family: ui-monospace, monospace; font-size: 12px; color: var(--text-3); }
.pos-card .stat-row { display: flex; gap: 14px; font-size: 12px; color: var(--text-2); }
.qr-view { text-align: center; padding: 10px; }
.qr-box {
  width: 200px; height: 200px; margin: 0 auto 12px;
  border: 2px dashed var(--border); border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-3); overflow: hidden; position: relative;
}
.qr-box video { width: 100%; height: 100%; object-fit: cover; }

.status-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-green { background: var(--success); }
.dot-red { background: var(--danger); }
.dot-amber { background: var(--warning); }

.empty {
  text-align: center; padding: 36px 16px; color: var(--text-3);
}
.empty svg { width: 42px; height: 42px; opacity: .4; margin-bottom: 10px; }
.empty p { font-size: 13.5px; }

/* ============ PORTAL PUBLIK WARGA ============ */
.pub-wrap { min-height: 100dvh; display: flex; flex-direction: column; }
.pub-header {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 12px 20px; display: flex; align-items: center; gap: 16px;
  position: sticky; top: 0; z-index: 40; box-shadow: var(--shadow);
}
.pub-brand { display: flex; align-items: center; gap: 10px; }
.pub-brand b { display: block; font-size: 15px; }
.pub-brand span { font-size: 11.5px; color: var(--text-3); }
.pub-nav { display: flex; gap: 4px; flex-wrap: wrap; }
.pub-nav a {
  padding: 7px 12px; border-radius: 8px; font-size: 13px; color: var(--text-2);
  transition: background .15s, color .15s;
}
.pub-nav a:hover { background: var(--surface-2); color: var(--text); }
.pub-nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.pub-user { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; }
.pub-content { flex: 1; max-width: 1080px; width: 100%; margin: 0 auto; padding: 24px 20px 40px; }
.pub-footer {
  text-align: center; padding: 18px; font-size: 12px; color: var(--text-3);
  border-top: 1px solid var(--border); background: var(--surface);
}
.hero-card {
  background: linear-gradient(135deg, #0f766e 0%, #0e7490 60%, #1e3a8a 100%);
  color: #fff; border-radius: var(--radius); padding: 28px 24px;
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  box-shadow: var(--shadow-lg);
}
.hero-card h1 { font-size: 22px; margin-bottom: 6px; }
.hero-card p { font-size: 13.5px; opacity: .85; }
.hero-badge {
  background: rgba(255, 255, 255, .15); border: 1px solid rgba(255, 255, 255, .3);
  border-radius: 999px; padding: 8px 14px; font-size: 12px; white-space: nowrap;
}
.action-card { display: flex; align-items: center; gap: 14px; transition: transform .15s, box-shadow .15s; }
.action-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.action-card > svg { width: 20px; height: 20px; color: var(--text-3); flex: none; }
.contact-row { padding: 8px 0; font-size: 13.5px; border-bottom: 1px dashed var(--border); }
.contact-row:last-child { border-bottom: 0; }
.chk-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.chk-item {
  display: flex; align-items: center; gap: 7px; font-size: 13px; padding: 7px 9px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); cursor: pointer;
}
.chk-item .code { font-family: ui-monospace, monospace; font-size: 11px; color: var(--text-3); }

@media (max-width: 768px) {
  .pub-header { flex-wrap: wrap; padding: 10px 14px; }
  .pub-nav { order: 3; width: 100%; overflow-x: auto; }
  .hero-card { flex-direction: column; align-items: flex-start; }
  .chk-grid { grid-template-columns: 1fr; }
}

/* ============ SCROLLBAR ============ */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ============ RESPONSIVE ============ */
@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
  .sidebar { transform: translateX(-105%); box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .main { margin-left: 0; }
  .menu-btn { display: inline-flex; }
  .content { padding: 16px; }
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .field-row { grid-template-columns: 1fr; }
  .toolbar .btn span { display: none; }
}
@media (max-width: 520px) {
  .grid-4 { grid-template-columns: 1fr; }
  .login-card { padding: 28px 20px; }
  .topbar { padding: 0 14px; }
  .page-head h2 { font-size: 17px; }
}

/* ============ ANIMATIONS ============ */
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes slide-in { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }
.fade-in { animation: rise .3s ease; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}