:root {
  --ink: #202938;
  --muted: #6f7887;
  --line: #e7ebf0;
  --panel: #ffffff;
  --bg: #f6f7f9;
  --nav: #132b33;
  --nav-2: #1d3c45;
  --accent: #f59f45;
  --accent-dark: #d97e20;
  --blue: #172a55;
  --green: #18864b;
  --red: #c83a35;
  --shadow: 0 12px 34px rgba(31, 42, 55, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(320px, 480px) 1fr;
  background: linear-gradient(120deg, var(--nav) 0%, #203b43 48%, var(--bg) 48%);
}

.login-brand {
  color: white;
  padding: 56px;
  align-self: end;
}

.logo-mark {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: var(--accent);
  color: white;
  font-weight: 800;
  margin-bottom: 18px;
}

.login-brand h1 {
  margin: 0;
  font-size: 42px;
  line-height: 1;
  letter-spacing: 0;
}

.login-brand p {
  max-width: 360px;
  color: #c9d7db;
  line-height: 1.6;
}

.login-panel {
  width: min(440px, calc(100vw - 32px));
  margin: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 30px;
}

.login-panel h2 {
  margin: 0 0 8px;
  font-size: 26px;
}

.login-panel p,
.hint {
  color: var(--muted);
  font-size: 14px;
}

.field {
  display: grid;
  gap: 7px;
  margin-top: 16px;
}

.field span {
  color: #384456;
  font-size: 13px;
  font-weight: 700;
}

.field input,
.field select,
.field textarea,
.search {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  padding: 12px 13px;
  outline: none;
}

.field textarea {
  min-height: 180px;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(245, 159, 69, 0.18);
}

.primary,
.secondary,
.ghost,
.danger {
  min-height: 42px;
  border-radius: 8px;
  padding: 0 15px;
  font-weight: 800;
}

.primary {
  background: var(--accent);
  color: white;
}

.primary:hover {
  background: var(--accent-dark);
}

.secondary {
  background: var(--blue);
  color: white;
}

.ghost {
  background: white;
  color: var(--ink);
  border: 1px solid var(--line);
}

.danger {
  background: #fff1f1;
  color: var(--red);
}

.error {
  color: var(--red);
  font-size: 14px;
  margin-top: 12px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
  background: white;
  border-right: 1px solid var(--line);
  padding: 22px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  font-weight: 900;
  color: var(--nav);
  margin-bottom: 28px;
}

.brand .logo-mark {
  width: 42px;
  height: 42px;
  margin: 0;
  border-radius: 10px;
}

.nav-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  margin: 22px 0 8px;
}

.nav-button {
  width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 8px;
  background: transparent;
  color: #3b4657;
  padding: 0 12px;
  text-align: left;
  font-weight: 800;
}

.nav-button.active {
  background: #fff4e8;
  color: var(--accent-dark);
}

.nav-count {
  margin-left: auto;
  min-width: 28px;
  border-radius: 999px;
  background: #eef2f7;
  color: #334155;
  font-size: 12px;
  line-height: 1;
  padding: 6px 8px;
  text-align: center;
}

.nav-button.active .nav-count {
  background: #ffe2c0;
  color: var(--accent-dark);
}

.nav-empty {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  padding: 8px 12px;
}

.content {
  min-width: 0;
}

.topbar {
  height: 76px;
  display: flex;
  align-items: center;
  gap: 14px;
  justify-content: space-between;
  padding: 0 28px;
  background: white;
  border-bottom: 1px solid var(--line);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 260px;
}

.user-pill {
  background: #f2f5f8;
  border-radius: 8px;
  padding: 10px 12px;
  font-weight: 800;
  color: #3c4656;
}

.page {
  padding: 26px 28px;
}

.page-head {
  display: flex;
  gap: 16px;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 22px;
}

.page-title h1 {
  margin: 0 0 6px;
  font-size: 28px;
}

.page-title p {
  margin: 0;
  color: var(--muted);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.quick-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.quick-filter {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: #334155;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 900;
}

.quick-filter strong {
  min-width: 24px;
  border-radius: 999px;
  background: white;
  color: var(--blue);
  line-height: 1;
  padding: 5px 7px;
  text-align: center;
}

.quick-filter.active {
  border-color: var(--accent);
  background: #fff4e8;
  color: var(--accent-dark);
}

.stats {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.list-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.list-card {
  min-height: 82px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  padding: 16px;
  text-align: left;
}

.list-card:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(245, 159, 69, 0.12);
}

.list-card span {
  color: #384456;
  font-weight: 900;
}

.list-card strong {
  font-size: 26px;
}

.device-cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: stretch;
  gap: 12px;
  margin-bottom: 18px;
}

.device-chart {
  min-height: 260px;
  height: 100%;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  padding: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.device-chart.status-chart,
.device-chart.metric-chart {
  height: 100%;
}

.device-chart.metric-chart {
  display: grid;
  align-content: start;
  gap: 8px;
}

.metric-chart-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.metric-chart-head > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.metric-filter {
  display: flex;
  gap: 4px;
}

.metric-filter button {
  min-height: 26px;
  border-radius: 6px;
  background: #f2f5f8;
  color: #334155;
  padding: 0 8px;
  font-size: 11px;
  font-weight: 900;
}

.metric-filter button.active {
  background: #fff4e8;
  color: var(--accent-dark);
}

.device-chart.breakdown-chart {
  height: 100%;
}

.device-chart.missing-chart {
  height: 100%;
}

.device-chart.missing-summary {
  height: auto;
  min-height: 260px;
}

.device-chart > span,
.chart-head span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  margin-bottom: 8px;
}

.chart-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
}

