/* Shared components: buttons, cards, pills, forms, tables, toggles, dialogs, toasts, callouts. */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 8px 16px;
  border-radius: var(--r-sm); border: 1px solid var(--line);
  background: var(--surface); color: var(--ink);
  font-weight: 700; font-size: var(--fs-sm); cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { border-color: var(--ink-2); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { border-color: var(--primary); opacity: .92; }
.btn-ghost { border-color: transparent; background: none; color: var(--muted); }
.btn-ghost:hover { color: var(--ink); border-color: transparent; background: var(--surface-2); }
.btn-danger { color: var(--bad); }
.btn-lg { min-height: 48px; padding: 12px 22px; font-size: var(--fs-md); }
.btn-sm { min-height: 32px; padding: 4px 12px; font-size: var(--fs-xs); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; transform: none; }
.btn svg { width: 16px; height: 16px; flex: none; }
.link-btn { border: 0; background: none; padding: 0; color: var(--muted); font-weight: 700; font-size: var(--fs-sm); cursor: pointer; }
.link-btn:hover { color: var(--ink); text-decoration: underline; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 20px 22px;
  min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-title { font-size: var(--fs-lg); }
.card-sub { font-size: var(--fs-xs); color: var(--muted); }
.card.is-alert { border-color: var(--accent); }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: var(--fs-xs); font-weight: 700;
  padding: 3px 10px; border-radius: var(--r-pill);
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.pill-accent { background: var(--accent-tint); color: var(--accent-ink); }
.pill-good { background: var(--good-soft); color: var(--good); }
.pill-bad { background: var(--bad-soft); color: var(--bad); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }
.pill-ink { background: var(--primary); color: var(--on-primary); }
.req-tag { font-size: .6875rem; font-weight: 700; padding: 2px 8px; border-radius: var(--r-pill); background: var(--surface-2); color: var(--muted); }

.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: var(--line-soft); color: var(--ink-2);
  font-size: .6875rem; font-weight: 700; letter-spacing: .02em;
}
.avatar-lg { width: 44px; height: 44px; font-size: var(--fs-sm); }

.bar { height: 8px; border-radius: var(--r-pill); background: var(--line-soft); overflow: hidden; display: flex; }
.bar > span { display: block; height: 100%; background: var(--ink-2); }
.bar > span.accent { background: var(--accent); }
.bar > span.ink { background: var(--ink); }

/* Forms */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label, .field .label { font-size: var(--fs-sm); font-weight: 700; }
.input, .select, .textarea {
  width: 100%; min-height: 42px; padding: 9px 12px;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink);
}
.textarea { min-height: 140px; resize: vertical; line-height: 1.5; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px var(--accent-tint); }
.input[aria-invalid="true"] { border-color: var(--bad); }
.field-hint { font-size: var(--fs-xs); color: var(--muted); }
.field-error { font-size: var(--fs-xs); color: var(--bad); font-weight: 700; }
.form-grid { display: grid; gap: 16px; }

/* Toggle switch */
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 46px; height: 26px; margin: 0; cursor: pointer; }
.switch .track { width: 46px; height: 26px; border-radius: 13px; background: var(--line-soft); position: relative; transition: background .15s; flex: none; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--surface); box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::after { transform: translateX(20px); background: var(--on-primary); }
.switch input:focus-visible + .track { outline: 3px solid var(--accent); outline-offset: 2px; }
.switch input:disabled + .track { opacity: .5; }
.switch .state { font-size: var(--fs-xs); color: var(--muted); min-width: 60px; text-align: right; }

