/* IHOME web/PWA: light office theme, organisation colours = green and white.
   Fonts are shipped with the app (no CDN) so Persian text looks the same everywhere. */

@font-face { font-family: "Vazirmatn"; src: url("/fonts/Vazirmatn-Regular.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Vazirmatn"; src: url("/fonts/Vazirmatn-Medium.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Vazirmatn"; src: url("/fonts/Vazirmatn-SemiBold.woff2") format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Vazirmatn"; src: url("/fonts/Vazirmatn-Bold.woff2") format("woff2"); font-weight: 700 800; font-display: swap; }

:root {
  --bg: #f2f9f8;
  --surface: #ffffff;
  --surface-2: #f7fcfb;
  --line: #cde8e3;
  --line-strong: #a9d6cc;
  --text: #0e2f2a;
  --muted: #587a73;
  --accent: #0f9d8a;
  --accent-2: #0b4f4a;
  --accent-soft: #e2f5f1;
  --accent-ink: #ffffff;
  --red: #c93c3c;
  --red-soft: #fde9e9;
  --amber: #9a6a12;
  --amber-soft: #fff4dc;
  --shadow: 0 1px 2px rgba(11, 79, 74, .04);
  --shadow-lift: 0 2px 6px rgba(11, 79, 74, .06);
  --radius: 20px;
  --ease: cubic-bezier(.2, .8, .2, 1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: "Vazirmatn", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  background:
    radial-gradient(900px 480px at 50% -12%, #d4efdf 0%, transparent 70%),
    linear-gradient(180deg, #eef8f2 0%, var(--bg) 42%, #f7fbf9 100%) fixed;
}
body { padding-bottom: env(safe-area-inset-bottom); padding-top: env(safe-area-inset-top); }
button, input, select { font: inherit; }
button { cursor: pointer; transition: transform .12s var(--ease), background .2s, border-color .2s, box-shadow .2s, opacity .2s; }
button:active { transform: scale(.97); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.busy { opacity: .6; }
button:focus-visible { outline: 3px solid rgba(15, 157, 138, .35); outline-offset: 2px; }

/* motion */
@keyframes fadeUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: scale(.94); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(15,157,138,.45); } 50% { box-shadow: 0 0 0 6px rgba(15,157,138,0); } }
@keyframes scan { 0% { top: 6%; } 50% { top: 92%; } 100% { top: 6%; } }
@keyframes rot { to { transform: rotate(360deg); } }
.fade-up { animation: fadeUp .45s var(--ease) both; }
.pop { animation: pop .38s var(--ease) both; }

.shell { max-width: 440px; margin: 0 auto; padding: 0 16px 40px; }
.shell.wide { max-width: 1100px; }

h1 { margin: 8px 0 6px; font-size: 24px; font-weight: 800; }
h2 { font-size: 18px; font-weight: 700; margin: 0; }
h3 { font-weight: 700; }

/* brand + auth card */
.card-auth {
  margin: 8vh auto 0; max-width: 390px; padding: 28px 22px;
  border-radius: 26px; background: var(--surface); border: 1px solid var(--line);
  box-shadow: var(--shadow-lift);
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 700; letter-spacing: 4px; color: var(--accent-2); }
.brand .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); animation: pulse 2.4s infinite; }
.card-auth label { display: block; margin-bottom: 14px; color: var(--muted); font-size: 14px; font-weight: 500; }
.card-auth input, .card-auth select {
  display: block; width: 100%; margin-top: 6px; padding: 13px 14px; border-radius: 14px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); font-size: 16px;
  transition: border-color .2s, box-shadow .2s;
}
.card-auth input:focus, .card-auth select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px rgba(15,157,138,.14); }
.primary {
  width: 100%; padding: 14px; border: 0; border-radius: 15px;
  background: linear-gradient(135deg, #22a862, var(--accent-2)); color: #fff;
  font-size: 16px; font-weight: 700; box-shadow: 0 8px 20px rgba(23,132,76,.28);
}
.primary:hover:not(:disabled) { filter: brightness(1.05); }
.ghost { padding: 9px 14px; border-radius: 12px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--accent-2); font-size: 13px; font-weight: 600; }
.ghost:hover { border-color: var(--accent); background: var(--accent-soft); }
.big { padding: 14px 18px; font-size: 15px; }
.wide-btn { width: 100%; margin-top: 10px; }
.err { color: var(--red); min-height: 22px; font-size: 14px; margin: 8px 0 0; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 0; line-height: 1.8; }
.links { margin: 18px 0 0; text-align: center; font-size: 13px; color: var(--muted); }
.links a { color: var(--accent-2); text-decoration: none; font-weight: 600; }

/* signup method cards */
.methods { display: grid; gap: 10px; margin-top: 12px; }
.method {
  display: flex; align-items: center; gap: 14px; width: 100%; padding: 14px; border-radius: 18px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); text-align: right; box-shadow: var(--shadow);
}
.method:hover { border-color: var(--accent); transform: translateY(-1px); box-shadow: var(--shadow-lift); }
.method b { display: block; font-size: 15px; font-weight: 700; }
.method small { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; line-height: 1.7; }
.method em { color: var(--amber); font-style: normal; }
.m-ico { flex: 0 0 46px; height: 46px; border-radius: 15px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-2); font-weight: 800; font-size: 15px; }

