/* ============================================
   SIM RS Pendidikan - Custom CSS
   Bootstrap 5-like utility classes + components
   ============================================ */

/* --- CSS Variables --- */
:root {
  --color-primary: #0d6efd;
  --color-primary-dark: #0b5ed7;
  --color-success: #198754;
  --color-success-dark: #157347;
  --color-danger: #dc3545;
  --color-danger-dark: #bb2d3b;
  --color-warning: #ffc107;
  --color-secondary: #6c757d;
  --color-light: #f8f9fa;
  --color-dark: #212529;
  --color-white: #fff;
  --color-muted: #6c757d;
  --color-border: #dee2e6;
  --radius: 0.375rem;
  --shadow-sm: 0 0.125rem 0.25rem rgba(0,0,0,0.075);
  --shadow: 0 0.5rem 1rem rgba(0,0,0,0.15);
  --font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-size-sm: 0.875rem;
  --font-size-xs: 0.75rem;
}

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-family);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--color-dark);
  background-color: var(--color-white);
  -webkit-text-size-adjust: 100%;
}

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

h1, h2, h3, h4, h5, h6 { margin-top: 0; margin-bottom: 0.5rem; font-weight: 600; line-height: 1.2; }
h4 { font-size: 1.25rem; }
h5 { font-size: 1.1rem; }
h6 { font-size: 0.95rem; }

p { margin-top: 0; margin-bottom: 1rem; }
ul, ol { padding-left: 2rem; }
dl { margin: 0; }
dt { font-weight: 600; }
dd { margin-left: 0; margin-bottom: 0.5rem; }

/* --- Layout --- */
.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
}

.container-fluid {
  width: 100%;
  padding: 0 1rem;
}

/* Grid */
.row {
  display: flex;
  flex-wrap: wrap;
  margin: 0 -0.5rem;
}

.row > * {
  padding: 0 0.5rem;
}

.row.g-3 { gap: 1rem 0; }
.row.g-3 > * { padding: 0 0.5rem; }

.col-6 { flex: 0 0 50%; max-width: 50%; }
.col-11 { flex: 0 0 91.666%; max-width: 91.666%; }
.col-12 { flex: 0 0 100%; max-width: 100%; }

@media (min-width: 576px) {
  .col-sm-8 { flex: 0 0 66.666%; max-width: 66.666%; }
}

@media (min-width: 768px) {
  .col-md-3 { flex: 0 0 25%; max-width: 25%; }
  .col-md-6 { flex: 0 0 50%; max-width: 50%; }
  .col-md-8 { flex: 0 0 66.666%; max-width: 66.666%; }
  .col-md-9 { flex: 0 0 75%; max-width: 75%; }
}

@media (min-width: 992px) {
  .col-lg-4 { flex: 0 0 33.333%; max-width: 33.333%; }
  .col-lg-6 { flex: 0 0 50%; max-width: 50%; }
}

/* --- Navbar --- */
.navbar {
  display: flex;
  align-items: center;
  padding: 0.5rem 1rem;
  position: relative;
  z-index: 1050;
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--color-white) !important;
  font-weight: 700;
  font-size: 1.1rem;
  text-decoration: none !important;
  margin-right: 1rem;
  white-space: nowrap;
}

.navbar-toggler {
  display: none;
  background: none;
  border: none;
  color: var(--color-white);
  padding: 0.375rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 1.25rem;
  line-height: 1;
  margin-left: auto;
  transition: background-color 0.15s;
}

.navbar-toggler:hover {
  background-color: rgba(255,255,255,0.15);
}

.navbar-toggler-icon {
  display: inline-block;
  width: 1.5em;
  height: 1.5em;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%28255, 255, 255, 0.75%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 100%;
  vertical-align: middle;
}

.navbar-collapse {
  display: flex;
  align-items: center;
  flex-grow: 1;
}

.navbar-nav {
  display: flex;
  list-style: none;
  margin: 0;
  padding: 0;
  gap: 0.25rem;
  align-items: center;
}

.navbar-nav.me-auto { margin-right: auto; }

.nav-link {
  color: rgba(255,255,255,0.8) !important;
  text-decoration: none !important;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  font-size: var(--font-size-sm);
  display: flex;
  align-items: center;
  gap: 0.375rem;
  white-space: nowrap;
  cursor: pointer;
  transition: color 0.15s, background-color 0.15s;
}

.nav-link:hover,
.nav-link.active {
  color: var(--color-white) !important;
  background-color: rgba(255,255,255,0.15);
}

.bg-primary { background-color: var(--color-primary); }
.bg-success { background-color: var(--color-success); }

/* --- Desktop/mobile nav visibility --- */
.sidebar-header { display: none; }
.sidebar-bottom-nav { display: none; }
.desktop-nav { display: flex; }

/* --- Navbar overlay (mobile backdrop) --- */
.navbar-overlay {
  display: none;
}

