/* =========================================================
   Tools Perangkat Ajar — Premium UI/UX + Mobile Responsive
   ========================================================= */

/* ========= DESIGN TOKENS ========= */
:root {
  /* Surfaces */
  --bg: #FAFAFB;
  --surface: #FFFFFF;
  --surface-2: #F5F6F8;
  --surface-3: #EDEFF3;
  --surface-hover: #F9F9FB;

  /* Borders */
  --border: #E8EAEF;
  --border-strong: #D4D7DE;
  --border-focus: #C9BDF9;

  /* Text */
  --text: #15171E;
  --text-muted: #6B7280;
  --text-faint: #A0A5B1;
  --text-inverse: #FFFFFF;

  /* Primary (Indigo/Violet premium) */
  --primary: #6C3FF5;
  --primary-hover: #5A2FD9;
  --primary-active: #4D25BE;
  --primary-soft: #F1EBFE;
  --primary-softer: #F8F5FF;

  /* Semantic */
  --success: #0D9E6E;
  --success-soft: #E5F7F1;
  --warning: #DD8500;
  --warning-soft: #FFF4E0;
  --danger: #DF3A3A;
  --danger-soft: #FCEBEB;
  --info: #0C7BEF;
  --info-soft: #E8F2FE;

  /* Spacing scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;

  /* Radii */
  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  /* Shadows — layered for depth */
  --shadow-xs: 0 1px 2px rgba(20, 22, 40, 0.04);
  --shadow-sm: 0 1px 3px rgba(20, 22, 40, 0.06), 0 1px 2px rgba(20, 22, 40, 0.03);
  --shadow: 0 4px 12px rgba(20, 22, 40, 0.06), 0 1px 3px rgba(20, 22, 40, 0.04);
  --shadow-lg: 0 12px 32px rgba(20, 22, 40, 0.10), 0 2px 6px rgba(20, 22, 40, 0.04);
  --shadow-xl: 0 24px 60px rgba(20, 22, 40, 0.14), 0 8px 16px rgba(20, 22, 40, 0.06);
  --shadow-focus: 0 0 0 3px rgba(108, 63, 245, 0.15);

  /* Layout */
  --header-h: 64px;
  --sidebar-w: 272px;
  --mobile-nav-h: 68px;
  --font-base: 16px;

  /* Transitions */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --transition: 200ms var(--ease);
  --transition-fast: 120ms var(--ease);
}

/* ========= RESET ========= */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html {
  font-size: var(--font-base);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  scroll-behavior: smooth;
}
body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
a { color: var(--primary); text-decoration: none; transition: color var(--transition-fast); }
a:hover { color: var(--primary-hover); }
h1, h2, h3, h4 { line-height: 1.25; font-weight: 700; letter-spacing: -0.015em; }
img, svg { display: block; max-width: 100%; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--primary-soft); color: var(--primary); }

/* Premium scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-full);
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-faint);
  background-clip: padding-box;
  border: 2px solid transparent;
}

/* ========= APP SHELL ========= */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ========= HEADER ========= */
.app-header {
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--header-h);
}
.app-header-inner {
  height: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 var(--space-6);
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
  white-space: nowrap;
  flex-shrink: 0;
  color: var(--text);
  padding: 4px 8px 4px 4px;
  margin-left: -4px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
}
.brand:hover { background: var(--surface-2); }
.brand:active { transform: scale(0.98); }
.brand:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), #8B5CF6);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  font-size: 11px;
  letter-spacing: 0.03em;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(108, 63, 245, 0.25);
}

.pkg-tabs {
  display: flex;
  gap: 2px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 4px;
  background: var(--surface-2);
  border-radius: var(--radius);
  align-self: center;
  max-width: 560px;
  margin: 0 auto;
}
.pkg-tabs::-webkit-scrollbar { display: none; }
.pkg-tab {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}
.pkg-tab:hover { color: var(--text); }
.pkg-tab.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow-xs);
}
.pkg-tab-add {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}
.pkg-tab-add:hover { color: var(--primary); background: var(--primary-softer); }