.chart-head strong {
  font-size: 32px;
  line-height: 0.9;
  color: #111827;
}

.breakdown-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 8px;
}

.breakdown-head.compact {
  margin-top: -2px;
}

.breakdown-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.breakdown-head select {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 800;
  padding: 7px 10px;
}

.metric-row {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 12px;
}

.metric-stack {
  display: grid;
  gap: 8px;
}

.metric-row > strong {
  font-size: 34px;
  line-height: 1;
  min-width: 44px;
}

.metric-row span {
  display: block;
  color: #293755;
  font-size: 12px;
  font-weight: 900;
  margin-bottom: 5px;
}

.metric-row.reused > strong {
  color: var(--green);
}

.recent-types {
  display: grid;
  gap: 4px;
  max-height: 112px;
  overflow: auto;
}

.recent-types > div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  font-weight: 800;
  color: #293755;
}

.recent-types span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-bars {
  display: grid;
  gap: 8px;
}

.status-bar > div:first-child,
.rank-meta {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: baseline;
  margin-bottom: 5px;
}

.status-bar span,
.rank-meta span {
  color: #293755;
  font-weight: 800;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-bar strong,
.rank-meta strong {
  font-size: 14px;
}

.status-track,
.rank-track {
  height: 8px;
  background: #edf1f5;
  border-radius: 999px;
  overflow: hidden;
}

.status-fill,
.rank-fill {
  height: 100%;
  border-radius: 999px;
}

.status-fill.stock {
  background: linear-gradient(90deg, #334155, #64748b);
}

.status-fill.lease {
  background: linear-gradient(90deg, #2563eb, #60a5fa);
}

.status-fill.use,
.rank-fill {
  background: linear-gradient(90deg, #16a34a, #86efac);
}

.status-fill.today {
  background: linear-gradient(90deg, #f59e0b, #facc15);
}

.rank-list {
  max-height: 82px;
  overflow: auto;
  padding-right: 4px;
}

.breakdown-chart .rank-list {
  max-height: 210px;
}

.missing-chart .rank-list {
  max-height: 148px;
}

.missing-summary .rank-list {
  max-height: 190px;
}

.missing-layout {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.missing-table {
  min-width: 0;
}

.rank-row {
  padding: 6px 0;
  border-top: 1px solid #edf1f5;
}

.device-card-empty {
  color: var(--muted);
  font-weight: 800;
}

.stat {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.stat span {
  color: var(--muted);
  font-weight: 800;
  font-size: 13px;
}

.stat strong {
  display: block;
  margin-top: 8px;
  font-size: 30px;
}

.table-card,
.form-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.sync-note {
  margin: -4px 0 18px;
  background: #eef9f4;
  border: 1px solid #cfeee0;
  border-radius: 8px;
  color: #146c3f;
  font-weight: 800;
  padding: 12px 14px;
}

.table-toolbar {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.filters {
  display: grid;
  grid-template-columns: repeat(5, minmax(145px, 1fr));
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfd;
}

.filter-field {
  display: grid;
  gap: 5px;
}

.filter-field span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.filter-field input {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  padding: 8px 10px;
  outline: none;
}

.filter-field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(245, 159, 69, 0.18);
}

.small {
  min-height: 32px;
  padding: 0 10px;
  font-size: 12px;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1040px;
}

.backup-table {
  min-width: 760px;
}

.download-link {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border-radius: 8px;
  background: var(--blue);
  color: white;
  font-weight: 900;
  padding: 0 12px;
  text-decoration: none;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 14px 16px;
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

tr.reused-row td {
  background: #e9f9ef;
}

tr.reused-row:hover td {
  background: #d9f4e3;
}

th {
  position: relative;
  background: #f8fafc;
  color: #293755;
  font-size: 13px;
  font-weight: 900;
}

.filter-th {
  padding: 0;
}

.filter-head {
  width: 100%;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: #f8fafc;
  color: #293755;
  padding: 0 14px;
  text-align: left;
  font-weight: 900;
}

.filter-head:hover,
.filter-head.active {
  background: #fff4e8;
  color: var(--accent-dark);
}

.filter-head strong {
  min-width: 22px;
  min-height: 22px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: var(--accent);
  color: white;
  font-size: 11px;
}

.filter-arrow {
  color: var(--muted);
  font-size: 12px;
}

.filter-menu {
  position: absolute;
  top: calc(100% - 1px);
  left: 8px;
  z-index: 20;
  width: 260px;
  max-width: calc(100vw - 32px);
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 10px;
}

.filter-menu-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 8px;
}

.filter-options {
  max-height: 280px;
  overflow: auto;
  display: grid;
  gap: 2px;
}

.filter-option {
  min-height: 34px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-radius: 6px;
  padding: 0 8px;
  color: #384456;
  font-weight: 700;
}

.filter-option:hover {
  background: #f8fafc;
}

.filter-option input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.filter-empty {
  color: var(--muted);
  padding: 10px 8px;
  font-weight: 700;
}

td {
  color: #4c5665;
  font-size: 14px;
}

.serial {
  color: var(--ink);
  font-weight: 900;
}

.badge {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 900;
}

.badge.stock {
  color: #146c3f;
  background: #e8f7ef;
}

.badge.lease {
  color: #1c5a8f;
  background: #eaf5ff;
}

.badge.use {
  color: #8a5b13;
  background: #fff5d8;
}

.badge.warn {
  color: #8a5b13;
  background: #fff5d8;
}

.badge.danger {
  color: #9f1d1d;
  background: #fee2e2;
}

.form-card {
  padding: 20px;
  max-width: 760px;
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(11, 21, 28, 0.42);
  padding: 18px;
}

.modal {
  width: min(760px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  background: white;
  border-radius: 8px;
  padding: 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
}

.modal h2 {
  margin-top: 0;
}

.hidden {
  display: none !important;
}

@media (max-width: 900px) {
  .login-shell,
  .app-shell {
    grid-template-columns: 1fr;
  }

  .login-brand {
    padding: 30px 24px 0;
    align-self: start;
  }

  .sidebar {
    display: flex;
    overflow-x: auto;
    gap: 10px;
    align-items: center;
    padding: 12px;
  }

  .brand,
  .nav-title {
    display: none;
  }

  .nav-button {
    width: auto;
    min-width: max-content;
  }

  .topbar,
  .page-head,
  .table-toolbar {
    align-items: stretch;
    flex-direction: column;
    height: auto;
  }

  .topbar {
    padding: 16px;
  }

  .page {
    padding: 18px 14px;
  }

  .stats,
  .device-cards,
  .split,
  .filters {
    grid-template-columns: 1fr;
  }

  .device-chart.breakdown-chart {
    grid-column: span 1;
  }
}
