/* EduCore Master Stylesheet — Built per spec/17 Design System */

:root {
  /* Brand Merah (Flag-Saturated Red) */
  --color-brand-50: #FFF5F6;
  --color-brand-100: #FDE7EA;
  --color-brand-200: #F8C4CC;
  --color-brand-600: #C8102E;
  --color-brand-700: #A50D26;
  --color-brand-800: #8E0B20;

  /* Neutral Warm Ink & Paper */
  --color-ink-900: #16110F;
  --color-ink-700: #3A302C;
  --color-ink-500: #6B615C;
  --color-ink-550: #5C514A;
  --color-ink-450: #7A6E69;
  --color-ink-300: #9A8F8A;
  --color-line-strong: #E7E1DC;
  /* status families used by the console pills, bars, alerts and notes (values as they were written inline) */
  --color-ok-ink: #166534;
  --color-ok-soft: #E8F6EC;
  --color-ok-line: #BBE5C8;
  --color-ok-fill: #16A34A;
  --color-warn-ink: #92400E;
  --color-warn-soft: #FEF3C7;
  --color-warn-line: #FDE68A;
  --color-warn-wash: #FFFBEB;
  --color-warn-fill: #D97706;
  --color-alert-ink: #B91C1C;
  --color-alert-soft: #FEF2F2;
  --color-alert-line: #FECACA;
  --color-line: #E5DDD9;
  --color-input-border: #857A74; /* form controls: 3:1+ on white (WCAG 1.4.11); --color-line stays for dividers */
  --color-surface-alt: #F7F4F2;
  --color-surface-tint: #F3EFEC;   /* console: hover and zebra tint, one step darker than surface-alt */
  --color-surface-faint: #FBF9F8;  /* console: the faintest panel background */
  --color-line-soft: #EFE8E4;      /* console: row separators inside a card (--color-line frames the card) */
  --color-ink-600: #3D3532;        /* console: secondary text and rail items */
  --color-surface: #FFFFFF;

  /* Semantic */
  --color-success: #0E7A4F;
  --color-success-bg: #E6F4EE;
  --color-warning: #9A5A00;
  --color-warning-bg: #FDF1E0;
  --color-danger: #B3261E;
  --color-danger-bg: #FCE9E7;
  --color-info: #1B5FA8;
  --color-info-bg: #E8F0FA;

  /* Attendance */
  --color-att-hadir: #0E7A4F;
  --color-att-hadir-bg: #E6F4EE;
  --color-att-terlambat: #9A5A00;
  --color-att-terlambat-bg: #FDF1E0;
  --color-att-sakit: #1B5FA8;
  --color-att-sakit-bg: #E8F0FA;
  --color-att-izin: #6B615C;
  --color-att-izin-bg: #F0ECE9;
  --color-att-alpa: #B3261E;
  --color-att-alpa-bg: #FCE9E7;
  --color-att-dispen: #7C3AED;
  --color-att-dispen-bg: #F3E8FF;

  /* Radii */
  --radius-none: 0px;
  --radius-sm: 4px;
  --radius-full: 9999px;
}

/* Reset & Base Typography */
*, ::before, ::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  border-width: 0;
  border-style: solid;
  border-color: var(--color-line);
}

html {
  font-family: 'IBM Plex Sans', 'IBM Plex Sans Fallback', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--color-ink-900);
  background-color: var(--color-surface-alt);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Typography tokens */
.font-display { font-family: 'Plus Jakarta Sans', 'Plus Jakarta Sans Fallback', sans-serif; }
.font-sans { font-family: 'IBM Plex Sans', 'IBM Plex Sans Fallback', sans-serif; }
.font-mono { font-family: 'IBM Plex Mono', 'IBM Plex Mono Fallback', monospace; }

