:root {
  --bg: #f4f6f3;
  --surface: #ffffff;
  --ink: #17211c;
  --muted: #617067;
  --line: #d8ded8;
  --primary: #126b5d;
  --primary-dark: #0b4d43;
  --accent: #d39f2f;
  --danger: #bb3a35;
  --ok: #2f8c56;
  --warn: #c48a19;
  --shadow: 0 18px 45px rgba(34, 44, 38, 0.11);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, Segoe UI, Arial, sans-serif;
  letter-spacing: 0;
}

body.locked .app-shell {
  display: none;
}

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

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.login-screen {
  display: none;
  min-height: 100vh;
  padding: 24px;
  place-items: center;
  background:
    linear-gradient(120deg, rgba(16, 40, 32, 0.92), rgba(18, 107, 93, 0.86)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160' viewBox='0 0 160 160'%3E%3Cg fill='none' stroke='%23ffffff' stroke-opacity='.16' stroke-width='2'%3E%3Cpath d='M20 42h120M20 80h120M20 118h120M42 20v120M80 20v120M118 20v120'/%3E%3C/g%3E%3C/svg%3E");
}

body.locked .login-screen {
  display: grid;
}

.login-card {
  width: min(100%, 460px);
  padding: 26px;
  border: 1px solid rgba(255, 255, 255, 0.32);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.26);
}

.login-card h1 {
  margin-bottom: 6px;
}

.login-card p {
  color: var(--muted);
}

.login-brand {
  color: var(--ink);
  margin-bottom: 18px;
}

.login-brand small {
  color: var(--muted);
}

.demo-access {
  display: grid;
  gap: 7px;
  margin-top: 18px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf8;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.demo-access strong {
  color: var(--ink);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 18px;
  background: #102820;
  color: #f6faf8;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 8px;
  background: #f2c14e;
  color: #102820;
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  color: #b8c7c0;
  margin-top: 3px;
}

.nav {
  display: grid;
  gap: 6px;
  margin-top: 18px;
}

.nav button {
  min-height: 42px;
  padding: 10px 12px;
  border-radius: 7px;
  background: transparent;
  color: #dce8e3;
  text-align: left;
}

.nav button:hover,
.nav button.active {
  background: #1e4438;
  color: #ffffff;
}

.main {
  min-width: 0;
  padding: 28px;
}

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

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

h1 {
  margin-bottom: 4px;
  font-size: 30px;
}

h2 {
  margin-bottom: 0;
  font-size: 18px;
}

.topbar p {
  color: var(--muted);
  margin-bottom: 0;
}

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

.session-badge {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.primary,
.ghost,
.report-actions button,
.icon-button {
  min-height: 40px;
  border-radius: 7px;
  padding: 9px 14px;
  white-space: nowrap;
}

.primary {
  background: var(--primary);
  color: white;
  font-weight: 700;
}

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

.ghost,
.report-actions button,
.icon-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.icon-button {
  width: 42px;
  padding: 0;
  font-size: 20px;
}

.view {
  display: none;
}

.active-view {
  display: block;
}

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

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

.metric {
  padding: 18px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

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

.panel {
  padding: 18px;
  min-width: 0;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.split,
.grid-two {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
  gap: 18px;
}

.grid-two {
  grid-template-columns: minmax(280px, 420px) 1fr;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 12px;
}

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

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px 11px;
  background: #fff;
  color: var(--ink);
}

.field textarea {
  resize: vertical;
}

.compact select {
  background: #17362d;
  color: #fff;
  border-color: #2f5d50;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

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

table {
  width: 100%;
  border-collapse: collapse;
}

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

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 10px;
  background: #e8f2ee;
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 800;
}

.pill.warning {
  background: #fff3d7;
  color: #7d5400;
}

.record-list,
.alert-list,
.permission-list {
  display: grid;
  gap: 10px;
}

.record,
.alert,
.permission-row,
.item-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfb;
}

.record strong,
.alert strong {
  display: block;
  margin-bottom: 4px;
}

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

.danger-button {
  min-height: 32px;
  border-radius: 7px;
  padding: 6px 10px;
  background: #fff1ef;
  color: var(--danger);
  border: 1px solid #f0c4bf;
  font-size: 12px;
  font-weight: 800;
}

.danger-button:hover {
  background: #ffe3df;
}

.record small,
.alert small,
.material-card small {
  color: var(--muted);
}

.material-grid,
.check-grid,
.item-editor {
  display: grid;
  gap: 10px;
}

.material-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.material-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px;
  background: #fbfcfb;
}

.material-card header,
.item-row header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  margin-right: 6px;
}

.green {
  background: var(--ok);
}

.yellow {
  background: var(--warn);
}

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

.check-grid {
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  margin: 8px 0 16px;
}

.check-card {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.check-card input {
  margin-top: 3px;
}

.item-row {
  display: grid;
  grid-template-columns: 1fr 150px;
  gap: 14px;
  align-items: center;
}

.readonly .item-row {
  grid-template-columns: 1fr;
}

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

.signature-box {
  display: grid;
  gap: 8px;
}

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

canvas {
  width: 100%;
  max-width: 100%;
  height: 160px;
  border: 1px dashed #9ea99f;
  border-radius: 8px;
  background: #fff;
  touch-action: none;
}

#epiSignature {
  height: 180px;
}

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

.report-output {
  min-height: 280px;
  overflow: auto;
  margin: 0;
  padding: 14px;
  border-radius: 8px;
  background: #102820;
  color: #edf7f3;
  white-space: pre-wrap;
}

.ai-text {
  color: #25332c;
  line-height: 1.55;
}

.permission-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  transform: translateY(20px);
  opacity: 0;
  max-width: 360px;
  padding: 13px 16px;
  border-radius: 8px;
  background: #102820;
  color: #fff;
  box-shadow: var(--shadow);
  transition: 180ms ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.pdf-sheet {
  display: none;
}

.pdf-table {
  width: 100%;
  margin-top: 14px;
  border-collapse: collapse;
}

.pdf-table th,
.pdf-table td {
  border: 1px solid #b8c1bb;
}

.signature-preview {
  max-width: 230px;
  max-height: 72px;
  border: 1px solid #cbd3ce;
  background: #fff;
}

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

  .sidebar {
    position: static;
    height: auto;
  }

  .nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .split,
  .grid-two,
  .form-row,
  .signature-grid,
  .metrics {
    grid-template-columns: 1fr;
  }

  .main {
    padding: 20px;
  }

  .topbar {
    flex-direction: column;
  }

  .top-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 560px) {
  .main,
  .sidebar {
    padding: 16px;
  }

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

  h1 {
    font-size: 24px;
  }

  .item-row {
    grid-template-columns: 1fr;
  }
}

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

  .app-shell,
  .toast {
    display: none !important;
  }

  .pdf-sheet {
    display: block;
    padding: 18mm;
    color: #111;
    font-family: Arial, sans-serif;
  }

  .pdf-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 14px;
    border-bottom: 2px solid #111;
    margin-bottom: 14px;
  }

  .pdf-header strong,
  .pdf-header span {
    display: block;
  }

  .pdf-header strong {
    font-size: 22px;
  }

  .pdf-header canvas {
    width: 96px;
    height: 96px;
    border: 0;
  }
}
