/* StudyPass — Components
   Buttons, fields, panels, tables, badges, tabs, meters, modal, toast, lock.
   Square, hairline, spacious. Weight is reserved; colour is an accent.
*/

/* ==============================================================
   BUTTON
   ============================================================== */
.btn {
  --btn-height: var(--control-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: var(--btn-height);
  min-height: var(--touch-min);
  padding-inline: var(--space-5);
  border: var(--border-hair) solid transparent;
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  line-height: 1;
  letter-spacing: var(--tracking-normal);
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
  max-width: 100%;
  cursor: pointer;
  transition:
    background-color var(--duration-base) var(--ease-default),
    border-color var(--duration-base) var(--ease-default),
    color var(--duration-base) var(--ease-default);
}
.btn:hover { text-decoration: none; }
.btn:disabled,
.btn[aria-disabled='true'] {
  cursor: not-allowed;
  background: var(--bg-disabled);
  border-color: transparent;
  color: var(--fg-disabled);
}

.btn--primary {
  background: var(--bg-brand);
  border-color: var(--bg-brand);
  color: var(--fg-on-brand);
}
.btn--primary:hover { background: #0F52D8; border-color: #0F52D8; }
[data-theme='dark'] .btn--primary:hover { background: #4E8AFF; border-color: #4E8AFF; }

.btn--secondary {
  background: transparent;
  border-color: var(--edge-hair);
  color: var(--fg-strong);
}
.btn--secondary:hover { border-color: var(--edge-strong); }

.btn--inverse {
  background: var(--brand-white);
  border-color: var(--brand-white);
  color: var(--brand-navy);
}
.btn--inverse:hover { background: var(--brand-sky); border-color: var(--brand-sky); }

.btn--ghost {
  background: transparent;
  border-color: var(--edge-inverse);
  color: var(--fg-on-dark);
}
.btn--ghost:hover { border-color: var(--fg-on-dark); }

.btn--quiet {
  background: transparent;
  border-color: transparent;
  color: var(--fg-brand);
  padding-inline: var(--space-2);
}
.btn--quiet:hover { color: var(--fg-strong); }

.btn--danger {
  background: transparent;
  border-color: var(--edge-error);
  color: var(--brand-orange);
}
.btn--danger:hover { background: var(--brand-orange); color: var(--brand-white); }

.btn--sm { --btn-height: var(--control-sm); min-height: 0; font-size: var(--text-xs); padding-inline: var(--space-4); }
.btn--lg { --btn-height: var(--control-lg); font-size: var(--text-md); padding-inline: var(--space-6); }
.btn--block { display: flex; width: 100%; }
.btn--icon { padding-inline: 0; width: var(--btn-height); }

/* On narrow screens long labels must wrap rather than push the page sideways.
   Mongolian labels run 20-40% longer than the English original. */
@media (max-width: 560px) {
  .btn {
    white-space: normal;
    text-wrap: balance;
    height: auto;
    min-height: var(--btn-height);
    padding-block: var(--space-3);
    line-height: 1.25;
  }
}

/* Grouped controls sit flush — space goes around a group, never inside it */
.btn-group { display: inline-flex; }
.btn-group .btn + .btn { margin-left: calc(-1 * var(--border-hair)); }

/* ==============================================================
   FIELD
   ============================================================== */
.field { display: block; }
.field + .field { margin-top: var(--space-5); }

.field__label {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--fg-strong);
  margin-bottom: var(--space-2);
}
.field__label .req { color: var(--brand-orange); margin-left: 0.15em; }

.field__hint {
  display: block;
  font-size: var(--text-xs);
  color: var(--fg-muted);
  margin-top: var(--space-2);
}
.field__error {
  display: block;
  font-size: var(--text-xs);
  color: var(--brand-orange);
  margin-top: var(--space-2);
  font-weight: var(--weight-medium);
}

.input,
.textarea,
.select {
  display: block;
  width: 100%;
  height: var(--control-md);
  padding: 0 var(--space-4);
  background: var(--bg-canvas);
  border: var(--border-hair) solid var(--edge-hair);
  border-radius: var(--radius);
  color: var(--fg-default);
  font-size: var(--text-md);
  transition: border-color var(--duration-base) var(--ease-default);
}
.input:hover, .textarea:hover, .select:hover { border-color: var(--neutral-32); }
.input::placeholder, .textarea::placeholder { color: var(--fg-placeholder); }
.input:disabled, .textarea:disabled, .select:disabled {
  background: var(--bg-disabled);
  color: var(--fg-disabled);
  cursor: not-allowed;
}
.input[aria-invalid='true'],
.textarea[aria-invalid='true'] { border-color: var(--edge-error); border-width: var(--border-medium); }

.textarea {
  height: auto;
  min-height: 9rem;
  padding: var(--space-3) var(--space-4);
  line-height: var(--leading-body);
  resize: vertical;
}

.select {
  appearance: none;
  padding-right: var(--space-7);
  background-image:
    linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position:
    calc(100% - var(--space-5) - 5px) calc(50% - 2px),
    calc(100% - var(--space-5)) calc(50% - 2px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}

/* Checkbox & radio — square, hairline, no custom SVG */
.choice {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  cursor: pointer;
  font-size: var(--text-sm);
  line-height: var(--leading-heading);
  min-height: var(--touch-min);
  padding-block: var(--space-2);
}
.choice input {
  appearance: none;
  flex: none;
  width: 20px; height: 20px;
  margin-top: 1px;
  border: var(--border-hair) solid var(--edge-hair);
  background: var(--bg-canvas);
  border-radius: var(--radius);
  cursor: pointer;
  display: grid;
  place-content: center;
  transition: border-color var(--duration-fast) var(--ease-default),
              background-color var(--duration-fast) var(--ease-default);
}
.choice input:hover { border-color: var(--edge-strong); }
.choice input:checked { background: var(--bg-brand); border-color: var(--bg-brand); }
.choice input[type='checkbox']:checked::after {
  content: '';
  width: 10px; height: 5px;
  border-left: 2px solid var(--fg-on-brand);
  border-bottom: 2px solid var(--fg-on-brand);
  transform: rotate(-45deg) translate(1px, -1px);
}
.choice input[type='radio']:checked::after {
  content: '';
  width: 8px; height: 8px;
  background: var(--fg-on-brand);
}

/* Selectable answer row — the practice-question primitive */
.option {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  width: 100%;
  padding: var(--space-4) var(--space-5);
  border: var(--border-hair) solid var(--edge-hair);
  background: var(--bg-canvas);
  color: var(--fg-default);
  text-align: left;
  font-size: var(--text-md);
  line-height: var(--leading-heading);
  cursor: pointer;
  transition: border-color var(--duration-base) var(--ease-default),
              background-color var(--duration-base) var(--ease-default);
}
.option + .option { margin-top: calc(-1 * var(--border-hair)); }
.option:hover { border-color: var(--edge-strong); position: relative; z-index: 1; }
.option__key {
  flex: none;
  width: 28px; height: 28px;
  display: grid; place-content: center;
  border: var(--border-hair) solid var(--edge-hair);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--fg-muted);
}
.option[aria-pressed='true'],
.option.is-selected {
  border-color: var(--edge-brand);
  border-width: var(--border-medium);
  position: relative; z-index: 2;
}
.option[aria-pressed='true'] .option__key,
.option.is-selected .option__key {
  background: var(--bg-brand);
  border-color: var(--bg-brand);
  color: var(--fg-on-brand);
}

/* ==============================================================
   PANEL
   ============================================================== */
.panel {
  background: var(--bg-raised);
  border: var(--border-hair) solid var(--edge-hair);
  border-radius: var(--radius);
}
.panel__body { padding: var(--space-6); }
.panel__header,
.panel__footer { padding: var(--space-4) var(--space-6); }
.panel__header {
  border-bottom: var(--border-hair) solid var(--edge-hair);
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-4);
}
.panel__footer {
  border-top: var(--border-hair) solid var(--edge-hair);
  background: var(--bg-subtle);
}
.panel--subtle { background: var(--bg-subtle); }
.panel--flush { border: 0; }
.panel--accent { border-left-width: var(--border-heavy); border-left-color: var(--edge-brand); }
.panel--inverse {
  background: var(--bg-inverse);
  border-color: var(--bg-inverse);
  color: var(--fg-on-dark);
}
.panel--inverse .t-label { color: var(--fg-on-dark-muted); }
.panel--inverse .t-figure,
.panel--inverse .band,
.panel--inverse h2, .panel--inverse h3 { color: var(--fg-on-dark); }
.panel--inverse .band--boxed { border-color: var(--edge-inverse); }

/* Panels sharing edges in a grid — collapse the double hairline */
.panel-set { display: grid; gap: 0; }
.panel-set > .panel + .panel { margin-top: calc(-1 * var(--border-hair)); }
@media (min-width: 760px) {
  .panel-set--row { grid-auto-flow: column; grid-auto-columns: 1fr; }
  .panel-set--row > .panel + .panel { margin-top: 0; margin-left: calc(-1 * var(--border-hair)); }
}

/* ==============================================================
   TABLE
   ============================================================== */
.table { width: 100%; font-size: var(--text-sm); }
.table th,
.table td {
  text-align: left;
  padding: var(--space-4);
  border-bottom: var(--border-hair) solid var(--edge-hair);
  vertical-align: top;
}
.table thead th {
  font-family: var(--font-body);
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--fg-subtle);
  border-bottom-color: var(--edge-hair);
  white-space: nowrap;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--bg-subtle); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table--fixed { table-layout: fixed; }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
