:root {
  --bg: #eef5fb;
  --panel: #ffffff;
  --ink: #102235;
  --muted: #5c6f82;
  --line: #cddbe8;
  --blue: #0d5ea8;
  --blue-dark: #083d70;
  --blue-soft: #e0f0ff;
  --green: #0d7a45;
  --green-soft: #dcf7e9;
  --amber: #946200;
  --amber-soft: #fff2cc;
  --red: #a32020;
  --red-soft: #ffe2e2;
  --shadow: 0 16px 38px rgba(16, 34, 53, 0.10);
}

* { box-sizing: border-box; }

html {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(13, 94, 168, 0.16), transparent 32rem),
    linear-gradient(180deg, #f7fbff 0%, var(--bg) 100%);
  color: var(--ink);
  font-family: "Aptos", "Segoe UI", sans-serif;
  line-height: 1.45;
  max-width: 100%;
  overflow-x: hidden;
}

a { color: var(--blue); }
a:hover { color: var(--blue-dark); }

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--blue-dark);
  color: white;
  padding: 0.75rem 1rem;
  z-index: 10;
}
.skip-link:focus { left: 1rem; top: 1rem; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 0.7rem clamp(1rem, 3vw, 2rem);
  background: rgba(255, 255, 255, 0.88);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--ink);
  text-decoration: none;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.7rem;
  background: var(--blue);
  color: white;
  font-size: 0.9rem;
}

nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: center;
}

nav a {
  color: var(--ink);
  text-decoration: none;
  padding: 0.55rem 0.75rem;
  border-radius: 999px;
  font-weight: 650;
}
nav a.active, nav a:hover {
  background: var(--blue-soft);
  color: var(--blue-dark);
}
nav form { margin: 0; }
.nav-logout {
  padding: 0.55rem 0.75rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}
