:root {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #17202d;
  background: #f2f4f7;
  --ink: #111722;
  --muted: #697386;
  --line: #dfe3e8;
  --red: #e30613;
  --shadow: 0 22px 56px rgba(8, 12, 35, .24);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
button, input { font: inherit; }

body.portal-active {
  color: #f8f8ff;
  background-color: #15102f;
  background-image:
    radial-gradient(ellipse 80% 64% at 8% 6%, rgba(40, 116, 255, .9) 0, rgba(40, 116, 255, .25) 42%, transparent 70%),
    radial-gradient(ellipse 72% 62% at 92% 12%, rgba(177, 66, 255, .82) 0, rgba(177, 66, 255, .2) 43%, transparent 70%),
    radial-gradient(ellipse 76% 66% at 62% 88%, rgba(55, 25, 168, .88) 0, rgba(55, 25, 168, .18) 48%, transparent 72%),
    linear-gradient(145deg, #090c28 0%, #1c1450 48%, #291353 100%);
  background-attachment: fixed;
}

.splash, .login-screen { min-height: 100vh; display: grid; place-items: center; }
.splash { text-align: center; color: var(--muted); }
.brand-mark { display: grid; place-items: center; width: 58px; height: 58px; border-radius: 16px; background: var(--red); color: #fff; font-size: 31px; font-weight: 950; margin: auto; }
.login-screen { padding: 24px; background: radial-gradient(circle at 20% 15%, #303a4a 0, transparent 32%), linear-gradient(145deg, #111722, #1d2634); }
.login-card { width: min(430px, 100%); padding: 38px; background: #fff; border-radius: 24px; box-shadow: 0 30px 90px #0007; text-align: center; }
.login-card h1 { margin: 22px 0 4px; font-size: 32px; }
.login-card p { margin: 0; color: var(--muted); }
.pin-dots { display: flex; justify-content: center; gap: 14px; margin: 28px 0 22px; }
.pin-dot { width: 16px; height: 16px; border: 2px solid #b7bec8; border-radius: 50%; }
.pin-dot.filled { background: var(--red); border-color: var(--red); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.key { height: 58px; border: 1px solid var(--line); border-radius: 13px; background: #f7f8fa; font-size: 20px; font-weight: 850; cursor: pointer; }
.key:hover { background: #edf0f4; }
.key:active { transform: translateY(1px); }
.key.action { font-size: 15px; color: var(--muted); }
.login-submit { width: 100%; margin-top: 12px; padding: 14px; border: 0; border-radius: 12px; background: var(--red); color: #fff; font-weight: 850; cursor: pointer; }
.login-submit:disabled { opacity: .45; }
.login-error { min-height: 22px; margin-top: 14px; color: #ad2027; font-weight: 700; }

.topbar { height: 72px; background: rgba(10, 11, 35, .52); border-bottom: 1px solid rgba(255, 255, 255, .13); box-shadow: 0 8px 36px rgba(5, 4, 25, .13); backdrop-filter: blur(24px) saturate(130%); -webkit-backdrop-filter: blur(24px) saturate(130%); color: #fff; display: flex; align-items: center; padding: 0 max(20px, calc((100vw - 1240px) / 2)); gap: 14px; }
.topbar .brand-mark { width: 42px; height: 42px; border-radius: 11px; font-size: 22px; margin: 0; }
.brand-copy strong { display: block; font-size: 17px; }
.brand-copy span { color: #c8c9df; font-size: 12px; }
.user-area { margin-left: auto; display: flex; align-items: center; gap: 11px; }
.avatar { display: grid; place-items: center; width: 39px; height: 39px; border-radius: 50%; background: rgba(255, 255, 255, .16); border: 1px solid rgba(255, 255, 255, .15); font-weight: 850; }
.user-name { font-weight: 750; font-size: 14px; }
.user-role { color: #c5c6dc; font-size: 12px; }
.logout { border: 1px solid rgba(255, 255, 255, .22); background: rgba(255, 255, 255, .08); color: #fff; border-radius: 9px; padding: 8px 11px; cursor: pointer; }
.logout:hover { background: rgba(255, 255, 255, .15); }

.main { max-width: 1240px; margin: auto; padding: 38px 20px 80px; }
.hero { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin-bottom: 35px; }
.hero h1 { margin: 0 0 7px; font-size: clamp(29px, 5vw, 43px); letter-spacing: -.035em; }
.hero p { margin: 0; color: #d6d5e8; font-size: 17px; }
.date { color: #d6d5e8; font-size: 14px; }
.section { margin: 30px 0; }
.section-head { display: flex; align-items: center; gap: 11px; margin-bottom: 14px; }
.section-head h2 { font-size: 19px; margin: 0; }
.section-head span { padding: 4px 8px; border: 1px solid rgba(255, 255, 255, .18); border-radius: 20px; background: rgba(255, 255, 255, .12); color: #fff; font-size: 11px; font-weight: 850; text-transform: uppercase; letter-spacing: .06em; }
.app-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 15px; }
.app-card { position: relative; display: flex; flex-direction: column; min-height: 190px; padding: 20px; background: linear-gradient(145deg, rgba(255, 255, 255, .94), rgba(244, 242, 255, .82)); border: 1px solid rgba(255, 255, 255, .68); border-radius: 20px; box-shadow: 0 8px 28px rgba(7, 8, 34, .12), inset 0 1px 0 rgba(255, 255, 255, .85); backdrop-filter: blur(18px) saturate(120%); -webkit-backdrop-filter: blur(18px) saturate(120%); transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease; text-decoration: none; color: #16182a; overflow: hidden; }
.app-card:hover { transform: translateY(-4px); box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, .9); border-color: rgba(255, 255, 255, .92); }
.app-card:active { transform: translateY(-1px); }
.app-card:focus-visible { outline: 3px solid #b8dcff; outline-offset: 3px; }
.app-top { display: flex; justify-content: space-between; align-items: start; }
.app-icon { display: grid; place-items: center; width: 52px; height: 52px; border-radius: 14px; color: #fff; font-size: 17px; font-weight: 950; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .24), 0 8px 18px rgba(29, 23, 69, .16); }
.app-icon.red { background: #e30613; }
.app-icon.blue { background: #1769c2; }
.app-icon.orange { background: #d46b13; }
.app-icon.green { background: #21804d; }
.app-icon.cyan { background: #14859a; }
.app-icon.purple { background: #7157aa; }
.app-icon.violet { background: linear-gradient(145deg, #6547da, #a14fde); }
.version { font-size: 11px; font-weight: 850; color: #51566b; background: rgba(255, 255, 255, .62); border: 1px solid rgba(84, 74, 120, .1); border-radius: 20px; padding: 5px 8px; }
.app-card h3 { margin: 18px 0 7px; font-size: 21px; }
.app-card p { margin: 0; color: #5d6273; line-height: 1.48; font-size: 14px; }
.empty { padding: 24px; background: rgba(255, 255, 255, .86); border: 1px dashed rgba(255, 255, 255, .72); border-radius: 16px; color: #5d6273; }
#toast { position: fixed; right: 18px; bottom: 18px; z-index: 100; background: #111722; color: #fff; padding: 12px 16px; border-radius: 10px; opacity: 0; transform: translateY(8px); transition: .2s; pointer-events: none; }
#toast.show { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  .app-card { transition: none; }
}

@media (max-width: 900px) {
  .app-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 620px) {
  .login-card { padding: 28px 22px; }
  .topbar { height: 66px; }
  .brand-copy span, .user-copy { display: none; }
  .main { padding: 27px 15px 65px; }
  .hero { display: block; }
  .date { margin-top: 12px; }
  .app-grid { grid-template-columns: 1fr; }
  .app-card { min-height: 176px; }
  .logout { padding: 8px; }
  .section { margin: 25px 0; }
}

.brand-link { color: #fff; text-decoration: none; }
.back-link { color: #fff; text-decoration: none; padding: 9px 13px; border: 1px solid rgba(255,255,255,.25); border-radius: 10px; font-weight: 750; }
.admin-main { max-width: 1420px; }
.admin-title { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin: 14px 0 24px; }
.admin-title h1 { margin: 0; color: #fff; }
.admin-title p:not(.eyebrow) { margin: 8px 0 0; color: #d6d6e8; }
.eyebrow { margin: 0 0 7px; color: #b9a8ff; font-size: 12px; font-weight: 850; letter-spacing: .14em; }
.admin-add,.admin-save { border: 0; border-radius: 12px; padding: 13px 18px; background: linear-gradient(135deg,#7657ff,#a14fff); color: #fff; font-weight: 850; cursor: pointer; box-shadow: 0 10px 25px rgba(75,42,180,.28); }
.admin-layout { display: grid; grid-template-columns: minmax(240px,320px) minmax(0,1fr); gap: 18px; align-items: start; }
.people-panel,.editor-panel { border: 1px solid rgba(255,255,255,.17); border-radius: 20px; background: rgba(18,21,49,.65); box-shadow: 0 20px 60px rgba(8,5,32,.25); backdrop-filter: blur(18px); }
.people-panel { padding: 10px; position: sticky; top: 86px; }
.people-list { display: grid; gap: 6px; }
.person-row { width: 100%; display: grid; grid-template-columns: 42px 1fr; align-items: center; gap: 11px; border: 1px solid transparent; border-radius: 13px; padding: 11px; background: transparent; color: #fff; text-align: left; cursor: pointer; }
.person-row:hover,.person-row.active { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.15); }
.person-row span:last-child { display: grid; gap: 3px; min-width: 0; }
.person-row strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person-row small { color: #b9bbd3; }
.person-avatar { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 12px; background: linear-gradient(135deg,#7353ff,#c249df); font-weight: 900; }
.editor-panel { padding: clamp(18px,3vw,30px); }
.editor-head { display: flex; justify-content: space-between; align-items: start; gap: 18px; }
.editor-head h2 { margin: 0; color: #fff; font-size: 28px; }
.switch-line { display: flex; align-items: center; gap: 8px; color: #fff; font-weight: 750; }
.identity-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 13px; margin: 22px 0 28px; }
.identity-grid label { display: grid; gap: 7px; color: #e8e8f2; font-size: 13px; font-weight: 750; }
.identity-grid input,.identity-grid select { width: 100%; min-height: 48px; border: 1px solid rgba(255,255,255,.2); border-radius: 11px; padding: 11px 13px; background: rgba(255,255,255,.09); color: #fff; }
.identity-grid select option { color: #111; }
.permission-head h3 { margin: 0; color: #fff; }
.permission-head p { margin: 6px 0 16px; color: #b9bbd3; }
.permission-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; }
.permission-card { border: 1px solid rgba(255,255,255,.16); border-radius: 15px; padding: 14px; background: rgba(255,255,255,.06); transition: opacity .2s,border-color .2s; }
.permission-card.disabled { opacity: .58; }
.app-access { display: grid; grid-template-columns: auto 42px 1fr; gap: 10px; align-items: center; color: #fff; cursor: pointer; }
.app-access input,.capability-list input,.switch-line input { width: 18px; height: 18px; accent-color: #8c68ff; }
.app-access span:last-child,.capability-list label span { display: grid; gap: 3px; }
.app-access small,.capability-list small { color: #b9bbd3; font-weight: 500; line-height: 1.35; }
.capability-list { display: grid; gap: 9px; margin: 13px 0 0 28px; padding-top: 12px; border-top: 1px solid rgba(255,255,255,.12); }
.capability-list label { display: grid; grid-template-columns: 18px 1fr; gap: 9px; color: #fff; cursor: pointer; }
.save-bar { position: sticky; bottom: 12px; display: flex; justify-content: flex-end; align-items: center; gap: 14px; margin-top: 22px; padding: 12px; border: 1px solid rgba(255,255,255,.15); border-radius: 14px; background: rgba(13,15,39,.88); backdrop-filter: blur(14px); color: #ffd0d0; }
.admin-save:disabled { opacity: .55; cursor: wait; }
.admin-error { padding: 20px; border-radius: 14px; background: rgba(140,20,35,.65); color: #fff; }
.empty-note { color: #b9bbd3; padding: 12px; }
.pin-change-card form { display: grid; gap: 14px; margin-top: 24px; text-align: left; }
.pin-change-card label { display: grid; gap: 7px; color: var(--ink); font-weight: 750; }
.pin-change-card form,.pin-change-card label,.pin-change-card input,.pin-change-card .login-submit { width: 100%; min-width: 0; max-width: 100%; }
.pin-change-card input { min-height: 50px; border: 1px solid var(--line); border-radius: 11px; padding: 11px 13px; text-align: center; font-size: 20px; letter-spacing: .25em; }
.pin-status-box { display: flex; justify-content: space-between; align-items: center; gap: 15px; margin: -10px 0 26px; padding: 14px; border: 1px solid rgba(255,255,255,.16); border-radius: 14px; background: rgba(255,255,255,.06); }
.pin-status-box div { display: grid; gap: 4px; }
.pin-status-box span { color: #b9bbd3; font-size: 13px; }
.pin-status-box .back-link,.temporary-pin-actions .back-link { background: rgba(255,255,255,.08); cursor: pointer; }
.temporary-pin-panel { color: #fff; text-align: center; padding: 24px 10px; }
.temporary-pin-panel h2 { margin: 0; font-size: 28px; }
.temporary-pin-panel p:not(.eyebrow) { color: #c8c9df; }
.temporary-pin-value { margin: 28px auto; font-size: clamp(42px,8vw,68px); font-weight: 950; letter-spacing: .18em; font-variant-numeric: tabular-nums; }
.temporary-pin-actions { display: flex; justify-content: center; gap: 12px; }

@media (max-width: 900px) {
  .admin-layout { grid-template-columns: 1fr; }
  .people-panel { position: static; }
  .people-list { display: flex; overflow-x: auto; }
  .person-row { min-width: 230px; }
}
@media (max-width: 620px) {
  .admin-title { align-items: stretch; flex-direction: column; }
  .identity-grid,.permission-grid { grid-template-columns: 1fr; }
  .editor-panel { padding: 16px; }
  .editor-head { align-items: stretch; flex-direction: column; }
  .back-link { padding: 8px; font-size: 13px; }
}