.text-display { font-family: 'Plus Jakarta Sans', 'Plus Jakarta Sans Fallback', sans-serif; font-weight: 800; font-size: 3rem; line-height: 1.1; }
.text-h1 { font-family: 'Plus Jakarta Sans', 'Plus Jakarta Sans Fallback', sans-serif; font-weight: 700; font-size: 2rem; line-height: 1.2; }
.text-h2 { font-family: 'Plus Jakarta Sans', 'Plus Jakarta Sans Fallback', sans-serif; font-weight: 700; font-size: 1.375rem; line-height: 1.3; }
.text-h3 { font-family: 'IBM Plex Sans', 'IBM Plex Sans Fallback', sans-serif; font-weight: 600; font-size: 1.125rem; line-height: 1.4; }
.text-body { font-family: 'IBM Plex Sans', 'IBM Plex Sans Fallback', sans-serif; font-weight: 400; font-size: 0.9375rem; line-height: 1.5; }
.text-body-sm { font-family: 'IBM Plex Sans', 'IBM Plex Sans Fallback', sans-serif; font-weight: 400; font-size: 0.8125rem; line-height: 1.4; }
.text-label { font-family: 'IBM Plex Mono', 'IBM Plex Mono Fallback', monospace; font-weight: 600; font-size: 0.6875rem; line-height: 1.2; text-transform: uppercase; letter-spacing: 0.05em; }

/* Color utilities */
.text-brand-600 { color: var(--color-brand-600); }
.text-brand-700 { color: var(--color-brand-700); }
.bg-brand-50 { background-color: var(--color-brand-50); }
.bg-brand-600 { background-color: var(--color-brand-600); }
.bg-brand-700 { background-color: var(--color-brand-700); }
.bg-brand-800 { background-color: var(--color-brand-800); }

.text-ink-900 { color: var(--color-ink-900); }
.text-ink-700 { color: var(--color-ink-700); }
.text-ink-500 { color: var(--color-ink-500); }
.bg-surface { background-color: var(--color-surface); }
.bg-surface-alt { background-color: var(--color-surface-alt); }
.border-line { border-color: var(--color-line); }

/* Semantic utilities */
.text-success { color: var(--color-success); }
.bg-success { background-color: var(--color-success); }
.bg-success-subtle { background-color: var(--color-success-bg); }

.text-warning { color: var(--color-warning); }
.bg-warning { background-color: var(--color-warning); }
.bg-warning-subtle { background-color: var(--color-warning-bg); }

.console-impersonation-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 20px;
  background: #fff3cd;
  color: #664d03;
  font-size: 14px;
}

.text-danger { color: var(--color-danger); }
.bg-danger { background-color: var(--color-danger); }
.bg-danger-subtle { background-color: var(--color-danger-bg); }

.text-info { color: var(--color-info); }
.bg-info { background-color: var(--color-info); }
.bg-info-subtle { background-color: var(--color-info-bg); }

/* Institutional Radii & Elevation */
.rounded-none { border-radius: 0px !important; }
.rounded-sm { border-radius: 4px; }
.rounded-full { border-radius: 9999px; }

.shadow-flat { box-shadow: none; }
.shadow-raised { box-shadow: 0 4px 12px rgba(22, 17, 15, 0.08); }
.shadow-overlay { box-shadow: 0 16px 32px rgba(22, 17, 15, 0.16); }

/* Standard Button Components */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: 'IBM Plex Sans', 'IBM Plex Sans Fallback', sans-serif;
  font-weight: 500;
  font-size: 0.9375rem;
  height: 40px;
  padding: 0 16px;
  border-radius: 4px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 150ms ease-out, opacity 150ms ease-out;
}
.btn:focus-visible {
  outline: 2px solid var(--color-brand-600);
  outline-offset: 2px;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background-color: var(--color-brand-600);
  color: #FFFFFF;
}
.btn-primary:hover:not(:disabled) {
  background-color: var(--color-brand-700);
}
.btn-primary:active:not(:disabled) {
  background-color: var(--color-brand-800);
}

.btn-secondary {
  background-color: var(--color-surface);
  color: var(--color-ink-900);
  border: 1px solid var(--color-line);
}
.btn-secondary:hover:not(:disabled) {
  background-color: var(--color-surface-alt);
}

