/* Reusable components — light SaaS theme */

/* --- Buttons --- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 16px; border-radius: var(--radius-sm);
  font-size: 0.82rem; font-weight: 500;
  border: 1px solid transparent; transition: all .15s;
  white-space: nowrap; cursor: pointer;
  min-height: var(--tap-target);
}
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-hover); box-shadow: var(--shadow-blue); }
.btn-ghost { border-color: var(--line); color: var(--navy); background: #fff; }
.btn-ghost:hover { background: var(--bg-soft); border-color: var(--blue); color: var(--blue); }
.btn-dark { background: var(--navy); color: #fff; }
.btn-dark:hover { background: var(--navy-700); }
.btn-subtle { color: var(--text-muted); }
.btn-subtle:hover { color: var(--navy); background: var(--bg-soft); }
.btn-sm { padding: 6px 12px; font-size: 0.74rem; }

/* --- Cards --- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .15s, border-color .15s;
}
.card:hover { box-shadow: var(--shadow-md); }
.card .card-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.card .card-head h3 { font-size: 1rem; font-weight: 600; }
.card .card-head .meta { font-size: 0.72rem; color: var(--text-muted); font-weight: 500; }

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  display: flex; flex-direction: column; gap: 6px;
  position: relative; overflow: hidden;
  box-shadow: var(--shadow-xs);
}
.stat-card .lbl { font-size: 0.7rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); }
.stat-card .val { font-family: var(--font-display); font-weight: 600; font-size: 1.7rem; color: var(--navy); letter-spacing: -0.02em; }
.stat-card .delta { font-size: 0.74rem; font-weight: 500; color: var(--green); }
.stat-card .delta.neg  { color: var(--red); }
.stat-card .delta.warn { color: var(--amber); }
.stat-card .ico {
  position: absolute; right: 16px; top: 16px; font-size: 0.95rem;
  width: 30px; height: 30px; border-radius: 7px;
  background: var(--blue-50); color: var(--blue);
  display: grid; place-items: center;
}

/* --- Traffic lights --- */
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; vertical-align: middle; }
.dot.green { background: var(--green); box-shadow: 0 0 0 3px var(--green-50); }
.dot.amber { background: var(--amber); box-shadow: 0 0 0 3px var(--amber-50); }
.dot.red   { background: var(--red);   box-shadow: 0 0 0 3px var(--red-50); }
.dot.grey  { background: var(--grey); }

.signal { display: inline-flex; align-items: center; gap: 7px; font-size: 0.78rem; color: var(--text-muted); }
.signal .lbl { font-weight: 500; }

/* --- Badges --- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 8px; border-radius: 4px;
  font-size: 0.7rem; font-weight: 500;
  border: 1px solid var(--border); color: var(--text-muted);
  background: var(--bg-soft);
}
.badge.blue   { color: var(--blue); border-color: #b8e7f7; background: var(--blue-50); }
.badge.green  { color: var(--green); border-color: #b9ecd6; background: var(--green-50); }
.badge.amber  { color: #b07700; border-color: #f2d894; background: var(--amber-50); }
.badge.red    { color: var(--red); border-color: #fbc7c7; background: var(--red-50); }
.badge.solid  { background: var(--blue); color: #fff; border-color: transparent; }

.cert-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 4px;
  font-size: 0.72rem; font-weight: 500;
}
.cert-badge.padi { background: var(--padi-bg); color: var(--padi); }
.cert-badge.ssi  { background: var(--ssi-bg);  color: var(--ssi); }
.cert-badge.tdi  { background: var(--tdi-bg);  color: var(--tdi); }
.cert-badge.sdi  { background: var(--sdi-bg);  color: var(--sdi); }
.cert-badge.none { background: var(--bg-soft); color: var(--text-soft); border: 1px dashed var(--border); }

/* --- Tables --- */
.table-wrap {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); overflow: hidden;
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.tbl { width: 100%; min-width: 720px; border-collapse: collapse; }
.tbl thead th {
  text-align: left;
  font-size: 0.7rem; font-weight: 600;
  letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-muted); padding: 13px 18px;
  border-bottom: 1px solid var(--border); background: var(--bg-soft);
}
.tbl tbody td {
  padding: 13px 18px; border-bottom: 1px solid var(--border-soft);
  font-size: 0.88rem; vertical-align: middle; color: var(--navy);
}
.tbl tbody tr { transition: background .1s; cursor: pointer; }
.tbl tbody tr:hover { background: var(--bg-soft); }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl .name-cell { display: flex; align-items: center; gap: 11px; }
.tbl .name-cell .ini {
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg, var(--blue), #73d2f1);
  color: #fff;
  display: grid; place-items: center;
  font-size: 0.74rem; font-weight: 600;
}
.tbl .name-cell .sub { font-size: 0.74rem; color: var(--text-muted); margin-top: 2px; }
.tbl .row-actions { text-align: right; }

