:root {
  --primary: #0d9488;
  --primary-dark: #0f766e;
  --primary-light: #14b8a6;
  --accent: #0ea5e9;
  --bg: #f1f5f9;
  --sidebar-w: 256px;
  --sidebar-w-collapsed: 76px;
  --sidebar-bg: linear-gradient(180deg, #0f766e 0%, #0d9488 60%, #0b7a6e 100%);
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, .08);
  --shadow: 0 4px 16px rgba(15, 23, 42, .06);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, .10);
  --radius: 14px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }

body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: #1e293b;
  margin: 0;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary-dark); text-decoration: none; }
a:hover { color: var(--primary); }

/* ============ LAYOUT ============ */
.app {
  display: flex;
  min-height: 100vh;
}

/* ============ SIDEBAR ============ */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: #e2e8f0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 1040;
  transition: width .25s ease;
  box-shadow: 4px 0 24px rgba(15, 23, 42, .10);
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,.10);
  white-space: nowrap;
  overflow: hidden;
}
.sidebar-brand .logo {
  width: 38px; height: 38px;
  flex: 0 0 38px;
  background: rgba(255,255,255,.15);
  border-radius: 10px;
  display: grid; place-items: center;
  color: #fff;
}
.sidebar-brand .logo svg { width: 22px; height: 22px; }
.sidebar-brand .name {
  font-weight: 700;
  font-size: 1.02rem;
  line-height: 1.2;
  color: #fff;
}
.sidebar-brand .sub {
  font-size: .72rem;
  color: rgba(255,255,255,.65);
  letter-spacing: .04em;
  text-transform: uppercase;
}

.sidebar-nav {
  flex: 1;
  padding: 14px 12px;
  overflow-y: auto;
  overflow-x: hidden;
}
.sidebar-nav .nav-label {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: rgba(255,255,255,.45);
  padding: 12px 14px 6px;
  white-space: nowrap;
}
.sidebar-nav .nav-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 11px 14px;
  border-radius: 10px;
  color: rgba(255,255,255,.82);
  font-size: .92rem;
  font-weight: 500;
  margin-bottom: 2px;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.sidebar-nav .nav-item .icon {
  width: 22px; flex: 0 0 22px;
  display: grid; place-items: center;
  font-size: 1.1rem;
}
.sidebar-nav .nav-item:hover {
  background: rgba(255,255,255,.10);
  color: #fff;
}
.sidebar-nav .nav-item.active {
  background: rgba(255,255,255,.16);
  color: #fff;
  box-shadow: inset 3px 0 0 #fff;
}
.sidebar-nav .nav-item .text { transition: opacity .15s; }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid rgba(255,255,255,.10);
}
.sidebar-footer .user-mini {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255,255,255,.08);
  white-space: nowrap;
  overflow: hidden;
}
.sidebar-footer .avatar {
  width: 34px; height: 34px;
  flex: 0 0 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: #78350f;
  font-weight: 700;
  display: grid; place-items: center;
  font-size: .85rem;
}
.sidebar-footer .user-mini .uname {
  font-size: .85rem; font-weight: 600; color: #fff;
  line-height: 1.2;
}
.sidebar-footer .user-mini .urole {
  font-size: .7rem; color: rgba(255,255,255,.6);
}

/* Collapsed */
.app.sidebar-collapsed .sidebar { width: var(--sidebar-w-collapsed); }
.app.sidebar-collapsed .sidebar .name,
.app.sidebar-collapsed .sidebar .sub,
.app.sidebar-collapsed .sidebar .nav-label,
.app.sidebar-collapsed .sidebar .nav-item .text,
.app.sidebar-collapsed .sidebar .user-mini .uname,
.app.sidebar-collapsed .sidebar .user-mini .urole { opacity: 0; }
.app.sidebar-collapsed .main { margin-left: var(--sidebar-w-collapsed); }

