/* Hostinger Sensor Dashboard — clean light theme.
   Colors follow the validated data-viz palette (status colors fixed). */
:root {
  --page:        #eef1f5;
  --surface:     #ffffff;
  --surface-2:   #f7f9fb;
  --ink:         #0b0b0b;
  --ink-2:       #52514e;
  --muted:       #898781;
  --grid:        #e1e0d9;
  --line:        #e6e8ec;
  --accent:      #2a78d6;   /* series-1 blue */
  --accent-soft: #cde2fb;
  /* status (fixed, never themed) */
  --good:     #0ca30c;
  --good-ink: #067006;
  --warning:  #fab219;
  --serious:  #ec835a;
  --critical: #d03b3b;
  --low:      #2a78d6;
  --shadow:   0 1px 2px rgba(11,11,11,.06), 0 2px 8px rgba(11,11,11,.05);
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--page); color: var(--ink); -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
button { font-family: inherit; cursor: pointer; }

/* ===== Login ===== */
.login-wrap {
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 18px;
  background: radial-gradient(1200px 600px at 50% -10%, #dbe7f7 0%, var(--page) 55%);
}
.login-card {
  background: var(--surface); width: 340px; padding: 30px 28px;
  border-radius: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px;
  border: 1px solid var(--line);
}
.login-brand { font-weight: 700; font-size: 20px; display: flex; align-items: center; gap: 9px; }
.login-sub { margin: -6px 0 6px; color: var(--muted); font-size: 14px; }
.login-card label { font-size: 13px; color: var(--ink-2); display: flex; flex-direction: column; gap: 6px; font-weight: 500; }
.login-card input {
  padding: 11px 12px; border: 1px solid #d5d8dd; border-radius: 9px; font-size: 15px;
  background: var(--surface-2); transition: border-color .15s, box-shadow .15s;
}
.login-card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: #fff; }
#login-btn {
  margin-top: 6px; padding: 12px; border: none; border-radius: 9px; font-size: 15px; font-weight: 600;
  background: var(--accent); color: #fff; transition: filter .15s;
}
#login-btn:hover { filter: brightness(1.06); }
#login-btn:disabled { opacity: .6; cursor: default; }
.login-err { color: var(--critical); font-size: 13px; min-height: 16px; text-align: center; }
.login-foot { color: var(--muted); font-size: 12px; }

.logo-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: conic-gradient(from 200deg, var(--good), var(--accent), var(--good));
  box-shadow: 0 0 0 3px rgba(12,163,12,.14); display: inline-block;
}

/* ===== Topbar ===== */
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--surface);
  border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 20px;
  padding: 10px 22px; box-shadow: 0 1px 0 rgba(11,11,11,.03);
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 210px; }
.brand-title { font-weight: 700; font-size: 16px; line-height: 1.1; }
.brand-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 10px; }
.tabs button {
  border: none; background: transparent; padding: 7px 14px; border-radius: 7px;
  font-size: 14px; font-weight: 500; color: var(--ink-2); display: flex; align-items: center; gap: 7px;
}
.tabs button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.badge {
  background: var(--critical); color: #fff; font-size: 11px; font-weight: 700;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  display: inline-flex; align-items: center; justify-content: center;
}

.topright { margin-left: auto; display: flex; align-items: center; gap: 18px; }
.clock { text-align: right; }
.clock-time { font-weight: 700; font-size: 16px; font-variant-numeric: tabular-nums; letter-spacing: .5px; }
.clock-zone { font-size: 11px; color: var(--muted); }
.conn { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--ink-2); }
.conn-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); transition: background .3s; }
.conn.live .conn-dot { background: var(--good); box-shadow: 0 0 0 3px rgba(12,163,12,.16); animation: pulse 2s infinite; }
.conn.down .conn-dot { background: var(--critical); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .45; } }
.user-menu { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--ink-2); }
.user-menu button { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 7px 12px; font-size: 13px; color: var(--ink-2); }
.user-menu button:hover { background: var(--surface-2); }

/* ===== Views ===== */
.view { max-width: 1360px; margin: 0 auto; padding: 22px; }
.view-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 16px; }
.view-head h2 { margin: 0; font-size: 20px; }