.header-right {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.save-badge {
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  transition: all var(--transition-fast);
}
.save-badge.saved { background: var(--success-soft); color: var(--success); }
.save-badge.dirty { background: var(--warning-soft); color: var(--warning); }
.save-badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 16px;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:active { transform: scale(0.94); }

.menu-btn { display: none; }

/* Mobile header */
@media (max-width: 900px) {
  .app-header-inner { padding: 0 var(--space-4); gap: var(--space-2); }
  .brand span { display: none; }
  .pkg-tabs {
    max-width: none;
    margin: 0;
    flex: 1;
    padding: 3px;
  }
  .pkg-tab { padding: 5px 10px; font-size: 12px; }
  .save-badge span { display: none; }
  .save-badge { padding: 6px 8px; }
  .menu-btn { display: inline-flex; }
}

/* ========= BODY GRID ========= */
.app-body {
  flex: 1;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--space-6);
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  gap: var(--space-6);
  align-items: start;
}
.app-body.home {
  display: block;
  max-width: 1120px;
}

/* Tablet */
@media (max-width: 1024px) {
  .app-body {
    padding: var(--space-5);
    gap: var(--space-5);
  }
}

/* Mobile */
@media (max-width: 900px) {
  .app-body {
    grid-template-columns: 1fr;
    padding: var(--space-4);
    gap: var(--space-4);
    padding-bottom: calc(var(--mobile-nav-h) + var(--space-4) + env(safe-area-inset-bottom, 0px));
  }
}

/* ========= STEPPER ========= */
.stepper {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-3);
  position: sticky;
  top: calc(var(--header-h) + var(--space-4));
  max-height: calc(100vh - var(--header-h) - var(--space-8));
  max-height: calc(100dvh - var(--header-h) - var(--space-8));
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stepper-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
  padding: 0 var(--space-2);
}
.stepper-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
}
.stepper-close { display: none; }

.step-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  width: 100%;
  text-align: left;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  position: relative;
}
.step-item:hover { background: var(--surface-2); color: var(--text); }
.step-item.active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}
.step-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--text-faint);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
  transition: all var(--transition-fast);
}
.step-item.active .step-num { background: var(--primary); color: #fff; }
.step-item.done:not(.active) .step-num { background: var(--success); color: #fff; }
.step-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Mobile: stepper becomes slide-in drawer */
.stepper-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 30, 0.5);
  z-index: 55;
  animation: fadeIn 0.2s var(--ease);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
@media (max-width: 900px) {
  .stepper {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    max-height: 100vh;
    max-height: 100dvh;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform 280ms var(--ease);
    border-radius: 0;
    border-right: 1px solid var(--border);
    border-top: none;
    border-bottom: none;
    border-left: none;
    padding: var(--space-4);
    padding-top: calc(var(--space-4) + env(safe-area-inset-top, 0px));
    box-shadow: var(--shadow-xl);
  }
  .stepper.mobile-open { transform: translateX(0); }
  .stepper-backdrop.mobile-open { display: block; }
  .stepper-close { display: inline-flex; }
  .stepper-title { font-size: 12px; }
  .step-item { padding: 12px 12px; font-size: 14px; }
  .step-num { width: 28px; height: 28px; font-size: 12px; }
}

/* ========= WORKSPACE ========= */
.workspace {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* ========= PAGE HEADER ========= */
.page-header {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: var(--space-2);
}
.page-eyebrow {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.page-eyebrow strong { color: var(--primary); }
.page-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  line-height: 1.2;
}
.page-sub {
  font-size: 13px;
  color: var(--text-muted);
}
@media (max-width: 640px) {
  .page-title { font-size: 20px; }
  .page-sub { font-size: 12px; }
}

/* ========= ACTION BAR ========= */
.action-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.action-bar-info {
  font-size: 13px;
  color: var(--text-muted);
  min-width: 0;
}
.action-bar-info strong { color: var(--text); font-weight: 600; }
.action-bar-actions {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  align-items: center;
}

@media (max-width: 640px) {
  .action-bar {
    padding: var(--space-3);
    gap: var(--space-2);
    flex-direction: column;
    align-items: stretch;
  }
  .action-bar-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-2);
  }
  .action-bar-actions .btn {
    width: 100%;
    justify-content: center;
  }
  .action-bar-actions .btn-primary {
    grid-column: 1 / -1;
  }
}

