/* 디자인 시스템 v2 · shared components (docs/DESIGN.md).
   Loaded last on every staff/family page so the shared look wins over
   older feature styles. Tokens live in src/styles.css :root. */

/* ── Numbers ─────────────────────────────────────────────────────────── */
.jj-num,
.tabular,
time,
td.is-num,
th.is-num {
  font-variant-numeric: tabular-nums;
}

/* ── Page container ──────────────────────────────────────────────────── */
.jj-page {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px 32px 48px;
}
.jj-page.is-wide {
  max-width: 1600px;
}
@media (max-width: 1023px) {
  .jj-page {
    padding: 24px 24px 40px;
  }
}
@media (max-width: 700px) {
  .jj-page {
    padding: 16px 16px 32px;
  }
}

/* ── Page header ─────────────────────────────────────────────────────── */
.jj-page-header {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 48px;
  margin: 0 0 20px;
}
.jj-icon-tile {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: var(--jj-radius-card);
  background: var(--jj-primary-100);
  color: var(--jj-primary);
  overflow: hidden;
}
.jj-icon-tile svg {
  width: 22px;
  height: 22px;
}
.jj-icon-tile:has(img) {
  background: var(--jj-surface);
  box-shadow: inset 0 0 0 1px var(--jj-border);
}
.jj-icon-tile img {
  width: 40px;
  height: 40px;
  object-fit: contain;
  transform: scale(1.18);
}
.jj-page-header-text {
  display: grid;
  gap: 2px;
  min-width: 0;
  flex: 1;
}
.jj-page-header h1 {
  margin: 0;
  word-break: keep-all;
  overflow-wrap: anywhere;
  color: var(--jj-text);
  font: var(--jj-text-title);
  letter-spacing: -0.4px;
}
.jj-page-eyebrow {
  color: var(--jj-text-tertiary);
  font-size: 12px;
  font-weight: 600;
  line-height: 16px;
}
.jj-page-description {
  color: var(--jj-text-tertiary);
  font-size: 14px;
  line-height: 20px;
}
.jj-page-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  margin-left: auto;
}
@media (max-width: 700px) {
  .jj-page-header {
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
  }
  .jj-page-header .jj-icon-tile {
    width: 36px;
    height: 36px;
  }
  .jj-page-header h1 {
    font-size: 20px;
    line-height: 28px;
  }
  .jj-page-description {
    font-size: 13px;
    line-height: 18px;
  }
  .jj-page-header-text {
    flex: 1 1 calc(100% - 52px);
  }
  .jj-page-actions {
    margin-left: 0;
    width: 100%;
    justify-content: flex-start;
  }
  /* One action stays beside the title while the title keeps ~7 characters;
     a long one drops to its own line instead of squeezing the title. */
  .jj-page-header:has(.jj-page-actions > :only-child) .jj-page-header-text {
    flex: 1 1 0;
    min-width: 120px;
  }
  .jj-page-actions:has(> :only-child) {
    width: auto;
    margin-left: auto;
  }
}

/* ── Buttons ─────────────────────────────────────────────────────────── */
.jj-btn,
a.jj-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--jj-control-h);
  padding: 0 14px;
  border: 1px solid var(--jj-border-strong);
  border-radius: var(--jj-radius-control);
  background: var(--jj-surface);
  color: var(--jj-gray-800);
  font-size: 14px;
  font-weight: 600;
  line-height: 20px;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}
.jj-btn svg {
  width: 18px;
  height: 18px;
}
.jj-btn:hover {
  background: var(--jj-gray-50);
  border-color: var(--jj-gray-400);
  text-decoration: none;
}
.jj-btn.is-primary,
.jj-btn.primary {
  background: var(--jj-primary);
  border-color: var(--jj-primary);
  color: var(--jj-white);
}
.jj-btn.is-primary:hover,
.jj-btn.primary:hover {
  background: var(--jj-primary-hover);
  border-color: var(--jj-primary-hover);
}
.jj-btn.is-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--jj-gray-700);
}
.jj-btn.is-ghost:hover {
  background: var(--jj-gray-100);
  color: var(--jj-gray-900);
}
.jj-btn.is-danger {
  background: var(--jj-surface);
  border-color: var(--jj-border-strong);
  color: var(--jj-danger-fg);
}
.jj-btn.is-danger:hover {
  background: var(--jj-danger-bg);
  border-color: var(--jj-danger);
}
.jj-btn.is-danger-solid {
  background: var(--jj-danger);
  border-color: var(--jj-danger);
  color: var(--jj-white);
}
.jj-btn.is-sm {
  min-height: var(--jj-control-h-sm);
  padding: 0 10px;
  font-size: 13px;
}
.jj-btn.is-lg {
  min-height: var(--jj-control-h-lg);
  padding: 0 20px;
  font-size: 16px;
}
.jj-btn.is-icon {
  width: var(--jj-control-h);
  padding: 0;
}
.jj-btn.is-icon.is-sm {
  width: var(--jj-control-h-sm);
}
@media (max-width: 700px) {
  .jj-btn.is-primary.is-block-mobile {
    width: 100%;
    min-height: var(--jj-control-h-lg);
  }
}

