:root {
  --ink: #18211f;
  --muted: #64736f;
  --line: #d8e1de;
  --green: #126b45;
  --red: #b3261e;
  --blue: #17617a;
  --shadow: 0 18px 50px rgba(30, 42, 38, .12);
  --app-font-family: Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(23, 97, 122, .14), transparent 34rem),
    linear-gradient(135deg, #f5efe3, #edf4f1 55%, #f8f3e8);
  font-family: var(--app-font-family);
}
a { color: var(--blue); }
h1, h2, h3 { margin-top: 0; line-height: 1.08; }
h1 { font-size: clamp(2rem, 4vw, 4.2rem); }
button, .button {
  border: 0;
  border-radius: 999px;
  padding: .75rem 1rem;
  background: var(--ink);
  color: white;
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: .72rem .8rem;
  background: white;
  font: inherit;
}
label { display: grid; gap: .35rem; font-weight: 700; }
small, .muted { color: var(--muted); }
table { width: 100%; border-collapse: collapse; }
th, td { border-bottom: 1px solid var(--line); padding: .7rem; text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: .85rem; }
dt { color: var(--muted); font-size: .82rem; }
dd { margin: 0; font-weight: 800; }

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .8rem 1.3rem;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.86);
  position: sticky;
  top: 0;
  z-index: 3;
  backdrop-filter: blur(14px);
}
.brand {
  display: flex;
  align-items: center;
  gap: .7rem;
  color: var(--ink);
  font-weight: 800;
  text-decoration: none;
}
.brand img { width: auto; object-fit: contain; }
.menu-toggle, .menu-button { display: none; }
.menu-panel { display: flex; align-items: center; gap: .8rem; margin-left: auto; }
nav { display: flex; gap: .8rem; flex-wrap: nowrap; }
nav a { color: var(--ink); font-weight: 600; text-decoration: none; }
.logout button { border: 1px solid var(--line); background: transparent; color: var(--ink); }