/* Site filter chips */
.site-filter { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.site-chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 8px 16px; font-size: 13px; font-weight: 500; color: var(--ink-2);
  display: flex; align-items: center; gap: 8px;
}
.site-chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.site-chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--good); }
.site-chip.has-alert .dot { background: var(--critical); }

/* Search bar */
.search-bar { position: relative; max-width: 440px; margin: 0 0 20px; }
.search-bar .search-ico { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); pointer-events: none; }
#sensor-search { width: 100%; padding: 10px 14px 10px 36px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); font-size: 14px; color: var(--ink); box-shadow: var(--shadow); }
#sensor-search::placeholder { color: var(--muted); }
#sensor-search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-empty { text-align: center; padding: 44px 20px; color: var(--muted); font-size: 14px; }

/* Greenhouse tab selector */
.gh-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 20px; }
.gh-tab {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 8px 20px; font-size: 13px; font-weight: 600; color: var(--ink-2);
  transition: background .15s, color .15s, border-color .15s;
}
.gh-tab:hover { background: var(--surface-2); }
.gh-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); box-shadow: var(--shadow); }
@media (max-width: 560px) {
  .gh-tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
  .gh-tab { flex: 0 0 auto; }
}

/* Logical sensor groups */
.sensor-group { background: var(--surface-2); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px 16px; margin-bottom: 16px; }
.group-h { display: flex; align-items: center; gap: 10px; margin: 0 0 12px; }
.group-h .group-name { font-size: 15px; font-weight: 700; color: var(--ink); letter-spacing: -.2px; }
.group-h .group-count { font-size: 11px; font-weight: 600; color: var(--muted); background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; }