/* verification code shown on screen */
.code-box { margin: 14px 0 4px; padding: 16px; border-radius: 18px; background: var(--accent-soft); border: 1.5px dashed var(--accent); text-align: center; }
.code-digits { font-size: 40px; letter-spacing: 12px; font-weight: 800; color: var(--accent-2); direction: ltr; display: inline-block; }

/* segmented control */
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 5px; border-radius: 15px; background: var(--surface-2); border: 1px solid var(--line); margin-bottom: 16px; }
.seg button { padding: 10px; border: 0; border-radius: 11px; background: transparent; color: var(--muted); font-weight: 600; }
.seg button.on { background: var(--surface); color: var(--accent-2); box-shadow: var(--shadow); }

/* top bar */
.top {
  position: sticky; top: 0; z-index: 5; margin: 0 -16px; padding: 14px 18px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: rgba(255,255,255,.88); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.top .home { font-weight: 800; font-size: 17px; color: var(--text); }
.top .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.banner { margin: 12px 0 0; padding: 10px 14px; border-radius: 14px; background: var(--amber-soft); color: var(--amber); font-size: 13px; font-weight: 500; }
.actions-row { display: flex; gap: 10px; margin: 16px 0 0; }
.scan-btn { flex: 1; }

/* empty state */
.empty { color: var(--muted); text-align: center; margin-top: 40px; font-size: 14px; }
.empty-card { margin-top: 18px; padding: 28px 20px; border-radius: var(--radius); text-align: center; background: var(--surface); border: 1.5px dashed var(--line-strong); box-shadow: var(--shadow); }
.empty-card h2 { margin: 10px 0 6px; font-size: 17px; }
.empty-card p { color: var(--muted); font-size: 14px; line-height: 1.9; margin: 0; }
.empty-ico { width: 62px; height: 62px; margin: 0 auto; border-radius: 20px; display: grid; place-items: center; font-size: 28px; background: var(--accent-soft); color: var(--accent-2); }

/* panel (one per unit) */
.panel { margin-top: 18px; padding: 18px; border-radius: 24px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.badge { font-size: 12px; font-weight: 700; padding: 5px 11px; border-radius: 999px; }
.badge.on { background: var(--accent-soft); color: var(--accent-2); }
.badge.off { background: var(--red-soft); color: var(--red); }
.sub-line { font-size: 12px; color: var(--muted); margin-top: 3px; }
.linkish { border: 0; background: none; color: var(--muted); font-size: 12px; text-decoration: underline; padding: 0; }
.linkish:hover { color: var(--red); }
.unpair-row { margin-top: 12px; text-align: left; }

/* rooms */
.room { margin-top: 16px; padding: 16px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--line); }
.room-head { display: flex; align-items: center; gap: 10px; margin-bottom: 2px; }
.room-head h3 { margin: 0; font-size: 17px; font-weight: 800; color: var(--text); }
.room-ico { width: 36px; height: 36px; border-radius: 13px; display: grid; place-items: center; background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }
.room-ico svg, .dico svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.group { margin-top: 14px; }
.group-title { display: flex; align-items: center; justify-content: space-between; font-size: 12px; color: var(--accent-2); font-weight: 700; margin-bottom: 8px; padding-bottom: 6px; border-bottom: 1px dashed var(--line-strong); }
.group-title span { color: var(--muted); font-weight: 600; background: var(--surface); border-radius: 999px; padding: 1px 8px; }
.dgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }

