/* Shared v4 components. Existing pages receive reduced-motion via this import. */
@import './motion.css';

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--canvas); color: var(--text); font: var(--text-base)/1.55 var(--font-ui); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; }
html { -webkit-tap-highlight-color: transparent; }
button, a { touch-action: manipulation; }
button { cursor: pointer; color: inherit; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, p, figure { margin: 0; }
h1 { font-size: var(--text-title); line-height: 1.35; letter-spacing: -.8px; }
h2 { font-size: var(--text-lg); line-height: 1.5; }
h3 { font-size: var(--text-base); }
small, .small { font-size: var(--text-xs); }
svg { display: block; }
svg.i { width: auto; height: auto; max-width: 100%; flex: none; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--a8); outline-offset: 3px; }
::selection { background: var(--a6); color: var(--a12); }
.muted { color: var(--g11); }
.accent-text { color: var(--a11); }
.eyebrow { font-size: var(--text-xs); letter-spacing: 1.7px; font-weight: 650; color: var(--a11); }
.num, .number { font-family: var(--font-num); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.number { font-size: var(--text-number); line-height: 1.15; font-weight: 700; }
.number small { font-size: var(--text-sm); letter-spacing: 0; margin-left: var(--s-2); font-weight: 400; }
.fun { font-family: var(--font); font-weight: 600; }

/* Four levels; bare legacy .button retains an outline surface. */
.btn, .button, .icon-button, .text-button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: var(--h-btn); min-height: var(--h-btn); padding: 0 14px;
  border: 1px solid var(--g7); border-radius: var(--r-control);
  background: var(--surface); color: var(--g12); font: inherit; font-size: 13.5px;
  font-weight: 500; line-height: 1; white-space: nowrap; cursor: pointer;
  transition: background var(--duration) var(--ease), border-color var(--duration), transform 100ms var(--ease);
}
.btn.primary, .button.primary { background: var(--a9); border-color: transparent; color: var(--on-accent); }
.btn.secondary, .button.secondary { background: var(--surface); border-color: var(--line-2); color: var(--g12); }
.btn.outline, .button.outline { background: var(--surface); border-color: var(--g7); color: var(--g12); }
.btn.ghost, .button.ghost, .text-button { background: transparent; border-color: transparent; color: var(--g11); }
.btn.tonal, .button.tonal, .button.soft { background: var(--a3); border-color: transparent; color: var(--a12); }
.btn.sm, .button.sm, .button.small, .icon-button.sm { height: var(--h-btn-sm); min-height: var(--h-btn-sm); padding: 0 10px; font-size: 12.5px; border-radius: var(--r-sm); }
.btn.icon, .button.icon, .icon-button { width: var(--h-btn); padding: 0; flex-shrink: 0; }
.btn.icon.sm, .button.icon.sm, .icon-button.sm { width: var(--h-btn-sm); padding: 0; }
.btn svg, .button svg, .icon-button svg { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.btn:focus-visible, .button:focus-visible, .icon-button:focus-visible, .text-button:focus-visible { outline: 3px solid var(--a8); outline-offset: 3px; }
:where(button, .btn, .button, .icon-button, .input):disabled, :where(.btn, .button, .icon-button)[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }

.badge { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: var(--r-pill); font-size: 12px; font-weight: 500; white-space: nowrap; background: var(--g3); color: var(--g11); }
.badge.accent { background: var(--a3); color: var(--a11); }
.badge.ok { background: var(--ok-3); color: var(--ok-11); }
.badge.warn, .badge.warning { background: var(--warn-3); color: var(--warn-11); }
.badge.bad { background: var(--bad-3); color: var(--bad-11); }
.badge.info { background: var(--info-3); color: var(--info-11); }
.badge.neutral { background: var(--g3); color: var(--g11); }
.dot { width: 6px; height: 6px; flex: none; border-radius: 50%; background: currentColor; }

.field { display: grid; gap: var(--s-2); font-size: var(--text-sm); font-weight: 600; min-width: 0; }
.input, input:not([type="checkbox"]):not([type="radio"]), select, textarea { width: 100%; min-width: 0; height: var(--h-btn); padding: 0 12px; border: 1px solid var(--g7); border-radius: var(--r-control); background: var(--surface); color: var(--g12); }
textarea { height: auto; min-height: 96px; padding: 10px 12px; resize: vertical; }
.input:focus, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; border-color: var(--a8); box-shadow: 0 0 0 3px var(--a4); }
.input[aria-invalid="true"], input[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--bad-9); }
input::placeholder, textarea::placeholder { color: var(--g11); opacity: 1; }
input[type="checkbox"], input[type="radio"] { width: 19px; height: 19px; accent-color: var(--a9); }
.check { min-height: 44px; min-width: 44px; display: inline-flex; align-items: center; gap: var(--s-3); }

