/* Karagiannis Security Systems (R) - www.karagiannis-security.gr
   KSS Thermo phone app. Dark, calm, same family as the device's own page. */

:root {
  --bg: #0b1220;
  --card: #121b2d;
  --line: #233047;
  --text: #e8eef7;
  --muted: #8fa0b8;
  --accent: #3b82f6;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --violet: #b794ff;
  --cyan: #22d3ee;
  --radius: 14px;
  --gap: 12px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
body.no-scroll { overflow: hidden; }

h1, h2, h3, p, ul, ol { margin: 0; }
h3 { font-size: 1rem; margin: 18px 0 8px; }
button, input, select { font: inherit; color: inherit; }
img { display: block; }

.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;
}
.muted { color: var(--muted); }
.strong { color: var(--text); font-weight: 600; }
.label { color: var(--muted); font-size: .875rem; }
.noscript { padding: 24px 16px; text-align: center; }

/* ------------------------------------------------------------ bars and banners */
.bar {
  position: sticky; top: 0; z-index: 30;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
  padding-left: calc(16px + env(safe-area-inset-left));
  padding-right: calc(16px + env(safe-area-inset-right));
  background: #3a2a06; color: #ffe2a8; border-bottom: 1px solid var(--amber);
  font-size: .9375rem; text-align: center;
}
/* While the offline bar is showing it owns the top edge; the header scrolls with the page. */
.bar:not([hidden]) ~ #view-main .top { padding-top: 0; position: static; }
.bar:not([hidden]) ~ .login { padding-top: 32px; }

.banner {
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: var(--gap);
  border: 1px solid var(--amber); background: rgba(245, 158, 11, .12); color: #ffe2a8;
}
.banner.is-red { border-color: var(--red); background: rgba(239, 68, 68, .14); color: #ffd0d0; }

/* ------------------------------------------------------------ cards and forms */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: var(--gap);
}
.card-title { font-size: 1rem; font-weight: 600; margin-bottom: 8px; }
.note { color: var(--muted); }

