@import url('https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,400;0,500;0,600;0,700;1,400&display=swap');

:root {
  --bg: #f3f6f4;
  --bg-accent: #e7efe9;
  --surface: #ffffff;
  --ink: #13261c;
  --muted: #5b6f63;
  --line: #d5e0d8;
  --brand: #1f6b45;
  --brand-2: #0f4c33;
  --brand-soft: #dff3e7;
  --brand-rgb: 31, 107, 69;
  --sidebar-1: #123528;
  --sidebar-2: #0d2a1f;
  --sidebar-3: #0a2118;
  --warn: #b45309;
  --danger: #b42318;
  --info: #175cd3;
  --shadow: 0 18px 40px rgba(19, 38, 28, 0.08);
  --radius: 18px;
  --sidebar: 272px;
  --font: "Montserrat", sans-serif;
  --display: "Montserrat", sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(var(--brand-rgb), .12), transparent 28%),
    linear-gradient(180deg, color-mix(in srgb, var(--bg) 80%, #fff) 0%, var(--bg) 42%, color-mix(in srgb, var(--bg) 88%, var(--brand-soft)) 100%);
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
img { max-width: 100%; display: block; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar) 1fr;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 18px;
  background: linear-gradient(180deg, var(--sidebar-1) 0%, var(--sidebar-2) 55%, var(--sidebar-3) 100%);
  color: #edf7f1;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow: auto;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 8px 10px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand img {
  width: 46px; height: 46px; object-fit: contain;
  background: rgba(255,255,255,.08); border-radius: 12px; padding: 6px;
}
.brand strong {
  font-family: var(--display);
  font-size: 1.15rem;
  display: block;
  line-height: 1.15;
}
.brand span { color: #9fbfb0; font-size: .82rem; }

.nav-group { display: flex; flex-direction: column; gap: 6px; }
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 12px; border-radius: 12px;
  color: #d7ebe1; transition: .18s ease;
}
.nav-link:hover, .nav-link.active {
  background: rgba(255,255,255,.1);
  color: #fff;
}
.nav-link.active { box-shadow: inset 0 0 0 1px rgba(255,255,255,.08); }

.sidebar-footer {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid rgba(255,255,255,.08);
  display: grid; gap: 10px;
}

.main {
  min-width: 0;
  padding: 22px 24px 40px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}
.topbar-left {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  min-width: 0;
}
.topbar-titles { min-width: 0; }
.topbar h1 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(1.5rem, 2vw, 2rem);
  letter-spacing: -.02em;
}
.topbar p { margin: 4px 0 0; color: var(--muted); }

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}
.top-actions-extra {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--brand-2);
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
  flex: 0 0 auto;
  transition: .15s ease;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { border-color: color-mix(in srgb, var(--brand) 40%, var(--line)); }
.icon-btn.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.view-switch-icons {
  display: inline-flex;
  gap: 8px;
  align-items: center;
}
.mode-when-mobile { display: none; }
.mode-when-desktop { display: inline-grid; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.stat .label { color: var(--muted); font-size: .9rem; }
.stat .value {
  font-family: var(--display);
  font-size: 2rem;
  margin-top: 6px;
  color: var(--brand-2);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; flex-wrap: wrap;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fff, #f8fbf9);
}
.panel-head h2 { margin: 0; font-size: 1.05rem; }
.panel-body { padding: 18px; }

.toolbar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: end;
}

