:root {
  color-scheme: dark;
  --bg: #101113;
  --bg-deep: #0b0c0e;
  --surface: #18191d;
  --surface-2: #202126;
  --surface-3: #292a30;
  --field: #111216;
  --line: rgba(255, 255, 255, 0.13);
  --line-strong: rgba(255, 255, 255, 0.23);
  --text: #f7f7f8;
  --muted: #a8aab2;
  --quiet: #7b7e88;
  --red: #ef3128;
  --red-dark: #7d1717;
  --red-soft: rgba(239, 49, 40, 0.14);
  --green: #42d17d;
  --green-soft: rgba(66, 209, 125, 0.14);
  --amber: #f3b642;
  --amber-soft: rgba(243, 182, 66, 0.14);
  --blue-soft: rgba(83, 144, 255, 0.13);
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background: linear-gradient(145deg, var(--bg-deep) 0%, #171316 42%, var(--bg) 100%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: var(--red);
  color: #fff;
  padding: 10px 18px;
  font-weight: 900;
  cursor: pointer;
}

button:disabled {
  opacity: 0.62;
  cursor: wait;
}

.login-shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(980px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(320px, 1fr);
  gap: 34px;
  align-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(239, 49, 40, 0.12), rgba(24, 25, 29, 0.98) 36%, rgba(24, 25, 29, 0.96));
  padding: 40px;
  box-shadow: var(--shadow);
}

.login-logo {
  display: block;
  width: 100%;
  max-width: 430px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #24252a;
  padding: 28px;
}

.eyebrow,
.kicker {
  margin: 0 0 8px;
  color: var(--red);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.08;
}

h1 {
  font-size: 46px;
}

h2 {
  font-size: 29px;
}

h3 {
  font-size: 20px;
}

.muted,
.login-version {
  color: var(--muted);
}

.login-version {
  margin: 14px 0 0;
  font-size: 17px;
  font-weight: 800;
}

form {
  display: grid;
  gap: 18px;
  margin-top: 28px;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-weight: 800;
}

input {
  min-height: 50px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  color: var(--text);
  padding: 10px 14px;
  font-weight: 700;
}

.message {
  margin-top: 18px;
  border: 1px solid rgba(255, 176, 176, 0.72);
  border-radius: 10px;
  background: rgba(239, 49, 40, 0.15);
  color: #ff9892;
  padding: 14px;
  font-weight: 800;
}

.portal-shell {
  min-height: 100dvh;
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 24px;
  padding-bottom: 70px;
}

.portal-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 24px;
  align-items: stretch;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: linear-gradient(110deg, rgba(239, 49, 40, 0.18), rgba(32, 33, 38, 0.98) 42%, rgba(24, 25, 29, 0.96));
  padding: 26px;
  box-shadow: var(--shadow);
}

.portal-brand {
  display: grid;
  grid-template-columns: 170px minmax(0, 1fr);
  gap: 24px;
  align-items: center;
}

.portal-logo {
  width: 170px;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #24252a;
  padding: 18px;
}

.portal-brand h1 {
  font-size: 41px;
}

.portal-brand .muted {
  margin: 10px 0 0;
  max-width: 920px;
  font-weight: 700;
  line-height: 1.45;
}

.portal-side {
  display: flex;
  min-width: 228px;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-end;
  gap: 10px;
}

.secondary-button {
  border: 1px solid var(--line-strong);
  background: var(--surface-3);
  color: var(--text);
}

.status-pill,
.badge,
.record-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 12px;
  color: var(--text);
  font-size: 13px;
  font-weight: 900;
  white-space: nowrap;
}

.status-pill {
  border-color: rgba(66, 209, 125, 0.42);
  background: var(--green-soft);
  color: #98ecc0;
}

.muted-pill {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
}

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

.summary-grid article {
  position: relative;
  min-height: 116px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(32, 33, 38, 0.92);
  padding: 18px;
}

.summary-grid article::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--red);
}

.summary-grid article:nth-child(2)::before {
  background: var(--amber);
}

.summary-grid article:nth-child(3)::before {
  background: var(--green);
}

.summary-grid span,
.summary-grid small {
  display: block;
  color: var(--muted);
  font-weight: 800;
}

.summary-grid strong {
  display: block;
  margin: 8px 0 2px;
  font-size: 34px;
  line-height: 1;
}

.tabs {
  display: flex;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(18, 19, 23, 0.92);
  padding: 6px;
  margin-bottom: 22px;
}

.tab {
  flex: 1;
  min-width: 0;
  background: transparent;
  color: var(--muted);
}

.tab.active {
  background: var(--red-soft);
  color: #ff756f;
}

.tab-panel {
  padding: 0;
}

.section-intro {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin: 6px 0 18px;
}

.section-note {
  display: grid;
  min-width: 180px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  padding: 12px 14px;
}

.section-note strong {
  font-size: 26px;
  line-height: 1;
}

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

.location-card {
  margin-bottom: 28px;
}

.location-grid {
  display: grid;
  gap: 12px;
}

.location-tile {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 128px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(32, 33, 38, 0.92);
  color: var(--text);
  padding: 18px;
  text-align: left;
}