/* ============ MAIN ============ */
.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-width: 0;
  transition: margin-left .25s ease;
}
.topbar {
  background: #fff;
  height: 64px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 1030;
  box-shadow: var(--shadow-sm);
}
.topbar .btn-toggle {
  width: 40px; height: 40px;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  background: #fff;
  color: #475569;
  display: grid; place-items: center;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.topbar .btn-toggle:hover { background: #f8fafc; color: var(--primary); }
.topbar .page-title { font-size: 1.15rem; font-weight: 700; margin: 0; color: #0f172a; }
.topbar .page-sub { font-size: .78rem; color: #94a3b8; margin: 0; }
.topbar .spacer { flex: 1; }
.topbar .topbar-user {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px 6px 6px;
  border-radius: 999px;
  background: #f1f5f9;
  cursor: pointer;
}
.topbar .topbar-user .avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff; font-weight: 700; font-size: .8rem;
  display: grid; place-items: center;
}
.topbar .topbar-user .uname { font-size: .86rem; font-weight: 600; color: #1e293b; }

.content {
  padding: 24px;
  flex: 1;
}

/* ============ CARDS ============ */
.card {
  border: none;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background: #fff;
}
.card-header {
  background: transparent;
  border-bottom: 1px solid #f1f5f9;
  padding: 18px 22px;
  font-weight: 700;
  color: #0f172a;
}
.card-body { padding: 22px; }

/* Stat cards */
.stat-card {
  border-radius: var(--radius);
  padding: 20px;
  background: #fff;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 16px;
  border: 1px solid #f1f5f9;
  height: 100%;
  transition: transform .15s, box-shadow .15s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.stat-card .icon {
  width: 52px; height: 52px;
  border-radius: 14px;
  display: grid; place-items: center;
  font-size: 1.4rem;
  color: #fff;
  flex: 0 0 52px;
}
.stat-card .stat-val { font-size: 1.7rem; font-weight: 800; line-height: 1; color: #0f172a; }
.stat-card .stat-lbl { font-size: .82rem; color: #64748b; margin-top: 4px; }
.bg-teal   { background: linear-gradient(135deg, #0d9488, #14b8a6); }
.bg-blue   { background: linear-gradient(135deg, #0ea5e9, #38bdf8); }
.bg-amber  { background: linear-gradient(135deg, #f59e0b, #fbbf24); }
.bg-violet { background: linear-gradient(135deg, #8b5cf6, #a78bfa); }

/* ============ BUTTONS ============ */
.btn { border-radius: 10px; font-weight: 600; padding: 9px 16px; }
.btn-sm { padding: 6px 12px; font-size: .82rem; }
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-gradient {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border: none;
  color: #fff;
}
.btn-gradient:hover { color: #fff; filter: brightness(1.05); }
.btn-icon {
  width: 36px; height: 36px;
  padding: 0;
  display: inline-grid; place-items: center;
  border-radius: 9px;
}

/* ============ TABLE ============ */
.table-card { overflow: hidden; }
.table { margin: 0; }
.table thead th {
  background: #f8fafc;
  color: #64748b;
  font-size: .74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  border: none;
  padding: 14px 18px;
  position: sticky; top: 0;
}
.table tbody td {
  padding: 14px 18px;
  vertical-align: middle;
  border-color: #f1f5f9;
  color: #334155;
}
.table tbody tr:hover { background: #f8fafc; }
.table tbody tr:nth-child(even) { background: #fbfcfd; }

/* ============ BADGE ============ */
.badge-jenis {
  padding: 5px 11px;
  border-radius: 999px;
  font-size: .74rem;
  font-weight: 600;
  display: inline-block;
}
.bj-masuk     { background: #dbeafe; color: #1e40af; }
.bj-keluar    { background: #fef3c7; color: #92400e; }
.bj-undangan  { background: #ede9fe; color: #5b21b6; }
.bj-edaran    { background: #d1fae5; color: #065f46; }
.bj-tugas     { background: #fce7f3; color: #9d174d; }
.bj-dispensasi{ background: #ffedd5; color: #9a3412; }
.bj-lain      { background: #e2e8f0; color: #334155; }

/* ============ FORM ============ */
.form-control, .form-select {
  border-radius: 10px;
  border-color: #e2e8f0;
  padding: 10px 14px;
  font-size: .92rem;
}
.form-control:focus, .form-select:focus {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 4px rgba(20, 184, 166, .14);
}
.form-floating > label { padding-left: 14px; }
.input-group-text {
  background: #f8fafc;
  border-color: #e2e8f0;
  color: #64748b;
  border-radius: 10px;
}

/* ============ SEARCH/FILTER BAR ============ */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
}
.toolbar .search-box {
  position: relative;
  flex: 1;
  min-width: 220px;
  max-width: 420px;
}
.toolbar .search-box .bi {
  position: absolute;
  top: 50%; left: 14px;
  transform: translateY(-50%);
  color: #94a3b8;
}
.toolbar .search-box input { padding-left: 40px; }

/* ============ EMPTY STATE ============ */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: #64748b;
}
.empty-state svg { width: 84px; height: 84px; opacity: .55; margin-bottom: 14px; }
.empty-state h5 { color: #334155; font-weight: 700; }
.empty-state p { font-size: .9rem; }

/* ============ PAGINATION ============ */
.pagination .page-link {
  border: none;
  color: #475569;
  margin: 0 3px;
  border-radius: 9px !important;
  min-width: 38px;
  text-align: center;
  font-weight: 600;
}
.pagination .page-item.active .page-link {
  background: var(--primary);
  color: #fff;
}
.pagination .page-link:hover { background: #f1f5f9; color: var(--primary-dark); }

/* ============ LOGIN ============ */
.login-wrap {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  background: #f1f5f9;
}
.login-aside {
  background: linear-gradient(150deg, #0f766e 0%, #0d9488 55%, #0ea5e9 120%);
  color: #fff;
  padding: 56px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative;
  overflow: hidden;
}
.login-aside::before {
  content: "";
  position: absolute;
  width: 420px; height: 420px;
  border-radius: 50%;
  background: rgba(255,255,255,.08);
  top: -120px; right: -120px;
}
.login-aside::after {
  content: "";
  position: absolute;
  width: 260px; height: 260px;
  border-radius: 50%;
  background: rgba(255,255,255,.06);
  bottom: -80px; left: -60px;
}
.login-aside h1 { font-size: 2.1rem; font-weight: 800; margin-bottom: 14px; position: relative; }
.login-aside p { color: rgba(255,255,255,.85); font-size: 1rem; position: relative; max-width: 420px; }
.login-aside .feat { margin-top: 32px; position: relative; }
.login-aside .feat div { display: flex; align-items: center; gap: 12px; padding: 8px 0; color: rgba(255,255,255,.92); }
.login-main {
  display: grid;
  place-items: center;
  padding: 40px;
}
.login-card {
  width: 100%;
  max-width: 380px;
}
.login-card .logo {
  width: 56px; height: 56px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: 16px;
  display: grid; place-items: center;
  color: #fff;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.login-card h2 { font-weight: 800; color: #0f172a; }
.login-card .sub { color: #64748b; margin-bottom: 26px; }

@media (max-width: 860px) {
  .login-wrap { grid-template-columns: 1fr; }
  .login-aside { display: none; }
}

/* ============ SCANNER MODAL ============ */
.scanner-stage {
  position: relative;
  background: #0f172a;
  border-radius: 12px;
  overflow: hidden;
  aspect-ratio: 4/3;
}
.scanner-stage video, .scanner-stage canvas {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.scanner-overlay {
  position: absolute; inset: 0;
  pointer-events: none;
  background:
    linear-gradient(rgba(15,23,42,.45), rgba(15,23,42,.45)),
    radial-gradient(transparent 55%, rgba(15,23,42,.7) 75%);
}
.scan-guide {
  position: absolute;
  inset: 8% 8%;
  border: 2px dashed rgba(255,255,255,.5);
  border-radius: 10px;
}
.page-thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
}
.page-thumb {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #e2e8f0;
  aspect-ratio: 3/4;
  background: #f8fafc;
}
.page-thumb img { width: 100%; height: 100%; object-fit: cover; }
.page-thumb .rm {
  position: absolute; top: 4px; right: 4px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: rgba(15,23,42,.7);
  color: #fff; border: none;
  display: grid; place-items: center;
  font-size: .7rem;
  cursor: pointer;
}
.page-thumb .pg {
  position: absolute; bottom: 4px; left: 4px;
  background: rgba(15,23,42,.7);
  color: #fff; font-size: .68rem;
  padding: 1px 6px; border-radius: 5px;
}
.scanner-loading {
  position: absolute; inset: 0;
  background: rgba(15,23,42,.85);
  color: #fff;
  display: none;
  place-items: center;
  text-align: center;
  z-index: 5;
}
.scanner-loading.show { display: grid; }
.scanner-loading .spin {
  width: 42px; height: 42px;
  border: 4px solid rgba(255,255,255,.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ TOAST ============ */
.toast-container { z-index: 1090; }

/* ============ FILE PREVIEW ============ */
.file-preview {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  overflow: hidden;
}
.file-preview embed, .file-preview img {
  width: 100%;
  display: block;
  min-height: 400px;
}

/* ============ MISC ============ */
.text-muted-2 { color: #94a3b8 !important; }
.divider { height: 1px; background: #f1f5f9; margin: 18px 0; }
.cursor-pointer { cursor: pointer; }

/* Responsive */
@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); }
  .app.sidebar-open .sidebar { transform: translateX(0); }
  .main { margin-left: 0 !important; }
  .sidebar-backdrop {
    position: fixed; inset: 0;
    background: rgba(15,23,42,.45);
    z-index: 1035;
    display: none;
  }
  .app.sidebar-open .sidebar-backdrop { display: block; }
}

@media (max-width: 575.98px) {
  .content { padding: 16px; }
  .topbar { padding: 0 14px; }
  .topbar .page-title { font-size: 1rem; }
  .card-body { padding: 16px; }
}
