/* DL Asset Tracker — mobile-first stylesheet. No framework; tokens below drive everything.
   Palette comes from the Divine Logic logo: deep red squares on white. */

:root {
  --bg: #f5f2f2;
  --surface: #ffffff;
  --surface-2: #f3eeee;
  --text: #1d1717;
  --text-muted: #6a5c5c;
  --border: #e2dada;
  /* --primary fills (buttons, bars); --primary-ink is the brand red where it has to read as text. */
  --primary: #8e1212;
  --primary-ink: #8e1212;
  --primary-contrast: #ffffff;
  --primary-soft: #fae9e9;
  /* Deliberately brighter than the brand red so "destructive" still reads as different from "branded". */
  --danger: #c62828;
  --danger-soft: #fdecea;
  --warning: #8a5a00;
  --warning-soft: #fff3d6;
  --success: #1f7a3d;
  --success-soft: #e4f4e9;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(45, 20, 20, 0.08), 0 4px 12px rgba(45, 20, 20, 0.06);
  --topbar-h: 52px;
  --bottomnav-h: 60px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14100f;
    --surface: #1d1817;
    --surface-2: #272020;
    --text: #ece5e4;
    --text-muted: #a99b9a;
    --border: #392e2e;
    /* Fills keep the brand red; text switches to a lighter rose that is readable on dark surfaces. */
    --primary: #a81717;
    --primary-ink: #f0968e;
    --primary-contrast: #ffffff;
    --primary-soft: #3a1512;
    --danger: #ff6a5a;
    --danger-soft: #3a1c19;
    --warning: #e0b04a;
    --warning-soft: #3a2f12;
    --success: #5dcf83;
    --success-soft: #16301f;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { margin: 0 0 0.5rem; line-height: 1.2; }
h1.page-title { font-size: 1.45rem; margin: 0.25rem 0 1rem; }
h2 { font-size: 1.1rem; }
h1:focus { outline: none; }
a { color: var(--primary-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
p { margin: 0 0 0.75rem; }
.muted { color: var(--text-muted); }
.small { font-size: 0.875rem; }

/* Shell */
.app-shell { min-height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px;
  background: var(--surface);
  color: var(--text);
  border-bottom: 2px solid var(--primary);
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; font-weight: 700; min-width: 0; }
.brand:hover { text-decoration: none; }
.brand-logo { height: 26px; width: auto; display: block; flex-shrink: 0; }
.brand-logo-lg { height: 58px; }
.brand-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-menu { display: flex; align-items: center; gap: 8px; min-width: 0; }
.user-name { max-width: 34vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.9rem; color: var(--text-muted); }

/* Narrow phones: the logo alone identifies the app, and the signed-in name is on the More page. */
@media (max-width: 400px) {
  .brand-logo { height: 22px; }
  .user-name { display: none; }
}

.page {
  flex: 1;
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
  padding: 12px 16px calc(var(--bottomnav-h) + var(--safe-bottom) + 16px);
}

.main-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  height: calc(var(--bottomnav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex; justify-content: space-around; align-items: stretch;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--text-muted); font-size: 0.72rem; text-decoration: none;
}
.nav-item:hover { text-decoration: none; }
.nav-item.active { color: var(--primary-ink); font-weight: 600; }
.nav-icon { font-size: 1.15rem; line-height: 1; }

/* Login */
.login-shell { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; gap: 20px; }
.login-brand { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.login-brand h1 { font-size: 1.6rem; margin: 0.5rem 0 0; }
.login-card { width: 100%; max-width: 380px; border-top: 3px solid var(--primary); }

/* Cards & lists */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  margin: 0 0 14px;
}
.link-list { list-style: none; margin: 0; padding: 0; }
.link-list li { padding: 10px 0; border-top: 1px solid var(--border); }
.link-list li:first-child { border-top: 0; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 0.875rem; font-weight: 600; color: var(--text-muted); }
.input, select.input, textarea.input {
  width: 100%;
  font: inherit;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  min-height: 44px;
}
.input:focus { outline: 2px solid var(--primary-ink); outline-offset: 1px; border-color: var(--primary-ink); }
.input.invalid, .invalid > .input { border-color: var(--danger); }
.validation-message { color: var(--danger); font-size: 0.85rem; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 16px;
  font: inherit; font-weight: 600;
  border-radius: 10px; border: 1px solid transparent;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: filter 120ms ease, background-color 120ms ease;
}
.btn:hover { text-decoration: none; filter: brightness(0.94); }
.btn:disabled { opacity: 0.6; cursor: default; filter: none; }
.btn-primary { background: var(--primary); color: var(--primary-contrast); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-2); filter: none; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: inherit; border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); filter: none; }
.btn-sm { min-height: 34px; padding: 4px 10px; font-size: 0.85rem; }
.btn-xl { min-height: 64px; font-size: 1.15rem; margin-bottom: 16px; }
.btn-block { width: 100%; }

/* Notices & badges */
.notice { padding: 10px 12px; border-radius: 10px; margin: 0 0 12px; background: var(--surface-2); border: 1px solid var(--border); }
.notice-error { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.notice-warning { background: var(--warning-soft); border-color: var(--warning); color: var(--warning); }
.notice-success { background: var(--success-soft); border-color: var(--success); color: var(--success); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; background: var(--surface-2); color: var(--text-muted); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-primary { background: var(--primary-soft); color: var(--primary-ink); }

/* Loading */
.loading { display: flex; align-items: center; gap: 10px; padding: 24px 0; color: var(--text-muted); }
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--primary-ink);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Boot progress (before Blazor starts) */
.boot { min-height: 100dvh; display: grid; place-items: center; }
.loading-progress { position: relative; display: block; width: 8rem; height: 8rem; }
.loading-progress circle { fill: none; stroke: var(--border); stroke-width: 0.6rem; transform-origin: 50% 50%; transform: rotate(-90deg); }
.loading-progress circle:last-child {
  stroke: var(--primary);
  stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
  transition: stroke-dasharray 0.05s ease-in-out;
}
.loading-progress-text { position: absolute; text-align: center; font-weight: bold; inset: calc(20vh + 3.25rem) 0 auto 0.2rem; }
.loading-progress-text:after { content: var(--blazor-load-percentage-text, "Loading"); }

#blazor-error-ui {
  color-scheme: light only;
  background: lightyellow; color: #333;
  bottom: 0; box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
  box-sizing: border-box; display: none; left: 0; padding: 0.6rem 1.25rem 0.7rem 1.25rem;
  position: fixed; width: 100%; z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }

/* Page header with action */
.page-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.page-header .page-title { margin: 0.25rem 0; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }

/* Item lists (tap targets) */
.item-list { list-style: none; margin: 0 0 14px; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.item-list li + li { border-top: 1px solid var(--border); }
.item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; min-height: 56px; padding: 10px 14px;
  color: inherit; text-decoration: none; text-align: left;
  background: transparent; border: 0; font: inherit; cursor: pointer;
}
.item:hover { text-decoration: none; background: var(--surface-2); }
.item-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1 1 auto; }
.item-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-side { display: flex; gap: 6px; flex-shrink: 0; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

/* Definition lists */
.details { display: grid; grid-template-columns: minmax(110px, 35%) 1fr; gap: 8px 12px; margin: 0; }
.details dt { color: var(--text-muted); font-size: 0.875rem; }
.details dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.prewrap { white-space: pre-wrap; }

/* Checkboxes */
.checkbox { display: inline-flex; align-items: center; gap: 8px; min-height: 32px; cursor: pointer; }
.checkbox input { width: 20px; height: 20px; accent-color: var(--primary); }
code { font-size: 0.9em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

/* Device forms */
.req { color: var(--danger); }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 0 14px; }
@media (min-width: 640px) { .form-grid { grid-template-columns: 1fr 1fr; } }
.inline-input { display: flex; gap: 8px; }
.inline-input .input { flex: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); font-size: 0.9rem; }
.chip-remove { border: 0; background: transparent; color: var(--text-muted); font-size: 1.1rem; line-height: 1; cursor: pointer; padding: 0 2px; }
.chip-remove:hover { color: var(--danger); }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.sticky-actions { position: sticky; bottom: calc(var(--bottomnav-h) + var(--safe-bottom) + 8px); background: var(--bg); padding: 8px 0; z-index: 5; }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.pager { justify-content: space-between; align-items: center; }

