/* =====================================================================
   COMPONENTS  ·  reusable building blocks shared by every agent
   ===================================================================== */

/* === SECTION: BUTTONS === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 46px;
  padding: 12px 20px;
  border: 1.5px solid transparent;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: var(--fs-md);
  line-height: 1.1;
  text-align: center;
  white-space: nowrap;
  transition: background .15s var(--ease), border-color .15s var(--ease), transform .1s var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px); }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn[disabled] { opacity: .45; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not([disabled]) { background: var(--accent-hover); color: var(--accent-ink); }
.btn-ghost { background: transparent; border-color: var(--accent); color: var(--accent); }
.btn-ghost:hover:not([disabled]) { background: rgba(229, 111, 73, .1); color: var(--accent-hover); }
.btn-quiet { background: var(--circle); color: var(--cream); }
.btn-quiet:hover:not([disabled]) { background: #275354; color: var(--white); }
.btn-ink { background: var(--ink); color: var(--cream); }
.btn-ink:hover:not([disabled]) { background: #143e40; color: var(--white); }
.btn-ok { background: var(--ok); color: var(--white); }
.btn-ok:hover:not([disabled]) { background: #1c5d3e; }
.btn-line { background: transparent; border-color: var(--surface-line); color: var(--surface-ink); }
.btn-line:hover:not([disabled]) { background: var(--surface-2); }
.btn-sm { min-height: 36px; padding: 8px 14px; font-size: var(--fs-sm); border-radius: 10px; }
.btn-block { width: 100%; }
.btn-icon {
  width: 42px; height: 42px; min-height: 0; padding: 0;
  border-radius: var(--radius-pill);
}
.btn-row { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
/* === /SECTION: BUTTONS === */

/* === SECTION: CARDS === */
.card {
  background: var(--bg-alt);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--sp-5);
}
.sheet {
  background: var(--surface);
  color: var(--surface-ink);
  border-radius: var(--radius);
  padding: var(--sp-5);
  box-shadow: var(--shadow-1);
}
.sheet .muted, .sheet .lead { color: var(--surface-sub); }
.sheet .h-page, .sheet .h-display { color: var(--ink); }
.sheet + .sheet, .card + .card { margin-top: var(--sp-4); }
.sheet-head {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--sp-4);
}
.sheet-flush { padding: 0; overflow: hidden; }
.sheet-flush > .sheet-head { padding: var(--sp-5) var(--sp-5) 0; }
@media (max-width: 599px) {
  .card, .sheet { padding: var(--sp-4); border-radius: 16px; }
  .sheet-flush { padding: 0; }
  .sheet-flush > .sheet-head { padding: var(--sp-4) var(--sp-4) 0; }
}
/* === /SECTION: CARDS === */

/* === SECTION: BADGES AND PILLS === */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-xs);
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
  background: var(--surface-2);
  color: var(--surface-sub);
}
.badge svg { width: 13px; height: 13px; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-bad { background: var(--bad-soft); color: var(--bad); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-accent { background: var(--accent); color: var(--ink); }
.badge-dark { background: var(--circle); color: var(--cream); }
.badge-outline { background: transparent; border: 1px solid currentColor; }

.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ok-dark);
  box-shadow: 0 0 0 3px rgba(132, 211, 166, .18);
}
.status-dot.is-off { background: var(--warn-dark); box-shadow: 0 0 0 3px rgba(242, 196, 107, .18); }

.pill-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  background: var(--bg-alt);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 600;
  white-space: nowrap;
}
.pill-status .pill-icon { display: none; width: 18px; height: 18px; }
@media (max-width: 599px) {
  .pill-status .pill-label, .pill-status .status-dot { display: none; }
  .pill-status .pill-icon { display: block; }
  .pill-status { padding: 8px; color: var(--ok-dark); }
  .pill-status[aria-pressed="true"] { color: var(--warn-dark); border-color: var(--warn-dark); }
}
/* === /SECTION: BADGES AND PILLS === */

/* === SECTION: USER CHIP === */
.user-chip {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 4px 12px 4px 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--bg-alt);
  color: var(--cream);
  max-width: 220px;
}
.user-chip:hover { border-color: var(--accent); }
.user-chip-text { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; line-height: 1.15; }
.user-chip-name { font-size: var(--fs-sm); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 130px; }
.user-chip-role { font-size: 11px; color: var(--muted); white-space: nowrap; }
.user-chip svg { width: 16px; height: 16px; color: var(--muted); flex: none; }
@media (max-width: 599px) {
  .user-chip { padding: 3px; }
  .user-chip-text, .user-chip > svg { display: none; }
}
.avatar {
  width: 34px; height: 34px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--circle);
  color: var(--cream);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.02em;
}
.avatar-accent { background: var(--accent); color: var(--ink); }
.avatar-lg { width: 48px; height: 48px; font-size: 16px; }
.sheet .avatar { background: var(--card); color: var(--ink); }
/* === /SECTION: USER CHIP === */