/* --- Filter chips --- */
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.chip {
  padding: 7px 13px; border-radius: 999px;
  font-size: 0.76rem; font-weight: 500;
  color: var(--text-muted); border: 1px solid var(--border);
  background: #fff;
  transition: all .12s;
}
.chip:hover { color: var(--navy); border-color: var(--blue); }
.chip.active { color: #fff; background: var(--navy); border-color: var(--navy); }
.chip .ct {
  display: inline-block; margin-left: 6px;
  padding: 1px 6px; border-radius: 3px;
  background: var(--bg-soft); color: var(--text-muted);
  font-size: 0.62rem; font-weight: 600;
}
.chip.active .ct { background: rgba(255,255,255,0.18); color: #fff; }

/* --- Tasks / checklist --- */
.task {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--border-soft);
}
.task:last-child { border-bottom: none; }
.task .check {
  width: 18px; height: 18px; border-radius: 4px;
  border: 1.5px solid var(--line); flex-shrink: 0;
  display: grid; place-items: center; cursor: pointer; transition: all .12s;
  background: #fff;
}
.task .check.done { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 700; font-size: 0.75rem; }
.task.done .label { color: var(--text-soft); text-decoration: line-through; }
.task .label { flex: 1; font-size: 0.9rem; color: var(--navy); }
.task .who { font-size: 0.72rem; color: var(--text-muted); font-weight: 500; }

/* --- List rows --- */
.list-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--border-soft);
  cursor: pointer; transition: background .1s;
}
.list-row:last-child { border-bottom: none; }
.list-row:hover { background: var(--bg-soft); margin: 0 -10px; padding: 12px 10px; border-radius: 6px; }
.list-row .ico-pill {
  width: 36px; height: 36px; border-radius: 8px;
  background: var(--blue-50); color: var(--blue);
  display: grid; place-items: center; font-size: 1rem; flex-shrink: 0;
}
.list-row .ico-pill.amber { background: var(--amber-50); color: #b07700; }
.list-row .ico-pill.green { background: var(--green-50); color: var(--green); }
.list-row .body { flex: 1; min-width: 0; }
.list-row .body .pri { font-size: 0.9rem; color: var(--navy); font-weight: 500; }
.list-row .body .sub { font-size: 0.74rem; color: var(--text-muted); margin-top: 2px; }
.list-row .end { font-size: 0.82rem; color: var(--navy); text-align: right; font-weight: 500; }
.list-row .end .lbl { font-size: 0.62rem; letter-spacing: .08em; color: var(--text-muted); text-transform: uppercase; font-weight: 600; }

/* --- Modal --- */
.scrim {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(14,51,60,0.45); backdrop-filter: blur(4px);
  display: grid; place-items: center; padding: 20px;
  animation: fadeUp .22s ease;
}
.modal {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 28px; min-width: 480px; max-width: 90vw; max-height: 86vh;
  overflow: auto; box-shadow: var(--shadow-lg);
}
.modal-close {
  position: sticky;
  z-index: 1;
  float: right;
  top: -16px;
  right: -16px;
  width: 36px;
  height: 36px;
  margin: -12px -12px 0 12px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 1.6rem;
  font-weight: 400;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-sm);
}
.modal-close:hover { color: var(--navy); background: var(--bg-soft); }
.modal-close:focus-visible { outline: 3px solid var(--blue-50); outline-offset: 2px; }
.modal h2 { margin-bottom: 6px; font-size: 1.3rem; }
.modal p.muted { margin-bottom: 16px; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }
.modal .field { margin-bottom: 14px; }
.modal .field label { display: block; font-size: 0.72rem; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.modal .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* --- Toasts --- */
.toast-stack {
  position: fixed; top: 84px; right: 24px; z-index: 100;
  display: flex; flex-direction: column; gap: 10px; pointer-events: none;
}
.toast {
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--blue);
  border-radius: var(--radius-md); padding: 12px 18px;
  font-size: 0.86rem; box-shadow: var(--shadow-md);
  animation: fadeUp .25s ease; pointer-events: auto;
  min-width: 280px; color: var(--navy);
}
.toast.warn  { border-left-color: var(--amber); }
.toast.error { border-left-color: var(--red); }
.toast .t-title { font-size: 0.7rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--blue); margin-bottom: 3px; }
.toast.warn  .t-title { color: #b07700; }
.toast.error .t-title { color: var(--red); }

/* Touch-friendly shift close modal for Drifter/Deco Stop phones */
.shift-close-modal {
  width: min(520px, calc(100vw - 24px));
}
.shift-close-modal .shift-close-form {
  min-width: 0 !important;
}
.shift-close-modal .admin-input {
  min-height: 48px;
  font-size: 1rem;
}
.shift-close-modal textarea.admin-input {
  min-height: 72px;
}
.shift-close-modal .modal-actions .btn {
  min-height: 50px;
}
@media (max-width: 640px) {
  .scrim {
    padding: 8px;
    align-items: end;
  }
  .modal {
    box-sizing: border-box;
    min-width: 0;
    width: 100%;
    max-width: 100%;
    max-height: min(92dvh, 92vh);
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    border-radius: 18px 18px 0 0;
    padding: 18px;
  }
  .modal .grid-2 { grid-template-columns: 1fr; }
  .modal .field input,
  .modal .field select,
  .modal .field textarea { max-width: 100%; font-size: 16px; }
  /* Several reusable admin forms set a desktop minimum width in their own
     stylesheet. Keep every modal form inside the bottom sheet on a phone. */
  .modal .admin-form { min-width: 0; max-width: 100%; }
  .modal .admin-grid { grid-template-columns: 1fr; }
  .modal .admin-input { min-height: 44px; font-size: 16px; }
  .modal-close {
    top: -8px;
    right: -8px;
    margin: -6px -6px 0 10px;
    width: 40px;
    height: 40px;
  }
  .modal .actions,
  .modal-actions {
    flex-direction: column-reverse;
  }
  .modal .actions .btn,
  .modal-actions .btn {
    width: 100%;
    min-height: 44px;
    justify-content: center;
    white-space: normal;
    text-align: center;
  }
  .modal.shift-close-modal {
    min-width: 0 !important;
    width: 100%;
    max-width: 100%;
    max-height: min(92dvh, 92vh);
    border-radius: 18px 18px 0 0;
    padding: 18px;
  }
  .shift-close-modal h2 {
    font-size: 1.15rem;
    line-height: 1.25;
  }
  .shift-close-modal .modal-lead {
    font-size: 0.84rem;
    line-height: 1.4;
  }
  .shift-close-modal .admin-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .shift-close-modal .admin-field label {
    font-size: 0.78rem;
  }
  .shift-close-modal .admin-input {
    min-height: 54px;
    font-size: 1.05rem;
  }
  .shift-close-modal .modal-actions {
    position: sticky;
    bottom: -18px;
    flex-direction: column-reverse;
    gap: 8px;
    background: linear-gradient(180deg, rgba(255,255,255,0), var(--surface) 18px);
    padding-top: 22px;
    padding-bottom: 4px;
  }
  .shift-close-modal .modal-actions .btn {
    width: 100%;
    justify-content: center;
    min-height: 54px;
  }

  .toast-stack {
    top: calc(12px + var(--safe-top));
    right: calc(12px + var(--safe-right));
    left: calc(12px + var(--safe-left));
  }
  .toast { min-width: 0; width: 100%; }
}