/* ========= MOBILE BOTTOM NAV ========= */
.mobile-nav {
  display: none;
}
@media (max-width: 900px) {
  .mobile-nav {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: var(--mobile-nav-h);
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: saturate(180%) blur(16px);
    -webkit-backdrop-filter: saturate(180%) blur(16px);
    border-top: 1px solid var(--border);
    z-index: 35;
    padding: var(--space-2) var(--space-3);
    padding-bottom: calc(var(--space-2) + env(safe-area-inset-bottom, 0px));
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    box-shadow: 0 -4px 16px rgba(20, 22, 40, 0.06);
  }
  .mobile-nav-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--surface-2);
    transition: all var(--transition-fast);
    flex: 1;
    justify-content: center;
    min-height: 44px;
    max-width: 140px;
  }
  .mobile-nav-btn:active:not(:disabled) { transform: scale(0.97); }
  .mobile-nav-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
  }
  .mobile-nav-btn.primary {
    background: var(--primary);
    color: #fff;
  }
  .mobile-nav-btn.primary:hover { background: var(--primary-hover); }
  .mobile-nav-center {
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .mobile-nav-step {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-muted);
    padding: 4px 10px;
    background: var(--surface-2);
    border-radius: var(--radius-full);
  }
}

/* ========= CARDS ========= */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  transition: box-shadow var(--transition-fast);
}
.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
}
.card-title { font-size: 15px; font-weight: 700; letter-spacing: -0.01em; }
.card-sub { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

@media (max-width: 640px) {
  .card { padding: var(--space-4); border-radius: var(--radius); }
  .card-title { font-size: 14px; }
  .card-sub { font-size: 12px; }
}

/* ========= EMPTY STATE ========= */
.empty-state {
  padding: var(--space-8) var(--space-4);
  text-align: center;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  color: var(--text-muted);
  font-size: 13px;
  background: var(--surface-hover);
}
.empty-state-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-faint);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
}
.empty-state strong { color: var(--text); font-size: 14px; }

/* ========= FORMS ========= */
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}
@media (max-width: 640px) {
  .form-row { grid-template-columns: 1fr; }
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: var(--space-3);
}
.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.005em;
}
.field .hint {
  font-size: 12px;
  color: var(--text-faint);
  line-height: 1.4;
}

.input, .textarea, .select {
  width: 100%;
  padding: 10px 14px;
  min-height: 42px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 14px;
  line-height: 1.4;
  color: var(--text);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
}
.input:hover, .textarea:hover, .select:hover { border-color: var(--text-faint); }
.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--shadow-focus);
  background: var(--surface);
}
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.textarea { resize: vertical; min-height: 88px; }
.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* Mobile: increase touch targets */
@media (max-width: 640px) {
  .input, .textarea, .select {
    min-height: 46px;
    padding: 12px 14px;
    font-size: 16px; /* prevents iOS zoom */
  }
}

/* ========= CHECKBOX CARDS ========= */
.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: var(--space-2);
}
.checkbox-card {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  transition: all var(--transition-fast);
  line-height: 1.45;
  background: var(--surface);
}
.checkbox-card:hover { border-color: var(--primary); background: var(--surface-hover); }
.checkbox-card.checked {
  background: var(--primary-softer);
  border-color: var(--primary);
}
.checkbox-card input {
  margin-top: 2px;
  accent-color: var(--primary);
  flex-shrink: 0;
  width: 16px;
  height: 16px;
}

