:root {
  color-scheme: light;
  --bg: #f4f7f4;
  --surface: #ffffff;
  --text: #18211c;
  --muted: #64706a;
  --line: #dbe3dc;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --good: #167247;
  --warn: #a15c06;
  --danger: #b42318;
  --shadow: 0 18px 45px rgba(24, 33, 28, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 28px clamp(18px, 4vw, 56px);
  background: #17362f;
  color: #fff;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.secondary-link {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 6px;
  padding: 9px 12px;
  color: #fff;
  text-decoration: none;
  font-weight: 800;
}

.eyebrow {
  margin: 0 0 8px;
  color: #b8ddd6;
  font-weight: 700;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(26px, 4vw, 42px);
  line-height: 1.2;
}

.shell {
  width: min(1380px, calc(100% - 32px));
  margin: 28px auto 48px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

.metric,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  padding: 20px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 10px;
  font-size: 34px;
}

.metric.good strong {
  color: var(--good);
}

.metric.warning strong {
  color: var(--warn);
}

.metric.danger strong {
  color: var(--danger);
}

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

.import-panel,
.scan-panel,
.finance-panel {
  margin-bottom: 18px;
}

.finance-kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.finance-kpi {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fbfdfb;
}

.finance-kpi span {
  display: block;
  color: var(--muted);
  font-weight: 800;
}

.finance-kpi strong {
  display: block;
  margin-top: 8px;
  font-size: clamp(22px, 3vw, 30px);
  overflow-wrap: anywhere;
}

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

.bi-toolbar {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr)) auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 12px;
}

.active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 36px;
  margin-bottom: 16px;
}

.filter-chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
  background: #eef6f3;
  color: var(--accent-dark);
  cursor: pointer;
  font-weight: 800;
}

.filter-chip span {
  margin-inline-start: 8px;
}

.muted-chip {
  cursor: default;
  color: var(--muted);
  background: #f5f7f5;
}

.chart-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fbfdfb;
}

.chart-card h3 {
  margin: 0 0 14px;
  font-size: 17px;
}

.bar-chart {
  display: grid;
  gap: 12px;
}

.bar-row {
  display: grid;
  gap: 6px;
  width: 100%;
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  text-align: inherit;
}

.bar-row:hover .bar-track span {
  background: var(--accent-dark);
}

.bar-label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--text);
  font-weight: 800;
}

.bar-label span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-label strong {
  color: var(--muted);
  direction: ltr;
}

.bar-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5ece7;
}

.bar-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.donut-chart {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 20px;
  align-items: center;
}

.donut {
  width: 142px;
  height: 142px;
  border-radius: 50%;
  background: conic-gradient(
    var(--good) 0 calc(var(--open) * 1%),
    var(--danger) calc(var(--open) * 1%) calc((var(--open) + var(--closed)) * 1%),
    #9aa59f calc((var(--open) + var(--closed)) * 1%) 100%
  );
  position: relative;
}

.donut::after {
  content: "";
  position: absolute;
  inset: 28px;
  border-radius: 50%;
  background: #fbfdfb;
}

.chart-legend,
.asset-detail-list {
  margin: 0;
}

.chart-legend {
  display: grid;
  gap: 10px;
}

.chart-legend div,
.legend-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.legend-row {
  width: 100%;
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  text-align: inherit;
}

.chart-legend dt {
  color: var(--muted);
  font-weight: 800;
}

.chart-legend dd {
  margin: 0;
  font-weight: 900;
}

.rank-list {
  display: grid;
  gap: 10px;
}