/* Segmented control (role toggle on sign-in) */
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: var(--r-pill); background: var(--surface-2); border: 1px solid var(--line-soft); }
.segmented button { border: 0; border-radius: var(--r-pill); padding: 9px 12px; font-weight: 700; font-size: var(--fs-sm); background: none; color: var(--muted); cursor: pointer; }
.segmented button[aria-pressed="true"] { background: var(--primary); color: var(--on-primary); }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); }
table.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th { text-align: left; font-size: .6875rem; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); font-weight: 700; padding: 12px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .num, .table th.num { text-align: right; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover td { background: var(--surface-2); }
.sort-btn { border: 0; background: none; padding: 0; font: inherit; color: inherit; letter-spacing: inherit; text-transform: inherit; cursor: pointer; display: inline-flex; gap: 4px; align-items: center; }
.sort-btn[aria-sort] { color: var(--ink); }
.person { display: flex; align-items: center; gap: 10px; font-weight: 700; white-space: nowrap; }

/* Tiles */
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 16px 20px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.tile-label { font-size: .6875rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.tile-value { font-family: var(--font-display); font-size: 2rem; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; }
.tile-note { font-size: var(--fs-xs); color: var(--muted); }
.tile.is-alert { border-color: var(--accent); }
.tile.is-alert .tile-value { color: var(--accent); }

/* Callouts and feedback */
.callout { border-radius: var(--r-md); padding: 14px 16px; background: var(--surface-2); display: flex; gap: 12px; align-items: flex-start; }
.callout-icon { width: 24px; height: 24px; border-radius: 50%; flex: none; display: grid; place-items: center; background: var(--surface); color: var(--ink); font-weight: 700; font-size: var(--fs-xs); }
.callout strong.callout-title { display: block; font-size: var(--fs-sm); margin-bottom: 2px; }
.callout-accent { background: var(--accent-soft); border: 1px dashed var(--accent); }
.feedback { border-radius: var(--r-md); padding: 12px 16px; border: 1px solid transparent; }
.feedback-title { font-weight: 700; display: flex; align-items: center; gap: 6px; }
.feedback p { font-size: var(--fs-sm); margin-top: 4px; }
.feedback.good { background: var(--good-soft); border-color: var(--good); color: var(--ink); }
.feedback.good .feedback-title { color: var(--good); }
.feedback.bad { background: var(--bad-soft); border-color: var(--bad); }
.feedback.bad .feedback-title { color: var(--bad); }
.feedback.info { background: var(--surface-2); border-color: var(--line); }
.feedback.warn { background: var(--warn-soft); border-color: var(--warn); }
.feedback.warn .feedback-title { color: var(--warn); }

.empty { padding: 24px; text-align: center; color: var(--muted); font-size: var(--fs-sm); }

/* Dialog */
.dialog-scrim { position: fixed; inset: 0; background: var(--scrim); z-index: 50; display: grid; place-items: start center; overflow-y: auto; padding: max(40px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) 40px max(16px, env(safe-area-inset-left, 0px)); }
.dialog { width: min(600px, 100%); background: var(--surface); border-radius: 12px; border: 1px solid var(--line); box-shadow: var(--shadow); }
.dialog-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line-soft); }
.dialog-head h2 { font-size: var(--fs-xl); flex: 1; min-width: 0; }
.dialog-body { padding: 18px 20px 22px; display: flex; flex-direction: column; gap: 18px; }
.icon-btn { width: 36px; height: 36px; border-radius: var(--r-sm); border: 0; background: none; color: var(--muted); cursor: pointer; display: grid; place-items: center; font-size: 20px; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

/* Toast */
.toasts { position: fixed; right: max(16px, env(safe-area-inset-right, 0px)); bottom: max(16px, env(safe-area-inset-bottom, 0px)); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; pointer-events: none; }
.toast { background: var(--primary); color: var(--on-primary); padding: 10px 16px; border-radius: var(--r-sm); font-size: var(--fs-sm); font-weight: 700; box-shadow: var(--shadow); max-width: 360px; animation: toast-in .2s ease-out; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* Prose (lesson bodies) */
.prose { display: flex; flex-direction: column; gap: 14px; max-width: 68ch; }
.prose p, .prose li { line-height: 1.6; }
.prose ul { margin: 0; padding-left: 1.25rem; display: flex; flex-direction: column; gap: 6px; }
.prose code { font-size: .875em; background: var(--surface-2); padding: 1px 6px; border-radius: 4px; }
.prose pre { margin: 0; background: var(--code-bg); color: var(--code-ink); padding: 16px 18px; border-radius: var(--r-md); overflow-x: auto; font-size: var(--fs-sm); line-height: 1.6; }
.prose pre code { background: none; padding: 0; color: inherit; font-size: inherit; }
.prose pre .cm { color: #9AA1AC; }
.prose pre .kw { color: var(--code-key); }
.prose blockquote { margin: 0; border-left: 3px solid var(--line); padding: 4px 0 4px 16px; display: flex; flex-direction: column; gap: 6px; color: var(--ink-2); }
.prose h4 { font-size: var(--fs-md); }

.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.muted { color: var(--muted); }
.small { font-size: var(--fs-sm); }
.xsmall { font-size: var(--fs-xs); }

@media (max-width: 820px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile { padding: 14px 16px; }
  .tile-value { font-size: 1.625rem; }
  .card { padding: 16px; }
}

.feedback-title svg, .pill svg, .callout svg { width: 16px; height: 16px; flex: none; }
.pill svg { width: 12px; height: 12px; }