@media (max-width: 640px) {
  .checkbox-grid { grid-template-columns: 1fr; }
  .checkbox-card { padding: 12px; min-height: 48px; align-items: center; }
  .checkbox-card input { width: 18px; height: 18px; }
}

/* ========= BUTTONS ========= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  transition: all var(--transition-fast);
  white-space: nowrap;
  min-height: 40px;
  border: 1px solid transparent;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: scale(0.98); }

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 1px 2px rgba(108, 63, 245, 0.2);
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  box-shadow: 0 4px 12px rgba(108, 63, 245, 0.25);
}
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--text-faint);
}
.btn-ghost { color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover:not(:disabled) { background: #C42F2F; }
.btn-sm { padding: 7px 12px; font-size: 13px; min-height: 34px; }

@media (max-width: 640px) {
  .btn { min-height: 44px; padding: 10px 16px; }
  .btn-sm { min-height: 38px; padding: 8px 12px; }
}

/* ========= TABLE ========= */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  position: relative;
}
/* Scroll hint on mobile */
@media (max-width: 900px) {
  .table-wrap::after {
    content: '⟷';
    position: sticky;
    right: 8px;
    bottom: 8px;
    float: right;
    background: var(--text);
    color: #fff;
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 6px;
    opacity: 0.7;
    pointer-events: none;
  }
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 600px;
}
.table th {
  background: var(--surface-2);
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
}
.table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--surface-hover); }
.table .cell-input, .table .cell-textarea {
  width: 100%;
  border: none;
  background: transparent;
  padding: 8px 6px;
  border-radius: 4px;
  font-size: 13px;
  line-height: 1.45;
  min-height: 32px;
  transition: background var(--transition-fast);
}
.table .cell-input:focus, .table .cell-textarea:focus {
  background: var(--surface);
  outline: 2px solid var(--primary-soft);
}
.table .cell-textarea {
  resize: vertical;
  min-height: 48px;
  font-family: inherit;
}

@media (max-width: 640px) {
  .table { font-size: 12px; }
  .table th { padding: 8px 10px; font-size: 10px; }
  .table td { padding: 4px 6px; }
  .table .cell-input, .table .cell-textarea {
    font-size: 16px;
    padding: 8px 4px;
    min-height: 40px;
  }
}

/* ========= BADGES ========= */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text-muted);
  white-space: nowrap;
  letter-spacing: 0.01em;
}
.badge-primary { background: var(--primary-soft); color: var(--primary); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }

/* ========= MODAL ========= */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 30, 0.55);
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6) var(--space-4);
  overflow-y: auto;
  animation: fadeIn 0.18s var(--ease);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.modal {
  background: var(--surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 640px;
  max-height: calc(100vh - var(--space-8));
  max-height: calc(100dvh - var(--space-8));
  display: flex;
  flex-direction: column;
  animation: slideUp 0.22s var(--ease);
  margin: auto;
  overflow: hidden;
}
.modal.wide { max-width: 820px; }
@keyframes slideUp {
  from { transform: translateY(12px) scale(0.98); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}
.modal-header {
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-shrink: 0;
}
.modal-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.modal-body {
  padding: var(--space-5);
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  flex-shrink: 0;
  background: var(--surface-hover);
}

@media (max-width: 640px) {
  .modal-backdrop {
    padding: 0;
    align-items: flex-end;
  }
  .modal {
    max-width: 100%;
    max-height: 92vh;
    max-height: 92dvh;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    animation: slideUpMobile 0.25s var(--ease);
  }
  @keyframes slideUpMobile {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }
  .modal-header { padding: var(--space-3) var(--space-4); }
  .modal-body { padding: var(--space-4); }
  .modal-footer { padding: var(--space-3) var(--space-4); padding-bottom: calc(var(--space-3) + env(safe-area-inset-bottom, 0px)); }
}

/* ========= TOAST ========= */
#toast-root {
  position: fixed;
  bottom: var(--space-5);
  right: var(--space-5);
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-width: 420px;
  pointer-events: none;
}
.toast {
  background: var(--text);
  color: #fff;
  padding: 12px 18px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  animation: toastIn 0.24s var(--ease);
  pointer-events: auto;
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.warning { background: var(--warning); }
@keyframes toastIn {
  from { transform: translateY(10px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@media (max-width: 640px) {
  #toast-root {
    left: var(--space-4);
    right: var(--space-4);
    bottom: calc(var(--mobile-nav-h) + var(--space-3) + env(safe-area-inset-bottom, 0px));
    max-width: none;
  }
  .toast { font-size: 13px; padding: 10px 14px; }
}

/* ========= HOME / DASHBOARD ========= */
.hero {
  background: linear-gradient(135deg, var(--primary) 0%, #8B5CF6 100%);
  color: #fff;
  border-radius: var(--radius-xl);
  padding: var(--space-8) var(--space-6);
  margin-bottom: var(--space-6);
  position: relative;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(108, 63, 245, 0.2);
}
.hero::before {
  content: '';
  position: absolute;
  top: -50%;
  right: -10%;
  width: 320px;
  height: 320px;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.14) 0%, transparent 70%);
  pointer-events: none;
}
.hero-title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  position: relative;
}
.hero-sub {
  font-size: 14px;
  opacity: 0.92;
  margin-top: 4px;
  position: relative;
}
.hero-progress {
  margin-top: var(--space-5);
  position: relative;
}
.progress-track {
  height: 8px;
  background: rgba(255, 255, 255, 0.28);
  border-radius: var(--radius-full);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: #fff;
  border-radius: var(--radius-full);
  transition: width 0.6s var(--ease);
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.4);
}
.hero-meta {
  margin-top: var(--space-2);
  font-size: 13px;
  opacity: 0.92;
  font-weight: 500;
}

@media (max-width: 640px) {
  .hero {
    padding: var(--space-6) var(--space-4);
    margin-bottom: var(--space-4);
    border-radius: var(--radius-lg);
  }
  .hero-title { font-size: 20px; }
  .hero-sub { font-size: 13px; }
  .hero-meta { font-size: 12px; }
}

.dashboard-section { margin-top: var(--space-4); }
.dashboard-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
}
.dashboard-section-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--space-4);
}
@media (max-width: 640px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
    gap: var(--space-3);
  }
}

.dash-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  text-align: left;
  transition: all var(--transition-fast);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.dash-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}
.dash-card.done {
  border-color: var(--success);
  background: linear-gradient(135deg, var(--surface), var(--success-soft));
}
.dash-card.done:hover { box-shadow: 0 4px 16px rgba(13, 158, 110, 0.15); }
.dash-num {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-faint);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 4px;
  transition: all var(--transition-fast);
}
.dash-card.done .dash-num { background: var(--success); color: #fff; }
.dash-title { font-size: 14px; font-weight: 600; color: var(--text); }
.dash-sub { font-size: 12px; color: var(--text-muted); }

/* ========= SETTINGS ========= */
.provider-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-2);
}
.provider-card {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: left;
  background: var(--surface);
}
.provider-card:hover { border-color: var(--primary); }
.provider-card.active {
  border-color: var(--primary);
  background: var(--primary-softer);
  box-shadow: var(--shadow-focus);
}
.provider-title { font-size: 14px; font-weight: 600; }
.provider-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ========= AI MODAL ========= */
.ai-instructions {
  background: var(--primary-soft);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  font-size: 13px;
  line-height: 1.55;
  color: var(--text);
}
.ai-instructions strong { color: var(--primary); }
.ai-instructions ol { margin-left: var(--space-4); margin-top: 6px; }
.ai-instructions li { margin-bottom: 4px; }
.provider-links {
  display: flex;
  gap: var(--space-2);
  margin: var(--space-3) 0;
  flex-wrap: wrap;
}
.provider-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 7px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  transition: all var(--transition-fast);
  background: var(--surface);
}
.provider-link:hover {
  border-color: var(--primary);
  background: var(--primary-softer);
  color: var(--primary);
  text-decoration: none;
}
.ai-textarea {
  min-height: 180px;
  font-family: ui-monospace, 'Menlo', 'Consolas', monospace;
  font-size: 12px;
  line-height: 1.55;
}
.ai-validation {
  margin-top: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.5;
}
.ai-validation.ok { background: var(--success-soft); color: var(--success); }
.ai-validation.err { background: var(--danger-soft); color: var(--danger); }

