/* =====================================================================
   Fungo Climate Control — shared styles
   ===================================================================== */

:root {
  --bg: #f5f3ee;
  --bg-2: #ebe7dd;
  --card: #ffffff;
  --ink: #1f2a24;
  --ink-muted: #6b7569;
  --line: #e3ded3;
  --primary: #2d5f3f;
  --primary-2: #3d7a52;
  --accent: #b88838;
  --good: #2f9e57;
  --warn: #d97706;
  --bad: #c0392b;
  --shadow: 0 1px 2px rgba(20, 30, 25, 0.04), 0 8px 24px rgba(20, 30, 25, 0.06);
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 28px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-2) 100%);
  display: grid; place-items: center;
  color: white;
  font-weight: 700;
  font-size: 18px;
  box-shadow: var(--shadow);
}
.brand-text h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.2px;
}
.brand-text small { color: var(--ink-muted); font-size: 12px; }

.topnav { display: flex; gap: 4px; flex: 1; justify-content: center; }
.topnav a {
  padding: 8px 16px;
  border-radius: 8px;
  color: var(--ink-muted);
  font-size: 14px;
  font-weight: 500;
}
.topnav a:hover { background: var(--bg-2); color: var(--ink); text-decoration: none; }
.topnav a.active { background: var(--bg-2); color: var(--primary); }

.topbar-right { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.live-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px;
  background: #eaf6ee;
  color: #1f6e3d;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.live-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--good);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.85); }
}
.clock {
  font-variant-numeric: tabular-nums;
  color: var(--ink-muted);
  font-size: 13px;
}
.user-chip {
  display: inline-flex; flex-direction: column; line-height: 1.15;
  padding: 4px 10px; border-left: 1px solid var(--line);
}
.user-name { font-size: 13px; font-weight: 600; }
.user-role {
  font-size: 10px; color: var(--ink-muted);
  text-transform: uppercase; letter-spacing: 0.5px;
}
.logout-link {
  font-size: 12px;
  color: var(--ink-muted);
  padding: 6px 10px;
  border-radius: 6px;
}
.logout-link:hover { background: var(--bg-2); text-decoration: none; }

.container {
  max-width: 1320px;
  margin: 0 auto;
  padding: 24px 28px 64px;
}

/* ---------- Flash messages ---------- */
.flash {
  padding: 12px 16px;
  border-radius: 10px;
  margin-bottom: 18px;
  font-size: 14px;
  border: 1px solid transparent;
}
.flash.ok  { background: #eaf6ee; color: #1f6e3d; border-color: #c9e7d3; }
.flash.err { background: #fbe2dd; color: #8a261b; border-color: #f1cac1; }

/* ---------- Section heads ---------- */
.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 6px 0 14px;
}
.section-head h2 {
  margin: 0;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--ink-muted);
  font-weight: 600;
}
.section-head .hint { font-size: 12px; color: var(--ink-muted); }

/* ---------- Stat strip ---------- */
.stat-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.stat-card .lbl {
  font-size: 11px;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}
.stat-card .val {
  font-size: 26px;
  font-weight: 700;
  margin-top: 4px;
  letter-spacing: -0.5px;
}
.stat-card .delta { font-size: 12px; color: var(--ink-muted); margin-top: 2px; }

/* ---------- Room grid ---------- */
.rooms {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}
.room {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
  position: relative;
  /* overflow visible so the status dropdown can extend below the card */
  overflow: visible;
}
.room:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  border-color: #d8d2c4;
}
.room.selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(45, 95, 63, 0.12), var(--shadow);
}
.room::before {
  content: ""; position: absolute;
  left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--good);
}
.room.warn::before { background: var(--warn); }
.room.bad::before  { background: var(--bad); }
.room.stale::before { background: #888; }

.room-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 14px;
}
.room-title { font-size: 15px; font-weight: 700; margin: 0; }
.room-phase { font-size: 12px; color: var(--ink-muted); margin-top: 2px; }