/* Mobile navbar — slide-from-top dropdown */
@media (max-width: 991.98px) {
  .navbar-toggler { display: block; }

  /* Overlay: darkens content below navbar */
  .navbar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 1040;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
  }

  .navbar-overlay.show {
    opacity: 1;
    pointer-events: auto;
  }

  /* Slide-down panel */
  .navbar-collapse {
    display: flex;
    flex-direction: column;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--color-white);
    z-index: 1050;
    padding: 0;
    overflow-y: auto;
    max-height: 0;
    opacity: 0;
    transform: translateY(-0.5rem);
    transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.25s ease,
                transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 24px rgba(0,0,0,0.12);
    border-radius: 0 0 0.75rem 0.75rem;
  }

  .navbar-collapse.show {
    max-height: 80vh;
    opacity: 1;
    transform: translateY(0);
  }

  /* Hide the sidebar header (no need for close/user in dropdown) */
  .sidebar-header {
    display: none;
  }

  /* Nav items — left aligned, generously padded to look centered */
  .navbar-nav {
    flex-direction: column;
    width: 100%;
    gap: 0;
    padding: 0.5rem 0;
  }

  .navbar-nav.me-auto { margin-right: 0; flex: none; }

  .navbar-nav li {
    width: 100%;
  }

  .nav-link {
    color: var(--color-dark) !important;
    padding: 0.75rem 2rem;
    border-radius: 0;
    font-size: 0.9375rem;
    font-weight: 450;
    justify-content: flex-start;
  }

  .nav-link .bi {
    color: var(--color-muted);
    font-size: 1.125rem;
    width: 1.5rem;
    text-align: center;
  }

  .nav-link:hover {
    color: var(--color-dark) !important;
    background-color: var(--color-light);
  }

  .nav-link.active {
    color: var(--color-primary) !important;
    background-color: #e8f0fe;
    font-weight: 500;
  }

  .nav-link.active .bi {
    color: var(--color-primary);
  }

  /* Dropdown in mobile: flat list with section label */
  .nav-dropdown .nav-dropdown-toggle {
    pointer-events: none;
    font-size: var(--font-size-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.75rem 2rem 0.25rem;
    color: var(--color-muted) !important;
    background: none !important;
    opacity: 1;
    justify-content: flex-start;
  }

  .nav-dropdown .nav-dropdown-toggle::after { display: none; }

  .nav-dropdown .nav-dropdown-menu {
    display: block;
    position: static;
    box-shadow: none;
    border: none;
    background: transparent;
    padding: 0;
    min-width: 0;
  }

  .nav-dropdown .nav-dropdown-item {
    color: var(--color-dark);
    padding: 0.75rem 2rem 0.75rem 2.75rem;
    border-radius: 0;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.5rem;
    font-size: 0.9375rem;
    text-decoration: none;
  }

  .nav-dropdown .nav-dropdown-item .bi {
    color: var(--color-muted);
    font-size: 1.125rem;
    width: 1.5rem;
    text-align: center;
  }

  .nav-dropdown .nav-dropdown-item:hover {
    background: var(--color-light);
    color: var(--color-dark);
    text-decoration: none;
  }

  .nav-dropdown .nav-dropdown-item.active {
    color: var(--color-primary);
    background: #e8f0fe;
    font-weight: 500;
  }

  .nav-dropdown .nav-dropdown-item.active .bi {
    color: var(--color-primary);
  }

  /* Hide desktop dropdown on mobile */
  .desktop-nav { display: none !important; }

  /* Logout section */
  .sidebar-logout {
    border-top: 1px solid var(--color-border);
    padding: 0.75rem 2rem;
  }

  .sidebar-logout-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.625rem 1rem;
    font-size: 0.9375rem;
    font-weight: 500;
    font-family: inherit;
    color: var(--color-danger);
    background: none;
    border: 1px solid var(--color-danger);
    border-radius: var(--radius);
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s;
  }

  .sidebar-logout-btn:hover {
    background: var(--color-danger);
    color: var(--color-white);
  }
}

/* --- Dropdown (custom, Stimulus-driven) --- */
.nav-dropdown {
  position: relative;
}

.nav-dropdown-toggle::after {
  content: "";
  display: inline-block;
  width: 0;
  height: 0;
  margin-left: 0.3rem;
  vertical-align: middle;
  border-top: 0.3em solid;
  border-right: 0.3em solid transparent;
  border-left: 0.3em solid transparent;
}

.nav-dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 1000;
  min-width: 10rem;
  padding: 0.5rem 0;
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.nav-dropdown-menu.nav-dropdown-menu-end {
  left: auto;
  right: 0;
}

.nav-dropdown.open > .nav-dropdown-menu {
  display: block;
}

.nav-dropdown-item {
  display: block;
  width: 100%;
  padding: 0.375rem 1rem;
  color: var(--color-dark);
  text-decoration: none;
  font-size: var(--font-size-sm);
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
}

.nav-dropdown-item:hover {
  background-color: var(--color-light);
  color: var(--color-dark);
  text-decoration: none;
}

.nav-dropdown-item.active {
  background-color: var(--color-primary);
  color: var(--color-white);
}