/* Opt in per table: only tables that genuinely need the room get a floor. */
.table--wide { min-width: 560px; }

/* ==============================================================
   BADGE / TAG
   ============================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  height: 24px;
  padding-inline: var(--space-3);
  border: var(--border-hair) solid var(--edge-hair);
  border-radius: var(--radius);
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--fg-muted);
  white-space: nowrap;
}
.badge--brand { border-color: var(--edge-brand); color: var(--fg-brand); }
.badge--pass  { border-color: var(--status-pass);  color: var(--fg-strong); }
.badge--warn  { border-color: var(--status-warn);  color: var(--fg-strong); }
.badge--alert { border-color: var(--status-alert); color: var(--fg-strong); }
.badge--solid { background: var(--bg-inverse); border-color: var(--bg-inverse); color: var(--fg-on-dark); }
.badge__dot { width: 6px; height: 6px; flex: none; background: currentColor; }
.badge--pass  .badge__dot { background: var(--status-pass); }
.badge--warn  .badge__dot { background: var(--status-warn); }
.badge--alert .badge__dot { background: var(--status-alert); }

/* Band chip — the product's signature marker */
.band {
  display: inline-flex;
  align-items: baseline;
  gap: 0.15em;
  font-family: var(--font-display);
  font-weight: var(--weight-bold);
  font-variant-numeric: tabular-nums;
  letter-spacing: var(--tracking-tight);
  color: var(--fg-strong);
}
.band--boxed {
  padding: var(--space-2) var(--space-3);
  border: var(--border-medium) solid var(--edge-strong);
  line-height: 1;
}