/* device cards */
.dcard {
  padding: 14px; border-radius: 20px; background: var(--surface); border: 1px solid var(--line);
  box-shadow: var(--shadow); transition: transform .2s var(--ease), border-color .25s, box-shadow .25s, background .3s;
}
.dcard.ctl:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); }
.dcard.on { border-color: var(--accent); background: linear-gradient(160deg, #f1fbf5, #e2f5ea); box-shadow: 0 6px 18px rgba(15,157,138,.14); }
.dcard.ro-only { opacity: .94; }
.dhead { display: flex; align-items: center; gap: 10px; }
.dico { width: 42px; height: 42px; flex: 0 0 42px; border-radius: 15px; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); transition: background .3s, color .3s; }
.dcard.on .dico { background: var(--accent); color: #fff; box-shadow: 0 4px 12px rgba(15,157,138,.35); }
.dtitle { min-width: 0; flex: 1; }
.dname { font-size: 15px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dmeta { font-size: 11px; color: var(--muted); margin-top: 2px; min-height: 13px; }
.spin { width: 16px; height: 16px; flex: 0 0 16px; border-radius: 50%; border: 2px solid var(--accent-soft); border-top-color: var(--accent); animation: rot .8s linear infinite; }

/* single switch */
.toggle {
  position: relative; width: 100%; height: 62px; margin-top: 12px; border-radius: 16px;
  border: 1px solid var(--line-strong); background: var(--surface-2); color: var(--text);
  font-size: 15px; font-weight: 700; display: flex; align-items: center; justify-content: space-between; padding: 0 14px;
}
.toggle .t { font-size: 15px; font-weight: 700; }
.toggle .knob { width: 24px; height: 24px; border-radius: 50%; background: #b5c9bd; transition: transform .3s var(--ease), background .3s, box-shadow .3s; }
.toggle.on { border-color: transparent; background: linear-gradient(135deg, #22a862, var(--accent-2)); color: #fff; box-shadow: 0 8px 18px rgba(23,132,76,.25); }
.toggle.on .knob { background: #fff; box-shadow: 0 0 12px rgba(255,255,255,.8); transform: translateX(-4px); }
.toggle:disabled .knob { background: #cfddd5; }

/* multi-channel */
.chans { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; margin-top: 12px; }
.chan {
  min-height: 52px; border-radius: 15px; border: 1px solid var(--line-strong); background: var(--surface-2); color: var(--text);
  padding: 8px 10px; display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 13px;
}
.chan .cdot { width: 10px; height: 10px; border-radius: 50%; background: #b5c9bd; flex: 0 0 10px; transition: background .25s, box-shadow .25s; }
.chan.on { border-color: transparent; background: linear-gradient(135deg, #22a862, var(--accent-2)); color: #fff; box-shadow: 0 6px 14px rgba(23,132,76,.22); }
.chan.on .cdot { background: #fff; box-shadow: 0 0 8px rgba(255,255,255,.9); }
.chan .cl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dcard .toggle { margin-top: 12px; }

/* read-only readouts */
.ros { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 12px; }
.ro { background: var(--surface-2); border-radius: 13px; padding: 8px 10px; font-size: 11px; color: var(--muted); }
.ro b { display: block; margin-top: 2px; color: var(--text); font-size: 14px; font-weight: 700; }
.derr { margin-top: 8px; font-size: 12px; color: var(--red); font-weight: 500; }

/* legacy relay/curtain pieces (kept for older screens) */
.card { padding: 12px; border-radius: 18px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); }
.name { font-size: 14px; font-weight: 700; }
.meta { font-size: 11px; color: var(--muted); }
.keys { display: flex; overflow-x: auto; gap: 3px; margin-top: 10px; padding-bottom: 4px; }
.key { flex: 0 0 calc((100% - 15px) / 6); height: 120px; border-radius: 0 0 8px 8px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--muted); display: flex; align-items: flex-end; justify-content: center; padding-bottom: 8px; font-size: 12px; font-weight: 700; }
.key.on { background: var(--accent-soft); color: var(--accent-2); border-color: var(--accent); }
.curtain { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 12px; }
.curtain button { height: 56px; border-radius: 12px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); font-size: 13px; }
.curtain button.on { border: 2px solid var(--accent); }
.cards { display: flex; gap: 12px; flex-wrap: wrap; }

/* scanner */
.scan { margin-top: 18px; text-align: center; }
.frame { position: relative; width: 100%; max-width: 360px; aspect-ratio: 1 / 1; margin: 0 auto; border-radius: 24px; overflow: hidden; background: #0c1f17; border: 2px solid var(--accent); box-shadow: 0 0 0 6px rgba(15,157,138,.12); }
.frame video { width: 100%; height: 100%; object-fit: cover; }
.scan-line { position: absolute; left: 8%; right: 8%; height: 2px; background: var(--accent); box-shadow: 0 0 12px var(--accent); animation: scan 2.6s ease-in-out infinite; }

/* toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff; padding: 12px 18px; border-radius: 15px; font-size: 14px; font-weight: 500;
  z-index: 20; max-width: 90vw; text-align: center; box-shadow: 0 10px 28px rgba(15,42,30,.25); animation: fadeUp .3s var(--ease) both;
}
.toast[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