/* ── Segmented control & filter chips ────────────────────────────────── */
.jj-segmented {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  max-width: 100%;
  padding: 3px;
  border-radius: 10px;
  background: var(--jj-gray-150);
  overflow-x: auto;
  scrollbar-width: none;
}
.jj-segmented > :is(button, a) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--jj-radius-control);
  background: transparent;
  color: var(--jj-gray-600);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  text-decoration: none;
  box-shadow: none;
}
.jj-segmented > :is(button, a):hover {
  background: transparent;
  color: var(--jj-gray-900);
}
.jj-segmented
  > :is(
    [aria-selected="true"],
    [aria-pressed="true"],
    [aria-current="page"],
    .active,
    .is-active
  ) {
  background: var(--jj-surface);
  color: var(--jj-gray-900);
  font-weight: 600;
  box-shadow: var(--jj-shadow-1);
}
.jj-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.jj-chip,
.jj-chips > :is(button, a) {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--jj-border);
  border-radius: var(--jj-radius-pill);
  background: var(--jj-surface);
  color: var(--jj-gray-700);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  text-decoration: none;
}
.jj-chip:hover,
.jj-chips > :is(button, a):hover {
  background: var(--jj-gray-50);
  border-color: var(--jj-gray-300);
}
.jj-chip :is(b, .jj-count),
.jj-chips > :is(button, a) :is(b, .jj-count) {
  color: var(--jj-gray-600);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.jj-chip:is([aria-pressed="true"], [aria-selected="true"], .active, .is-active),
.jj-chips
  > :is(button, a):is(
    [aria-pressed="true"],
    [aria-selected="true"],
    [aria-current="page"],
    .active,
    .is-active
  ) {
  border-color: var(--jj-gray-900);
  background: var(--jj-gray-900);
  color: var(--jj-white);
  font-weight: 600;
}
.jj-chip:is([aria-pressed="true"], [aria-selected="true"], .active, .is-active)
  :is(b, .jj-count),
.jj-chips
  > :is(button, a):is(
    [aria-pressed="true"],
    [aria-selected="true"],
    [aria-current="page"],
    .active,
    .is-active
  )
  :is(b, .jj-count) {
  color: rgb(255 255 255 / 72%);
}

/* Underline tabs: sub-views inside a record (student detail, 내신). */
.jj-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--jj-border);
  overflow-x: auto;
  scrollbar-width: none;
}
.jj-tabs > :is(button, a) {
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  margin-bottom: -1px;
  background: transparent;
  color: var(--jj-gray-600);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
}
.jj-tabs > :is(button, a):hover {
  background: transparent;
  color: var(--jj-gray-900);
}
.jj-tabs > :is([aria-selected="true"], [aria-current="page"], .active) {
  border-bottom-color: var(--jj-gray-900);
  color: var(--jj-gray-900);
  font-weight: 600;
}