/* ==============================================================
   STATUS RULE — status is a rule, never a filled slab
   ============================================================== */
.note {
  border-left: var(--border-heavy) solid var(--edge-hair);
  padding: var(--space-1) 0 var(--space-1) var(--space-4);
  font-size: var(--text-sm);
  line-height: var(--leading-heading);
  color: var(--fg-default);
}
.note--pass  { border-left-color: var(--status-pass); }
.note--warn  { border-left-color: var(--status-warn); }
.note--alert { border-left-color: var(--status-alert); }
.note--info  { border-left-color: var(--status-info); }

/* ==============================================================
   TABS
   ============================================================== */
.tabs {
  display: flex;
  gap: var(--space-6);
  border-bottom: var(--border-hair) solid var(--edge-hair);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none;
  padding: var(--space-3) 0;
  margin-bottom: calc(-1 * var(--border-hair));
  border-bottom: var(--border-heavy) solid transparent;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--fg-muted);
  white-space: nowrap;
  transition: color var(--duration-base) var(--ease-default),
              border-color var(--duration-base) var(--ease-default);
}
.tab:hover { color: var(--fg-strong); text-decoration: none; }
.tab[aria-selected='true'],
.tab.is-active {
  color: var(--fg-strong);
  border-bottom-color: var(--edge-brand);
  font-weight: var(--weight-semibold);
}