.field { display: grid; gap: 6px; min-width: 0; }
.field label { font-size: .85rem; color: var(--muted); font-weight: 600; }
.field input, .field select, .field textarea,
input[type=text], input[type=password], input[type=date], input[type=file],
input[type=number], select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 11px 12px;
  color: var(--ink);
  outline: none;
}
.field textarea, textarea { min-height: 96px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus,
input:focus, select:focus, textarea:focus {
  border-color: color-mix(in srgb, var(--brand) 55%, #fff);
  box-shadow: 0 0 0 4px rgba(var(--brand-rgb), .12);
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 12px; padding: 11px 14px;
  background: var(--brand); color: #fff; font-weight: 600;
  cursor: pointer; transition: .15s ease; white-space: nowrap;
}
.btn:hover { background: var(--brand-2); }
.btn.secondary { background: var(--brand-soft); color: var(--brand-2); }
.btn.secondary:hover { background: color-mix(in srgb, var(--brand-soft) 70%, var(--brand)); }
.btn.danger { background: #fef3f2; color: var(--danger); }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.btn.small { padding: 7px 10px; font-size: .85rem; border-radius: 10px; }

.table-wrap { overflow: auto; }
table.data {
  width: 100%; border-collapse: collapse; min-width: 720px;
}
table.data th, table.data td {
  padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line);
  vertical-align: top;
}
table.data th {
  font-size: .78rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); background: #f7faf8; position: sticky; top: 0;
}
table.data tr:hover td { background: #f9fcfa; }

.badge {
  display: inline-flex; align-items: center;
  padding: 4px 8px; border-radius: 999px;
  font-size: .75rem; font-weight: 600;
  background: var(--brand-soft); color: var(--brand-2);
}
.badge.muted { background: #eef2f0; color: var(--muted); }
.badge.warn { background: #fff7ed; color: var(--warn); }

.aspek-row { display: flex; flex-wrap: wrap; gap: 6px; }
.aspek-btn {
  border: 0; border-radius: 999px; padding: 7px 10px;
  font-size: .78rem; font-weight: 700; cursor: pointer; color: #fff;
}
.aspek-btn.akademik { background: #175cd3; }
.aspek-btn.karakter { background: #7a5af8; }
.aspek-btn.sosial { background: #dd2590; }
.aspek-btn.disiplin { background: #b54708; }
.aspek-btn.potensi { background: #087443; }
.aspek-btn.filled { box-shadow: inset 0 0 0 2px rgba(255,255,255,.55); }

.alert {
  padding: 12px 14px; border-radius: 12px; margin-bottom: 14px;
  border: 1px solid transparent;
}
.alert.success { background: #ecfdf3; color: #067647; border-color: #abefc6; }
.alert.error { background: #fef3f2; color: #b42318; border-color: #fecdca; }

.login-page {
  position: relative;
  isolation: isolate;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  overflow: hidden;
  background: var(--sidebar-3);
}
.login-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}
.login-card {
  position: relative;
  z-index: 1;
  width: min(420px, 100%);
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(14px) saturate(1.15);
  -webkit-backdrop-filter: blur(14px) saturate(1.15);
  border: 1px solid rgba(255,255,255,.55);
  border-radius: 24px;
  padding: 28px;
  box-shadow: 0 30px 80px rgba(0,0,0,.28);
  animation: login-card-in .55s cubic-bezier(.22,1,.36,1) both;
}
@keyframes login-card-in {
  from { opacity: 0; transform: translateY(14px) scale(.98); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .login-card { animation: none; }
}
.login-card .logo {
  width: 78px; height: 78px; object-fit: contain; margin: 0 auto 10px;
}
.login-card h1 {
  margin: 0 0 6px; text-align: center;
  font-family: var(--display); font-size: 1.55rem; line-height: 1.2;
}
.login-card .sub { text-align: center; color: var(--muted); margin-bottom: 18px; }
.login-card .stack { display: grid; gap: 12px; }
.login-foot { text-align: center; color: var(--muted); font-size: .85rem; margin-top: 16px; }

.modal {
  position: fixed; inset: 0; display: none; place-items: center;
  background: rgba(10,20,15,.48); padding: 20px; z-index: 60;
}
.modal.open { display: grid; }
.modal-card {
  width: min(520px, 100%);
  background: #fff; border-radius: 20px;
  box-shadow: var(--shadow); overflow: hidden;
  display: flex; flex-direction: column;
}
.modal-card header,
.modal-card footer {
  padding: 18px 28px;
  border-bottom: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  flex-shrink: 0;
}
.modal-card footer {
  border-bottom: 0;
  border-top: 1px solid var(--line);
  justify-content: flex-end;
  gap: 10px;
}
/* Cover both old (form.body) and new (div.body) modal markup */
.modal-card .body,
.modal-card > form {
  padding: 24px 28px !important;
  display: grid !important;
  gap: 14px !important;
  max-height: 70vh;
  overflow: auto;
  margin: 0;
}
.modal-card form:has(> .body) {
  padding: 0 !important;
  display: flex !important;
  flex-direction: column;
  max-height: none;
  overflow: visible;
  gap: 0 !important;
}
.modal-card form:has(> .body) > .body {
  padding: 24px 28px !important;
}
.modal-card .body > .check-row,
.modal-card form > .check-row {
  display: flex; gap: 10px; align-items: center;
  padding: 2px 0;
}

.mobile-nav {
  display: none;
  position: fixed; left: 0; right: 0; bottom: 0;
  padding: 8px 10px calc(8px + var(--safe-bottom));
  background: rgba(255,255,255,.96);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  z-index: 40;
  gap: 4px;
}
.mobile-nav a {
  flex: 1;
  display: grid;
  justify-items: center;
  gap: 3px;
  text-align: center;
  padding: 8px 4px;
  border-radius: 14px;
  font-size: .7rem;
  color: var(--muted);
  font-weight: 600;
}
.mobile-nav a svg { width: 20px; height: 20px; }
.mobile-nav a.active {
  background: var(--brand-soft);
  color: var(--brand-2);
}

.card-list { display: none; gap: 12px; }
.student-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  background: #fff;
}
.student-card h3 { margin: 0 0 4px; font-size: 1rem; }
.student-card .meta { color: var(--muted); font-size: .86rem; margin-bottom: 10px; }
.student-card .actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

.pagination { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.pagination a, .pagination span {
  padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: #fff;
}
.pagination .active { background: var(--brand); color: #fff; border-color: var(--brand); }

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

.menu-toggle {
  display: none;
  border: 1px solid var(--line); background: #fff; border-radius: 12px;
  padding: 10px 12px; cursor: pointer;
}

/* Forced desktop / mobile via body class */
body.force-desktop .app-shell { grid-template-columns: var(--sidebar) 1fr; }
body.force-desktop .sidebar { display: flex !important; position: sticky; height: 100vh; transform: none; }
body.force-desktop .mobile-nav { display: none !important; }
body.force-desktop .card-list { display: none !important; }
body.force-desktop .table-wrap { display: block !important; }
body.force-desktop .main { padding-bottom: 40px; }
body.force-desktop .menu-toggle { display: none !important; }
body.force-desktop .mode-when-mobile { display: none !important; }
body.force-desktop .mode-when-desktop { display: inline-grid !important; }

body.force-mobile .app-shell { grid-template-columns: 1fr; }
body.force-mobile .sidebar,
body.force-mobile .menu-toggle,
body.force-mobile .backdrop { display: none !important; }
body.force-mobile .mobile-nav { display: flex; }
body.force-mobile .card-list { display: grid; }
body.force-mobile .table-desktop { display: none !important; }
body.force-mobile .main { padding: 14px 14px 96px; }
body.force-mobile .stat-grid { grid-template-columns: 1fr; }
body.force-mobile .topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  margin: -14px -14px 16px;
  padding: 12px 14px;
  background: color-mix(in srgb, var(--bg) 88%, #fff);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  align-items: center;
}
body.force-mobile .topbar h1 { font-size: 1.2rem; }
body.force-mobile .topbar p { display: none; }
body.force-mobile .top-actions-extra .btn { padding: 8px 10px; font-size: .82rem; }
body.force-mobile .grid-2, body.force-mobile .grid-3 { grid-template-columns: 1fr; }
body.force-mobile .mode-when-mobile { display: inline-grid !important; }
body.force-mobile .mode-when-desktop { display: none !important; }
body.force-mobile .panel { border-radius: 18px; }
body.force-mobile .home-shell { max-width: none; }

@media (max-width: 980px) {
  body:not(.force-desktop) .app-shell { grid-template-columns: 1fr; }
  body:not(.force-desktop) .sidebar,
  body:not(.force-desktop) .menu-toggle,
  body:not(.force-desktop) .backdrop { display: none !important; }
  body:not(.force-desktop) .mobile-nav { display: flex; }
  body:not(.force-desktop) .card-list { display: grid; }
  body:not(.force-desktop) .table-desktop { display: none; }
  body:not(.force-desktop) .main { padding: 14px 14px 96px; }
  body:not(.force-desktop) .stat-grid { grid-template-columns: 1fr; }
  body:not(.force-desktop) .topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    margin: -14px -14px 16px;
    padding: 12px 14px;
    background: color-mix(in srgb, var(--bg) 88%, #fff);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
    align-items: center;
  }
  body:not(.force-desktop) .topbar h1 { font-size: 1.2rem; }
  body:not(.force-desktop) .topbar p { display: none; }
  body:not(.force-desktop) .top-actions-extra .btn { padding: 8px 10px; font-size: .82rem; }
  body:not(.force-desktop) .grid-2,
  body:not(.force-desktop) .grid-3 { grid-template-columns: 1fr; }
  body:not(.force-desktop) .mode-when-mobile { display: inline-grid; }
  body:not(.force-desktop) .mode-when-desktop { display: none; }
  body:not(.force-desktop) .panel { border-radius: 18px; }
  body:not(.force-desktop) .home-shell { max-width: none; }
}

.backdrop {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 45;
}
.backdrop.show { display: block; }

/* Phone-style home menu */
.home-shell {
  max-width: 720px;
  margin: 0 auto;
  display: grid;
  gap: 18px;
}
.home-hero {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 20px 18px;
  border-radius: 22px;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--brand) 88%, #000), var(--brand-2));
  color: #fff;
  box-shadow: var(--shadow);
}
.home-hello { font-size: .9rem; opacity: .85; }
.home-hero h2 {
  margin: 2px 0 4px;
  font-family: var(--display);
  font-size: clamp(1.35rem, 3vw, 1.8rem);
  line-height: 1.15;
}
.home-hero p { margin: 0; opacity: .85; font-size: .9rem; }
.home-hero-badge {
  min-width: 84px;
  text-align: center;
  background: rgba(255,255,255,.14);
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 16px;
  padding: 10px 12px;
}
.home-hero-badge span {
  display: block;
  font-weight: 700;
  font-size: 1.05rem;
}
.home-hero-badge small {
  display: block;
  opacity: .8;
  font-size: .72rem;
  margin-top: 2px;
}
.home-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.home-stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 12px;
  text-align: center;
  box-shadow: var(--shadow);
}
.home-stat strong {
  display: block;
  font-family: var(--display);
  font-size: 1.45rem;
  color: var(--brand-2);
  line-height: 1.1;
}
.home-stat span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: .8rem;
  font-weight: 600;
}
.home-menu-section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.home-menu-title {
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--ink);
}
.app-menu-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.app-menu-item {
  display: grid;
  justify-items: center;
  text-align: center;
  gap: 8px;
  padding: 14px 10px 12px;
  border-radius: 18px;
  border: 1px solid transparent;
  background: color-mix(in srgb, var(--bg) 72%, #fff);
  transition: .16s ease;
  min-height: 128px;
  align-content: start;
}
.app-menu-item:hover {
  transform: translateY(-2px);
  border-color: color-mix(in srgb, var(--brand) 35%, var(--line));
  box-shadow: 0 10px 24px rgba(var(--brand-rgb), .12);
}
.app-menu-icon {
  width: 54px;
  height: 54px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.18);
}
.app-menu-icon svg { width: 26px; height: 26px; }
.app-menu-label {
  font-weight: 700;
  font-size: .9rem;
  color: var(--ink);
  line-height: 1.2;
}
.app-menu-desc {
  font-size: .72rem;
  color: var(--muted);
  line-height: 1.3;
}
.app-menu-item.tone-green .app-menu-icon { background: linear-gradient(145deg, #22a06b, #147a4e); }
.app-menu-item.tone-blue .app-menu-icon { background: linear-gradient(145deg, #3b82f6, #1d4ed8); }
.app-menu-item.tone-orange .app-menu-icon { background: linear-gradient(145deg, #f59e0b, #c2410c); }
.app-menu-item.tone-teal .app-menu-icon { background: linear-gradient(145deg, #14b8a6, #0f766e); }
.app-menu-item.tone-purple .app-menu-icon { background: linear-gradient(145deg, #a78bfa, #7c3aed); }
.app-menu-item.tone-slate .app-menu-icon { background: linear-gradient(145deg, #64748b, #334155); }
.app-menu-item.tone-pink .app-menu-icon { background: linear-gradient(145deg, #f472b6, #db2777); }

@media (max-width: 560px) {
  .home-hero { align-items: flex-start; }
  .app-menu-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .app-menu-item { min-height: 118px; padding: 12px 8px; }
  .app-menu-icon { width: 48px; height: 48px; border-radius: 14px; }
  .app-menu-icon svg { width: 22px; height: 22px; }
}
@media (min-width: 900px) {
  .app-menu-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
