* { box-sizing: border-box; }

:root {
  --bg: #f4f5f7;
  --bg-elevated: #ffffff;
  --bg-soft: #eef1f6;
  --text: #222222;
  --muted: #666d7a;
  --border: #d8dee8;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  --primary: #1456d9;
  --primary-hover: #0f46b1;
  --secondary: #5c6577;
  --danger: #b02a37;
  --topbar: #1d232f;
  --topbar-hover: #2c3648;
  --success-bg: #e6f7ea;
  --success-text: #137333;
  --warning-bg: #fff4db;
  --warning-text: #8a5b00;
  --danger-bg: #fde7ea;
  --danger-text: #b42318;
}

:root[data-theme="dark"] {
  --bg: #101318;
  --bg-elevated: #171b22;
  --bg-soft: #121821;
  --text: #e8ecf1;
  --muted: #a1abbb;
  --border: #2d3643;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  --primary: #6ea8ff;
  --primary-hover: #8bb9ff;
  --secondary: #6a7386;
  --danger: #d0606c;
  --topbar: #0b0f14;
  --topbar-hover: #202835;
  --success-bg: #12311d;
  --success-text: #8dd9a0;
  --warning-bg: #372c12;
  --warning-text: #f0c56f;
  --danger-bg: #3a161c;
  --danger-text: #f2a1ad;
}

html, body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  background: var(--topbar);
  color: #fff;
  padding: 14px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.topbar a { color: #fff; }
.brand a { font-weight: 700; font-size: 20px; }
.nav { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.nav a, .theme-toggle { padding: 8px 10px; border-radius: 8px; }
.nav a.active, .nav a:hover, .theme-toggle:hover { background: var(--topbar-hover); text-decoration: none; }
.theme-toggle {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.18);
  color: #fff;
  cursor: pointer;
}

.container { max-width: 1500px; margin: 0 auto; padding: 24px; }
h1, h2, h3 { margin-top: 0; }
.cards-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  margin-bottom: 16px;
}
.grid-2 {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  margin-bottom: 16px;
}
.stack { display: grid; gap: 16px; }
.detail-layout {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(320px, 420px) 1fr;
  margin-bottom: 16px;
}
.card {
  background: var(--bg-elevated);
  border-radius: 14px;
  padding: 18px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.stat-card .label { color: var(--muted); font-size: 14px; margin-bottom: 8px; }
.stat-card .value { font-size: 30px; font-weight: 700; }

.button, button {
  background: var(--primary);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
}
.button:hover, button:hover { background: var(--primary-hover); }
.button-secondary { background: var(--secondary); }
.button-danger { background: var(--danger); }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.table {
  width: 100%;
  border-collapse: collapse;
  overflow-x: auto;
}
.table th, .table td {
  border-bottom: 1px solid var(--border);
  padding: 10px 8px;
  text-align: left;
  vertical-align: top;
}
.table th { color: var(--muted); font-weight: 600; }
.table-compact th, .table-compact td { padding: 8px 6px; }

.form-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}
.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  color: var(--muted);
}
.form-grid input, .form-grid select, .form-grid textarea {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  color: var(--text);
  background: var(--bg-elevated);
}
.full-width { grid-column: 1 / -1; }
.actions-row { display: flex; gap: 10px; }
.inline-form { display: inline; }

.link-button {
  background: none;
  border: none;
  color: var(--primary);
  padding: 0;
  cursor: pointer;
}
.list-simple { margin: 0; padding-left: 18px; }

.chart-card { display: flex; flex-direction: column; overflow: hidden; }
.chart-wrap {
  position: relative;
  height: 340px;
  width: 100%;
  max-height: 340px;
  min-height: 340px;
  overflow: hidden;
}
.chart-wrap canvas {
  display: block;
  width: 100% !important;
  height: 340px !important;
  max-height: 340px !important;
}

.pre-wrap { white-space: pre-wrap; }

.photo-panel { display: grid; gap: 16px; align-content: start; }
.photo-box {
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 16px;
  overflow: hidden;
  background: var(--bg-soft);
  border: 1px solid var(--border);
}
.photo-box img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.photo-placeholder {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 700;
}
.doc-cards {
  display: grid;
  gap: 10px;
}
.doc-card {
  display: grid;
  gap: 4px;
  padding: 12px;
  border-radius: 12px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text);
}
.doc-card:hover {
  text-decoration: none;
  border-color: var(--primary);
}
.doc-card span {
  color: var(--muted);
  font-size: 13px;
}

.consumables-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}
.consumables-grid div {
  display: grid;
  gap: 6px;
  padding: 12px;
  border-radius: 12px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
}
.consumables-grid span {
  color: var(--muted);
  font-size: 13px;
}
.consumables-grid strong {
  font-size: 15px;
}

.pill {
  display: inline-flex;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}
.pill-ok { background: var(--success-bg); color: var(--success-text); }
.pill-warning { background: var(--warning-bg); color: var(--warning-text); }
.pill-danger { background: var(--danger-bg); color: var(--danger-text); }

.modal {
  width: min(760px, calc(100vw - 24px));
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px;
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow);
}
.modal::backdrop {
  background: rgba(0, 0, 0, 0.6);
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.icon-button {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  font-size: 24px;
  line-height: 1;
  padding: 4px 10px;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
}
.section-title {
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
  padding-top: 6px;
}

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

@media (max-width: 768px) {
  .container { padding: 14px; }
  .grid-2 { grid-template-columns: 1fr; }
  .chart-wrap, .chart-wrap canvas {
    height: 280px !important;
    min-height: 280px;
    max-height: 280px !important;
  }
}