/* ==============================================================
   METER — readiness, adherence, progress
   ============================================================== */
.meter {
  height: 6px;
  background: var(--bg-muted);
  overflow: hidden;
}
.meter__fill {
  height: 100%;
  background: var(--bg-brand);
  transition: width var(--duration-slow) var(--ease-out);
}
.meter--pass  .meter__fill { background: var(--status-pass); }
.meter--warn  .meter__fill { background: var(--status-warn); }
.meter--alert .meter__fill { background: var(--status-alert); }
.meter--tall { height: 10px; }

/* Marker for the target position on a scale */
.meter--targeted { position: relative; overflow: visible; }
.meter--targeted .meter__target {
  position: absolute;
  top: -4px; bottom: -4px;
  width: 2px;
  background: var(--fg-strong);
}

/* ==============================================================
   LOCK — the blurred higher-band wall. Says "not yet", never "pay up".
   ============================================================== */
.lock { position: relative; }
.lock__content {
  filter: blur(3.5px);
  opacity: 0.5;
  user-select: none;
  pointer-events: none;
}
.lock__label {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  gap: var(--space-2);
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--fg-strong);
}

/* ==============================================================
   MODAL
   ============================================================== */
.modal {
  border: 0;
  padding: 0;
  max-width: min(560px, calc(100vw - 2 * var(--gutter)));
  width: 100%;
  background: var(--bg-raised);
  color: var(--fg-default);
  box-shadow: var(--shadow-overlay);
  border-radius: var(--radius);
}
.modal::backdrop { background: var(--bg-overlay); }
.modal__header {
  display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4);
  padding: var(--space-5) var(--space-6);
  border-bottom: var(--border-hair) solid var(--edge-hair);
}
.modal__body { padding: var(--space-6); }
.modal__footer {
  display: flex; justify-content: flex-end; gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  border-top: var(--border-hair) solid var(--edge-hair);
  background: var(--bg-subtle);
}
.modal__close {
  flex: none;
  width: 32px; height: 32px;
  display: grid; place-content: center;
  color: var(--fg-muted);
  font-size: var(--text-lg);
  line-height: 1;
}
.modal__close:hover { color: var(--fg-strong); }

/* ==============================================================
   TOAST
   ============================================================== */
.toasts {
  position: fixed;
  bottom: var(--space-5);
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: min(420px, calc(100vw - 2 * var(--gutter)));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  background: var(--bg-inverse);
  color: var(--fg-on-dark);
  border-left: var(--border-heavy) solid var(--status-info);
  font-size: var(--text-sm);
  box-shadow: var(--shadow-overlay);
  animation: toast-in var(--duration-slow) var(--ease-out);
}
.toast--pass  { border-left-color: var(--status-pass); }
.toast--warn  { border-left-color: var(--status-warn); }
.toast--alert { border-left-color: var(--status-alert); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .toast { animation: none; }
}

/* ==============================================================
   EMPTY STATE
   ============================================================== */
.empty {
  border: var(--border-hair) dashed var(--edge-hair);
  padding: var(--space-8) var(--space-6);
  text-align: center;
  color: var(--fg-muted);
}
.empty h3 { margin-bottom: var(--space-2); }

/* ==============================================================
   SKELETON
   ============================================================== */
.skeleton {
  background: var(--bg-muted);
  animation: skeleton 1.4s ease-in-out infinite;
}
@keyframes skeleton { 0%,100% { opacity: 1 } 50% { opacity: 0.5 } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none } }
