/* Bryta UI component styles. Semantic tokens only (var(--b-*)); no raw colors. Mobile first:
   written for 360px and grown with min-width queries. Light and dark come from the theme file. */

*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--b-font-body);
  font-size: var(--b-size-md);
  line-height: 1.5;
  color: var(--b-color-on-surface);
  background: var(--b-color-surface);
}

h1, h2, h3 { font-family: var(--b-font-heading); line-height: 1.25; margin: 0 0 calc(var(--b-space-unit) * 3); }
h1 { font-size: var(--b-size-xl); }
h2 { font-size: var(--b-size-lg); }
p { margin: 0 0 calc(var(--b-space-unit) * 2); }
a { color: var(--b-color-link); }
ul { margin: 0; padding: 0; list-style: none; }

:focus-visible { outline: 3px solid var(--b-color-focus-ring); outline-offset: 2px; }

.b-icon {
  width: 1.25em;
  height: 1.25em;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -0.25em;
}

.b-visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.b-skip {
  position: absolute;
  left: calc(var(--b-space-unit) * 2);
  top: -10rem;
  z-index: 100;
  padding: calc(var(--b-space-unit) * 2) calc(var(--b-space-unit) * 4);
  background: var(--b-color-primary);
  color: var(--b-color-on-primary);
  border-radius: var(--b-radius-md);
}
.b-skip:focus { top: calc(var(--b-space-unit) * 2); }

/* ---- Shell ---- */

.b-shell { display: flex; flex-direction: column; min-height: 100vh; padding-bottom: calc(4.5rem + env(safe-area-inset-bottom)); }

.b-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: calc(var(--b-space-unit) * 3);
  padding: calc(var(--b-space-unit) * 2) calc(var(--b-space-unit) * 4);
  padding-top: calc(var(--b-space-unit) * 2 + env(safe-area-inset-top));
  background: var(--b-color-surface-chrome);
  border-bottom: 1px solid var(--b-color-border);
}
.b-brand { margin: 0; font-weight: 700; font-size: var(--b-size-lg); margin-right: auto; }
.b-areas ul, .b-nav ul, .b-bottom-nav ul { display: flex; gap: var(--b-space-unit); }
.b-prefs { display: flex; flex-wrap: wrap; gap: calc(var(--b-space-unit) * 3); align-items: center; margin-left: auto; }
.b-pref-group { display: flex; align-items: center; gap: var(--b-space-unit); }
.b-pref-group [aria-pressed="true"] { border-color: var(--b-color-primary); box-shadow: inset 0 0 0 1px var(--b-color-primary); }

.b-nav-item {
  display: flex;
  align-items: center;
  gap: calc(var(--b-space-unit) * 2);
  min-height: var(--b-size-touch-target);
  padding: 0 calc(var(--b-space-unit) * 3);
  border-radius: var(--b-radius-md);
  color: var(--b-color-on-surface);
  text-decoration: none;
}
.b-nav-item:hover { background: var(--b-color-surface-sunken); }
.b-nav-item[aria-current="page"] { background: var(--b-color-surface-sunken); font-weight: 600; box-shadow: inset 3px 0 0 var(--b-color-primary); }

.b-body { display: flex; flex: 1; min-width: 0; }
.b-nav { display: none; }
.b-main { flex: 1; min-width: 0; padding: calc(var(--b-space-unit) * 4); }
.b-main:focus { outline: none; }
.b-page-title { margin-bottom: calc(var(--b-space-unit) * 4); }

.b-bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  padding: var(--b-space-unit) var(--b-space-unit) calc(var(--b-space-unit) + env(safe-area-inset-bottom));
  background: var(--b-color-surface-chrome);
  border-top: 1px solid var(--b-color-border);
}
.b-bottom-nav ul { justify-content: space-around; }
.b-bottom-nav .b-nav-item { flex-direction: column; gap: 0; font-size: var(--b-size-sm); padding: var(--b-space-unit) calc(var(--b-space-unit) * 2); }
.b-bottom-nav .b-nav-item[aria-current="page"] { box-shadow: inset 0 -3px 0 var(--b-color-primary); }

@media (min-width: 48rem) {
  .b-shell { padding-bottom: 0; }
  .b-nav {
    display: block;
    width: 15rem;
    flex-shrink: 0;
    padding: calc(var(--b-space-unit) * 3);
    border-right: 1px solid var(--b-color-border);
    background: var(--b-color-surface-chrome);
  }
  .b-nav ul { flex-direction: column; }
  .b-bottom-nav { display: none; }
  .b-main { padding: calc(var(--b-space-unit) * 6); }
}

.b-live { position: absolute; }
.b-helpers { display: none; }