.page { width: min(1320px, calc(100% - 2rem)); margin: 2rem auto; }
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}
.eyebrow {
  color: var(--muted);
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.panel, .auth-card {
  border: 1px solid rgba(216,225,222,.9);
  border-radius: 24px;
  background: rgba(255,255,255,.88);
  box-shadow: var(--shadow);
}
.panel { padding: 1.2rem; margin-bottom: 1rem; overflow-x: auto; }
.auth-card { max-width: 440px; margin: 8vh auto; padding: 2rem; }
.stack { display: grid; gap: .9rem; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.form-grid.compact { margin-top: 1rem; }
.wide { grid-column: 1 / -1; }
.alert { border-radius: 16px; padding: .8rem 1rem; margin: .8rem 0; }
.alert-green { background: #e5f5ec; color: var(--green); }
.chip {
  display: inline-flex;
  margin: .2rem;
  padding: .25rem .55rem;
  border-radius: 999px;
  background: #e7efeb;
  color: #25433a;
  font-size: .82rem;
  font-weight: 700;
}
.chip-red { background: #fde8e6; color: var(--red); }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.monitoring-head { align-items: stretch; }
.monitoring-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(7rem, 1fr));
  gap: .7rem;
  min-width: min(100%, 35rem);
}
.stat-card {
  display: grid;
  align-content: center;
  min-height: 5.25rem;
  padding: .75rem .9rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255,255,255,.86);
}
.stat-card span { font-size: 1.65rem; font-weight: 900; line-height: 1; }
.stat-card small { color: var(--muted); font-weight: 800; }
.stat-ok span { color: var(--green); }
.stat-error span { color: var(--red); }
.monitor-controls {
  display: grid;
  grid-template-columns: minmax(16rem, 1fr) auto;
  gap: .8rem;
  align-items: center;
  margin-bottom: 1rem;
}
.search-field input {
  min-height: 3rem;
  border-radius: 12px;
  background: rgba(255,255,255,.9);
}
.segmented-control, .company-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
}
.segmented-control button,
.company-tab {
  border: 1px solid var(--line);
  background: rgba(255,255,255,.82);
  color: var(--ink);
}
.segmented-control button.is-active,
.company-tab.is-active {
  border-color: var(--ink);
  background: var(--ink);
  color: white;
}
.company-tabs { margin-bottom: 1rem; }
.company-panel { display: none; }
.company-panel.is-active { display: grid; gap: 1rem; }
.location-block { display: grid; gap: .8rem; }
.location-block[hidden] { display: none; }
.location-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 1rem;
  padding-bottom: .45rem;
  border-bottom: 1px solid rgba(216,225,222,.9);
}
.location-head h2 {
  margin-bottom: 0;
  font-size: clamp(1.35rem, 2.2vw, 2.1rem);
}
.location-counts {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: .35rem;
}
.plc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: .85rem;
}
.plc-card {
  display: grid;
  gap: .75rem;
  min-height: 14rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-left: 7px solid var(--green);
  border-radius: 14px;
  background: rgba(255,255,255,.9);
  box-shadow: 0 14px 36px rgba(30,42,38,.09);
}
.plc-card[hidden] { display: none; }
.plc-card.plc-error {
  border-left-color: var(--red);
  background: linear-gradient(180deg, rgba(253,232,230,.74), rgba(255,255,255,.92));
}
.plc-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}
.plc-card h3 { margin-bottom: .15rem; font-size: 1.25rem; overflow-wrap: anywhere; }
.plc-card p { margin: 0; overflow-wrap: anywhere; }
.plc-state-dot {
  flex: 0 0 auto;
  width: 1rem;
  height: 1rem;
  margin-top: .2rem;
  border-radius: 999px;
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(18,107,69,.12);
}
.plc-state-error {
  background: var(--red);
  box-shadow: 0 0 0 4px rgba(179,38,30,.13);
}
.plc-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
  color: var(--muted);
  font-size: .9rem;
  font-weight: 700;
}
.plc-meta span,
.plc-meta strong {
  border-radius: 999px;
  padding: .22rem .52rem;
  background: #edf4f1;
}
.plc-meta strong { background: #fde8e6; color: var(--red); }
.plc-error {
  border-radius: 12px;
  padding: .68rem .75rem;
  background: #fde8e6;
  color: var(--red);
  font-weight: 800;
  overflow-wrap: anywhere;
}
.plc-fields {
  display: grid;
  gap: .5rem;
  margin: 0;
}
.plc-fields div {
  display: grid;
  grid-template-columns: minmax(8rem, .9fr) minmax(0, 1.1fr);
  gap: .8rem;
  align-items: baseline;
  padding-bottom: .45rem;
  border-bottom: 1px solid rgba(216,225,222,.78);
}
.plc-fields div:last-child { border-bottom: 0; padding-bottom: 0; }
.plc-fields dt, .plc-fields dd { overflow-wrap: anywhere; }
.plc-fields dd { text-align: right; }
.plc-fields .field-abnormal dd { color: var(--red); }
.empty-filter {
  margin: .2rem 0 0;
  color: var(--muted);
  font-weight: 800;
}

.location-comments {
  display: grid;
  gap: .75rem;
  padding: .9rem;
  border: 1px solid rgba(216,225,222,.9);
  border-radius: 14px;
  background: rgba(255,255,255,.62);
}
.location-comments-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}
.location-comments-head h3 { margin: 0; font-size: 1.05rem; }
.comments { display: grid; gap: .6rem; margin: .8rem 0; }
.location-comment-list { margin: 0; }
.comment {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: .75rem;
  align-items: flex-start;
  padding: .75rem;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255,255,255,.82);
}
.comment-avatar {
  width: 42px;
  height: 42px;
  border: 2px solid rgba(255,255,255,.9);
  border-radius: 999px;
  object-fit: cover;
  box-shadow: 0 5px 16px rgba(24,33,31,.14);
}
.comment-avatar-fallback {
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #e7efeb, #cfdcd7);
  color: var(--ink);
  font-size: .82rem;
  font-weight: 900;
}
.comment-body { min-width: 0; }
.comment-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: .4rem;
}
.comment p { margin: .35rem 0 0; white-space: pre-wrap; }
.comment-delete-form { margin-left: auto; }
.comment-delete-form button {
  padding: .28rem .55rem;
  border: 1px solid rgba(179,38,30,.22);
  background: #fde8e6;
  color: var(--red);
  font-size: .78rem;
}
.location-comment-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: .65rem;
  align-items: end;
}
.location-comment-form textarea { min-height: 4.8rem; resize: vertical; }
.location-comment-form button { min-height: 2.8rem; }

.profile-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}
.avatar-large {
  display: grid;
  place-items: center;
  width: 112px;
  height: 112px;
  border-radius: 24px;
  background: #e7efeb;
  object-fit: cover;
  font-weight: 900;
}

@media (max-width: 1100px) {
  .topbar { flex-wrap: wrap; }
  .menu-button {
    display: inline-flex;
    align-items: center;
    gap: .55rem;
    margin-left: auto;
    border-radius: 999px;
    background: var(--ink);
    color: white;
    padding: .65rem .9rem;
    font-weight: 800;
    cursor: pointer;
  }
  .hamburger-icon {
    display: inline-grid;
    gap: .22rem;
    width: 1.1rem;
  }
  .hamburger-icon span {
    display: block;
    height: 2px;
    border-radius: 999px;
    background: currentColor;
  }
  .menu-panel {
    display: none;
    width: 100%;
    margin-left: 0;
    padding: .8rem;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: rgba(255,255,255,.94);
    box-shadow: var(--shadow);
  }
  .menu-toggle:checked ~ .menu-panel { display: grid; gap: .7rem; }
  nav { flex-direction: column; gap: .25rem; }
  nav a {
    padding: .68rem .75rem;
    border-radius: 14px;
    background: #edf4f1;
  }
  .logout button { width: 100%; text-align: left; }
}

@media (max-width: 820px) {
  .page-head, .profile-row { flex-direction: column; align-items: stretch; }
  .form-grid, .monitoring-stats, .monitor-controls { grid-template-columns: 1fr; }
  .location-head { align-items: stretch; flex-direction: column; }
  .location-counts { justify-content: flex-start; }
  .plc-fields div { grid-template-columns: 1fr; gap: .2rem; }
  .plc-fields dd { text-align: left; }
  .location-comment-form { grid-template-columns: 1fr; }
  .location-comment-form button { width: 100%; }
}