/* ========= PREVIEW DOC ========= */
.preview-doc {
  background: #fff;
  padding: var(--space-12);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  font-family: 'Times New Roman', serif;
  font-size: 11pt;
  line-height: 1.55;
  max-width: 900px;
  margin: 0 auto;
  color: #000;
}
.preview-doc h1 { font-size: 15pt; text-align: center; text-transform: uppercase; margin: 0 0 4px; }
.preview-doc h2 { font-size: 13pt; text-align: center; text-transform: uppercase; margin: 8px 0; }
.preview-doc h3 { font-size: 12pt; margin: 12px 0 6px; font-weight: 700; }
.preview-doc p { margin: 4px 0; }
.preview-doc table { width: 100%; border-collapse: collapse; margin: 8px 0; }
.preview-doc th,
.preview-doc td {
  border: 1px solid #333;
  padding: 6px 8px;
  vertical-align: top;
  text-align: left;
}
.preview-doc th { background: #f0f0f0; font-weight: 700; }
.preview-doc .kop-sekolah {
  border-bottom: 3px double #000;
  padding-bottom: 8px;
  margin-bottom: 16px;
}
.preview-doc .kop-sekolah h1 { font-size: 15pt; }
.preview-doc .kop-sekolah p { margin: 2px 0; text-align: center; font-size: 10pt; }
.preview-doc .signature-table td { text-align: center; padding: 8px; border: none; }
.preview-doc .signature-line {
  display: inline-block;
  min-width: 200px;
  border-bottom: 1px solid #000;
  margin-top: 60px;
}
.preview-doc .pre-line { white-space: pre-wrap; font-family: 'Times New Roman', serif; }
.preview-doc .meta { font-size: 10pt; color: #333; }

@media (max-width: 900px) {
  .preview-doc {
    padding: var(--space-6) var(--space-4);
    border-radius: var(--radius);
    font-size: 10pt;
  }
  .preview-doc h1 { font-size: 12pt; }
  .preview-doc h2 { font-size: 11pt; }
  .preview-doc h3 { font-size: 10.5pt; }
  .preview-doc th, .preview-doc td { padding: 4px 6px; font-size: 9pt; }
  .preview-doc .signature-line { min-width: 120px; margin-top: 40px; }
}

/* ========= PRINT ========= */
@media print {
  .app-header, .stepper, .stepper-backdrop, .action-bar,
  .page-header, .mobile-nav, .btn, .icon-btn { display: none !important; }
  .app-body {
    grid-template-columns: 1fr;
    padding: 0;
    max-width: 100%;
  }
  .preview-doc {
    box-shadow: none;
    padding: 0;
    border-radius: 0;
    max-width: 100%;
  }
  .preview-doc h2 { page-break-after: avoid; }
  .preview-doc table { page-break-inside: avoid; }
}

/* ========= UTILITIES ========= */
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.hidden { display: none !important; }

@media (max-width: 900px) {
  .desktop-only { display: none !important; }
}
@media (min-width: 901px) {
  .mobile-only { display: none !important; }
}

/* ========= REDUCED MOTION ========= */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