/* === SECTION: FORM FIELDS === */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-size: var(--fs-sm); font-weight: 700; }
.field-hint { font-size: var(--fs-xs); color: var(--surface-sub); }
.input, .select, .textarea {
  width: 100%;
  min-height: 50px;
  padding: 12px 14px;
  border: 1.5px solid var(--surface-line);
  border-radius: var(--radius-md);
  background: var(--white);
  color: var(--ink);
  font-size: 16px; /* 16px stops iPhone from zooming into fields */
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
  -webkit-appearance: none;
  appearance: none;
}
.select {
  padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23456260' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}
.textarea { min-height: 84px; resize: vertical; line-height: 1.4; }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(229, 111, 73, .22);
}
.input[type="time"] { font-variant-numeric: tabular-nums; }
.field-grid { display: grid; gap: var(--sp-4); }
.field-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 599px) {
  .field-grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field-grid-3 > .field:last-child { grid-column: 1 / -1; }
}

.check {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: 14px;
  border: 1.5px solid var(--surface-line);
  border-radius: var(--radius-md);
  background: var(--white);
  cursor: pointer;
}
.check:has(input:checked) { border-color: var(--accent); background: #fff7f3; }
.check input {
  width: 22px; height: 22px; margin: 0; flex: none;
  accent-color: var(--accent);
}
.check-text { display: flex; flex-direction: column; gap: 2px; }
.check-title { font-weight: 700; font-size: var(--fs-sm); }
.check-sub { font-size: var(--fs-xs); color: var(--surface-sub); }
/* === /SECTION: FORM FIELDS === */

/* === SECTION: SEGMENTED CONTROL === */
.segmented {
  display: inline-flex;
  padding: 4px;
  gap: 2px;
  border-radius: var(--radius-md);
  background: var(--bg-alt);
  border: 1px solid var(--line);
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}
.segmented::-webkit-scrollbar { display: none; }
.segmented button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 9px;
  font-size: var(--fs-sm);
  font-weight: 700;
  white-space: nowrap;
}
.segmented button:hover { color: var(--cream); }
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--ink); }
.sheet .segmented { background: var(--surface-2); border-color: var(--surface-line); }
.sheet .segmented button { color: var(--surface-sub); }
.sheet .segmented button:hover { color: var(--ink); }
.sheet .segmented button[aria-pressed="true"] { background: var(--ink); color: var(--cream); }
/* === /SECTION: SEGMENTED CONTROL === */