.location-tile:hover,
.location-tile:focus-visible {
  border-color: rgba(66, 209, 125, 0.62);
  background: rgba(35, 44, 39, 0.96);
}

.location-tile strong {
  font-size: 28px;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.location-main {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.location-status {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex: 0 0 240px;
}

.location-back {
  margin-bottom: 18px;
}

.location-card > header,
.card-heading,
.device-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.location-card > header {
  border-bottom: 1px solid var(--line);
  padding: 0 0 14px;
  margin-bottom: 16px;
}

.location-card > header h2 {
  margin-bottom: 5px;
}

.record-count {
  border-color: rgba(239, 49, 40, 0.35);
  background: var(--red-soft);
  color: #ff8b85;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 14px;
}

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

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

.device-list-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(32, 33, 38, 0.92);
  padding: 14px;
}

.device-list-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 0;
  text-align: left;
}

.device-list-main strong {
  display: block;
  margin-top: 4px;
  font-size: 24px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.device-list-main:hover strong,
.device-list-main:focus-visible strong {
  color: #9fe2b9;
}

.logbook {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(245, 245, 242, 0.96);
  color: #151515;
  padding: 22px;
}

.logbook .muted,
.logbook .empty,
.logbook .badge {
  color: #5f6268;
}

.logbook .kicker {
  color: #b42a24;
}

.logbook-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 4px solid #151515;
  padding-bottom: 16px;
  margin-bottom: 18px;
}

.logbook-header h2 {
  color: #151515;
}

.logbook-sections {
  display: grid;
  gap: 14px;
}

.logbook-section {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 16px;
  border: 1px solid #c8c9cc;
  border-radius: 8px;
  background: #fff;
  padding: 16px;
}

.logbook-section-number {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 8px;
  background: #151515;
  color: #fff;
  font-size: 26px;
  font-weight: 900;
}

.logbook-section h3 {
  margin: 0 0 12px;
  color: #151515;
  font-size: 22px;
}

.logbook-pages {
  display: grid;
  gap: 12px;
}

.logbook-page {
  border: 1px solid #d8d8d4;
  border-radius: 6px;
  background: #fafafa;
  padding: 14px;
}

.logbook-page h4 {
  margin: 0 0 12px;
  color: #151515;
  font-size: 18px;
}

.logbook-master-layout {
  display: grid;
  gap: 14px;
}

.logbook-master-layout.has-photo {
  grid-template-columns: minmax(260px, 1fr) minmax(280px, 1fr);
  align-items: start;
}

.logbook .logbook-master-data {
  display: grid;
  grid-template-columns: 1fr;
  margin-top: 0;
  border-top: 0;
  padding-top: 0;
}

.logbook .logbook-master-data .meta {
  width: 100%;
}

.logbook-plant-photo {
  margin: 0;
}

.logbook-plant-photo button {
  display: block;
  width: 100%;
  min-height: 260px;
  border: 1px solid #d8d8d4;
  border-radius: 6px;
  background: #f2f2f0;
  color: #5f6268;
  padding: 0;
  overflow: hidden;
}

.logbook-plant-photo img {
  display: block;
  width: 100%;
  height: 100%;
  max-height: 360px;
  object-fit: cover;
  background: #fff;
}

.logbook-plant-photo span {
  display: grid;
  min-height: 220px;
  place-items: center;
  padding: 16px;
}

.logbook .meta {
  background: #f2f2f0;
  border-color: #d8d8d4;
}

.logbook .meta span,
.logbook .document-meta span,
.logbook .document-meta small,
.logbook .task-list span {
  color: #666a70;
}

.logbook .meta strong,
.logbook .document-meta strong,
.logbook .task-list strong {
  color: #151515;
}

.logbook .equipment-data {
  border-top-color: #d8d8d4;
}

.card,
.deadline-card,
.history-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(32, 33, 38, 0.92);
  padding: 16px;
}

.device-card {
  border-top: 3px solid rgba(66, 209, 125, 0.72);
}

.device-card.is-due,
.deadline-card.is-due {
  border-top-color: var(--red);
}

.device-top h3,
.deadline-card h3,
.history-card h3 {
  overflow-wrap: anywhere;
}

.badge {
  color: var(--muted);
}

.badge.danger {
  border-color: rgba(239, 49, 40, 0.55);
  background: var(--red-soft);
  color: #ff8b85;
}

.meta-grid,
.equipment-data {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  margin-top: 14px;
}