.seg, .segmented { display: inline-flex; align-items: center; padding: 3px; gap: 2px; background: var(--g3); border-radius: var(--r-md); }
.seg button, .segmented button { height: 30px; padding: 0 14px; border: 0; border-radius: 9px; background: transparent; font: inherit; font-size: 13.5px; color: var(--g11); white-space: nowrap; }
.seg button[aria-selected="true"], .segmented button[aria-selected="true"], .seg button[aria-pressed="true"], .segmented button[aria-pressed="true"] { background: var(--surface); color: var(--g12); font-weight: 600; box-shadow: var(--shadow-1); }
.tabs { display: flex; gap: var(--s-5); border-bottom: 1px solid var(--g6); overflow-x: auto; scrollbar-width: none; }
.tabs button { position: relative; flex: none; height: 40px; padding: 0; border: 0; background: transparent; font: inherit; color: var(--g11); white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--g12); font-weight: 600; }
.tabs button[aria-selected="true"]::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2px; border-radius: 2px; background: var(--a9); }
.tabs button:focus-visible { outline-offset: -3px; }

.table, .data-table { width: 100%; border-collapse: collapse; text-align: left; }
.table th, .data-table th { height: 36px; padding: 0 12px; font-weight: 500; font-size: 12.5px; color: var(--g11); border-bottom: 1px solid var(--g6); background: var(--g2); }
.table td, .data-table td { height: 48px; padding: 6px 12px; border-bottom: 1px solid var(--g4); font-size: var(--text-sm); }
.table tr:last-child td, .data-table tr:last-child td { border-bottom: 0; }
.table .row-actions, .data-table .row-actions { display: flex; align-items: center; gap: 2px; opacity: .35; transition: opacity var(--duration); }
.table tr:focus-within .row-actions, .data-table tr:focus-within .row-actions { opacity: 1; }
@media (hover: none) { .table .row-actions, .data-table .row-actions { opacity: 1; } }

.card { min-width: 0; padding: var(--s-5); border: 1px solid var(--g6); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow-1); }
.card-h, .card-heading { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); margin-bottom: var(--s-4); }
.card-h h3 { font-size: 15px; font-weight: 600; }
.empty-state { display: grid; justify-items: center; align-content: center; gap: var(--s-3); padding: var(--s-8) var(--s-6); text-align: center; }
.empty-state p { max-width: 440px; color: var(--g11); }
.empty-state .i { width: 32px; height: 32px; color: var(--ink-3); }
.pager, .pagination { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: var(--s-3); padding: 10px 14px; border-top: 1px solid var(--g5); font-size: 12.5px; color: var(--g11); }
.pager-actions { display: flex; gap: 6px; }

/* Native details offers a keyboard-operable ⋯ disclosure without inline JS. */
.more-menu { position: relative; display: inline-block; }
.more-menu > summary { list-style: none; }
.more-menu > summary::-webkit-details-marker { display: none; }
.menu { position: absolute; z-index: 30; top: calc(100% + 6px); right: 0; min-width: 160px; max-width: calc(100vw - 32px); padding: 4px; border: 1px solid var(--g6); border-radius: var(--r-md); background: var(--surface); box-shadow: var(--shadow-2); }
.menu > button, .menu > a { display: flex; align-items: center; width: 100%; min-height: 32px; padding: 6px 10px; border: 0; border-radius: var(--r-sm); background: transparent; color: var(--g12); font-size: var(--text-sm); text-align: left; }
.menu > .danger { color: var(--bad-11); }
.menu > hr { margin: 4px; border: 0; border-top: 1px solid var(--g6); }
.dialog { border: 1px solid var(--g6); border-radius: var(--r-lg); padding: var(--s-6); max-width: 460px; max-height: calc(100dvh - 32px); overflow: auto; width: calc(100% - 32px); color: var(--g12); background: var(--surface); box-shadow: var(--shadow-2); }
.dialog::backdrop { background: var(--backdrop); }
.dialog p { margin: var(--s-4) 0; color: var(--g11); }
.dialog-heading, .dialog-footer { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); }
.dialog-footer { justify-content: flex-end; margin-top: var(--s-5); }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); max-width: calc(100% - 32px); border-radius: var(--r-control); padding: 12px 20px; background: var(--g12); color: var(--surface); z-index: 1000; box-shadow: var(--shadow-2); }
.toast.error { background: var(--bad-11); }