/* --- Card --- */
.card {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

.card-body { padding: 1.25rem; }

.card.card-primary { background: var(--color-primary); color: var(--color-white); border-color: var(--color-primary); }
.card.card-success { background: var(--color-success); color: var(--color-white); border-color: var(--color-success); }

.shadow-sm { box-shadow: var(--shadow-sm); }

/* --- Table --- */
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table.table {
  width: 100%;
  border-collapse: collapse;
}

table.table th,
table.table td {
  padding: 0.75rem;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

table.table thead th {
  background: var(--color-light);
  font-weight: 600;
  font-size: var(--font-size-sm);
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.025em;
}

table.table tbody tr:hover { background-color: #f8f9fa; }
table.table tbody tr:last-child td { border-bottom: none; }

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.5;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  text-decoration: none !important;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
  font-family: inherit;
}

.btn:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

.btn-primary { background: var(--color-primary); color: var(--color-white); border-color: var(--color-primary); }
.btn-primary:hover { background: var(--color-primary-dark); border-color: var(--color-primary-dark); color: var(--color-white); }

.btn-success { background: var(--color-success); color: var(--color-white); border-color: var(--color-success); }
.btn-success:hover { background: var(--color-success-dark); border-color: var(--color-success-dark); color: var(--color-white); }

.btn-outline-secondary { background: transparent; color: var(--color-secondary); border-color: var(--color-secondary); }
.btn-outline-secondary:hover { background: var(--color-secondary); color: var(--color-white); }

.btn-outline-danger { background: transparent; color: var(--color-danger); border-color: var(--color-danger); }
.btn-outline-danger:hover { background: var(--color-danger); color: var(--color-white); }

.btn-sm { padding: 0.25rem 0.5rem; font-size: var(--font-size-sm); }

/* button_to generates a form wrapping the button — make it inline */
.table td form { display: inline; }

/* --- Forms --- */
.form-label {
  display: block;
  margin-bottom: 0.375rem;
  font-weight: 500;
  font-size: var(--font-size-sm);
}

.form-control,
.form-select {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 1rem;
  font-family: inherit;
  line-height: 1.5;
  color: var(--color-dark);
  background-color: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-control:focus,
.form-select:focus {
  border-color: var(--color-primary);
  outline: 0;
  box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.25);
}

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 16px 12px;
  padding-right: 2.25rem;
}

/* --- Alerts --- */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: var(--font-size-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.alert-success { background: #d1e7dd; color: #0f5132; border: 1px solid #badbcc; }
.alert-danger { background: #f8d7da; color: #842029; border: 1px solid #f5c2c7; }

.alert-dismiss {
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: inherit;
  opacity: 0.5;
  padding: 0;
  line-height: 1;
}

.alert-dismiss:hover { opacity: 1; }

/* --- Badge --- */
.badge {
  display: inline-block;
  padding: 0.25em 0.5em;
  font-size: var(--font-size-xs);
  font-weight: 600;
  border-radius: var(--radius);
  line-height: 1;
}

.badge-primary { background: var(--color-primary); color: var(--color-white); }
.badge-success { background: var(--color-success); color: var(--color-white); }
.badge-danger { background: var(--color-danger); color: var(--color-white); }
.badge-secondary { background: #6c757d; color: var(--color-white); }

/* --- Description List (show pages) --- */
.dl-horizontal {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.5rem 1.5rem;
}

.dl-horizontal dt { text-align: right; color: var(--color-muted); font-weight: 500; font-size: var(--font-size-sm); }
.dl-horizontal dd { margin: 0; }

@media (max-width: 575.98px) {
  .dl-horizontal { grid-template-columns: 1fr; gap: 0.125rem 0; }
  .dl-horizontal dt { text-align: left; }
  .dl-horizontal dd { margin-bottom: 0.75rem; }
}

/* --- Stat Card (dashboard) --- */
.stat-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.stat-card .stat-icon {
  opacity: 0.5;
}

.stat-card .stat-icon .bi {
  font-size: 2.5rem;
}

.stat-card h2 { margin: 0; font-size: 2rem; }
.stat-card h6 { margin: 0 0 0.25rem; font-size: var(--font-size-sm); opacity: 0.85; }

/* --- Auth pages (login, password reset) --- */
.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-light);
  padding: 1rem;
}

.auth-card {
  width: 100%;
  max-width: 400px;
}

.auth-card .card { box-shadow: var(--shadow-sm); }

/* --- Page content wrapper --- */
.page-content { padding: 1.5rem 1rem; }

@media (min-width: 768px) {
  .page-content { padding: 1.5rem; }
}

/* --- Flex helpers --- */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 1rem; }

/* --- Spacing --- */
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-3 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 1.5rem; }
.mt-3 { margin-top: 1rem; }
.py-4 { padding-top: 1.5rem; padding-bottom: 1.5rem; }
.p-4 { padding: 1.5rem; }

/* --- Text --- */
.text-center { text-align: center; }
.text-end { text-align: right; }
.text-muted { color: var(--color-muted); }
.text-primary { color: var(--color-primary); }
.text-sm { font-size: var(--font-size-sm); }
.text-xs { font-size: var(--font-size-xs); }
.fw-bold { font-weight: 700; }

/* --- Icons (Bootstrap Icons font) --- */
.bi {
  vertical-align: -0.125em;
  flex-shrink: 0;
}