.equipment-data {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.device-section {
  margin-top: 16px;
}

.device-section h4 {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
}

.component-overview {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.component-heading,
.component-section-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.component-heading {
  margin-bottom: 12px;
}

.component-heading h4 {
  margin: 2px 0 0;
  color: var(--text);
  font-size: 18px;
  line-height: 1.2;
  text-transform: none;
}

.component-heading span,
.component-section-title span {
  flex: 0 0 auto;
  border: 1px solid rgba(66, 209, 125, 0.35);
  border-radius: 999px;
  background: rgba(66, 209, 125, 0.1);
  color: #9fe2b9;
  font-size: 12px;
  font-weight: 900;
  padding: 5px 9px;
}

.component-stack {
  display: grid;
  gap: 12px;
}

.component-section {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.025);
  padding: 12px;
}

.component-section-title {
  margin-bottom: 10px;
}

.component-section-title h5 {
  margin: 0;
  color: var(--text);
  font-size: 16px;
  line-height: 1.25;
}

.component-row {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(15, 16, 19, 0.5);
  padding: 12px;
}

.component-row + .component-row {
  margin-top: 10px;
}

.component-row-title {
  margin: 0 0 10px;
  color: var(--text);
  font-size: 15px;
  font-weight: 900;
}

.meta {
  min-height: 68px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(15, 16, 19, 0.58);
  padding: 10px 12px;
}

.meta span {
  display: block;
  overflow: hidden;
  color: var(--quiet);
  font-size: 12px;
  font-weight: 900;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.meta strong {
  display: block;
  margin-top: 5px;
  overflow-wrap: anywhere;
  font-size: 16px;
}

.document-list {
  display: grid;
  gap: 8px;
}

.document-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(15, 16, 19, 0.58);
  padding: 10px 12px;
}

.document-meta {
  min-width: 0;
}

.document-meta span,
.document-meta small {
  display: block;
  color: var(--quiet);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.document-meta strong {
  display: block;
  margin: 3px 0;
  overflow-wrap: anywhere;
}

.document-card button {
  min-height: 34px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  padding: 7px 12px;
}

.document-preview-dialog {
  width: min(1120px, calc(100vw - 28px));
  height: min(860px, calc(100dvh - 28px));
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  padding: 0;
  box-shadow: var(--shadow);
}

.document-preview-dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

.document-preview-dialog form {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100%;
  margin: 0;
}

.document-preview-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  padding: 14px;
}

.document-preview-header h3 {
  margin: 0 0 4px;
  overflow-wrap: anywhere;
}

.document-preview-header .muted {
  margin: 0;
}

.document-preview-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.document-preview-actions button {
  min-height: 38px;
}

.document-preview-body {
  min-height: 0;
  background: var(--bg-deep);
}

.document-preview-body iframe {
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

.document-preview-image-frame {
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  overflow: auto;
  padding: 16px;
}

.document-preview-image-frame img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.document-preview-fallback {
  display: grid;
  min-height: 260px;
  place-items: center;
  gap: 8px;
  padding: 24px;
  color: var(--muted);
  font-weight: 800;
  text-align: center;
}

.deadline-list,
.history-list {
  display: grid;
  gap: 12px;
}

.deadline-card,
.history-card {
  display: grid;
  gap: 10px;
  border-left: 4px solid var(--green);
}

.deadline-card.is-due {
  border-left-color: var(--red);
}

.task-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.task-list span,
.task-list strong {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 13px;
}

.task-list span {
  color: var(--muted);
}

.empty {
  color: var(--muted);
  font-weight: 800;
  padding: 20px 0;
}

@media (max-width: 920px) {
  .portal-shell {
    padding: 14px;
    padding-bottom: 48px;
  }

  .login-panel,
  .portal-hero,
  .portal-brand {
    grid-template-columns: 1fr;
  }

  .portal-logo {
    width: 210px;
  }

  .portal-side {
    min-width: 0;
  }

  .summary-grid,
  .meta-grid,
  .equipment-data {
    grid-template-columns: 1fr;
  }

  .section-intro,
  .location-card > header,
  .location-tile,
  .card-heading,
  .device-top {
    flex-direction: column;
  }

  .location-tile {
    align-items: flex-start;
    min-height: 0;
  }

  .location-status {
    flex: 0 0 auto;
    justify-content: flex-start;
  }

  .tabs {
    flex-wrap: wrap;
  }

  .tab {
    flex: 1 1 calc(50% - 8px);
  }

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

  .device-list-item,
  .device-list-main {
    grid-template-columns: 1fr;
  }

  .device-list-item {
    align-items: stretch;
  }

  .device-list-main {
    flex-direction: column;
    align-items: flex-start;
  }

  .logbook {
    padding: 14px;
  }

  .logbook-header,
  .logbook-section {
    grid-template-columns: 1fr;
  }

  .logbook-master-layout.has-photo {
    grid-template-columns: 1fr;
  }

  .logbook-header {
    flex-direction: column;
  }

  .document-card {
    grid-template-columns: 1fr;
  }

  .document-preview-header {
    display: grid;
  }

  .document-preview-actions {
    justify-content: stretch;
  }

  .document-preview-actions button {
    flex: 1;
  }
}

@media (max-width: 560px) {
  .login-shell {
    padding: 12px;
  }

  .login-panel {
    padding: 22px;
  }

  .login-logo {
    padding: 18px;
  }

  h1,
  .portal-brand h1 {
    font-size: 33px;
  }

  h2 {
    font-size: 24px;
  }

  .portal-hero,
  .card,
  .deadline-card,
  .history-card,
  .summary-grid article {
    border-radius: 10px;
  }

  .tabs {
    display: grid;
    grid-template-columns: 1fr;
  }
}
