/* Shared controls and layout, adapted from the accepted collaboration catalogue. */
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  height: 100%;
}
body {
  background: var(--bg);
  color: var(--fg);
  font: var(--fs-sm) / 1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  text-wrap: pretty;
}
b,
strong,
th {
  font-weight: var(--fw-semibold);
}
h1,
h2,
h3 {
  text-wrap: balance;
  margin: 0;
  font-weight: var(--fw-semibold);
}
button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}
a {
  color: inherit;
}
#root {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}
.k-i {
  width: 16px;
  height: 16px;
  flex: none;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.k-grow {
  flex: 1;
  min-width: 0;
}
.k-spacer {
  flex: 1;
}
.k-link {
  color: var(--brand-text);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.k-bad {
  color: var(--danger);
}

.k-frame {
  container: frame / inline-size;
  position: relative;
  width: var(--fw, 100%);
  max-width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  box-shadow: 0 0 0 1px var(--border); /* outside the frame, so no overlay edge doubles it */
}
.k-nav {
  grid-area: nav;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.k-nav-i {
  flex: 1;
  min-height: var(--touch);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: var(--fs-xs);
  color: var(--muted-fg);
  text-decoration: none;
}
.k-nav-i.on {
  color: var(--brand-text);
  font-weight: var(--fw-semibold);
}
.k-main {
  overflow: auto;
  min-width: 0;
}
/* ---------- page ---------- */
.k-page {
  padding: var(--sp-4);
  max-width: 960px;
  margin: 0 auto;
}
.k-page-h {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}
.k-page-h h1 {
  font-size: var(--fs-xl);
  flex: 1 1 10rem; /* wraps above the actions before it would shrink under them */
  min-width: 0;
}
.k-page-actions {
  display: flex;
  gap: var(--sp-2);
}
.k-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-3);
}
@container frame (min-width: 48rem) {
  .k-page {
    padding: var(--sp-5);
  }
}

/* ---------- controls ---------- */
.k-btn {
  min-height: var(--touch);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 0 var(--sp-3);
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--fg);
  font-size: var(--fs-sm);
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
}
.k-btn.icon {
  width: var(--touch);
  padding: 0;
}
.k-btn.primary {
  background: var(--brand);
  color: var(--brand-fg);
  border-color: transparent;
  font-weight: var(--fw-semibold);
}
.k-btn.ghost {
  border-color: transparent;
  background: transparent;
}
.k-btn.danger {
  color: var(--danger);
}
.k-btn[data-need='no'] {
  opacity: 0.6;
  cursor: not-allowed;
}
.k-input {
  width: 100%;
  min-height: var(--touch);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 0 var(--sp-3);
  font-size: var(--fs-md);
}
.k-textarea {
  padding: var(--sp-2) var(--sp-3);
  resize: vertical;
  display: block;
}
.k-input:focus {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}
.k-field {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}
.k-label {
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  color: var(--muted-fg);
}
.k-hint {
  font-size: var(--fs-xs);
  color: var(--muted-fg);
}
@container frame (min-width: 48rem) {
  .k-btn,
  .k-input {
    min-height: var(--control-h);
    font-size: var(--fs-sm);
  }
  .k-btn.icon {
    width: var(--control-h);
  }
}

