* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  height: 100%;
  height: 100dvh; /* suit la barre d'outils Safari qui apparait/disparait */
  background: #080818; color: #C0C0E0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overscroll-behavior-y: none;
}
body { display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 18px 14px;
  background: #0B0B20; border-bottom: 1px solid #14143A;
  position: sticky; top: 0; z-index: 10;
}
.brand { font-size: 17px; font-weight: 700; color: #8080FF; }
.brand span { color: #5050BB; }
.icon-btn {
  background: #1E1E3A; color: #B0B0D8; border: none; border-radius: 10px;
  width: 38px; height: 38px; font-size: 18px; display: flex; align-items: center; justify-content: center;
}
.icon-btn:active { background: #2A2A50; }

main#view {
  flex: 1; overflow-y: auto; padding: 14px 14px calc(env(safe-area-inset-bottom, 0px) + 90px);
  -webkit-overflow-scrolling: touch;
}

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; background: #0B0B20; border-top: 1px solid #14143A;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 20;
}
.tab {
  flex: 1; background: none; border: none; color: #45457A;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 10px 0 8px; font-size: 11px; font-family: inherit;
}
.tab.active { color: #A0A0FF; }
.tab-ic { font-size: 18px; }

/* Cards */
.card {
  background: #0E0E28; border-radius: 14px; padding: 14px 16px; margin-bottom: 10px;
  border: 1.5px solid transparent;
}
.card:active { background: #121232; }

.dev-row { display: flex; align-items: center; gap: 12px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #20205A; flex-shrink: 0; }
.dot.on { background: #40CC80; }
.dot.off { background: #CC4848; }
.dev-info { flex: 1; min-width: 0; }
.dev-name { font-size: 15px; font-weight: 600; color: #C8C8F8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dev-addr { font-size: 12px; color: #45457A; font-family: ui-monospace, Menlo, monospace; margin-top: 2px; }
.dev-badge { font-size: 10px; color: #6060A0; background: #14143A; padding: 3px 8px; border-radius: 5px; white-space: nowrap; }

.empty-hint { text-align: center; color: #2A2A55; font-size: 13px; margin-top: 60px; padding: 0 30px; }

/* Buttons */
.btn {
  display: block; width: 100%; text-align: center;
  background: #1E1E3A; color: #B0B0D8; border: none; border-radius: 12px;
  padding: 14px; font-size: 15px; font-weight: 500; margin-bottom: 8px; font-family: inherit;
}
.btn:active { background: #2A2A50; }
.btn-green { background: #142E1E; color: #40CC80; }
.btn-green:active { background: #1A3E28; }
.btn-purple { background: #28206A; color: #C0B0FF; }
.btn-purple:active { background: #342880; }
.btn-red { background: #2E1414; color: #CC5050; }
.btn-red:active { background: #3E1A1A; }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { margin-bottom: 8px; }

.section-label {
  font-size: 10px; font-weight: 600; color: #33336B; letter-spacing: .5px;
  margin: 18px 0 8px; text-transform: uppercase;
}

/* Detail panel (slide up) */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 30;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.sheet-backdrop.show { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31;
  background: #0B0B22; border-radius: 20px 20px 0 0;
  max-height: 88vh;
  max-height: 88dvh; /* suit la barre d'outils Safari qui apparait/disparait */
  overflow-y: auto;
  padding: 0 18px calc(env(safe-area-inset-bottom, 0px) + 24px);
  transform: translateY(100%); transition: transform .25s ease;
}
.sheet.show { transform: translateY(0); }
.sheet-handle { width: 40px; height: 4px; background: #22224A; border-radius: 2px; margin: 8px auto 14px; }
.sheet-toprow {
  display: flex; align-items: center; margin: 0 -18px 6px; padding: 0 18px 8px;
  position: sticky; top: 0; z-index: 1; background: #0B0B22;
}
.sheet-back {
  background: none; border: none; color: #6060A8; font-size: 14px; font-family: inherit;
  padding: 6px 4px;
}
.sheet-close {
  background: #1A1A38; border: none; color: #8080B0; font-size: 13px;
  width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.sheet-close:active { background: #2A2A50; }
.sheet-title { font-size: 19px; font-weight: 700; color: #C0C0FF; margin-bottom: 4px; }
.sheet-sub { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }

/* Forms */
input[type=text], input[type=password] {
  width: 100%; background: #12122A; border: 1px solid #22224A; color: #C0C0E0;
  border-radius: 10px; padding: 12px 14px; font-size: 15px; margin-bottom: 10px; font-family: inherit;
}
input[type=text]::placeholder, input[type=password]::placeholder { color: #33335E; }
select {
  width: 100%; background: #12122A; border: 1px solid #22224A; color: #C0C0E0;
  border-radius: 10px; padding: 12px 14px; font-size: 15px; margin-bottom: 10px; font-family: inherit;
}

.fab {
  position: fixed; right: 18px; bottom: calc(env(safe-area-inset-bottom, 0px) + 78px);
  width: 54px; height: 54px; border-radius: 50%; background: #28206A; color: #C0B0FF;
  border: none; font-size: 26px; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 20px rgba(40,32,106,.5); z-index: 15;
}
.fab:active { background: #342880; }

/* Remote */
.remote { display: flex; flex-direction: column; align-items: center; padding-top: 10px; }
.remote-row { display: flex; gap: 14px; margin-bottom: 16px; }
.rbtn {
  width: 52px; height: 52px; border-radius: 50%; background: #1A1A38; color: #C0C0E0;
  border: none; font-size: 20px; display: flex; align-items: center; justify-content: center;
}
.rbtn:active { background: #342880; }
.dpad { display: grid; grid-template-columns: 62px 62px 62px; grid-template-rows: 62px 62px 62px; gap: 8px; margin-bottom: 18px; }
.dpad button { background: #1A1A38; color: #C0C0E0; border: none; border-radius: 16px; font-size: 20px; }
.dpad button:active { background: #342880; }
.dpad .ok { background: #28206A; color: #fff; font-weight: 700; font-size: 15px; }
.dpad .empty { background: transparent; }

/* Peer cards (tailscale) */
.peer-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.peer-actions { display: flex; gap: 8px; flex-shrink: 0; }
.chip { font-size: 10px; padding: 3px 7px; border-radius: 5px; white-space: nowrap; }
.chip-ok { background: #102818; color: #40A060; }
.chip-off { background: #2A1414; color: #A05050; }
.small-btn { background: #1E1E3A; color: #B0B0D8; border: none; border-radius: 8px; padding: 9px 12px; font-size: 12px; font-family: inherit; }
.small-btn:active { background: #2A2A50; }
.small-btn.p { background: #28206A; color: #C0B0FF; }
.small-btn.g { background: #142E1E; color: #40CC80; }

/* Toast */
#toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 86px);
  transform: translate(-50%, 20px); background: #14142E; color: #C0C0E0;
  padding: 11px 18px; border-radius: 10px; font-size: 13px; z-index: 50;
  opacity: 0; transition: all .25s; pointer-events: none; max-width: 85vw; text-align: center;
  border: 1px solid #22224A;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.spin { display: inline-block; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Mirroring plein ecran */
.mirror-overlay {
  position: fixed; inset: 0; background: #000; z-index: 60;
  display: none; flex-direction: column;
}
.mirror-overlay.show { display: flex; }
.mirror-topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 10px 8px;
  background: #0B0B20; flex-shrink: 0;
}
.mirror-frame { flex: 1; width: 100%; border: none; background: #000; }

/* Login page */
body.login-page { align-items: center; justify-content: center; }
.login-box { width: 100%; max-width: 340px; padding: 24px; }
.login-box .brand { text-align: center; font-size: 20px; margin-bottom: 4px; }
.login-sub { text-align: center; font-size: 12px; color: #45457A; margin-bottom: 30px; }
.login-err { color: #E07070; font-size: 13px; text-align: center; margin-top: 12px; min-height: 18px; }