/* ===== Soil Diagnostics — light theme, custom layout (this group only) ===== */
/* Compact: gauges are capped so the soil cards stay close to the Air-card scale. */
.soil-grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: 12px; align-items: start; }
.soil-quad { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* scoped under .soil-lite so these beat the base .card rules regardless of source order */
.sensor-group.soil-lite .soil-card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px 8px; box-shadow: var(--shadow); cursor: pointer; transition: transform .12s, box-shadow .12s; overflow: hidden; }
.sensor-group.soil-lite .soil-card:hover { transform: translateY(-2px); box-shadow: 0 4px 14px rgba(11,11,11,.09); }
.soil-card-h { display: flex; align-items: center; gap: 6px; color: var(--ink-2); font-size: 11px; font-weight: 700; letter-spacing: .05em; }
.soil-card-h .soil-ch-ico { display: inline-flex; }
.soil-card-h .soil-ico { width: 14px; height: 14px; }
.soil-ch-ico.k-moist { color: #0ea5e9; } .soil-ch-ico.k-temp { color: #ef7c63; }
.soil-ch-ico.k-ph { color: #8b5cf6; } .soil-ch-ico.k-ec { color: #d4a017; }
.soil-card-h .soil-ch-t { flex: 1; } .soil-card-h .soil-dots { color: #b8b6af; font-weight: 700; }
.soil-gauge { width: 100%; max-width: 188px; height: auto; display: block; margin: 0 auto; }
.soil-area { width: 100%; max-width: 205px; height: 26px; display: block; margin: 0 auto; }

/* combined NPK card (N + P + K) */
.npk-card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 13px; }
.npk-title { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 13px; font-weight: 800; letter-spacing: .08em; border-bottom: 1px solid var(--line); padding-bottom: 9px; }
.npk-title .npk-leaf { font-size: 14px; }
.npk-rhead { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.npk-name { color: var(--ink-2); font-size: 11.5px; font-weight: 700; letter-spacing: .05em; }
.npk-val { color: var(--ink); font-size: 15px; font-weight: 800; }
.npk-val em { color: var(--muted); font-size: 10.5px; font-weight: 600; font-style: normal; }
.npk-bar { position: relative; height: 12px; border-radius: 6px; background: linear-gradient(90deg, #ef4444 0%, #f59e0b 30%, #22c55e 56%, #14b8a6 78%, #3b82f6 100%); }
.npk-marker { position: absolute; top: -4px; bottom: -4px; width: 0; border-left: 2px dotted var(--ink); }
.npk-marker::after { content: ''; position: absolute; top: -4px; left: -4px; width: 8px; height: 8px; border-radius: 50%; background: var(--ink); box-shadow: 0 0 0 2px #fff; }
.npk-scale { display: flex; justify-content: space-between; margin-top: 7px; font-size: 9.5px; font-weight: 700; letter-spacing: .05em; }
.npk-scale span:nth-child(1) { color: var(--critical); } .npk-scale span:nth-child(2) { color: var(--good); } .npk-scale span:nth-child(3) { color: var(--accent); }
.npk-ideal { text-align: center; margin-top: 5px; font-size: 9.5px; color: var(--muted); letter-spacing: .04em; }
.npk-empty { color: var(--muted); font-size: 12px; text-align: center; padding: 12px; }

@media (max-width: 720px) { .soil-grid { grid-template-columns: 1fr; } }
@media (max-width: 520px) { .soil-quad { grid-template-columns: 1fr; } }

/* Site + controller sections */
.site-block { margin-bottom: 30px; }
.site-h { display: flex; align-items: center; gap: 10px; margin: 0 0 4px; font-size: 17px; }
.site-h .count { font-size: 12px; color: var(--muted); font-weight: 400; }
.ctrl-block { margin-top: 14px; }
.ctrl-h {
  display: flex; align-items: center; gap: 9px; font-size: 13px; color: var(--ink-2);
  font-weight: 600; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 10px;
}
.ctrl-h .chip { font-size: 11px; background: var(--surface-2); border: 1px solid var(--line); padding: 2px 8px; border-radius: 6px; letter-spacing: 0; text-transform: none; color: var(--muted); font-weight: 500; }

/* Sensor cards grid */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(420px, 100%), 1fr)); gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--good);
  border-radius: var(--radius); padding: 14px 15px; box-shadow: var(--shadow);
  cursor: pointer; transition: transform .12s, box-shadow .12s; position: relative; overflow: hidden;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 4px 14px rgba(11,11,11,.09); }
.card.s-high { border-left-color: var(--critical); }
.card.s-low  { border-left-color: var(--low); }
.card.s-unknown { border-left-color: var(--muted); }
.card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.card-metric { font-size: 13px; color: var(--ink-2); font-weight: 600; display: flex; align-items: center; gap: 7px; }
.card-metric .ico { width: 16px; height: 16px; color: var(--muted); flex: none; }
.pill {
  font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
}
.pill.ok      { background: rgba(12,163,12,.12); color: var(--good-ink); }
.pill.high    { background: rgba(208,59,59,.12); color: var(--critical); }
.pill.low     { background: rgba(42,120,214,.12); color: var(--low); }
.pill.unknown { background: var(--surface-2); color: var(--muted); }
/* card body: semicircular gauge (left ~40%) + trend line chart (right ~60%) */
.card-split { display: flex; align-items: center; gap: 12px; margin: 12px 0 4px; }
.gauge-wrap { flex: 0 0 40%; max-width: 40%; }
.chart-wrap { flex: 1 1 60%; min-width: 0; }
.gauge, .trend { width: 100%; height: auto; display: block; }

.card-foot { display: flex; justify-content: space-between; align-items: baseline; margin-top: 6px; }
.card-updated { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.card-range { font-size: 11px; color: var(--muted); }

/* gauge — arc zones, needle, centered value + scale labels */
.g-track  { stroke: var(--grid); opacity: .55; }
.g-blue   { stroke: var(--low); }
.g-green  { stroke: var(--good); }
.g-yellow { stroke: var(--warning); }
.g-red    { stroke: var(--critical); }
.g-needle { stroke: var(--ink); stroke-width: 2.5; stroke-linecap: round; }
.g-hub    { fill: var(--ink); }
.g-val    { font-size: 25px; font-weight: 800; fill: var(--ink); letter-spacing: -.5px; }
.g-val.g-high    { fill: var(--critical); }
.g-val.g-low     { fill: var(--low); }
.g-val.g-unknown { fill: var(--muted); }
.g-unit   { font-size: 11px; font-weight: 600; fill: var(--muted); }
.g-end    { font-size: 10px; fill: var(--muted); font-variant-numeric: tabular-nums; }

/* trend — smooth line, dot markers, subtle grid, time/value axes */
.trend { overflow: visible; }
.tr-grid  { stroke: var(--grid); stroke-width: 1; opacity: .6; }
.tr-line  { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.tr-dot   { fill: var(--accent); stroke: #fff; stroke-width: 1; }
.tr-ylab, .tr-xlab { font-size: 9px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.tr-empty { font-size: 11px; fill: var(--muted); }
.card.flash::after {
  content: ""; position: absolute; inset: 0; background: var(--accent);
  opacity: .1; animation: flash .6s ease-out; pointer-events: none;
}
@keyframes flash { from { opacity: .16; } to { opacity: 0; } }

/* ===== Alerts view ===== */
.alert-row {
  display: flex; align-items: center; gap: 14px; background: var(--surface);
  border: 1px solid var(--line); border-left: 4px solid var(--critical);
  border-radius: 10px; padding: 14px 16px; margin-bottom: 10px; box-shadow: var(--shadow); cursor: pointer;
}
.alert-row.low { border-left-color: var(--low); }
.alert-row:hover { background: var(--surface-2); }
.alert-ico { font-size: 20px; }
.alert-main { flex: 1; }
.alert-title { font-weight: 600; }
.alert-loc { font-size: 12px; color: var(--muted); margin-top: 2px; }
.alert-val { text-align: right; }
.alert-val .v { font-size: 22px; font-weight: 700; }
.alert-val .lim { font-size: 12px; color: var(--muted); }
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty .big { font-size: 40px; margin-bottom: 8px; }

/* ===== Settings / thresholds ===== */
.thresholds-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.th-card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); }
.th-card h3 { margin: 0 0 3px; font-size: 15px; }
.th-card .unit-lbl { font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.th-inputs { display: flex; gap: 10px; align-items: flex-end; }
.th-inputs label { font-size: 12px; color: var(--ink-2); display: flex; flex-direction: column; gap: 5px; flex: 1; }
.th-inputs input { padding: 8px 10px; border: 1px solid #d5d8dd; border-radius: 8px; font-size: 15px; width: 100%; font-variant-numeric: tabular-nums; }
.th-inputs input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.th-save { border: none; background: var(--accent); color: #fff; border-radius: 8px; padding: 9px 14px; font-weight: 600; font-size: 13px; height: 37px; }
.th-save.saved { background: var(--good); }
.th-save:disabled { opacity: .5; }

/* ===== Modal ===== */
.modal-wrap { position: fixed; inset: 0; background: rgba(11,11,11,.42); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal { background: var(--surface); border-radius: 16px; width: min(760px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.3); padding: 22px; }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; }
.modal-title { font-size: 19px; font-weight: 700; }
.modal-sub { font-size: 13px; color: var(--muted); margin-top: 3px; }
.icon-btn { border: none; background: var(--surface-2); width: 34px; height: 34px; border-radius: 9px; font-size: 15px; color: var(--ink-2); }
.icon-btn:hover { background: var(--line); }
.modal-value { display: flex; align-items: center; gap: 12px; margin: 14px 0 4px; }
#modal-current { font-size: 34px; font-weight: 700; letter-spacing: -.5px; }
.range-row { display: flex; gap: 6px; margin: 14px 0; }
.range-row button { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 7px 14px; font-size: 13px; font-weight: 500; color: var(--ink-2); }
.range-row button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.chart-box { height: 320px; position: relative; }

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: 12px; padding: 10px 14px; }
  .brand { min-width: 0; }
  .tabs { order: 3; width: 100%; justify-content: center; }
  .topright { gap: 12px; }
  .clock { display: none; }
  .view { padding: 14px; }
}

/* Narrow cards: stack the gauge above the trend chart */
@media (max-width: 560px) {
  .card-split { flex-direction: column; align-items: stretch; }
  .gauge-wrap { flex: none; width: 72%; max-width: 72%; margin: 0 auto; }
  .chart-wrap { flex: none; width: 100%; }
}