.b-toasts {
  position: fixed;
  z-index: 50;
  left: calc(var(--b-space-unit) * 3);
  right: calc(var(--b-space-unit) * 3);
  bottom: calc(5rem + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: calc(var(--b-space-unit) * 2);
  pointer-events: none;
}
@media (min-width: 48rem) { .b-toasts { left: auto; width: 24rem; bottom: calc(var(--b-space-unit) * 6); } }

.b-toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: calc(var(--b-space-unit) * 2);
  padding: calc(var(--b-space-unit) * 3);
  background: var(--b-color-surface-raised);
  color: var(--b-color-on-surface);
  border: 1px solid var(--b-color-border);
  border-left: 6px solid var(--b-color-info);
  border-radius: var(--b-radius-md);
  box-shadow: var(--b-shadow-3);
}
.b-toast-success { border-left-color: var(--b-color-success); }
.b-toast-warning { border-left-color: var(--b-color-warning); }
.b-toast-error { border-left-color: var(--b-color-danger); }
.b-toast-text { flex: 1; margin: 0; }
.b-toast-close {
  border: 0;
  background: transparent;
  color: inherit;
  min-width: var(--b-size-touch-target);
  min-height: var(--b-size-touch-target);
  margin: calc(var(--b-space-unit) * -2);
  cursor: pointer;
}

/* ---- Layouts ---- */

.b-layout { display: grid; gap: calc(var(--b-space-unit) * 6); align-items: start; }
.b-region { display: flex; flex-direction: column; gap: calc(var(--b-space-unit) * 4); min-width: 0; }
@media (min-width: 64rem) {
  .b-layout-two-column { grid-template-columns: minmax(0, 2fr) minmax(18rem, 1fr); }
  .b-layout-register { grid-template-columns: minmax(0, 3fr) minmax(22rem, 2fr); }
  .b-layout-master-detail { grid-template-columns: minmax(16rem, 1fr) minmax(0, 2fr); }
  .b-layout-register .b-region-side {
    position: sticky;
    top: calc(var(--b-space-unit) * 4);
    padding: calc(var(--b-space-unit) * 4);
    background: var(--b-color-surface-raised);
    border: 1px solid var(--b-color-border);
    border-radius: var(--b-radius-lg);
    box-shadow: var(--b-shadow-1);
  }
}
.b-layout-dashboard .b-region-header { display: grid; gap: calc(var(--b-space-unit) * 4); grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); }

/* ---- Buttons ---- */

.b-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: calc(var(--b-space-unit) * 2);
  min-height: var(--b-size-touch-target);
  min-width: var(--b-size-touch-target);
  padding: 0 calc(var(--b-space-unit) * 4);
  font: inherit;
  font-weight: 600;
  line-height: 1.2;
  border-radius: var(--b-radius-md);
  border: 1px solid var(--b-color-border-strong);
  background: var(--b-color-surface-raised);
  color: var(--b-color-on-surface);
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--b-motion-fast), border-color var(--b-motion-fast);
  touch-action: manipulation;
}
.b-btn:hover { background: var(--b-color-surface-sunken); }
.b-btn-primary { background: var(--b-color-primary); border-color: var(--b-color-primary); color: var(--b-color-on-primary); }
.b-btn-primary:hover { background: var(--b-color-primary-hover); border-color: var(--b-color-primary-hover); }
.b-btn-danger { background: var(--b-color-danger); border-color: var(--b-color-danger); color: var(--b-color-on-danger); }
.b-btn-danger:hover { background: var(--b-color-danger); filter: brightness(0.92); }
.b-btn-link { background: transparent; border-color: transparent; color: var(--b-color-link); text-decoration: underline; }
.b-btn-link:hover { background: var(--b-color-surface-sunken); }
.b-btn-icon { padding: 0; }
.b-btn[disabled], .b-btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }

/* ---- Lists: grid and tiles ---- */

.b-toolbar { display: flex; gap: calc(var(--b-space-unit) * 2); margin-bottom: calc(var(--b-space-unit) * 3); }
.b-search { max-width: 24rem; }
.b-results { transition: opacity var(--b-motion-base); }
.b-results.b-busy { opacity: 0.6; }

.b-table-wrap { overflow-x: auto; border: 1px solid var(--b-color-border); border-radius: var(--b-radius-md); background: var(--b-color-surface-raised); }
.b-table { width: 100%; border-collapse: collapse; }
.b-table th, .b-table td { padding: calc(var(--b-space-unit) * 3); text-align: left; border-bottom: 1px solid var(--b-color-border); vertical-align: middle; }
.b-table th { font-size: var(--b-size-sm); color: var(--b-color-on-surface-muted); font-weight: 600; white-space: nowrap; background: var(--b-color-surface-sunken); }
.b-table tbody tr:last-child td { border-bottom: 0; }
.b-table .b-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.b-sort {
  display: inline-flex;
  align-items: center;
  gap: var(--b-space-unit);
  min-height: var(--b-size-touch-target);
  padding: 0;
  font: inherit;
  font-weight: 600;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}