.nav-logout:hover, .nav-logout:focus-visible { background: #fee2e2; color: #991b1b; }

main {
  width: min(1360px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.35rem 0 3rem;
}

.hero-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1.5rem;
  align-items: center;
  padding: clamp(1.2rem, 4vw, 2.2rem);
  margin-bottom: 1rem;
  border-radius: 1.6rem;
  color: #fff;
  background:
    linear-gradient(135deg, rgba(9, 57, 103, 0.92), rgba(13, 94, 168, 0.84)),
    radial-gradient(circle at 80% 20%, rgba(255, 255, 255, 0.22), transparent 20rem);
  box-shadow: var(--shadow);
}
.hero-panel .muted, .hero-panel .eyebrow { color: rgba(255, 255, 255, 0.78); }
.hero-panel h1 { color: #fff; }
.hero-actions, .quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.compact-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.metric {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem;
  border-radius: 1rem;
  background: #fff;
  border: 1px solid var(--line);
  text-decoration: none;
  color: var(--ink);
  box-shadow: 0 8px 22px rgba(16, 34, 53, 0.06);
}
.metric strong { font-size: 2rem; line-height: 1; }
.metric span { color: var(--muted); font-weight: 800; }
.metric.good { border-left: 0.35rem solid var(--green); }
.metric.warn { border-left: 0.35rem solid var(--amber); }
.metric.danger { border-left: 0.35rem solid var(--red); }

.workbench-grid {
  display: grid;
  grid-template-columns: 1.3fr 0.7fr;
  gap: 1rem;
}

h1, h2, h3 { letter-spacing: -0.035em; line-height: 1.1; }
h1 { margin: 0; font-size: clamp(2rem, 4vw, 3.35rem); }
h2 { margin: 0 0 0.35rem; font-size: clamp(1.35rem, 2vw, 1.8rem); }
p { margin: 0.3rem 0 0.75rem; }

.muted { color: var(--muted); }
.small { font-size: 0.88rem; }
.eyebrow {
  margin: 0 0 0.35rem;
  color: var(--blue);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.78rem;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  margin: 0.3rem 0 1.2rem;
}

.panel, .stat-card, .login-card {
  background: var(--panel);
  border: 1px solid rgba(205, 219, 232, 0.88);
  border-radius: 1.25rem;
  box-shadow: var(--shadow);
}

.panel {
  padding: clamp(1rem, 2.5vw, 1.4rem);
  margin-bottom: 1rem;
  min-width: 0;
}

.search-panel {
  position: sticky;
  top: 4.1rem;
  z-index: 3;
}

.panel-head {
  margin-bottom: 0.9rem;
}
.panel-head.inline {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.stats-grid, .workflow-grid, .detail-grid {
  display: grid;
  gap: 1rem;
  margin-bottom: 1rem;
}
.stats-grid > *, .workflow-grid > *, .detail-grid > * { min-width: 0; }
.stats-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.workflow-grid, .detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.stat-card {
  padding: 1rem;
  border-left: 0.45rem solid var(--blue);
}
.stat-card span, .stat-card small { display: block; color: var(--muted); }
.stat-card strong { display: block; font-size: clamp(2rem, 5vw, 3.6rem); line-height: 1; margin: 0.35rem 0; }
.stat-card.good { border-left-color: var(--green); }
.stat-card.warn { border-left-color: var(--amber); }
.stat-card.danger { border-left-color: var(--red); }

.stack {
  display: grid;
  gap: 0.65rem;
}

label {
  font-weight: 750;
  color: #183149;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  padding: 0.78rem 0.85rem;
  font: inherit;
  background: #fbfdff;
  color: var(--ink);
}

input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 3px solid rgba(13, 94, 168, 0.35);
  outline-offset: 2px;
}

.check {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 650;
}
.check input { width: auto; }

button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 2.6rem;
  border: 0;
  border-radius: 0.8rem;
  padding: 0.72rem 1rem;
  font: inherit;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}

.big {
  min-height: 3rem;
  padding-inline: 1.25rem;
}

.primary {
  background: var(--blue);
  color: white;
}
.primary:hover { background: var(--blue-dark); color: white; }

.secondary {
  background: var(--blue-soft);
  color: var(--blue-dark);
  border: 1px solid rgba(13, 94, 168, 0.16);
}
.secondary:hover { background: #cce6ff; color: var(--blue-dark); }

.danger-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.6rem;
  border: 1px solid rgba(163, 32, 32, 0.18);
  border-radius: 0.8rem;
  padding: 0.72rem 1rem;
  font: inherit;
  font-weight: 850;
  color: var(--red);
  background: var(--red-soft);
  cursor: pointer;
}
.danger-button:hover { background: #ffd1d1; }

.compact {
  min-height: 2.15rem;
  padding: 0.45rem 0.65rem;
  font-size: 0.9rem;
}
.wide { width: 100%; }

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.asset-create-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
  gap: 0.75rem;
  align-items: end;
}
.asset-create-form label {
  display: grid;
  gap: 0.35rem;
}
.asset-create-form .wide-field {
  grid-column: span 2;
}
.next-id {
  display: inline-flex;
  align-items: center;
  min-height: 2.3rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--blue-dark);
  font-weight: 850;
}

.asset-actions, .qr-actions {
  display: grid;
  gap: 0.55rem;
}

.loan-workflow {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}
.loan-card {
  padding: clamp(1rem, 2.5vw, 1.5rem);
  border-radius: 1.35rem;
  border: 1px solid var(--line);
  background: #fff;
  box-shadow: var(--shadow);
}
.loan-card-primary {
  border-top: 0.4rem solid var(--blue);
}
.loan-card-head {
  display: flex;
  gap: 0.8rem;
  align-items: flex-start;
  margin-bottom: 1rem;
}
.step-badge {
  display: inline-grid;
  place-items: center;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 999px;
  background: var(--blue);
  color: #fff;
  font-weight: 900;
  flex: 0 0 auto;
}

.item-list {
  display: grid;
  gap: 0.65rem;
}
.item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.85rem;
  padding: 0.8rem;
  border: 1px solid var(--line);
  border-radius: 0.9rem;
  background: #f9fcff;
}
.item-row strong, .item-row span {
  display: block;
}
.item-row span {
  color: var(--muted);
  font-size: 0.9rem;
}

.filter-bar {
  display: grid;
  grid-template-columns: minmax(16rem, 1fr) minmax(12rem, 16rem) auto auto;
  gap: 0.75rem;
  align-items: end;
}