.status-badge {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.status-badge.good  { background: #e6f5ec; color: #1f6e3d; }
.status-badge.warn  { background: #fbeede; color: #8a4f10; }
.status-badge.bad   { background: #fbe2dd; color: #8a261b; }
.status-badge.stale { background: #ececec; color: #555; }
.status-badge.clickable { cursor: pointer; user-select: none; }
.status-badge.clickable .caret { font-size: 9px; margin-left: 2px; opacity: 0.7; }

.status-wrap { position: relative; display: inline-block; }
.status-popover {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 30;
  min-width: 260px;
  max-width: 340px;
  width: max-content;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.18);
  padding: 10px 12px;
  font-size: 12px;
  color: var(--ink, #222);
  text-transform: none;
  letter-spacing: normal;
  font-weight: 400;
  text-align: left;
}
/* Little arrow pointing up to the badge */
.status-popover::before {
  content: '';
  position: absolute;
  top: -6px;
  right: 14px;
  width: 10px;
  height: 10px;
  background: #fff;
  border-left: 1px solid #e0e0e0;
  border-top: 1px solid #e0e0e0;
  transform: rotate(45deg);
}
.status-wrap.open .status-popover { display: block; }
.status-popover-head {
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ink-muted, #666);
  margin-bottom: 6px;
}
.status-popover-row {
  display: flex; align-items: flex-start; gap: 6px;
  padding: 4px 0;
  line-height: 1.35;
}
.status-popover-row + .status-popover-row { border-top: 1px solid #f0f0f0; }
.status-popover-dot {
  width: 8px; height: 8px; border-radius: 50%;
  flex-shrink: 0; margin-top: 5px;
}
.status-popover-row.warn .status-popover-dot { background: #d97706; }
.status-popover-row.bad  .status-popover-dot { background: #c0392b; }
.status-popover-row.warn { color: #8a4f10; }
.status-popover-row.bad  { color: #8a261b; }

.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.metric { display: flex; flex-direction: column; }
.metric-label {
  font-size: 11px;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  display: flex; align-items: center; gap: 5px;
  margin-bottom: 2px;
}
.metric-value {
  font-size: 22px; font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
}
.metric-value .unit { font-size: 13px; color: var(--ink-muted); font-weight: 500; margin-left: 2px; }
.metric-target {
  font-size: 10px;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

.room-foot {
  display: flex; gap: 10px; margin-top: 14px; padding-top: 12px;
  border-top: 1px dashed var(--line);
  font-size: 12px; color: var(--ink-muted); flex-wrap: wrap;
}
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 8px;
  background: var(--bg-2);
  border-radius: 999px;
  font-weight: 500;
}
.chip .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ink-muted); }
.chip.on .dot { background: var(--good); }
.chip.off .dot { background: #c4c4c4; }

.icn {
  width: 12px; height: 12px;
  stroke: currentColor; fill: none; stroke-width: 1.6;
  stroke-linecap: round; stroke-linejoin: round;
}

/* ---------- Panel + chart ---------- */
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 24px 18px;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}
.panel-head {
  display: flex; flex-wrap: wrap; gap: 14px;
  align-items: center; justify-content: space-between;
  margin-bottom: 18px;
}
.panel-title h3 { margin: 0 0 2px 0; font-size: 16px; font-weight: 700; }
.panel-title small { color: var(--ink-muted); font-size: 12px; }

.controls { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; }
.pill-group {
  display: inline-flex;
  background: var(--bg-2);
  border-radius: 999px;
  padding: 3px;
}
.pill-group button {
  border: 0; background: transparent;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12px; font-weight: 600;
  cursor: pointer;
  color: var(--ink-muted);
  letter-spacing: 0.3px;
  transition: all .15s ease;
}
.pill-group button:hover { color: var(--ink); }
.pill-group button.active {
  background: var(--card);
  color: var(--primary);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.chart-wrap { position: relative; height: 360px; }

/* ---------- Generic table (used on users page, audit log) ---------- */
.table-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.table-card-head {
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: center;
}
.table-card-head h3 { margin: 0; font-size: 15px; font-weight: 700; }

table.data {
  width: 100%; border-collapse: collapse; font-size: 14px;
}
table.data th, table.data td {
  text-align: left;
  padding: 12px 22px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
table.data tr:last-child td { border-bottom: 0; }
table.data th {
  background: #faf8f3;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--ink-muted);
  font-weight: 600;
}
table.data td.muted { color: var(--ink-muted); }
table.data td .uid {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  background: var(--bg-2);
  padding: 2px 6px; border-radius: 4px;
}

/* ---------- Form elements ---------- */
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  align-items: end;
}
label.field {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; color: var(--ink-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
label.field .hint {
  font-weight: 400;
  text-transform: none; letter-spacing: 0;
  font-size: 11px;
  color: var(--ink-muted);
  margin-top: -1px;
}
input[type="text"], input[type="number"], input[type="password"], select {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  outline: none;
  transition: border-color .12s ease, box-shadow .12s ease;
  color: var(--ink);
}
input[type="text"]:focus, input[type="number"]:focus,
input[type="password"]:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(45, 95, 63, 0.12);
}

button.btn, .btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 16px;
  border-radius: 8px;
  border: 0;
  background: var(--primary);
  color: white;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s ease;
}
button.btn:hover, .btn:hover { background: var(--primary-2); }
button.btn.secondary, .btn.secondary {
  background: var(--bg-2); color: var(--ink);
}
button.btn.secondary:hover, .btn.secondary:hover { background: #e0dac8; }
button.btn.danger, .btn.danger { background: var(--bad); }
button.btn.danger:hover { background: #a52f24; }
button.btn.small, .btn.small { padding: 6px 12px; font-size: 12px; }

/* ---------- Login page ---------- */
.login-wrap {
  min-height: 100vh;
  display: grid; place-items: center;
  background: linear-gradient(180deg, #f7f5ef 0%, #ebe6d8 100%);
  padding: 20px;
}
.login-card {
  width: 100%; max-width: 420px;
  background: var(--card);
  border-radius: 18px;
  box-shadow: 0 12px 40px rgba(20, 30, 25, 0.10);
  padding: 36px 32px 30px;
  text-align: center;
}
.login-card .logo { width: 56px; height: 56px; font-size: 26px; margin: 0 auto 14px; border-radius: 14px; }
.login-card h1 { margin: 0; font-size: 20px; }
.login-card .sub { color: var(--ink-muted); font-size: 13px; margin-top: 6px; }
.rfid-box {
  margin: 24px 0 8px;
  background: var(--bg);
  border: 1px dashed #cdc6b4;
  border-radius: 12px;
  padding: 22px 18px;
}
.rfid-box .scan-icon {
  width: 64px; height: 64px;
  margin: 0 auto 8px;
  border-radius: 16px;
  background: white;
  display: grid; place-items: center;
  border: 1px solid var(--line);
}
.rfid-box .scan-icon svg {
  width: 34px; height: 34px;
  stroke: var(--primary); fill: none; stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round;
  animation: scan-pulse 1.8s ease-in-out infinite;
}
@keyframes scan-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%      { transform: scale(1.08); opacity: 0.7; }
}
.rfid-box label {
  display: block; font-size: 12px; color: var(--ink-muted);
  text-transform: uppercase; letter-spacing: 0.6px; margin-bottom: 8px;
}
.rfid-box input {
  width: 100%;
  text-align: center;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 18px;
  letter-spacing: 2px;
  padding: 12px;
}
.login-card .small {
  margin-top: 16px;
  font-size: 12px;
  color: var(--ink-muted);
}

/* ---------- Alerts feed ---------- */
.alert-row {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.alert-row:last-child { border-bottom: 0; }
.alert-icon {
  width: 28px; height: 28px;
  border-radius: 8px;
  display: grid; place-items: center;
  font-size: 14px; flex-shrink: 0; font-weight: 700;
}
.alert-icon.warn { background: #fbeede; color: #8a4f10; }
.alert-icon.bad  { background: #fbe2dd; color: #8a261b; }
.alert-icon.info { background: #e7eef0; color: #2c5563; }
.alert-msg { flex: 1; }
.alert-msg b { font-weight: 600; }
.alert-time {
  color: var(--ink-muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

@media (max-width: 760px) {
  .stat-strip { grid-template-columns: repeat(2, 1fr); }
  .container { padding: 16px; }
  .topbar { padding: 12px 16px; }
  .topnav { order: 3; width: 100%; justify-content: flex-start; overflow-x: auto; }
}