.b-cell-label { display: none; }
.b-row-actions { text-align: right; white-space: nowrap; }
.b-region-side .b-table th, .b-region-side .b-table td { padding: calc(var(--b-space-unit) * 2); }
.b-row-actions .b-btn + .b-btn { margin-left: var(--b-space-unit); }

@media (max-width: 40rem) {
  .b-table-wrap { border: 0; background: transparent; }
  .b-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .b-table, .b-table tbody, .b-table tr, .b-table td { display: block; width: 100%; }
  .b-table tr {
    margin-bottom: calc(var(--b-space-unit) * 3);
    padding: calc(var(--b-space-unit) * 2);
    border: 1px solid var(--b-color-border);
    border-radius: var(--b-radius-md);
    background: var(--b-color-surface-raised);
  }
  .b-table td { display: flex; justify-content: space-between; gap: calc(var(--b-space-unit) * 3); border: 0; padding: calc(var(--b-space-unit) * 2); }
  .b-table td.b-num { text-align: right; }
  .b-cell-label { display: inline; color: var(--b-color-on-surface-muted); font-size: var(--b-size-sm); }
  .b-table td.b-row-actions { justify-content: flex-end; }
}

.b-list-footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: calc(var(--b-space-unit) * 3); margin-top: calc(var(--b-space-unit) * 3); }
.b-count { margin: 0; color: var(--b-color-on-surface-muted); font-size: var(--b-size-sm); }
.b-pager { display: flex; align-items: center; gap: calc(var(--b-space-unit) * 2); }
.b-page-number { font-variant-numeric: tabular-nums; }

.b-tile-list { display: grid; gap: calc(var(--b-space-unit) * 3); grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr)); }
.b-tile {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: flex-start;
  gap: calc(var(--b-space-unit) * 2);
  width: 100%;
  min-height: 6.5rem;
  padding: calc(var(--b-space-unit) * 4);
  font: inherit;
  text-align: left;
  color: var(--b-color-on-surface);
  background: var(--b-color-surface-raised);
  border: 1px solid var(--b-color-border-strong);
  border-radius: var(--b-radius-lg);
  box-shadow: var(--b-shadow-1);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform var(--b-motion-fast), box-shadow var(--b-motion-fast);
}
button.b-tile:hover { box-shadow: var(--b-shadow-2); border-color: var(--b-color-primary); }
button.b-tile:active { transform: scale(0.98); }
.b-tile-title { font-weight: 600; font-size: var(--b-size-lg); line-height: 1.3; }
.b-tile-value { font-size: var(--b-size-lg); font-variant-numeric: tabular-nums; color: var(--b-color-on-surface-muted); white-space: nowrap; }

/* ---- States ---- */

.b-empty, .b-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--b-space-unit) * 2);
  padding: calc(var(--b-space-unit) * 8) calc(var(--b-space-unit) * 4);
  text-align: center;
  color: var(--b-color-on-surface-muted);
  border: 1px dashed var(--b-color-border-strong);
  border-radius: var(--b-radius-lg);
}
.b-empty .b-icon, .b-error .b-icon { width: 2rem; height: 2rem; }
.b-error { color: var(--b-color-on-surface); border-style: solid; border-color: var(--b-color-danger); }
.b-error .b-icon { color: var(--b-color-danger); }
.b-error-ref { font-size: var(--b-size-sm); color: var(--b-color-on-surface-muted); font-family: var(--b-font-mono); }

/* ---- Forms ---- */

