/* J.A.R.V.I.S. autonome : coquille de l'appli (connexion, réglages, bandeau, visionneuse).
   Les couleurs viennent de themes.css (généré depuis config/themes/jarvis.yaml) ; valeurs de secours ici. */

:root {
  --primary-color: #00d4ff; --rgb-primary-color: 0, 212, 255; --primary-background-color: #05080d;
  --primary-text-color: #d6f6ff; --secondary-text-color: #6fa8bf; --disabled-text-color: #34586a;
  --error-color: #ff3b5c; --warning-color: #ffb020; --success-color: #29f2a5; --divider-color: rgba(0, 212, 255, .14);
  --card-background-color: rgba(9, 20, 35, .78); --text-primary-color: #02121a;
  --jv-font-head: var(--ha-font-family-heading, 'Orbitron', 'Rajdhani', sans-serif);
  --jv-font-body: var(--ha-font-family-body, 'Rajdhani', 'Segoe UI', sans-serif);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--lovelace-background, var(--primary-background-color));
  background-color: var(--primary-background-color);
  color: var(--primary-text-color); font-family: var(--jv-font-body); font-size: 16px;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
a { color: inherit; text-decoration: none; }
jarvis-panel { display: block; min-height: 100vh; min-height: 100dvh; }

/* ---------- réacteur ---------- */
.reactor { width: 100%; height: auto; filter: drop-shadow(0 0 24px rgba(var(--rgb-primary-color), .55)); }
.reactor .halo { fill: none; stroke: rgba(var(--rgb-primary-color), .12); stroke-width: 1; }
.reactor .dash { fill: none; stroke: var(--primary-color); }
.reactor .d1 { stroke-width: 2; stroke-dasharray: 4 10; opacity: .55; }
.reactor .d2 { stroke-width: 6; stroke-dasharray: 46 18; opacity: .8; }
.reactor .d3 { stroke-width: 2; stroke-dasharray: 110 30 10 30; opacity: .9; }
.reactor .segments rect { fill: rgba(var(--rgb-primary-color), .85); transition: fill .3s; }
.reactor .inner { fill: rgba(var(--rgb-primary-color), .08); stroke: var(--primary-color); stroke-width: 2; }
.reactor .core { animation: pulse 3.2s ease-in-out infinite; transform-origin: 100px 100px; }
.spin { transform-origin: 100px 100px; animation: spin 18s linear infinite; }
.spin.slow { animation-duration: 40s; } .spin.rev { animation-direction: reverse; animation-duration: 26s; }
.busy .spin { animation-duration: 2.4s; } .busy .spin.slow { animation-duration: 5s; } .busy .spin.rev { animation-duration: 3.2s; }
.busy .core { animation-duration: .7s; }
.granted .segments rect { fill: var(--success-color); }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: .85; transform: scale(.94); } 50% { opacity: 1; transform: scale(1.06); } }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes shake { 10%, 90% { transform: translateX(-2px); } 20%, 80% { transform: translateX(4px); } 30%, 50%, 70% { transform: translateX(-7px); } 40%, 60% { transform: translateX(7px); } }

/* ---------- écrans plein cadre ---------- */
.screen { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom)); }
.splash { min-height: 100vh; background: var(--primary-background-color); }
.splash-box { display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; animation: rise .4s ease; max-width: 420px; }
.splash-box .reactor { width: 150px; }
.splash-screen .reactor .spin { animation-duration: 3s; } .splash-screen .reactor .spin.slow { animation-duration: 6s; }
.status { margin: 0; font-family: var(--jv-font-head); font-size: 13px; letter-spacing: .28em; text-transform: uppercase; color: var(--primary-color); }
.offline .reactor .segments rect { fill: var(--error-color); }
.offline .status { color: var(--error-color); }
.hint { margin: 0; color: var(--secondary-text-color); font-size: 15px; line-height: 1.4; }