/* Photos */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; margin-bottom: 10px; }
.photo-tile { position: relative; margin: 0; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--border); }
.photo-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-tile-loading { display: grid; place-items: center; }
.photo-remove { position: absolute; top: 4px; right: 4px; background: rgba(0, 0, 0, 0.55); color: #fff; border-radius: 50%; width: 26px; height: 26px; }
.item-thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; flex-shrink: 0; background: var(--surface-2); }
.item-thumb-empty { display: grid; place-items: center; color: var(--text-muted); }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 2px solid var(--border); }
.timeline li { position: relative; padding: 0 0 14px 12px; }
.timeline li::before { content: ""; position: absolute; left: -19px; top: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); }
.changes { margin: 4px 0 0; padding-left: 16px; }
.prefill h2 { margin-bottom: 4px; }

/* Review */
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; text-align: center; }
.stat-value { display: block; font-size: 1.5rem; font-weight: 700; }
.stat-label { display: block; font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
h3.small { margin: 10px 0 6px; }

/* Camera scanner */
.scanner-card video { width: 100%; max-height: 60vh; border-radius: 10px; background: #000; object-fit: cover; }
.scanner-card select { width: 100%; margin-top: 8px; }
.scanner-card button { margin-top: 8px; }

/* ---------------------------------------------------------------------------
   Desktop (>= 900px). The phone layout stays the default; here the bottom bar
   becomes a navigation row under the header (flex order — same markup), the
   content column widens and the touch-sized blocks relax.
   --------------------------------------------------------------------------- */
@media (min-width: 900px) {
  :root {
    --topbar-h: 60px;
    --bottomnav-h: 0px;
  }

  .topbar { padding: 0 24px; border-bottom: 0; }

  .brand { gap: 12px; }
  .brand-logo { height: 34px; }
  .brand-text { font-size: 1.15rem; }
  .user-name { max-width: 260px; font-size: 0.95rem; }

  .main-nav {
    position: sticky; top: var(--topbar-h); bottom: auto; left: auto; right: auto;
    z-index: 19;
    height: auto; padding: 8px 24px;
    justify-content: center; gap: 6px;
    border-top: 0; border-bottom: 2px solid var(--primary);
  }
  .nav-item {
    flex: 0 0 auto; flex-direction: row; gap: 8px;
    padding: 8px 14px; border-radius: 10px;
    font-size: 0.95rem;
  }
  .nav-item:hover { background: var(--surface-2); }
  .nav-item.active { background: var(--primary-soft); }
  .nav-icon { font-size: 1.05rem; }

  .page { max-width: 1040px; padding: 22px 24px 48px; }
  h1.page-title { font-size: 1.8rem; }
  h2 { font-size: 1.2rem; }
  .card { padding: 18px 20px; margin-bottom: 18px; }

  /* Full-width buttons are a phone affordance; on a wide page they look adrift. */
  .btn-block { width: auto; min-width: 240px; }
  .login-card .btn-block { width: 100%; }
  .btn-xl { min-height: 56px; }

  .filters { grid-template-columns: repeat(3, 1fr); }
  /* A lone field on the page (the device search) should not stretch the whole column. */
  .page > .field { max-width: 520px; }
  .details { grid-template-columns: minmax(120px, 0.5fr) minmax(0, 1fr) minmax(120px, 0.5fr) minmax(0, 1fr); gap: 10px 24px; }
  .photo-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  .item-thumb { width: 52px; height: 52px; }
  .stat-row { gap: 14px; }
  .scanner-card video { display: block; max-width: 560px; max-height: 50vh; margin: 0 auto; }
  .scanner-card select, .scanner-card button { max-width: 560px; }
  .login-shell { gap: 24px; }
}

/* Wide desktop: the registration/edit form gets a third column of fields. */
@media (min-width: 1200px) {
  .page { max-width: 1120px; }
  .form-grid { grid-template-columns: repeat(3, 1fr); }
}
