/* ===========================================================================
   components.css - cards, buttons, badges, chips, alerts, tiles, misc
   =========================================================================== */

/* ------------------------------------------------------------------- card */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow-sm);
}

.card-head {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.card-head h2, .card-head h3 { font-size: 14.5px; }
.card-head p { font-size: 12.5px; color: var(--text-3); margin: 2px 0 0; }
.card-head .spacer { margin-left: auto; }

.card-body { padding: 18px; }
.card-body.tight { padding: 12px 18px; }
.card-body.flush { padding: 0; }

.card-foot {
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  background: var(--surface-2);
  border-radius: 0 0 var(--r) var(--r);
}

.section-title {
  display: flex; align-items: center; gap: 9px;
  font-size: 13px; font-weight: 600;
  color: var(--text);
  padding-bottom: 10px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.section-title .icon { color: var(--accent); }

/* ---------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 38px;
  padding: 0 15px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
}
.btn:hover { background: var(--surface-3); text-decoration: none; color: var(--text); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }

.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #991b1b; border-color: #991b1b; color: #fff; }
html[data-theme="dark"] .btn-danger { color: #2a0707; }

.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }

.btn-outline-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-outline-danger:hover { background: var(--danger-soft); color: var(--danger); }

.btn-sm { height: 32px; padding: 0 11px; font-size: 12.5px; }
.btn-lg { height: 44px; padding: 0 20px; font-size: 14.5px; }
.btn-block { width: 100%; }
.btn-icon { width: 38px; padding: 0; }

/* ----------------------------------------------------------------- badges */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px 3px 7px;
  border-radius: var(--r-pill);
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }

.badge-success { background: var(--success-soft); color: var(--success); }
.badge-info    { background: var(--info-soft);    color: var(--info); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger  { background: var(--danger-soft);  color: var(--danger); }
.badge-muted,
.badge-neutral { background: var(--muted-soft);   color: var(--muted); }

.chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: var(--r-sm);
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text-2);
  font-size: 11.5px;
  font-weight: 500;
  white-space: nowrap;
}

/* ---------------------------------------------------------------- avatars */

.avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent-soft);
  color: var(--accent-soft-text);
  font-size: 12.5px;
  font-weight: 700;
  flex: none;
  letter-spacing: .02em;
}
.avatar-lg { width: 68px; height: 68px; font-size: 22px; }
.avatar-sm { width: 28px; height: 28px; font-size: 11px; }

/* ----------------------------------------------------------------- alerts */

.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--r);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 13.5px;
  margin-bottom: 14px;
}
.alert .icon { flex: none; margin-top: 1px; }
.alert-success { background: var(--success-soft); border-color: transparent; color: var(--success); }
.alert-error   { background: var(--danger-soft);  border-color: transparent; color: var(--danger); }
.alert-info    { background: var(--info-soft);    border-color: transparent; color: var(--info); }
.alert-warning { background: var(--warning-soft); border-color: transparent; color: var(--warning); }
.alert .close { margin-left: auto; background: none; border: 0; color: inherit; cursor: pointer; opacity: .7; }
.alert .close:hover { opacity: 1; }

/* ---------------------------------------------------------------- KPI tiles */

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.grid-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 16px 18px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
  box-shadow: var(--shadow-sm);
  color: var(--text);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
a.stat:hover { text-decoration: none; border-color: var(--border-strong); box-shadow: var(--shadow); }

.stat-icon {
  width: 42px; height: 42px;
  border-radius: var(--r);
  display: grid; place-items: center;
  flex: none;
  background: var(--surface-3);
  color: var(--text-2);
}
.stat-icon.accent  { background: var(--accent-soft);  color: var(--accent-soft-text); }
.stat-icon.success { background: var(--success-soft); color: var(--success); }
.stat-icon.info    { background: var(--info-soft);    color: var(--info); }
.stat-icon.warning { background: var(--warning-soft); color: var(--warning); }
.stat-icon.danger  { background: var(--danger-soft);  color: var(--danger); }

/* ------------------------------------------------------- progress meter
   Budget against cost spent. The fill is clamped at 100% so an overrun
   stays inside the track; the colour, not the width, is what says it has
   gone over. */

.meter {
  height: 10px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
  border: 1px solid var(--border);
}
.meter-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transition: width var(--t-mid, .25s) ease;
}
.meter-fill.is-over { background: var(--danger); }

.stat-label { font-size: 12.5px; color: var(--text-2); }
.stat-value { font-size: 23px; font-weight: 650; line-height: 1.25; font-variant-numeric: tabular-nums; }
.stat-value.sm { font-size: 19px; }
.stat-hint { font-size: 12px; color: var(--text-3); margin-top: 2px; }