/* ---------- content ---------- */
.k-badge {
  display: inline-flex;
  align-items: center;
  padding: 0 var(--sp-2);
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  font-size: var(--fs-xs);
  white-space: nowrap;
  color: var(--muted-fg);
}
.k-badge.success {
  color: var(--success);
}
.k-badge.warning {
  color: var(--warning);
}
.k-badge.brand {
  color: var(--brand-text);
  background: var(--brand-subtle);
  border-color: transparent;
}
.k-list {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.k-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  min-height: var(--touch);
  text-decoration: none;
  border-bottom: 1px solid var(--border);
}
.k-row:last-child {
  border-bottom: 0;
}
.k-row-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.k-row-title {
  font-weight: var(--fw-semibold);
}
.k-row-meta {
  font-size: var(--fs-xs);
  color: var(--muted-fg);
}
.k-row-side {
  flex: none;
  display: flex;
  gap: var(--sp-2);
  align-items: center;
}
.k-empty {
  text-align: center;
  padding: 48px var(--sp-4);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  color: var(--muted-fg);
}
.k-empty-ic {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  color: var(--fg);
}
.k-empty h3 {
  color: var(--fg);
  font-size: var(--fs-lg);
}
.k-empty p {
  margin: 0;
  max-width: 40ch;
}
.k-notice {
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-3);
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  margin-bottom: var(--sp-3);
}
.k-notice p {
  margin: var(--sp-1) 0 0;
  color: var(--muted-fg);
}
.k-notice.error {
  border-color: var(--danger);
}
.k-prose p,
.k-prose ul,
.k-prose ol {
  margin: 0 0 var(--sp-3);
}
.k-prose h2,
.k-prose h3 {
  margin: var(--sp-4) 0 var(--sp-2);
  font-size: var(--fs-lg);
}

/* ---------- overlays: dialog, sheet, record; all live on the frame ---------- */
.k-scrim {
  position: absolute;
  inset: 0;
  background: var(--scrim);
  z-index: var(--z-overlay); /* same layer as overlays: DOM order stacks scrim, record, scrim, dialog */
}
.k-dialog,
.k-sheet,
.k-record {
  position: absolute;
  z-index: var(--z-overlay);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow);
  /* narrow frame: every overlay is a bottom sheet */
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 90%;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.k-ov-h {
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-2) var(--sp-2) var(--sp-4);
}
.k-ov-meta {
  margin-top: var(--sp-1);
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}
.k-ov-h:has(p),
.k-ov-h:has(.k-ov-meta) {
  align-items: flex-start; /* a title with a description: the x stays level with the title */
}
.k-ov-h h2 {
  font-size: var(--fs-lg);
}
.k-ov-h:has(p) h2,
.k-ov-h:has(.k-ov-meta) h2 {
  padding-top: var(--sp-2);
}
.k-ov-h p {
  margin: var(--sp-1) 0 0;
  color: var(--muted-fg);
}
.k-ov-b {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: var(--sp-2) var(--sp-4) var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}
.k-ov-f {
  flex: none;
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--border);
}
@container frame (min-width: 48rem) {
  .k-dialog {
    left: 50%;
    right: auto;
    top: 50%;
    bottom: auto;
    transform: translate(-50%, -50%);
    max-height: calc(100% - 48px);
    border-radius: var(--radius-lg);
  }
  .k-dialog.k-s {
    width: 420px;
  }
  .k-dialog.k-m {
    width: 560px;
  }
  .k-dialog.k-l {
    width: min(760px, calc(100% - 48px));
  }
  .k-sheet {
    /* a panel sized to its content at the top right, never a tall empty column */
    left: auto;
    right: var(--sp-4);
    top: var(--sp-4);
    bottom: auto;
    width: 360px;
    max-height: calc(100% - 32px);
    border-radius: var(--radius-lg);
  }
  .k-record {
    left: 50%;
    right: auto;
    top: var(--sp-4);
    bottom: auto;
    transform: translateX(-50%);
    width: min(880px, calc(100% - 48px));
    max-height: calc(100% - 32px); /* as tall as the record, never a tall empty panel */
    border-radius: var(--radius-lg);
  }
}

/* ---------- toast ---------- */
.k-dialog:focus,
.k-sheet:focus,
.k-record:focus {
  outline: none;
}
/* toast: at the top on narrow frames (sheets fill the bottom), bottom left on wide ones (overlay footers keep their
   buttons on the right), so it never covers an action */
.k-toast {
  position: absolute;
  z-index: var(--z-toast);
  left: var(--sp-3);
  right: var(--sp-3);
  top: var(--sp-2);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--fg);
  box-shadow: var(--shadow);
}
.k-toast .k-i {
  color: var(--success);
}
.k-toast.no .k-i,
.k-toast.demo .k-i {
  color: var(--muted-fg);
}
@container frame (min-width: 48rem) {
  .k-toast {
    top: auto;
    right: auto;
    left: var(--sp-4);
    bottom: var(--sp-4);
    max-width: 420px;
  }
}