/* Existing shell and grading class contracts. Sidebar scopes its .nav override. */
.brand { display: flex; align-items: center; gap: var(--s-3); font-weight: 750; font-size: var(--text-lg); white-space: nowrap; }
.brand-mark, .avatar { width: 40px; height: 40px; display: inline-grid; place-items: center; border-radius: var(--r-control); background: var(--accent-gradient); color: var(--on-accent); }
.brand-mark { font-size: 28px; line-height: 1; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--a4); color: var(--a11); font-size: 13px; font-weight: 600; flex: none; }
.nav { display: flex; align-items: center; padding: var(--s-1); gap: var(--s-1); background: var(--g3); border-radius: var(--r-pill); }
.nav a { border: 0; padding: 10px 21px; border-radius: var(--r-pill); white-space: nowrap; font-size: var(--text-sm); color: var(--g11); }
.nav a[aria-current="page"] { background: var(--surface); color: var(--a12); box-shadow: var(--shadow-1); font-weight: 650; }
.grade-a { --grade: var(--grade-a); --grade-bg: var(--grade-a-bg); }
.grade-b { --grade: var(--grade-b); --grade-bg: var(--grade-b-bg); }
.grade-c { --grade: var(--grade-c); --grade-bg: var(--grade-c-bg); }
.grade-d { --grade: var(--grade-d); --grade-bg: var(--grade-d-bg); }
.grade-label { color: var(--grade); background: var(--grade-bg); border-radius: var(--r-sm); padding: 8px 12px; }
.grade-buttons { display: flex; gap: var(--s-2); }
.grade-buttons button { width: 44px; height: 44px; border: 1px solid var(--g6); border-radius: var(--r-sm); color: var(--g11); background: var(--surface); font-weight: 700; }
.grade-buttons button[aria-pressed="true"] { color: var(--grade); background: var(--grade-bg); border-color: var(--grade); box-shadow: inset 0 0 0 1px var(--grade); }
.rule { border: 0; border-top: 1px solid var(--g6); margin: var(--s-4) 0; }
.skip { position: fixed; top: -80px; left: 16px; z-index: 1100; background: var(--surface); padding: 12px; }
.skip:focus { top: 12px; }
@media (hover: hover) {
  .btn:not(:disabled):not([aria-disabled="true"]):hover, .button:not(:disabled):not([aria-disabled="true"]):hover, .icon-button:not(:disabled):hover { background: var(--g2); border-color: var(--g8); }
  .btn.primary:not(:disabled):not([aria-disabled="true"]):hover, .button.primary:not(:disabled):not([aria-disabled="true"]):hover { background: var(--a10); border-color: transparent; }
  .btn.secondary:not(:disabled):not([aria-disabled="true"]):hover, .button.secondary:not(:disabled):not([aria-disabled="true"]):hover { background: var(--g4); border-color: transparent; }
  .button.soft:not(:disabled):hover { background: var(--a4); border-color: transparent; }
  .btn.ghost:not(:disabled):not([aria-disabled="true"]):hover, .button.ghost:not(:disabled):not([aria-disabled="true"]):hover, .text-button:not(:disabled):hover { background: var(--g3); border-color: transparent; color: var(--g12); }
  .table tr:hover td, .data-table tr:hover td { background: var(--a2); }
  .table tr:hover .row-actions, .data-table tr:hover .row-actions { opacity: 1; }
  .menu > button:not(:disabled):hover, .menu > a:hover { background: var(--g3); }
}
@media (max-width: 760px) {
  h1 { font-size: 27px; }
  .nav a { padding: 10px 13px; }
  .brand { font-size: 17px; }
  .card-heading { gap: 8px; }
  .data-table th, .data-table td { padding-left: 8px; padding-right: 8px; }
}

/* One neutral scrollbar treatment for every scrolling surface. */
* { scrollbar-width:thin; scrollbar-color:var(--g8) transparent; scrollbar-gutter:stable; }
::-webkit-scrollbar { width:6px; height:6px; }
::-webkit-scrollbar-track { background:transparent; }
::-webkit-scrollbar-thumb { background:var(--g8); border-radius:6px; }
::-webkit-scrollbar-thumb:hover { background:var(--g10); }

/* A button row has one filled primary; subsequent primary siblings are tonal. */
.btn.primary ~ .btn.primary, .button.primary ~ .button.primary {
 background: var(--accent-soft); color: var(--accent-strong); border-color: var(--accent-line);
}
.confirm-dialog { border-radius:var(--r-xl); box-shadow:var(--sh-3); }
