:root {
  --blue: #1f527f;
  --blue-dark: #173f64;
  --blue-light: #eaf3fb;
  --ink: #20242a;
  --muted: #697586;
  --line: #dfe6ee;
  --bg: #f4f7fb;
  --card: #fff;
  --green: #27825d;
  --orange: #b96d12;
  --red: #b42318;
  --shadow: 0 12px 34px rgba(31, 78, 120, .09);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  display: flex;
}
button, input, select, textarea { font: inherit; }
button:disabled { cursor: wait; opacity: .65; }
.auth-gate { display: none; position: fixed; inset: 0; z-index: 100; padding: 24px; background: radial-gradient(circle at 50% 20%, #e8f4fc, #d4e5f2 52%, #b8cfdf); align-items: center; justify-content: center; }
.auth-pending .auth-gate { display: flex; }
.auth-pending > .sidebar, .auth-pending > main { visibility: hidden; }
.auth-card { width: min(440px, 100%); padding: 34px; border: 1px solid rgba(255,255,255,.8); border-radius: 24px; background: rgba(255,255,255,.96); box-shadow: 0 28px 80px rgba(20,59,93,.2); display: grid; gap: 16px; }
.auth-card img { width: 92px; height: 92px; margin: 0 auto 4px; object-fit: contain; }
.auth-card h1 { margin: 0; color: var(--blue); text-align: center; }
.auth-card > p { margin: 0; color: var(--muted); line-height: 1.5; text-align: center; }
.auth-card .eyebrow { color: #2f75b5; }
.auth-card .auth-error { padding: 10px 12px; border-radius: 10px; color: var(--red); background: #fff0f0; text-align: left; }
.user-actions { display: flex; align-items: center; gap: 10px; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 282px;
  padding: 24px 18px;
  color: #fff;
  background: linear-gradient(180deg, #1d5787, #143b5d);
  display: flex;
  flex-direction: column;
  z-index: 10;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 4px 8px 28px; }
.brand img { width: 58px; height: 58px; object-fit: contain; border-radius: 17px; background: #fff; }
.brand strong { display: block; font-size: 20px; }
.brand span { display: block; max-width: 165px; margin-top: 3px; color: #cfe1f1; font-size: 11px; line-height: 1.35; }
.sidebar nav { display: grid; gap: 6px; }
.nav-item {
  border: 0;
  border-radius: 12px;
  padding: 12px 15px;
  color: #dbe9f5;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.nav-item:hover, .nav-item.active { color: #fff; background: rgba(255, 255, 255, .14); }
.sidebar-note {
  margin-top: auto;
  padding: 14px 10px;
  border-top: 1px solid rgba(255, 255, 255, .15);
  display: flex;
  gap: 10px;
  align-items: center;
}
.sidebar-note strong, .sidebar-note small { display: block; }
.sidebar-note small { margin-top: 2px; color: #bdd3e7; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: #ffb020; box-shadow: 0 0 0 5px rgba(255, 176, 32, .13); }
.status-dot.online { background: #51d49a; box-shadow: 0 0 0 5px rgba(81, 212, 154, .13); }

main { width: calc(100% - 282px); margin-left: 282px; padding: 28px 34px 60px; }
.topbar { margin-bottom: 24px; display: flex; justify-content: space-between; align-items: center; }
.topbar h1, .toolbar h2, .panel h2 { margin: 2px 0 0; }
.eyebrow { margin: 0; color: #2f75b5; font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.view { display: none; }
.view.active { display: block; }
.hidden { display: none !important; }

.metrics { margin-bottom: 18px; display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 14px; }
.metrics.small { grid-template-columns: repeat(4, minmax(130px, 1fr)); }
.metric { padding: 18px; border: 1px solid var(--line); border-radius: 16px; background: var(--card); box-shadow: var(--shadow); }
.metric strong { display: block; margin-bottom: 5px; color: var(--blue); font-size: 28px; }
.metric span { color: var(--muted); font-size: 13px; }
.metric small { display: block; margin-top: 4px; color: var(--muted); }
.grid.two { display: grid; grid-template-columns: 1.3fr 1fr; gap: 18px; }
.panel { padding: 22px; border: 1px solid var(--line); border-radius: 18px; background: var(--card); box-shadow: var(--shadow); }
.panel.compact { padding: 12px 16px; margin-bottom: 12px; display: flex; align-items: end; gap: 15px; }
.panel-title, .toolbar { display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.toolbar { margin-bottom: 18px; }
.toolbar p, .panel p, .section-heading p { color: var(--muted); line-height: 1.55; }
.toolbar p { margin: 5px 0 0; }
.accent-panel { background: linear-gradient(145deg, #eaf3fb, #fff); }
.flow { margin-top: 22px; display: flex; align-items: center; gap: 10px; }
.flow span { padding: 10px 14px; border: 1px solid #c8d9e9; border-radius: 12px; color: var(--blue); background: #fff; font-weight: 700; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.audit-card, .report-card { padding: 18px; border: 1px solid var(--line); border-radius: 16px; background: #fff; cursor: pointer; transition: .15s; }
.audit-card:hover, .report-card:hover { border-color: #8ab4d7; transform: translateY(-2px); box-shadow: var(--shadow); }
.audit-card h3, .report-card h3, .equipment-card h3 { margin: 8px 0; }
.meta, .muted { color: var(--muted); font-size: 13px; }
.stack { display: grid; gap: 8px; }
.stack-row { width: 100%; padding: 11px 0; border: 0; border-bottom: 1px solid var(--line); background: transparent; display: flex; justify-content: space-between; align-items: center; text-align: left; cursor: pointer; }

.primary, .secondary, .file-button {
  min-height: 42px;
  padding: 10px 15px;
  border-radius: 11px;
  cursor: pointer;
  font-weight: 650;
}
.primary { border: 1px solid var(--blue); color: #fff; background: var(--blue); }
.primary:hover { background: var(--blue-dark); }
.secondary, .file-button { border: 1px solid #b8c8d8; color: var(--blue); background: #fff; }
.link-button { padding: 4px; border: 0; color: #2f75b5; background: none; cursor: pointer; }
.link-button.danger { color: var(--red); }
.actions, .row-actions { display: flex; gap: 9px; align-items: center; }
.file-button input { display: none; }
.inline-control { min-width: 300px; }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 16px; background: #fff; }
.audit-points { margin-top: 18px; }
table { width: 100%; min-width: 880px; border-collapse: collapse; }
th, td { padding: 13px 14px; border-bottom: 1px solid var(--line); text-align: left; font-size: 13px; vertical-align: middle; }
th { position: sticky; top: 0; z-index: 1; color: #33556f; background: #edf3f8; }
tr:hover td { background: #f9fbfd; }
.point-row, .package-row { cursor: pointer; }

input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #c5d1de;
  border-radius: 10px;
  color: var(--ink);
  background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(47, 117, 181, .15); border-color: #2f75b5; }
input[readonly], textarea[readonly], select:disabled { color: #667085; background: #f2f5f8; }
.search { max-width: 520px; }
label { color: #344054; font-size: 13px; font-weight: 650; display: grid; gap: 6px; }
label small, .conditional-head small { color: var(--muted); font-weight: 400; }

.flash { position: sticky; top: 12px; z-index: 30; padding: 13px 16px; margin-bottom: 18px; border: 1px solid #bfe5ce; border-radius: 12px; color: #17653f; background: #e9f7ef; box-shadow: var(--shadow); }
.flash.error { border-color: #f0c3c3; color: #a32929; background: #fff0f0; }
.tag { display: inline-flex; padding: 5px 9px; border-radius: 20px; color: var(--blue); background: #e8f2fa; font-size: 12px; white-space: nowrap; }
.tag.success { color: #17653f; background: #e6f5ed; }
.tag.warning { color: #915b14; background: #fff4db; }
.progress { height: 7px; margin-top: 8px; overflow: hidden; border-radius: 8px; background: #e5ebf1; }
.progress i { display: block; height: 100%; background: var(--green); transition: width .2s; }
.notice { padding: 14px 16px; margin-bottom: 16px; border: 1px solid #c9dced; border-radius: 12px; color: #315774; background: #eef6fc; line-height: 1.5; }

.tabbar { margin-bottom: 16px; padding: 5px; border: 1px solid var(--line); border-radius: 14px; background: #fff; display: inline-flex; gap: 5px; }
.tab { padding: 10px 16px; border: 0; border-radius: 10px; color: var(--muted); background: transparent; cursor: pointer; font-weight: 650; }
.tab.active { color: #fff; background: var(--blue); }
.norm-tab { display: none; }
.norm-tab.active { display: block; }
.workspace-toolbar { justify-content: space-between; }
.workspace-toolbar label { width: min(620px, 70%); }
.cabinet-total { color: var(--blue); font-size: 21px; }
.equipment-grid { grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); }
.equipment-card { display: grid; gap: 14px; }
.equipment-fields { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

dialog {
  width: min(780px, 94vw);
  max-height: 94vh;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 20px;
  box-shadow: 0 30px 100px rgba(10, 33, 54, .28);
}
dialog.dialog-wide { width: min(1100px, 96vw); }
dialog::backdrop { background: rgba(12, 30, 48, .5); backdrop-filter: blur(2px); }
dialog form { max-height: 94vh; padding: 24px; overflow-y: auto; }
.dialog-head { position: sticky; top: -24px; z-index: 4; margin: -24px -24px 0; padding: 22px 24px 16px; border-bottom: 1px solid var(--line); background: rgba(255, 255, 255, .97); display: flex; justify-content: space-between; align-items: flex-start; }
.dialog-head h2 { margin: 3px 0 0; }
.icon-button { width: 36px; height: 36px; flex: 0 0 36px; padding: 0; border: 0; border-radius: 50%; background: #edf2f7; font-size: 23px; cursor: pointer; }
.dialog-actions { position: sticky; bottom: -24px; z-index: 4; margin: 20px -24px -24px; padding: 16px 24px; border-top: 1px solid var(--line); background: rgba(255, 255, 255, .97); display: flex; justify-content: flex-end; gap: 10px; }
.completion { margin: 16px 0 4px; padding: 13px 16px; border-radius: 12px; background: #f2f7fb; }
.completion > div:first-child { display: flex; justify-content: space-between; align-items: center; }
.completion span { color: var(--blue); font-weight: 800; }
.form-section { padding: 20px 0; border-bottom: 1px solid var(--line); }
.form-section:last-child { border-bottom: 0; }
.section-heading { margin-bottom: 14px; }
.section-heading h3 { margin: 0; font-size: 17px; }
.section-heading p { margin: 4px 0 0; font-size: 13px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .wide { grid-column: 1 / -1; }
.check-field { min-height: 44px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 11px; display: flex; align-items: center; gap: 10px; cursor: pointer; }
.check-field input { width: 20px; height: 20px; margin: 0; }
.conditional-panel { padding: 16px; border: 1px solid #bdd4e8; border-radius: 14px; background: #f5faff; }
.conditional-head { margin-bottom: 12px; display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.conditional-head strong, .conditional-head small { display: block; }
.temperature-row { margin-top: 9px; display: grid; grid-template-columns: minmax(130px, .5fr) 1fr 36px; gap: 10px; align-items: center; }
.photo-note { margin: 0; }
.details div { padding: 10px 0; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 150px 1fr; }
.details dt { color: var(--muted); }
.details dd { margin: 0; font-weight: 650; word-break: break-all; }

@media (max-width: 1120px) {
  .sidebar { width: 230px; }
  .brand span { display: none; }
  main { width: calc(100% - 230px); margin-left: 230px; padding: 24px; }
  .metrics, .metrics.small { grid-template-columns: repeat(2, 1fr); }
  .grid.two { grid-template-columns: 1fr; }
  .toolbar { align-items: flex-start; }
  .actions { flex-wrap: wrap; }
}

@media (max-width: 760px) {
  body { display: block; }
  .sidebar { position: static; width: 100%; height: auto; padding: 14px; }
  .brand { padding-bottom: 14px; }
  .brand span { display: block; }
  .sidebar nav { grid-template-columns: repeat(2, 1fr); }
  .sidebar-note { display: none; }
  main { width: 100%; margin: 0; padding: 16px; }
  .topbar, .toolbar, .panel-title { align-items: flex-start; flex-direction: column; }
  .topbar h1 { font-size: 23px; }
  .metrics, .metrics.small { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
  .inline-control, .workspace-toolbar label { width: 100%; min-width: 0; }
  .workspace-toolbar { align-items: stretch !important; flex-direction: column; }
  .tabbar { width: 100%; overflow-x: auto; }
  .tab { flex: 1; white-space: nowrap; }
  .equipment-fields { grid-template-columns: 1fr; }
  .temperature-row { grid-template-columns: 1fr 36px; }
  .temperature-row strong { grid-column: 1 / -1; }
  .conditional-head { align-items: stretch; flex-direction: column; }
}