.btn-ghost {
  background-color: transparent;
  color: var(--color-ink-700);
}
.btn-ghost:hover:not(:disabled) {
  background-color: var(--color-surface-alt);
}

.btn-destructive {
  background-color: var(--color-danger);
  color: #FFFFFF;
}
.btn-destructive:hover:not(:disabled) {
  opacity: 0.9;
}

/* Institutional Sharp Cards & Panels */
.card {
  background-color: var(--color-surface);
  border: 1px solid var(--color-line);
  border-radius: 0px;
  padding: 24px;
}

/* Form Inputs */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.form-note { display: flex; flex-direction: column; gap: 4px; }

/* One horizontal row of fields. Every field is a three-row subgrid (label, control, note), so the controls of
   neighbouring fields share a line however long a label wraps or whether a field has help text or an error below it.
   The action cell takes the control row, so its button sits level with the inputs. */
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0 12px;
  align-items: start;
}
.form-row > .form-group,
.form-row > .form-row-action {
  display: grid;
  grid-row: span 3;
  grid-template-rows: subgrid;
  row-gap: 8px;
  padding-bottom: 12px;
  min-width: 0;
}
.form-row > .form-row-action > :first-child { grid-row: 2; }
.form-row > .form-row-error { grid-column: 1 / -1; margin: 0 0 12px; color: var(--color-danger); }
.form-row .form-label { align-self: end; }
/* searchable_select.js swaps a long <select> for a combobox box; outside a form row it keeps a 220px floor, inside one it
   takes the cell's width like every other control so it cannot run under the next field. */
.ss-input { min-width: 220px; }
.form-row .ss-frame { display: block; min-width: 0; }
.form-row .ss-input { min-width: 0; }
.form-row .form-input,
.form-row select,
.form-row input:not([type=checkbox]):not([type=radio]) { width: 100%; min-width: 0; box-sizing: border-box; }

.form-label {
  font-family: 'IBM Plex Sans', 'IBM Plex Sans Fallback', sans-serif;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-ink-700);
}
.form-input {
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--color-input-border);
  border-radius: 4px;
  background-color: var(--color-surface);
  font-family: 'IBM Plex Sans', 'IBM Plex Sans Fallback', sans-serif;
  font-size: 0.9375rem;
  color: var(--color-ink-900);
}
.form-required { color: var(--color-danger); }
.form-input:focus {
  border-color: var(--color-brand-600);
  outline: 2px solid var(--color-brand-600);
  outline-offset: 2px;
}
.form-checkbox {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--color-brand-600);
  cursor: pointer;
}

.form-checks > div { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.form-checks input { flex: none; width: 18px; height: 18px; margin: 0; accent-color: var(--color-brand-600); cursor: pointer; }
.form-checks label { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }

/* HTMX Transition & Indicator Support */
.htmx-indicator {
  display: none;
}
.htmx-request .htmx-indicator {
  display: inline-flex;
}
.htmx-request.htmx-indicator {
  display: inline-flex;
}

/* Text for screen readers only: still read, never drawn (the standard visually-hidden recipe). Templates already used this
   class (chart columns, action-column headers) before it existed, so the text showed on screen. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Keyboard users: a visible focus ring everywhere unless a component draws its own (specificity 0 here, so any
   component rule such as `.btn:focus-visible` wins). */
:where(a, button, summary, select, input, textarea, [tabindex]):focus-visible {
  outline: 2px solid #C8102E;
  outline-offset: 2px;
}

/* "Skip to content": first thing a keyboard user reaches, hidden until focused. */
.skip-link {
  position: absolute;
  left: 8px;
  top: -48px;
  z-index: 1000;
  padding: 10px 16px;
  background: #16110F;
  color: #fff;
  border-radius: 6px;
  text-decoration: none;
}
.skip-link:focus { top: 8px; }
#console-content:focus { outline: none; }

/* Motion: people who ask the OS for less get none (SOP 1.3 item 9); state changes stay, the movement goes. */
@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; }
}

/* Hidden by a script toggling the class (strict CSP: a script cannot write `style="display:none"` attributes any more
   than a template can; it can still switch a class). !important so it beats a component's own display, as the inline did. */
