/* o2-home — clean theme. Light (white) and dark (black) with blue. */

:root {
  --accent: #0b6bcb;
  --accent-strong: #08529c;
  --accent-soft: #e7f1fb;
  --on: #f5a524;
  --on-soft: #fff4e0;
  --bg: #ffffff;
  --surface: #f5f7fa;
  --card: #ffffff;
  --text: #0f1720;
  --muted: #5f6b7a;
  --line: #e3e8ee;
  --danger: #c0392b;
  --ok: #1d7a4a;
  --shadow: 0 1px 2px rgba(15, 23, 32, .06), 0 8px 24px rgba(15, 23, 32, .06);
  --radius: 16px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --accent: #4ea1f3;
  --accent-strong: #8cc4fa;
  --accent-soft: #10223a;
  --on: #ffbf4d;
  --on-soft: #2e2410;
  --bg: #0a0c0f;
  --surface: #11151a;
  --card: #151a20;
  --text: #ebf0f5;
  --muted: #94a1b0;
  --line: #232b34;
  --danger: #ff6b5b;
  --ok: #3fbf7a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

body {
  background: var(--surface);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  /* Room for the notch and the home bar of the phones (installed app). */
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; margin-bottom: 1rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; margin-top: 1.25rem; }
p { margin: 0 0 1rem; }

.muted { color: var(--muted); }
.small { font-size: .875rem; }
[hidden] { display: none !important; }
form.inline { display: inline; margin: 0; }

code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85rem; }
code { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: .1rem .35rem; }
pre { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: .75rem; overflow-x: auto; margin: 0; }
code.token { word-break: break-all; flex: 1; }

/* ---------- Header ---------- */

.topbar {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
  padding: calc(.6rem + env(safe-area-inset-top)) 1rem .6rem;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: .5rem; color: var(--text); font-weight: 700; letter-spacing: -.02em; }
.brand:hover { text-decoration: none; }
.brand img { width: 30px; height: 30px; }
.brand span b { color: var(--accent); font-weight: 700; }

.nav { margin-left: auto; display: flex; align-items: center; gap: .2rem; flex-wrap: wrap; }
.nav a, .nav button.link {
  color: var(--muted); padding: .4rem .7rem; border-radius: 999px; font-size: .925rem;
  background: none; border: 0; cursor: pointer; font: inherit;
}
.nav a:hover, .nav button.link:hover { background: var(--surface); color: var(--text); text-decoration: none; }
.nav a.active { color: var(--accent); background: var(--accent-soft); }

.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--card); color: var(--text); cursor: pointer;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.icon-btn svg { width: 18px; height: 18px; }

.live-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); opacity: .5; margin: 0 .4rem; }
.live-dot.online { background: var(--ok); opacity: 1; box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 20%, transparent); }

/* ---------- Layout ---------- */

.page { max-width: 1000px; margin: 0 auto; padding: 1.5rem 1rem 4rem; }
.page.narrow { max-width: 420px; padding-top: 3rem; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.25rem; box-shadow: var(--shadow); margin-bottom: 1rem;
}
.card.empty { text-align: center; }
.offline-logo { width: 64px; height: 64px; margin-bottom: 1rem; }

/* ---------- Buttons & forms ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .65rem 1.1rem; border-radius: 999px; border: 1px solid transparent;
  background: var(--accent); color: #fff; font: inherit; font-weight: 600; cursor: pointer;
  text-decoration: none; transition: transform .1s ease, background .2s ease;
}
:root[data-theme="dark"] .btn { color: #06101c; }
.btn:hover { background: var(--accent-strong); text-decoration: none; }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .6; cursor: default; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn.ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); color: var(--danger); }
.btn.block { width: 100%; }
.btn.small { padding: .35rem .75rem; font-size: .85rem; }

label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .3rem; }
.field { margin-bottom: 1rem; }

input, select {
  width: 100%; padding: .6rem .8rem; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit;
}
input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }

.row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.row > input { flex: 1; min-width: 180px; width: auto; }
.row.tight { flex-wrap: nowrap; gap: .4rem; }
.row.tight select { min-width: 120px; padding: .35rem .6rem; }

.grid-form { display: grid; gap: 0 1rem; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); align-items: end; }
.grid-form .btn { margin-bottom: 1rem; }

.alert { padding: .75rem 1rem; border-radius: 12px; background: var(--accent-soft); color: var(--text); margin-bottom: 1rem; }
.alert p:last-child { margin-bottom: 0; }
.alert.ok { background: color-mix(in srgb, var(--ok) 12%, transparent); }
.alert.ok pre { margin-top: .4rem; background: var(--card); }
.alert.error { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }

.badge { display: inline-block; font-size: .75rem; padding: .05rem .5rem; border-radius: 999px; background: var(--accent-soft); color: var(--accent); margin-left: .4rem; }

/* ---------- Lists & tables ---------- */

.list { list-style: none; padding: 0; margin: 0 0 1rem; }
.list li { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .5rem 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }

.table-wrap { overflow-x: auto; margin-bottom: 1rem; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .5rem .5rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }

/* ---------- Home: cards of the entities ---------- */

.area { margin-bottom: 1.75rem; }
.area h2 { color: var(--muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .06em; margin-bottom: .75rem; }

.tiles { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.tiles form { margin: 0; }

.tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: .35rem; width: 100%; min-height: 120px;
  padding: 1rem; text-align: left; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--card); color: var(--text); box-shadow: var(--shadow); font: inherit;
  transition: background .2s ease, border-color .2s ease, transform .1s ease;
}
button.tile { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button.tile:active { transform: scale(.97); }
.tile.busy { opacity: .6; }
.tile-name { font-weight: 600; line-height: 1.25; margin-top: auto; }
.tile-state { color: var(--muted); font-size: .875rem; }
.tile.kind-sensor .tile-state { color: var(--text); font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; order: -1; }

/* Icons are SVG masks, so they take the colour of the text. */
.tile-icon {
  width: 30px; height: 30px; background: var(--muted);
  -webkit-mask: var(--icon) center / contain no-repeat; mask: var(--icon) center / contain no-repeat;
}
.kind-light .tile-icon { --icon: url(/static/img/icons/light.svg); }
.kind-switch .tile-icon { --icon: url(/static/img/icons/switch.svg); }
.kind-sensor .tile-icon { --icon: url(/static/img/icons/sensor.svg); width: 22px; height: 22px; }
.kind-binary_sensor .tile-icon { --icon: url(/static/img/icons/binary_sensor.svg); }

.tile.on { background: var(--on-soft); border-color: color-mix(in srgb, var(--on) 45%, transparent); }
.tile.on .tile-icon { background: var(--on); }
.tile.on .tile-state { color: var(--text); }

@media (max-width: 520px) {
  .page { padding: 1rem .75rem 3rem; }
  .tiles { grid-template-columns: repeat(2, 1fr); gap: .6rem; }
  .tile { min-height: 108px; padding: .85rem; }
  .nav a, .nav button.link { padding: .35rem .55rem; font-size: .875rem; }
}

/* ---------- Sign in ---------- */

.card.login { text-align: center; }
.login-logo { width: 64px; height: 64px; margin-bottom: .75rem; }