/* ---------- connexion ---------- */
.login-card { position: relative; width: min(400px, 100%); padding: 30px 26px 24px; border-radius: 20px; text-align: center;
  background: var(--card-background-color); border: 1px solid rgba(var(--rgb-primary-color), .28);
  box-shadow: 0 0 0 1px rgba(var(--rgb-primary-color), .05), 0 0 40px rgba(var(--rgb-primary-color), .12), inset 0 0 32px rgba(var(--rgb-primary-color), .05);
  animation: rise .45s ease; }
.login-card::before, .login-card::after { content: ""; position: absolute; width: 18px; height: 18px; border-color: var(--primary-color); border-style: solid; opacity: .8; }
.login-card::before { top: 8px; left: 8px; border-width: 2px 0 0 2px; border-top-left-radius: 7px; }
.login-card::after { bottom: 8px; right: 8px; border-width: 0 2px 2px 0; border-bottom-right-radius: 7px; }
.login-card.shake { animation: shake .45s ease; }
.login-reactor { width: 120px; margin: 0 auto 6px; }
.brand-title { margin: 0; font-family: var(--jv-font-head); font-weight: 700; font-size: 26px; letter-spacing: .32em; padding-left: .32em;
  color: var(--primary-color); text-shadow: 0 0 14px rgba(var(--rgb-primary-color), .55); }
.brand-sub { margin: 6px 0 22px; font-size: 13px; letter-spacing: .26em; text-transform: uppercase; color: var(--secondary-text-color); }
form { display: flex; flex-direction: column; gap: 14px; text-align: left; }
.step { display: flex; flex-direction: column; gap: 14px; }
.step[hidden] { display: none; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; letter-spacing: .2em; text-transform: uppercase; color: var(--secondary-text-color); }
input:not([type=checkbox]) { width: 100%; padding: 13px 15px; border-radius: 12px; border: 1px solid rgba(var(--rgb-primary-color), .3);
  background: rgba(var(--rgb-primary-color), .06); color: var(--primary-text-color); font: inherit; font-size: 17px; letter-spacing: .02em;
  text-transform: none; outline: none; transition: border-color .15s, box-shadow .15s; }