.mini-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 13px 14px;
  display: flex; align-items: center; gap: 11px;
  color: var(--text);
}
a.mini-stat:hover { text-decoration: none; border-color: var(--border-strong); }
.mini-stat .icon { color: var(--text-3); }
.mini-stat .v { font-size: 17px; font-weight: 650; font-variant-numeric: tabular-nums; }
.mini-stat .l { font-size: 12px; color: var(--text-2); }

/* --------------------------------------------------------------- progress */

.bar-track {
  display: block;
  height: 7px;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  overflow: hidden;
}
.bar-fill {
  display: block;
  height: 100%;
  min-width: 3px;
  border-radius: var(--r-pill);
  background: var(--accent);
}

.bar-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; }
.bar-row + .bar-row { margin-top: 13px; }
.bar-row .label { font-size: 13px; }
.bar-row .value { font-size: 12.5px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.bar-row .track { grid-column: 1 / -1; }

/* ------------------------------------------------------------------- list */

.list-plain > li {
  display: flex;
  gap: 11px;
  align-items: flex-start;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.list-plain > li:last-child { border-bottom: 0; }
.list-plain .icon-dot {
  width: 32px; height: 32px; border-radius: var(--r-sm);
  display: grid; place-items: center; flex: none;
  background: var(--surface-3); color: var(--text-2);
}
.list-plain .icon-dot.accent  { background: var(--accent-soft);  color: var(--accent-soft-text); }
.list-plain .icon-dot.success { background: var(--success-soft); color: var(--success); }
.list-plain .icon-dot.info    { background: var(--info-soft);    color: var(--info); }
.list-plain .icon-dot.warning { background: var(--warning-soft); color: var(--warning); }
.list-plain .icon-dot.danger  { background: var(--danger-soft);  color: var(--danger); }
.list-plain .t { font-size: 13.5px; font-weight: 500; }
.list-plain .m { font-size: 12.5px; color: var(--text-2); }
.list-plain .time { font-size: 11.5px; color: var(--text-3); margin-left: auto; white-space: nowrap; }

/* ------------------------------------------------------------ empty state */

.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-2);
}
.empty .icon-wrap {
  width: 56px; height: 56px;
  margin: 0 auto 14px;
  border-radius: var(--r-lg);
  background: var(--surface-3);
  color: var(--text-3);
  display: grid; place-items: center;
}
.empty h3 { margin-bottom: 6px; }
.empty p { font-size: 13.5px; max-width: 420px; margin: 0 auto 16px; }

/* ------------------------------------------------------------------- tabs */

.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.tab {
  padding: 10px 14px;
  font-size: 13.5px;
  color: var(--text-2);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* ----------------------------------------------------------------- charts */

.chart-legend { display: flex; flex-wrap: wrap; gap: 10px 18px; margin-top: 14px; }
.legend-item { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-2); }
.legend-swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend-item .v { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

.donut-wrap { position: relative; display: grid; place-items: center; }
.donut-center {
  position: absolute; text-align: center;
}
.donut-center .v { font-size: 22px; font-weight: 650; line-height: 1.1; }
.donut-center .l { font-size: 11.5px; color: var(--text-3); }

.chart-svg { width: 100%; height: auto; display: block; }
.chart-grid { stroke: var(--border); stroke-width: 1; stroke-dasharray: 3 4; }
.chart-axis-label { fill: var(--text-3); font-size: 10.5px; }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 2.25; stroke-linejoin: round; stroke-linecap: round; }
.chart-area { fill: var(--accent); opacity: .10; }
.chart-point { fill: var(--surface); stroke: var(--accent); stroke-width: 2; }

/* ------------------------------------------------------------------ misc */

.divider-v { width: 1px; height: 24px; background: var(--border); }

.kv { display: grid; grid-template-columns: minmax(140px, 190px) 1fr; gap: 10px 18px; }
.kv dt { color: var(--text-2); font-size: 12.5px; }
.kv dd { margin: 0; font-size: 13.5px; }
.value-block { display: block; white-space: pre-wrap; }

.callout {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 14px 16px;
  border-radius: var(--r);
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.callout.danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.callout.danger strong { color: var(--danger); }

/* =========================================================================
   Record photography
   Thumbnails in lists, the hero photo on a detail page, the picker on a
   form and the lightbox that enlarges any of them. Flat fills only.
   ========================================================================= */

/* ------------------------------------------------------------- thumbnails */

.thumb {
  width: 46px; height: 46px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  overflow: hidden;
  cursor: zoom-in;
  display: block;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb:hover,
.thumb:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); outline: none; }
.thumb.thumb-placeholder { background: var(--surface-3); border-style: dashed; cursor: pointer; }
.thumb.thumb-placeholder img { object-fit: contain; padding: 2px; opacity: .9; }