/* Month switcher (수납 · 휴가 일정): ‹ 2026년 10월 › + a quiet link. */
.jj-month-switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.jj-month-switch > strong {
  min-width: 112px;
  color: var(--jj-text);
  font-size: 17px;
  font-weight: 700;
  line-height: 24px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.jj-month-switch > .jj-btn.is-icon svg {
  width: 18px;
  height: 18px;
}
.jj-month-link {
  min-height: var(--jj-control-h);
  padding: 0 10px;
  border: 0;
  border-radius: var(--jj-radius-control);
  background: transparent;
  color: var(--jj-primary);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.jj-month-link:hover {
  background: var(--jj-primary-50);
}

/* ── Fields ──────────────────────────────────────────────────────────── */
.jj-field {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: var(--jj-text-secondary);
  font-size: 13px;
  font-weight: 600;
  line-height: 18px;
}
.jj-input,
.jj-select,
.jj-field > :is(input:not([type="checkbox"], [type="radio"]), select) {
  width: 100%;
  min-height: var(--jj-input-h);
  padding: 0 12px;
  border: 1px solid var(--jj-border-strong);
  border-radius: var(--jj-radius-control);
  background-color: var(--jj-surface);
  color: var(--jj-text);
  font-size: 15px;
  font-weight: 400;
}
.jj-select,
select.jj-input {
  appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23646e7b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
}
/* Every single-choice select on the main screens and in shared dialogs
   gets the same chevron instead of the platform arrow. */
:is(.jj-page, .ops-content, .ss, #family-root, dialog.jj-dialog, .bl-student)
  select:not([multiple], [size]) {
  appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23646e7b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
}
.jj-field-hint {
  color: var(--jj-text-tertiary);
  font-size: 12px;
  font-weight: 400;
  line-height: 16px;
}

/* ── Cards ───────────────────────────────────────────────────────────── */
.jj-card {
  border: 1px solid var(--jj-border);
  border-radius: var(--jj-radius-card);
  background: var(--jj-surface);
  padding: 20px;
}
.jj-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.jj-card-header h2,
.jj-card-title {
  margin: 0;
  color: var(--jj-text);
  font: var(--jj-text-section);
}
.jj-section-title {
  margin: 0 0 12px;
  color: var(--jj-text);
  font: var(--jj-text-section);
}

/* ── Data table ──────────────────────────────────────────────────────── */
.jj-table-wrap {
  overflow: auto;
  border: 1px solid var(--jj-border);
  border-radius: var(--jj-radius-card);
  background: var(--jj-surface);
}
.jj-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 14px;
}
.jj-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  height: 40px;
  padding: 0 16px;
  border-bottom: 1px solid var(--jj-border);
  background: var(--jj-gray-50);
  color: var(--jj-text-tertiary);
  font-size: 12px;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}
.jj-table td {
  height: 48px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--jj-divider);
  color: var(--jj-text);
  vertical-align: middle;
}
.jj-table tbody tr:last-child td {
  border-bottom: 0;
}
.jj-table tbody tr:hover td {
  background: var(--jj-gray-50);
}
.jj-table :is(th, td).is-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ── Stat tiles ──────────────────────────────────────────────────────── */
.jj-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}
.jj-stat {
  display: grid;
  gap: 4px;
  padding: 16px;
  border: 1px solid var(--jj-border);
  border-radius: var(--jj-radius-card);
  background: var(--jj-surface);
}
.jj-stat > span:first-child {
  color: var(--jj-text-tertiary);
  font-size: 13px;
  font-weight: 500;
}
.jj-stat strong {
  color: var(--jj-text);
  font-size: 22px;
  font-weight: 700;
  line-height: 30px;
  font-variant-numeric: tabular-nums;
}
.jj-stat small {
  color: var(--jj-text-tertiary);
  font-size: 12px;
}

/* ── Status badges ───────────────────────────────────────────────────── */
.jj-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 8px;
  border-radius: var(--jj-radius-xs);
  background: var(--jj-gray-100);
  color: var(--jj-gray-700);
  font-size: 12px;
  font-weight: 600;
  line-height: 16px;
  white-space: nowrap;
}
.jj-badge.is-success {
  background: var(--jj-success-bg);
  color: var(--jj-success-fg);
}
.jj-badge.is-warning {
  background: var(--jj-warning-bg);
  color: var(--jj-warning-fg);
}
.jj-badge.is-danger {
  background: var(--jj-danger-bg);
  color: var(--jj-danger-fg);
}
.jj-badge.is-info {
  background: var(--jj-primary-100);
  color: var(--jj-primary-hover);
}

/* ── Empty state ─────────────────────────────────────────────────────── */
.jj-empty {
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 40px 20px;
  color: var(--jj-text-tertiary);
  text-align: center;
}
.jj-empty-icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin-bottom: 6px;
  border-radius: var(--jj-radius-pill);
  background: var(--jj-gray-100);
  color: var(--jj-gray-500);
}
.jj-empty-icon svg {
  width: 22px;
  height: 22px;
}
.jj-empty-art {
  width: 144px;
  height: 96px;
  margin-bottom: 4px;
  object-fit: contain;
}
.jj-empty strong {
  color: var(--jj-text);
  font-size: 15px;
  font-weight: 600;
  line-height: 22px;
}
.jj-empty p {
  max-width: 360px;
  font-size: 13px;
  line-height: 18px;
}
.jj-empty :is(button, .jj-btn) {
  margin-top: 10px;
}