.b-form { display: flex; flex-direction: column; gap: calc(var(--b-space-unit) * 4); max-width: 40rem; }
.b-field { display: flex; flex-direction: column; gap: var(--b-space-unit); }
.b-field-label, .b-choices legend { font-weight: 600; }
.b-required { margin-left: var(--b-space-unit); font-weight: 400; font-size: var(--b-size-sm); color: var(--b-color-on-surface-muted); }
.b-input {
  width: 100%;
  min-height: var(--b-size-touch-target);
  padding: calc(var(--b-space-unit) * 2) calc(var(--b-space-unit) * 3);
  font: inherit;
  color: var(--b-color-on-surface);
  background: var(--b-color-surface);
  border: 1px solid var(--b-color-border-strong);
  border-radius: var(--b-radius-md);
}
textarea.b-input { min-height: 6rem; resize: vertical; }
.b-field-invalid .b-input { border: 2px solid var(--b-color-danger); }
.b-field-error { display: flex; align-items: center; gap: var(--b-space-unit); margin: 0; color: var(--b-color-danger); font-weight: 600; font-size: var(--b-size-sm); }
.b-check { display: flex; align-items: center; gap: calc(var(--b-space-unit) * 2); min-height: var(--b-size-touch-target); }
.b-check input { width: 1.25rem; height: 1.25rem; accent-color: var(--b-color-primary); }
.b-choices { border: 0; padding: 0; margin: 0; }
.b-errors {
  padding: calc(var(--b-space-unit) * 4);
  border: 2px solid var(--b-color-danger);
  border-radius: var(--b-radius-md);
  background: var(--b-color-surface-raised);
}
.b-errors p { font-weight: 600; }
.b-errors ul { list-style: disc; padding-left: calc(var(--b-space-unit) * 5); }
.b-form-actions { display: flex; gap: calc(var(--b-space-unit) * 2); }

/* ---- Point of sale: keypad, stat ---- */

.b-keypad { display: flex; flex-direction: column; gap: calc(var(--b-space-unit) * 2); max-width: 26rem; }
.b-keypad-display { font-size: var(--b-size-xl); font-family: var(--b-font-mono); text-align: right; letter-spacing: 0.04em; min-height: calc(var(--b-size-touch-target) * 1.3); }
.b-keypad-keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: calc(var(--b-space-unit) * 2); }
.b-key {
  min-height: calc(var(--b-size-touch-target) * 1.45);
  font: inherit;
  font-size: var(--b-size-xl);
  font-weight: 600;
  color: var(--b-color-on-surface);
  background: var(--b-color-surface-raised);
  border: 1px solid var(--b-color-border-strong);
  border-radius: var(--b-radius-md);
  cursor: pointer;
  touch-action: manipulation;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: calc(var(--b-space-unit) * 2);
}
.b-key:active { transform: scale(0.97); }
.b-key-wide { grid-column: 1 / -1; }
.b-key-enter { background: var(--b-color-primary); border-color: var(--b-color-primary); color: var(--b-color-on-primary); font-size: var(--b-size-lg); }
.b-key[disabled] { opacity: 0.55; }

.b-stat { padding: calc(var(--b-space-unit) * 4); background: var(--b-color-surface-raised); border: 1px solid var(--b-color-border); border-radius: var(--b-radius-lg); }
.b-stat-label { margin: 0; color: var(--b-color-on-surface-muted); font-size: var(--b-size-sm); font-weight: 600; }
.b-stat-value { margin: 0; font-size: var(--b-size-display); font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; white-space: nowrap; }

.b-actionbar { display: flex; flex-wrap: wrap; gap: calc(var(--b-space-unit) * 2); }
.b-actionbar .b-btn { flex: 1 1 auto; }

.b-detail dl, .b-card dl { display: grid; grid-template-columns: max-content 1fr; gap: calc(var(--b-space-unit) * 2) calc(var(--b-space-unit) * 4); margin: 0 0 calc(var(--b-space-unit) * 3); }
.b-detail dt, .b-card dt { color: var(--b-color-on-surface-muted); font-weight: 600; }
.b-detail dd, .b-card dd { margin: 0; }
.b-card { padding: calc(var(--b-space-unit) * 4); background: var(--b-color-surface-raised); border: 1px solid var(--b-color-border); border-radius: var(--b-radius-lg); }

/* ---- Dialogs ---- */

.b-dialog {
  width: min(34rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  padding: calc(var(--b-space-unit) * 5);
  color: var(--b-color-on-surface);
  background: var(--b-color-surface-raised);
  border: 1px solid var(--b-color-border);
  border-radius: var(--b-radius-lg);
  box-shadow: var(--b-shadow-3);
}
.b-dialog::backdrop { background: var(--b-color-overlay); opacity: 0.6; }
.b-dialog-header { display: flex; align-items: center; justify-content: space-between; gap: calc(var(--b-space-unit) * 3); margin-bottom: calc(var(--b-space-unit) * 4); }
.b-dialog-header h2 { margin: 0; }
.b-dialog-actions { display: flex; justify-content: flex-end; gap: calc(var(--b-space-unit) * 2); margin-top: calc(var(--b-space-unit) * 4); }

@media (forced-colors: active) {
  .b-btn, .b-key, .b-tile, .b-input { border: 1px solid ButtonText; }
  :focus-visible { outline-color: Highlight; }
  .b-nav-item[aria-current="page"] { outline: 2px solid Highlight; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