.avatar.has-photo { background: var(--surface-3); overflow: hidden; padding: 0; }
.avatar.has-photo img { width: 100%; height: 100%; object-fit: cover; display: block; border-radius: 50%; }

/* --------------------------------------------------- detail page preview */

.img-preview {
  display: block;
  width: 100%;
  max-width: 240px;
  padding: 0;
  margin-top: 2px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface-2);
  overflow: hidden;
  cursor: zoom-in;
}
.img-preview img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; }
.img-preview.is-placeholder { border-style: dashed; background: var(--surface-3); }
.img-preview.is-placeholder img { object-fit: contain; padding: 6px; }
.img-preview.is-round { width: 92px; height: 92px; max-width: none; border-radius: 50%; }
.img-preview.is-round img { aspect-ratio: 1; }
.img-preview:hover { border-color: var(--accent); }

.view-hero .hero-photo {
  width: 132px;
  padding: 0;
  flex: none;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface-2);
  overflow: hidden;
  cursor: zoom-in;
}
.view-hero .hero-photo img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; }
.view-hero .hero-photo.is-placeholder { border-style: dashed; background: var(--surface-3); }
.view-hero .hero-photo.is-placeholder img { object-fit: contain; padding: 8px; }
.view-hero .hero-photo:hover { border-color: var(--accent); }
.view-hero .hero-photo.is-round { width: 68px; height: 68px; border-radius: 50%; }
.view-hero .hero-photo.is-round img { aspect-ratio: 1; height: 100%; object-fit: cover; }

/* ---------------------------------------------------------- image picker */

.image-picker {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.image-picker .ip-preview {
  margin: 0;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface-2);
  overflow: hidden;
}
.image-picker .ip-preview img {
  width: 100%; aspect-ratio: 4 / 3;
  object-fit: contain;
  display: block;
  background: var(--surface-3);
}
.image-picker .ip-preview figcaption {
  padding: 6px 8px;
  font-size: 11.5px;
  color: var(--text-3);
  text-align: center;
  border-top: 1px solid var(--border);
}
.image-picker.is-round .ip-preview { border-radius: 50%; width: 132px; height: 132px; }
.image-picker.is-round .ip-preview img { aspect-ratio: 1; height: 100%; object-fit: cover; }
.image-picker.is-round .ip-preview figcaption { display: none; }

.image-picker .ip-controls { display: grid; gap: 10px; }
.image-picker .ip-or {
  display: flex; align-items: center; gap: 10px;
  font-size: 11.5px; color: var(--text-3);
  text-transform: uppercase; letter-spacing: .05em;
}
.image-picker .ip-or::before,
.image-picker .ip-or::after { content: ''; height: 1px; flex: 1; background: var(--border); }
.image-picker .ip-remove { font-size: 12.5px; color: var(--text-2); }
.image-picker .file-drop { margin: 0; }

/* -------------------------------------------------------------- lightbox */

.lightbox {
  position: fixed; inset: 0;
  z-index: 120;
  display: none;
  padding: 24px;
  background: rgba(15, 23, 42, .78);
}
.lightbox.is-open { display: grid; place-items: center; }
.lightbox-inner {
  max-width: min(760px, 100%);
  max-height: 100%;
  display: flex; flex-direction: column; gap: 12px;
  padding: 14px;
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}
.lightbox img {
  max-width: 100%;
  max-height: min(68vh, 560px);
  object-fit: contain;
  border-radius: var(--r-sm);
  background: var(--surface-3);
}
.lightbox-caption {
  color: var(--text);
  font-size: 13.5px;
  font-weight: 500;
  text-align: center;
}
.lightbox-close {
  position: absolute; top: 16px; right: 16px;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border: 1px solid rgba(226, 232, 240, .35);
  border-radius: var(--r-pill);
  background: rgba(15, 23, 42, .5);
  color: #f8fafc;
  cursor: pointer;
}
.lightbox-close:hover { background: rgba(15, 23, 42, .8); }

@media (max-width: 720px) {
  .image-picker { grid-template-columns: 1fr; }
  .image-picker .ip-preview { max-width: 220px; }
  .thumb { width: 38px; height: 38px; }
}

@media print {
  .lightbox { display: none !important; }
  .thumb, .img-preview, .hero-photo { border-color: #cbd5e1; }
}

.list-plain > li > .thumb { width: 38px; height: 38px; flex: none; }