.form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { color: var(--muted); font-size: .875rem; }
.field input {
  width: 100%; min-height: 48px; padding: 10px 12px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; outline: none;
  font-size: 16px;                      /* 16px stops iPhone from zooming into the field */
}
.field input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.hint { color: var(--muted); font-size: .8125rem; }
.msg { padding: 10px 12px; border-radius: 10px; background: rgba(239, 68, 68, .14); color: #ffd0d0; font-size: .9375rem; }
.msg.msg-ok { background: rgba(34, 197, 94, .14); color: #c9f7d9; }

.btn {
  min-height: 48px; padding: 10px 16px; border-radius: 10px; cursor: pointer;
  background: transparent; border: 1px solid var(--line); font-weight: 600;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .6; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { border-color: #fff; }
.btn-danger { color: #ffb4b4; border-color: rgba(239, 68, 68, .5); }

.icon-btn {
  width: 44px; height: 44px; flex: none; display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 0; border-radius: 50%; cursor: pointer; color: var(--text);
}
.icon-btn:hover { background: rgba(255, 255, 255, .06); }

/* ------------------------------------------------------------ login */
.login {
  max-width: 400px; margin: 0 auto;
  padding: calc(48px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right))
           calc(24px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  display: flex; flex-direction: column; align-items: stretch;
}
.login-logo { align-self: center; width: 96px; height: 96px; border-radius: 22px; }
.login-title { text-align: center; font-size: 1.625rem; margin-top: 16px; letter-spacing: .01em; }
.login-sub { text-align: center; color: var(--muted); margin-bottom: 24px; }
.brand { text-align: center; color: var(--muted); font-size: .8125rem; margin-top: 16px; }

/* ------------------------------------------------------------ header */
.top {
  position: sticky; top: 0; z-index: 20;
  background: rgba(11, 18, 32, .94); border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.top-in {
  max-width: 840px; margin: 0 auto; min-height: 56px;
  display: flex; align-items: center; gap: 10px;
  padding: 6px calc(12px + env(safe-area-inset-right)) 6px calc(16px + env(safe-area-inset-left));
}
.top-logo { height: 32px; width: auto; max-width: 96px; flex: none; }
.top-titles { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.2; }
.top-app { font-weight: 700; }
.top-device { color: var(--muted); font-size: .8125rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-select { flex: 0 1 auto; min-width: 0; }
.top-select select {
  max-width: 44vw; min-height: 44px; padding: 6px 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
}

.content {
  max-width: 840px; margin: 0 auto;
  padding: var(--gap) calc(12px + env(safe-area-inset-right)) 8px calc(12px + env(safe-area-inset-left));
}
.foot {
  text-align: center; color: var(--muted); font-size: .8125rem;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
}

/* ------------------------------------------------------------ thermometer card */
.probe-name { font-size: 1rem; font-weight: 600; color: var(--muted); overflow-wrap: anywhere; }
.probe-temp {
  display: flex; align-items: baseline; gap: 6px; margin-top: 2px;
  font-variant-numeric: tabular-nums; font-feature-settings: "tnum";
}
.probe-value { font-size: 56px; line-height: 1.1; font-weight: 700; letter-spacing: -.02em; }
.probe-unit { font-size: 1.5rem; color: var(--muted); font-weight: 600; }
.probe-state { font-weight: 600; margin-top: 2px; overflow-wrap: anywhere; }

.probe.st-ok .probe-state { color: var(--green); }
.probe.st-wait .probe-state, .probe.st-wait .probe-value { color: var(--amber); }
.probe.st-alarm .probe-state, .probe.st-alarm .probe-value { color: var(--red); }
.probe.st-alarm { border-color: rgba(239, 68, 68, .7); }
.probe.st-byp .probe-state { color: var(--violet); }
.probe.st-idle .probe-state { color: var(--muted); }
.probe.is-stale .probe-value, .probe.is-stale .probe-unit { color: var(--muted); }
.probe.is-stale .probe-state { color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.chip {
  display: inline-flex; align-items: center; min-height: 28px; padding: 3px 10px;
  border: 1px solid var(--line); border-radius: 999px; font-size: .8125rem; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.chip.chip-hi { border-color: rgba(239, 68, 68, .55); color: #ffc9c9; }
.chip.chip-lo { border-color: rgba(34, 211, 238, .5); color: #c5f4fb; }
.chip.chip-alarm { border-color: var(--red); background: rgba(239, 68, 68, .16); color: #ffd0d0; font-weight: 600; }
.chip.chip-byp { border-color: var(--violet); color: var(--violet); }

.range { display: flex; gap: 6px; margin-top: 16px; }
.range button {
  flex: 1 1 0; min-height: 44px; padding: 6px 4px; cursor: pointer;
  background: transparent; border: 1px solid var(--line); border-radius: 10px; color: var(--muted);
  font-size: .875rem; font-weight: 600; white-space: nowrap;
}
.range button[aria-pressed="true"] { background: rgba(59, 130, 246, .18); border-color: var(--accent); color: var(--text); }

.chart { margin-top: 10px; min-height: 190px; }
.chart:empty { min-height: 0; margin-top: 0; }      /* nothing to draw (e.g. no connection): no blank block */
.chart svg { display: block; width: 100%; height: 190px; }
.chart text { font-size: 11px; font-variant-numeric: tabular-nums; }
.chart-note { font-size: .8125rem; margin-top: 4px; font-variant-numeric: tabular-nums; }
.legend { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px; font-size: .75rem; color: var(--muted); }
.legend li { display: inline-flex; align-items: center; gap: 6px; }

/* ------------------------------------------------------------ weather, alarms, info */
.weather { display: flex; align-items: center; gap: 14px; position: relative; }
.wx-icon { width: 64px; height: 64px; flex: none; }
.wx-icon svg { display: block; width: 64px; height: 64px; }
.wx-main { display: flex; flex-direction: column; min-width: 0; padding-bottom: 14px; }
.wx-temp { font-size: 1.75rem; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.wx-desc { color: var(--muted); font-size: .9375rem; overflow-wrap: anywhere; }
.wx-credit { position: absolute; right: 12px; bottom: 8px; font-size: .6875rem; color: var(--muted); }

.alarm-list { list-style: none; padding: 0; }
.alarm-list li { padding: 10px 0; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 2px; }
.alarm-list li:first-child { border-top: 0; padding-top: 2px; }
.alarm-kind { font-weight: 600; }
.alarm-kind.k-hi { color: #ffb4b4; }
.alarm-kind.k-lo { color: #a8eefa; }
.alarm-kind.k-sens { color: #ffe2a8; }
.alarm-when { color: var(--muted); font-size: .875rem; font-variant-numeric: tabular-nums; }
.alarm-open { color: var(--red); font-weight: 600; }

.info { padding-top: 8px; padding-bottom: 8px; }
.info-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); }
.info-row:first-child { border-top: 0; }
.info-row > span:last-child { text-align: right; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------ sheets */
.sheet {
  position: fixed; inset: 0; z-index: 50; background: rgba(3, 7, 15, .72);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet-box {
  width: 100%; max-width: 520px; max-height: 92vh; max-height: 92dvh; overflow-y: auto;
  background: var(--card); border: 1px solid var(--line); border-bottom: 0;
  border-radius: 18px 18px 0 0;
  padding: 8px calc(16px + env(safe-area-inset-right)) calc(20px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  animation: sheet-up .18s ease-out;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 52px; }
.sheet-head h2 { font-size: 1.125rem; }
.sheet-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }
.about { margin-top: 8px; color: var(--muted); font-size: .875rem; }
.about p { margin-top: 6px; }
.about h3 { color: var(--text); }
.steps { padding-left: 22px; color: var(--text); }
.steps li { margin: 6px 0; }
.sheet p { margin-top: 8px; }
.sheet .field, .sheet .form p { margin-top: 0; }

@keyframes sheet-up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (min-width: 640px) {
  .sheet { align-items: center; }
  .sheet-box { border-radius: 18px; border-bottom: 1px solid var(--line); }
  .content { padding-top: 16px; }
  .probe-value { font-size: 64px; }
}

@media (max-width: 359px) {
  .card { padding: 14px 12px; }
  .probe-value { font-size: 52px; }
  .range button { font-size: .8125rem; }
  .top-logo { max-width: 64px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