/* === SECTION: STAT TILES === */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3); }
@media (min-width: 768px) { .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.stat {
  padding: var(--sp-4);
  border-radius: 14px;
  background: var(--bg-alt);
  border: 1px solid var(--line);
  min-width: 0;
}
.stat-label { color: var(--muted); font-size: var(--fs-xs); font-weight: 600; }
.stat-value {
  margin-top: 4px;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--white);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.stat-note { margin-top: 2px; font-size: var(--fs-xs); color: var(--muted); }
.stat-warn .stat-value { color: var(--warn-dark); }
.stat-bad .stat-value { color: var(--bad-dark); }
.stat-ok .stat-value { color: var(--ok-dark); }
.sheet .stat { background: var(--white); border-color: var(--surface-line); }
.sheet .stat-label, .sheet .stat-note { color: var(--surface-sub); }
.sheet .stat-value { color: var(--ink); }
.sheet .stat-warn .stat-value { color: var(--warn); }
.sheet .stat-bad .stat-value { color: var(--bad); }
.sheet .stat-ok .stat-value { color: var(--ok); }
/* === /SECTION: STAT TILES === */

/* === SECTION: DATA TABLE === */
.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.table {
  width: 100%;
  min-width: 760px;
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
}
.table th, .table td {
  padding: 10px 12px;
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--surface-line);
  white-space: nowrap;
}
.table thead th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  color: var(--surface-sub);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.table .col-num { text-align: right; }
.table .col-center { text-align: center; }
.table .col-sticky {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--surface);
  box-shadow: 1px 0 0 var(--surface-line);
}
.table thead .col-sticky { z-index: 2; background: var(--surface-2); }
.table tbody tr:hover td { background: #efebdf; }
.table tbody tr:hover .col-sticky { background: #efebdf; }
.table .row-group td {
  background: var(--card);
  color: var(--ink);
  font-weight: 800;
  font-size: var(--fs-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.table .row-group .col-sticky { background: var(--card); }
.table tfoot td {
  font-weight: 800;
  background: var(--surface-2);
  border-bottom: 0;
}
.table tfoot .col-sticky { background: var(--surface-2); }
.cell-empty { color: #b9b3a1; }
.cell-missing { color: var(--bad); font-weight: 800; }
.cell-pending { color: var(--warn); font-weight: 700; }
.cell-over { color: var(--bad); font-weight: 800; }
.cell-person { display: flex; flex-direction: column; line-height: 1.25; }
.cell-person small { color: var(--surface-sub); font-size: 11px; font-weight: 600; }
/* === /SECTION: DATA TABLE === */

/* === SECTION: LIST ROWS === */
.list { display: flex; flex-direction: column; }
.list-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 14px 0;
  border-bottom: 1px solid var(--surface-line);
}
.list-row:last-child { border-bottom: 0; }
.list-main { flex: 1; min-width: 0; }
.list-title { font-weight: 700; line-height: 1.3; }
.list-sub { font-size: var(--fs-sm); color: var(--surface-sub); line-height: 1.35; }
.list-end { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: none; }
.list-hours { font-weight: 800; font-size: var(--fs-lg); font-variant-numeric: tabular-nums; }
/* === /SECTION: LIST ROWS === */

/* === SECTION: NOTICES === */
.notice {
  display: flex;
  gap: var(--sp-3);
  align-items: flex-start;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--info-soft);
  color: var(--info);
  font-size: var(--fs-sm);
  line-height: 1.4;
}
.notice svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.notice-warn { background: var(--warn-soft); color: var(--warn); }
.notice-bad { background: var(--bad-soft); color: var(--bad); }
.notice-ok { background: var(--ok-soft); color: var(--ok); }
.notice strong { font-weight: 800; }
.notice-dark {
  background: var(--bg-alt);
  border: 1px solid var(--line);
  color: var(--muted);
}
.notice-dark strong { color: var(--cream); }
/* === /SECTION: NOTICES === */

/* === SECTION: EMPTY STATE === */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-6) var(--sp-4);
  text-align: center;
  color: var(--surface-sub);
}
.empty svg { width: 40px; height: 40px; color: var(--ok); }
.empty-title { font-weight: 800; color: var(--ink); font-size: var(--fs-lg); }
/* === /SECTION: EMPTY STATE === */

/* === SECTION: MODAL === */
.modal {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 48px);
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-2);
  overflow: auto;
}
.modal::backdrop { background: rgba(4, 20, 21, .72); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.modal[open] { animation: modal-in .22s var(--ease); }
@keyframes modal-in { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }
.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-5) var(--sp-5) var(--sp-3);
}
.modal-body { padding: 0 var(--sp-5) var(--sp-5); }
.modal-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--sp-2);
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--surface-line);
  background: var(--surface-2);
}
.modal-close {
  border: 0;
  background: var(--surface-2);
  color: var(--ink);
  width: 36px; height: 36px;
  border-radius: 50%;
  display: grid; place-items: center;
  flex: none;
}
.modal-close svg { width: 18px; height: 18px; }
@media (max-width: 599px) {
  .modal {
    width: 100vw;
    max-width: 100vw;
    margin: auto 0 0;
    border-radius: 20px 20px 0 0;
    max-height: 92dvh;
  }
  .modal-foot { padding-bottom: max(var(--sp-4), env(safe-area-inset-bottom)); }
  .modal-foot .btn { flex: 1; }
}
/* === /SECTION: MODAL === */

/* === SECTION: TOASTS === */
.toast-region {
  position: fixed;
  z-index: 80;
  left: 50%;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px);
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  width: min(440px, calc(100vw - 24px));
  pointer-events: none;
}
@media (min-width: 1024px) { .toast-region { bottom: 24px; } }
.toast {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--cream);
  color: var(--ink);
  box-shadow: var(--shadow-2);
  font-size: var(--fs-sm);
  font-weight: 600;
  pointer-events: auto;
  animation: toast-in .25s var(--ease);
}
.toast svg { width: 20px; height: 20px; flex: none; color: var(--ok); }
.toast.is-leaving { opacity: 0; transform: translateY(8px); transition: all .2s var(--ease); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
/* === /SECTION: TOASTS === */

/* === SECTION: PAGE HEAD === */
.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-4);
  margin-bottom: var(--sp-5);
}
.page-head-text { display: flex; flex-direction: column; gap: var(--sp-2); min-width: 0; }
.stack { display: flex; flex-direction: column; gap: var(--sp-4); }
.stack-lg { display: flex; flex-direction: column; gap: var(--sp-6); }
.row { display: flex; align-items: center; gap: var(--sp-3); }
.row-wrap { flex-wrap: wrap; }
.row-between { justify-content: space-between; }
/* === /SECTION: PAGE HEAD === */