.is-hidden { display: none !important; }
/* Sign out is a POST (a cross-site GET must not end a session): the form sits inline and the button reads as the link it replaced. */
.logout-form { display: inline-flex; margin: 0; }
.link-button { background: none; border: 0; padding: 0; font: inherit; cursor: pointer; min-height: 24px; }
.link-button:hover { text-decoration: underline !important; }
.login-notice { margin: 0 0 24px; padding: 12px; background: var(--color-success-bg); border: 1px solid var(--color-success); color: var(--color-success); font-size: 0.875rem; }

/* Language switch in the base template: one segmented control, both segments the same width so a busy segment never moves its neighbour. */
.lang-switch { display: inline-flex; align-items: stretch; border: 1px solid var(--color-line); border-radius: 999px; overflow: hidden; background: var(--color-surface); }
.lang-switch-btn { min-width: 40px; padding: 4px 12px; border: 0; background: transparent; color: var(--color-ink-700); font: inherit; font-size: 0.75rem; font-weight: 600; letter-spacing: 0.04em; cursor: pointer; transition: background-color 150ms ease-out; }
.lang-switch-btn + .lang-switch-btn { border-left: 1px solid var(--color-line); }
.lang-switch-btn:hover:not(:disabled):not(.is-active) { background: var(--color-surface-alt); }
.lang-switch-btn:focus-visible { outline: 2px solid var(--color-brand-600); outline-offset: -2px; }
.lang-switch-btn.is-active { background: var(--color-brand-600); color: var(--color-surface); --busy-ink: var(--color-surface); }

/* Busy button: the double-submit guard (console_actions.js) adds .is-busy to the pressed submit button. The label stays in place (so the button
   keeps its width) but is hidden, and a ring sized from the button's own font size turns in its centre. --busy-ink is the ring colour,
   set per variant because the label colour itself is made transparent. */
.is-busy { position: relative; color: transparent !important; pointer-events: none; --busy-ink: var(--color-ink-900); }
.is-busy::after { content: ""; position: absolute; top: 50%; left: 50%; box-sizing: border-box; width: 1.1em; height: 1.1em; margin: -0.55em 0 0 -0.55em; border: 2px solid transparent; border-top-color: var(--busy-ink); border-right-color: var(--busy-ink); border-radius: 50%; animation: busy-spin 700ms linear infinite; }
.btn-primary.is-busy, .btn-destructive.is-busy, #btn-confirm-force-submit.is-busy { --busy-ink: #FFFFFF; }
.btn-ghost.is-busy { --busy-ink: var(--color-ink-700); }
.is-busy:disabled { opacity: 0.8; cursor: progress; }
@keyframes busy-spin { to { transform: rotate(360deg); } }

/* Two tiny utilities for places where a script or a condition picks the class (no style attribute under the strict CSP). */
.u-m0 { margin: 0; }
.u-fw600 { font-weight: 600; }
.u-mt8 { margin-top: 8px; }

/* The calendar OAuth callback page (apps/calendar_sync/views.py, a small standalone document). */
.cal-callback { font-family: system-ui, sans-serif; padding: 2rem; }
.cal-callback h2.is-ok { color: #1a7f37; }
.cal-callback h2.is-fail { color: #c8102e; }

/* Touch targets on a phone (WCAG 2.5.8, SOP 1.3 item 8: 44 px) for the controls outside the console: the public site header, its buttons,
   the sign-in and password-reset pages. The console has its own phone block in console.css. Found by measuring every public page at 375 px. */
@media (max-width: 599px) {
  .btn, .form-input, .lang-switch-btn, .lang-switcher-trigger, .site-brand { min-height: 44px; box-sizing: border-box; }
  .lang-switch-btn { min-width: 44px; }
  input:is([type="text"], [type="email"], [type="tel"], [type="password"], [type="search"], [type="number"], [type="url"], [type="date"]), select, textarea { min-height: 44px; box-sizing: border-box; }
  .site-brand { display: inline-flex; align-items: center; }
}