/* ── Dialogs & sheets ────────────────────────────────────────────────── */
dialog {
  border: 0;
  border-radius: var(--jj-radius-sheet);
  box-shadow: var(--jj-shadow-2);
  color: var(--jj-text);
}
dialog::backdrop {
  background: rgb(15 20 27 / 40%);
}
/* Shared dialog frame. `.jj-dialog` scrolls as one sheet; its
   `.jj-dialog-header` and action row `.jj-dialog-footer` stay pinned so the
   buttons never scroll away (desktop when it overflows, always on phones).
   A footer inside a padded scroller cancels that padding with
   --jj-dialog-pad-x / --jj-dialog-pad-b so it still spans edge to edge. */
dialog.jj-dialog {
  width: min(var(--jj-dialog-w, 520px), calc(100vw - 32px));
  max-width: calc(100vw - 32px);
  max-height: calc(100dvh - 48px);
  padding: 0;
  border: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--jj-surface);
  word-break: keep-all;
}
dialog.jj-dialog .jj-dialog-header {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 60px;
  padding: 10px 12px 10px 20px;
  border-bottom: 1px solid var(--jj-divider);
  background: var(--jj-surface);
}
dialog.jj-dialog .jj-dialog-header h2 {
  margin: 0;
  font: var(--jj-text-section);
}
.jj-dialog-footer,
dialog.jj-dialog .jj-dialog-footer {
  position: sticky;
  bottom: calc(-1 * var(--jj-dialog-pad-b, 0px));
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin: 4px calc(-1 * var(--jj-dialog-pad-x, 0px))
    calc(-1 * var(--jj-dialog-pad-b, 0px));
  padding: 12px 20px calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--jj-divider);
  background: var(--jj-surface);
}
.jj-dialog-footer > :is(p, span, [role="alert"]) {
  flex: 1 1 0;
  min-width: 0;
  margin: 0;
}
.jj-dialog-footer > :is(p, [role="alert"]):empty {
  display: none;
}
.jj-dialog-footer > [role="alert"]:not(:empty) {
  flex-basis: 100%;
  order: -1;
}
.jj-dialog-footer > :is(button, .jj-btn) {
  min-height: var(--jj-control-h);
}
@media (max-width: 600px) {
  /* Phones: a bottom sheet with full-width, thumb-sized actions. */
  /* The phone keyboard's 작성 도구 bar (mobile-input.js) sits under the sheet. */
  dialog.jj-dialog:modal {
    width: 100%;
    max-width: 100%;
    max-height: calc(
      var(--jj-visible-height, 100dvh) - var(--jj-input-tools, 0px) - 16px -
        env(safe-area-inset-top, 0px)
    );
    margin: auto 0 var(--jj-input-tools, 0px);
    border-radius: var(--jj-radius-sheet) var(--jj-radius-sheet) 0 0;
  }
  dialog.jj-dialog .jj-dialog-header {
    min-height: 56px;
    padding-left: 16px;
  }
  .jj-dialog-footer,
  dialog.jj-dialog .jj-dialog-footer {
    flex-wrap: wrap;
    padding-inline: 16px;
  }
  .jj-dialog-footer > span:empty {
    display: none;
  }
  .jj-dialog-footer > :is(button, .jj-btn):not(.is-quiet) {
    flex: 1 1 0;
    min-height: var(--jj-control-h-lg);
  }
  .jj-dialog-footer > :is(button, .jj-btn):is(.primary, .is-primary, .danger) {
    flex-grow: 2;
  }
}
@media (max-width: 600px) and (prefers-reduced-motion: no-preference) {
  dialog.jj-dialog:modal[open] {
    animation: jj-sheet-in var(--jj-duration-slow, 180ms)
      var(--jj-ease, ease-out);
  }
  @keyframes jj-sheet-in {
    from {
      transform: translateY(24px);
      opacity: 0.6;
    }
  }
}

/* ── Toasts ──────────────────────────────────────────────────────────── */
#toast,
#ops-status {
  border-radius: var(--jj-radius-card) !important;
  background: var(--jj-gray-900) !important;
  color: var(--jj-white) !important;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--jj-shadow-2) !important;
}

/* ── 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;
  }
}