.rank-row {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.rank-row > span {
  display: inline-grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 50%;
  background: #e5ece7;
  font-weight: 900;
}

.rank-row strong,
.rank-row small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-row small {
  color: var(--muted);
  direction: ltr;
  text-align: right;
}

.rank-row b {
  color: var(--accent-dark);
  direction: ltr;
}

.bi-detail-section {
  margin-top: 18px;
}

.compact-heading {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
}

.compact-heading p {
  margin-bottom: 0;
}

.finance-table {
  min-width: 1120px;
}

.finance-table td:nth-last-child(-n + 3),
.finance-table th:nth-last-child(-n + 3) {
  direction: ltr;
  text-align: left;
}

.import-form {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.panel {
  padding: 22px;
}

.section-heading h2 {
  margin-bottom: 6px;
  font-size: 22px;
}

.section-heading p {
  color: var(--muted);
  margin-bottom: 20px;
}

.form-status {
  min-height: 20px;
  margin: -8px 0 4px;
  color: var(--muted);
  font-weight: 700;
}

.form-status.success {
  color: var(--good);
}

.form-status.error {
  color: var(--danger);
}

form {
  display: grid;
  gap: 15px;
}

label,
.camera-field {
  display: grid;
  gap: 7px;
  color: #29362f;
  font-weight: 700;
}

.field-label {
  display: block;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 11px 12px;
  background: #fbfdfb;
  color: var(--text);
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(15, 118, 110, 0.14);
}

.primary-action {
  border: 0;
  border-radius: 6px;
  padding: 12px 18px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 800;
}

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

.secondary-action {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 12px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font-weight: 800;
}

.auth-body {
  display: grid;
  min-height: 100vh;
  place-items: center;
  background: #17362f;
}

.auth-shell {
  width: min(420px, calc(100% - 28px));
}

.auth-panel h1 {
  margin-bottom: 22px;
}

.auth-form {
  display: grid;
  gap: 16px;
}

.field-body {
  background: #eef3ef;
}

.field-topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  background: #17362f;
  color: #fff;
}

.field-topbar h1 {
  font-size: 22px;
}

.field-shell {
  display: grid;
  gap: 14px;
  width: min(720px, calc(100% - 20px));
  margin: 14px auto 32px;
}

.field-work-card,
.field-asset-panel {
  padding: 16px;
}

.field-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.field-search-form,
.field-inspection-form {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}

.save-inspection {
  min-height: 48px;
}

.camera-panel {
  position: relative;
  display: grid;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfdfb;
  overflow: hidden;
}

.camera-panel.is-empty {
  min-height: 120px;
  place-items: center;
  color: var(--muted);
}

.camera-panel video,
.camera-panel img {
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 6px;
  object-fit: cover;
  background: #18211c;
}

#scannerView {
  width: 100%;
}

#scannerView video {
  display: block;
}

#scannerView canvas {
  display: none;
}

.camera-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.camera-actions button {
  min-height: 42px;
  padding-inline: 8px;
}

.camera-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.native-camera-action {
  width: 100%;
}

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

.scanner-live {
  border-style: solid;
  border-color: var(--accent);
}

.scan-controls,
.manual-search-form,
.inspection-form {
  display: grid;
  gap: 14px;
}

.manual-search-form {
  grid-template-columns: minmax(220px, 1fr) auto;
  align-items: end;
}

.asset-detail-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfdfb;
}

.asset-detail-header {
  display: grid;
  grid-template-columns: 80px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.asset-detail-header h3 {
  margin: 0 0 4px;
  font-size: 18px;
}

.asset-detail-header p {
  margin: 0;
  color: var(--muted);
  direction: ltr;
  text-align: right;
}

.asset-detail-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 16px;
  margin: 0;
}

.asset-detail-list div {
  min-width: 0;
}

.asset-detail-list dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.asset-detail-list dd {
  margin: 3px 0 0;
  overflow-wrap: anywhere;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 180px;
  gap: 12px;
  margin-bottom: 16px;
}

.table-wrap {
  overflow-x: auto;
}

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

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 13px 10px;
  text-align: right;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 14px;
}

.cell-subtext {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.status {
  display: inline-flex;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.status.good {
  color: var(--good);
  background: #eaf7ef;
}

.status.warning {
  color: var(--warn);
  background: #fff4df;
}

.status.danger {
  color: var(--danger);
  background: #fdeceb;
}

.delete-action {
  border: 1px solid #f1b8b2;
  border-radius: 6px;
  padding: 7px 10px;
  background: #fff7f6;
  color: var(--danger);
  cursor: pointer;
  font-weight: 800;
}

.asset-thumb {
  width: 72px;
  height: 54px;
  border-radius: 6px;
  object-fit: cover;
  border: 1px solid var(--line);
  background: #eef3ef;
}

.no-photo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 54px;
  border: 1px dashed var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.report-panel {
  margin-top: 18px;
}

.report-content {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.report-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fbfdfb;
}

.report-box h3 {
  margin: 0 0 10px;
  font-size: 18px;
}

.report-box ul {
  margin: 0;
  padding-inline-start: 20px;
  color: var(--muted);
  line-height: 1.8;
}

.empty {
  color: var(--muted);
  padding: 26px 10px;
  text-align: center;
}

@media (max-width: 980px) {
  .summary-grid,
  .workspace,
  .scan-grid,
  .finance-kpis,
  .charts-grid,
  .bi-toolbar,
  .report-content {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
  }
}

@media (max-width: 620px) {
  .shell {
    width: min(100% - 20px, 1380px);
  }

  .toolbar {
    grid-template-columns: 1fr;
  }

  .import-form,
  .manual-search-form,
  .donut-chart,
  .asset-detail-list {
    grid-template-columns: 1fr;
  }

  .compact-heading {
    display: block;
  }

  .panel,
  .metric {
    padding: 16px;
  }

  .field-actions {
    grid-template-columns: 1fr;
  }
}

@media print {
  body {
    background: #fff;
  }

  .topbar,
  form,
  .toolbar,
  .delete-action {
    display: none;
  }

  .shell {
    width: 100%;
    margin: 0;
  }

  .workspace,
  .report-content {
    display: block;
  }

  .panel,
  .metric {
    box-shadow: none;
    break-inside: avoid;
  }
}