input:not([type=checkbox]):focus { border-color: var(--primary-color); box-shadow: 0 0 0 3px rgba(var(--rgb-primary-color), .18); }
input[name=code] { font-family: var(--jv-font-head); font-size: 22px; letter-spacing: .4em; text-align: center; }
.mfa-hint { margin: 0; color: var(--secondary-text-color); font-size: 15px; }
.err { margin: 0; min-height: 1.3em; color: var(--error-color); font-size: 15px; font-weight: 600; }
.btn { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 50px; padding: 0 22px; border-radius: 999px;
  background: var(--primary-color); color: var(--text-primary-color, #02121a); font-family: var(--jv-font-head); font-size: 13px; font-weight: 700;
  letter-spacing: .24em; text-transform: uppercase; box-shadow: 0 0 22px rgba(var(--rgb-primary-color), .35); transition: transform .12s, opacity .2s, background .3s; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .75; cursor: progress; }
.granted .btn { background: var(--success-color); box-shadow: 0 0 26px var(--success-color); }
.login .hint { margin-top: 16px; font-size: 14px; }

/* ---------- bandeau de reconnexion ---------- */
.banner { position: fixed; z-index: 30; left: 50%; top: max(12px, env(safe-area-inset-top)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-radius: 999px; max-width: calc(100% - 32px);
  background: rgba(20, 6, 10, .92); border: 1px solid var(--error-color); color: var(--primary-text-color); font-weight: 600;
  box-shadow: 0 0 22px rgba(255, 59, 92, .35); animation: rise .3s ease; }
.banner[hidden] { display: none; }
.banner ha-icon { color: var(--error-color); }

/* ---------- feuilles (réglages, caméra) ---------- */
.jv-overlay { position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: var(--mdc-dialog-scrim-color, rgba(0, 6, 12, .78)); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); animation: rise .2s ease; }
.jv-overlay[hidden] { display: none; }
.sheet { position: relative; width: min(480px, 100%); max-height: 88vh; max-height: 88dvh; overflow-y: auto; padding: 18px 20px 16px; border-radius: 18px;
  background: var(--secondary-background-color, #0a1220); border: 1px solid rgba(var(--rgb-primary-color), .3);
  box-shadow: 0 0 40px rgba(var(--rgb-primary-color), .14); }
.sheet-h { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px;
  font-family: var(--jv-font-head); font-size: 14px; letter-spacing: .28em; text-transform: uppercase; color: var(--primary-color); }
.x { width: 38px; height: 38px; border-radius: 11px; display: flex; align-items: center; justify-content: center;
  color: var(--primary-color); background: rgba(var(--rgb-primary-color), .1); }
.sheet h3 { margin: 18px 0 8px; font-family: var(--jv-font-head); font-size: 11px; font-weight: 500; letter-spacing: .28em; text-transform: uppercase; color: var(--secondary-text-color); }
.who { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 14px; background: rgba(var(--rgb-primary-color), .06); }
.who ha-icon { --mdc-icon-size: 34px; color: var(--primary-color); }
.who b { display: block; font-size: 18px; }
.who small, .opt small, .theme small { display: block; color: var(--secondary-text-color); font-size: 13px; }
.themes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.theme { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px 6px; border-radius: 14px; text-align: center;
  border: 1px solid rgba(var(--rgb-primary-color), .16); background: rgba(var(--rgb-primary-color), .04); transition: border-color .15s, background .15s; }
.theme b { font-family: var(--jv-font-head); font-size: 10px; letter-spacing: .14em; }
.theme.on { border-color: var(--primary-color); background: rgba(var(--rgb-primary-color), .12); }
.sw { width: 30px; height: 30px; border-radius: 50%; margin-bottom: 2px; }
.sw-jarvis { background: radial-gradient(circle, #fff 0 18%, #00d4ff 40%, #05080d 75%); box-shadow: 0 0 12px #00d4ff; }
.sw-friday { background: radial-gradient(circle, #fff 0 18%, #ff9f1c 40%, #0b0705 75%); box-shadow: 0 0 12px #ff9f1c; }
.sw-mark { background: radial-gradient(circle, #fff 0 18%, #ffcc33 38%, #e8222a 62%, #0c0405 80%); box-shadow: 0 0 12px #e8222a; }
.opt { width: 100%; display: flex; flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; margin-top: 8px;
  border-radius: 14px; text-align: left; background: rgba(var(--rgb-primary-color), .05); border: 1px solid rgba(var(--rgb-primary-color), .12);
  font-size: 16px; text-transform: none; letter-spacing: 0; color: var(--primary-text-color); cursor: pointer; }
.opt:hover { border-color: rgba(var(--rgb-primary-color), .4); }
.opt ha-icon { color: var(--primary-color); }
.opt.danger, .opt.danger ha-icon { color: var(--error-color); }
.opt input[type=checkbox] { appearance: none; -webkit-appearance: none; position: relative; width: 46px; height: 26px; flex: none; margin: 0;
  border-radius: 13px; background: var(--switch-unchecked-track-color, #1a2b38); cursor: pointer; transition: background .2s; }
.opt input[type=checkbox]::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--switch-unchecked-button-color, #4f8aa1); transition: transform .2s, background .2s; }
.opt input[type=checkbox]:checked { background: var(--switch-checked-track-color, rgba(0, 212, 255, .45)); }
.opt input[type=checkbox]:checked::after { transform: translateX(20px); background: var(--switch-checked-button-color, var(--primary-color)); box-shadow: 0 0 10px var(--primary-color); }
.ver { margin: 16px 0 0; text-align: center; font-size: 12px; letter-spacing: .14em; color: var(--disabled-text-color); }
.big-state { margin: 10px 0; font-family: var(--jv-font-head); font-size: 28px; text-align: center; }
.cam-view { width: min(1100px, 100%); }
.cam-box { border-radius: 12px; overflow: hidden; background: #000; aspect-ratio: 16 / 9; }
.cam-box img { width: 100%; height: 100%; object-fit: contain; display: block; }

@media (prefers-reduced-motion: reduce) { .spin, .core { animation: none !important; } }