.flash {
  padding: 0.9rem 1rem;
  border-radius: 1rem;
  margin-bottom: 1rem;
  font-weight: 750;
  border: 1px solid transparent;
}
.flash.success {
  background: var(--green-soft);
  color: var(--green);
  border-color: rgba(13, 122, 69, 0.2);
}
.flash.error {
  background: var(--red-soft);
  color: var(--red);
  border-color: rgba(163, 32, 32, 0.2);
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 1.85rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-weight: 850;
  font-size: 0.88rem;
  white-space: nowrap;
}
.status.available, .status.returned { background: var(--green-soft); color: var(--green); }
.status.loaned, .status.open { background: var(--amber-soft); color: var(--amber); }
.status.maintenance, .status.returned_damaged { background: var(--red-soft); color: var(--red); }
.status.lost, .status.cancelled { background: #e7e9ee; color: #465464; }

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  border: 1px solid var(--line);
  border-radius: 1rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}
td[data-label="ID"], th:first-child {
  white-space: nowrap;
}
th, td {
  padding: 0.75rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  text-align: left;
}
th {
  color: #244158;
  background: #f4f8fc;
  font-size: 0.88rem;
}
tr:last-child td { border-bottom: 0; }

.asset-name {
  font-weight: 850;
  max-width: 28rem;
  overflow-wrap: anywhere;
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
}
.inline-form select { width: auto; min-width: 11rem; }

.photo-link, .photo-card {
  display: grid;
  gap: 0.35rem;
  color: var(--ink);
  text-decoration: none;
}
.photo-link img {
  width: 9rem;
  max-height: 7rem;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  background: #f8fbff;
}
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
  gap: 1rem;
}
.photo-card {
  border: 1px solid var(--line);
  border-radius: 1rem;
  padding: 0.75rem;
  background: #f9fcff;
}
.photo-card img {
  width: 100%;
  height: 15rem;
  object-fit: contain;
  background: #eef5fb;
  border-radius: 0.75rem;
}
.photo-card code, .json {
  display: block;
  max-width: 34rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: #29465f;
  background: #f4f8fc;
  padding: 0.5rem;
  border-radius: 0.55rem;
}

.empty-state {
  padding: 1rem;
  background: #f7fbff;
  border: 1px dashed #aac3da;
  border-radius: 1rem;
}
.empty-state strong { display: block; margin-bottom: 0.25rem; }

.meta-list {
  display: grid;
  gap: 0.55rem;
  margin: 0.8rem 0 1rem;
}
.meta-list div {
  display: grid;
  grid-template-columns: 9rem 1fr;
  gap: 0.75rem;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.45rem;
}
.meta-list dt { color: var(--muted); font-weight: 750; }
.meta-list dd { margin: 0; overflow-wrap: anywhere; }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}
.login-shell { width: min(100%, 28rem); padding: 0; }
.login-card { padding: clamp(1.2rem, 4vw, 2rem); }
.login-brand { margin-bottom: 1rem; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 900px) {
  .topbar, .page-head, .panel-head.inline, .hero-panel {
    align-items: stretch;
    flex-direction: column;
  }
  .hero-panel, .workbench-grid, .compact-stats, .loan-workflow, .asset-create-form {
    grid-template-columns: 1fr;
  }
  .hero-actions .button, .quick-actions .button, .quick-actions form, .quick-actions button {
    width: 100%;
  }
  .asset-create-form .wide-field {
    grid-column: auto;
  }
  nav a { padding: 0.5rem 0.6rem; }
  .stats-grid, .workflow-grid, .detail-grid, .filter-bar {
    grid-template-columns: 1fr;
  }
  .filter-bar button, .filter-bar .button {
    width: 100%;
  }
  .inline-form select, .inline-form button {
    width: 100%;
  }
  .photo-link img {
    width: 100%;
    max-height: 14rem;
  }
  .asset-table {
    min-width: 0;
    border-collapse: separate;
    border-spacing: 0 0.75rem;
  }
  .asset-table thead {
    display: none;
  }
  .asset-table tbody, .asset-table tr, .asset-table td {
    display: block;
    width: 100%;
  }
  .asset-table tr {
    border: 1px solid var(--line);
    border-radius: 1rem;
    overflow: hidden;
    background: #fff;
  }
  .asset-table td {
    border-bottom: 1px solid var(--line);
    padding: 0.75rem;
  }
  .asset-table td:last-child {
    border-bottom: 0;
  }
  .asset-table td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 0.25rem;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 850;
    text-transform: uppercase;
    letter-spacing: 0.06em;
  }
  .asset-table .button-row,
  .asset-table .button-row .button {
    width: 100%;
  }
  .item-row {
    align-items: stretch;
    flex-direction: column;
  }
  .item-row .button {
    width: 100%;
  }
}
