/*
 * Oculux — design system v2
 * Apple-grade, futuristic, mobile-first. Light + dark.
 * Accent (--accent) is injected at runtime from the admin theme colour.
 */

/* ----------------------------------------------------------------------------
   Tokens
---------------------------------------------------------------------------- */
:root {
    --accent: #0066ff;
    --accent-rgb: 0, 102, 255;
    --accent-2: #5b8cff;

    --r-xl: 26px;
    --r-lg: 20px;
    --r: 16px;
    --r-sm: 12px;
    --r-pill: 999px;

    --space: 16px;
    --header-h: 60px;
    --tabbar-h: 64px;

    --ease: cubic-bezier(.22, .61, .36, 1);

    /* Light */
    --bg: #eef1f7;
    --bg-tint: radial-gradient(120% 120% at 100% 0%, rgba(var(--accent-rgb), .06), transparent 55%);
    --surface: #ffffff;
    --surface-2: #ffffff;
    --sunken: #e9edf4;
    --hairline: rgba(13, 18, 33, .07);
    --border: rgba(13, 18, 33, .09);
    --text: #0a0e1a;
    --text-2: #565d70;
    --text-3: #8b91a1;
    --bar-bg: rgba(255, 255, 255, .72);
    --shadow-sm: 0 1px 2px rgba(13, 18, 33, .05), 0 1px 1px rgba(13, 18, 33, .04);
    --shadow: 0 6px 24px rgba(13, 18, 33, .08), 0 1px 2px rgba(13, 18, 33, .05);
    --shadow-lg: 0 24px 60px rgba(13, 18, 33, .16);
    --glow: 0 8px 28px rgba(var(--accent-rgb), .35);

    --ok: #1aa251; --ok-bg: rgba(26, 162, 81, .12);
    --warn: #d98a04; --warn-bg: rgba(217, 138, 4, .14);
    --danger: #e0383e; --danger-bg: rgba(224, 56, 62, .12);

    /* Back-compat aliases for views written against the previous token names. */
    --surface-strong: var(--surface);
    --text-soft: var(--text-2);
    --text-faint: var(--text-3);
    --border-soft: var(--hairline);
    --radius: var(--r-lg);
    --radius-sm: var(--r-sm);
}

[data-theme="dark"] {
    --bg: #07080c;
    --bg-tint: radial-gradient(120% 120% at 100% 0%, rgba(var(--accent-rgb), .14), transparent 55%);
    --surface: #15171e;
    --surface-2: #1b1e27;
    --sunken: #0e1016;
    --hairline: rgba(255, 255, 255, .07);
    --border: rgba(255, 255, 255, .1);
    --text: #f4f6fc;
    --text-2: #a3aab9;
    --text-3: #6c7384;
    --bar-bg: rgba(18, 20, 27, .68);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 10px 34px rgba(0, 0, 0, .5);
    --shadow-lg: 0 30px 70px rgba(0, 0, 0, .6);
    --glow: 0 8px 30px rgba(var(--accent-rgb), .5);
    --ok-bg: rgba(26, 162, 81, .18);
    --warn-bg: rgba(217, 138, 4, .2);
    --danger-bg: rgba(224, 56, 62, .2);
}

/* ----------------------------------------------------------------------------
   Reset / base
---------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
* { -webkit-tap-highlight-color: transparent; }

html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; padding: 0; min-height: 100%; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
        system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--text);
    background: var(--bg-tint), var(--bg);
    background-attachment: fixed;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    line-height: 1.5;
    letter-spacing: -0.01em;
    font-size: 16px;
    overscroll-behavior-y: none;
}

a { color: var(--accent); text-decoration: none; }
a:hover { opacity: .85; }
img { max-width: 100%; }

h1, h2, h3 { margin: 0 0 .4em; font-weight: 700; letter-spacing: -0.03em; line-height: 1.15; }
h1 { font-size: clamp(1.5rem, 4.5vw, 2rem); }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .8em; }
.lead { font-size: 1.08rem; color: var(--text-2); line-height: 1.5; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); font-size: .85rem; }
.text-center { text-align: center; }

/* ----------------------------------------------------------------------------
   Layout helpers
---------------------------------------------------------------------------- */
.container { width: 100%; max-width: 1160px; margin: 0 auto; padding: 0 18px; }
.center-screen { min-height: 100svh; display: grid; place-items: center; padding: 24px 18px; padding-bottom: max(24px, env(safe-area-inset-bottom)); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 12px; align-items: center; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.hidden { display: none !important; }

/* ----------------------------------------------------------------------------
   Surfaces
---------------------------------------------------------------------------- */
.card, .glass {
    background: var(--surface);
    border: 1px solid var(--hairline);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow);
}
.card { padding: 22px; }
.glass {
    background: var(--bar-bg);
    backdrop-filter: saturate(180%) blur(26px);
    -webkit-backdrop-filter: saturate(180%) blur(26px);
}

/* ----------------------------------------------------------------------------
   Buttons
---------------------------------------------------------------------------- */
.btn {
    --btn-bg: var(--surface);
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 44px; padding: 0 20px; border-radius: var(--r-pill);
    border: 1px solid var(--hairline); background: var(--btn-bg); color: var(--text);
    font: inherit; font-weight: 600; font-size: .95rem; cursor: pointer;
    transition: transform .15s var(--ease), box-shadow .2s var(--ease), background .2s, opacity .15s;
    box-shadow: var(--shadow-sm); user-select: none; white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(.985); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-block { width: 100%; }

.btn-primary {
    background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 92%, white), var(--accent));
    color: #fff; border-color: transparent; box-shadow: var(--glow);
}
.btn-primary:hover { box-shadow: 0 10px 32px rgba(var(--accent-rgb), .45); }
.btn-ghost { background: color-mix(in srgb, var(--surface) 70%, transparent); }
.btn-ghost:hover { background: var(--sunken); }
.btn-danger { background: var(--danger); color: #fff; border-color: transparent; box-shadow: 0 8px 24px rgba(224,56,62,.32); }

/* ----------------------------------------------------------------------------
   Forms
---------------------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 16px; }
.field label { font-size: .8rem; font-weight: 600; color: var(--text-2); letter-spacing: 0; }

.input,
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="url"], input[type="time"], input[type="date"], input[type="search"],
select, textarea {
    width: 100%; min-height: 46px; padding: 12px 14px; border-radius: var(--r-sm);
    border: 1px solid var(--border); background: var(--surface); color: var(--text);
    font: inherit; font-size: .96rem; outline: none;
    transition: border-color .15s, box-shadow .15s, background .15s;
    -webkit-appearance: none; appearance: none;
}
textarea { min-height: 90px; line-height: 1.5; resize: vertical; }
select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%238b91a1' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px;
}
input::placeholder, textarea::placeholder { color: var(--text-3); }
.input:focus, input:focus, select:focus, textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(var(--accent-rgb), .15);
}
input[type="color"] { padding: 4px; min-height: 46px; cursor: pointer; }
input[type="file"] { padding: 9px 12px; }
input[type="range"] { -webkit-appearance: none; appearance: none; height: 6px; padding: 0; min-height: 0; background: var(--sunken); border-radius: 999px; border: none; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; border-radius: 50%; background: #fff; border: 2px solid var(--accent); box-shadow: var(--shadow-sm); cursor: pointer; }
input[type="checkbox"] { width: 20px; height: 20px; min-height: 0; accent-color: var(--accent); cursor: pointer; }

.input-group { position: relative; }
.input-group input { padding-right: 46px; }
.input-group .toggle-eye {
    position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
    width: 36px; height: 36px; display: grid; place-items: center;
    background: none; border: none; cursor: pointer; color: var(--text-3); border-radius: 10px;
}
.input-group .toggle-eye:hover { background: var(--sunken); color: var(--text-2); }

/* ----------------------------------------------------------------------------
   Badges / pills
---------------------------------------------------------------------------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px; border-radius: var(--r-pill); font-size: .76rem; font-weight: 700; letter-spacing: .01em; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }

/* ----------------------------------------------------------------------------
   Brand
---------------------------------------------------------------------------- */
.brand { display: inline-flex; align-items: center; gap: 9px; font-weight: 700; font-size: 1.15rem; letter-spacing: -0.03em; color: var(--text); }
.brand .dot { width: 11px; height: 11px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px rgba(var(--accent-rgb), .16), 0 0 18px var(--accent); }

/* ----------------------------------------------------------------------------
   Top app bar + bottom tab bar
---------------------------------------------------------------------------- */
.appbar {
    position: sticky; top: 0; z-index: 50;
    height: calc(var(--header-h) + env(safe-area-inset-top));
    padding-top: env(safe-area-inset-top);
    display: flex; align-items: center; justify-content: space-between;
    padding-left: 18px; padding-right: 18px; gap: 12px;
    background: var(--bar-bg); backdrop-filter: saturate(180%) blur(24px); -webkit-backdrop-filter: saturate(180%) blur(24px);
    border-bottom: 1px solid var(--hairline);
}
.appbar .nav-links { display: flex; align-items: center; gap: 4px; }
.appbar .nav-links a { padding: 8px 13px; border-radius: var(--r-pill); color: var(--text-2); font-weight: 600; font-size: .92rem; }
.appbar .nav-links a:hover { background: var(--sunken); color: var(--text); opacity: 1; }
.appbar .nav-links a.active { color: var(--accent); background: rgba(var(--accent-rgb), .12); }
.appbar .user-name { color: var(--text-3); font-size: .85rem; }

.tabbar { display: none; }

.app-main { padding-top: 22px; padding-bottom: 60px; }

/* Mobile: switch to bottom tab bar */
@media (max-width: 860px) {
    .appbar .nav-links, .appbar .user-name { display: none; }
    .tabbar {
        display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
        height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
        padding-bottom: env(safe-area-inset-bottom);
        background: var(--bar-bg); backdrop-filter: saturate(180%) blur(24px); -webkit-backdrop-filter: saturate(180%) blur(24px);
        border-top: 1px solid var(--hairline);
    }
    .tabbar a {
        flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
        color: var(--text-3); font-size: .68rem; font-weight: 600; letter-spacing: 0; padding-top: 8px;
    }
    .tabbar a svg { width: 24px; height: 24px; }
    .tabbar a.active { color: var(--accent); }
    .app-main { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px); }
}

/* ----------------------------------------------------------------------------
   Theme toggle
---------------------------------------------------------------------------- */
.theme-toggle {
    width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--hairline);
    background: var(--surface); cursor: pointer; display: grid; place-items: center; color: var(--text);
    box-shadow: var(--shadow-sm); transition: transform .15s var(--ease);
}
.theme-toggle:hover { transform: scale(1.06); }

/* ----------------------------------------------------------------------------
   Toasts
---------------------------------------------------------------------------- */
#toasts { position: fixed; top: calc(env(safe-area-inset-top) + 14px); right: 14px; left: 14px; display: flex; flex-direction: column; align-items: center; gap: 10px; z-index: 9999; pointer-events: none; }
.toast {
    width: 100%; max-width: 380px; padding: 14px 16px; border-radius: var(--r);
    background: var(--surface); border: 1px solid var(--hairline);
    box-shadow: var(--shadow-lg); display: flex; gap: 10px; align-items: center;
    font-size: .92rem; font-weight: 500; animation: toast-in .3s var(--ease); pointer-events: auto;
    border-left: 4px solid var(--accent);
}
.toast.ok { border-left-color: var(--ok); }
.toast.error { border-left-color: var(--danger); }
.toast.info { border-left-color: var(--accent); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-12px) scale(.97); } to { opacity: 1; transform: none; } }

/* ----------------------------------------------------------------------------
   Skeletons
---------------------------------------------------------------------------- */
.skeleton { position: relative; overflow: hidden; background: var(--sunken); border-radius: var(--r-sm); }
.skeleton::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%);
    background: linear-gradient(90deg, transparent, rgba(255,255,255,.35), transparent); animation: shimmer 1.4s infinite; }
[data-theme="dark"] .skeleton::after { background: linear-gradient(90deg, transparent, rgba(255,255,255,.06), transparent); }
@keyframes shimmer { 100% { transform: translateX(100%); } }

/* ----------------------------------------------------------------------------
   Install wizard
---------------------------------------------------------------------------- */
.wizard { width: 100%; max-width: 540px; }
.stepper { display: flex; gap: 6px; margin-bottom: 24px; }
.stepper .step { flex: 1; height: 5px; border-radius: 999px; background: var(--sunken); transition: background .3s; }
.stepper .step.active { background: var(--accent); }
.stepper .step.done { background: var(--ok); }
.req-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.req-list li { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-radius: var(--r-sm); background: var(--sunken); font-size: .92rem; }
.req-list .ok { color: var(--ok); font-weight: 700; }
.req-list .bad { color: var(--danger); font-weight: 700; }
.req-list .warn { color: var(--warn); font-weight: 700; }

/* ----------------------------------------------------------------------------
   Admin shell
---------------------------------------------------------------------------- */
.admin-shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100svh; gap: 20px; padding: 20px; }
.sidebar { padding: 22px 16px; display: flex; flex-direction: column; position: sticky; top: 20px; height: calc(100svh - 40px); border-radius: var(--r-xl); }
.admin-main { padding: 6px 6px 60px; min-width: 0; }
.side-link { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-radius: var(--r-sm); color: var(--text-2); font-weight: 600; font-size: .94rem; transition: background .15s, color .15s; }
.side-link:hover { background: var(--sunken); color: var(--text); opacity: 1; }
.side-link.active { background: rgba(var(--accent-rgb), .14); color: var(--accent); }

.metric-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 16px; }
.metric { padding: 22px; }
.metric .n { font-size: 2.1rem; font-weight: 750; letter-spacing: -0.04em; line-height: 1; }
.metric .l { color: var(--text-2); font-size: .9rem; margin-top: 6px; }

/* ----------------------------------------------------------------------------
   Tables
---------------------------------------------------------------------------- */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 13px 14px; border-bottom: 1px solid var(--hairline); vertical-align: middle; }
.table th { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); font-weight: 700; }
.table tr:last-child td { border-bottom: none; }
.table select { min-height: 38px; padding: 6px 28px 6px 10px; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ----------------------------------------------------------------------------
   Modal
---------------------------------------------------------------------------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(6, 8, 14, .5); backdrop-filter: blur(6px); display: grid; place-items: center; z-index: 1000; padding: 18px; padding-bottom: max(18px, env(safe-area-inset-bottom)); animation: fade .2s var(--ease); }
.modal { width: 100%; max-width: 560px; max-height: 88svh; overflow: auto; box-shadow: var(--shadow-lg); animation: pop .25s var(--ease); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(.97); } }

/* ----------------------------------------------------------------------------
   Live viewer + camera tiles
---------------------------------------------------------------------------- */
.live-toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.layout-btns { display: flex; gap: 4px; background: var(--sunken); padding: 4px; border-radius: var(--r-pill); }
.layout-btns .btn { min-height: 36px; padding: 0 14px; border: none; box-shadow: none; background: transparent; }
.layout-btns .btn.active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow-sm); }

.live-grid { display: grid; gap: 12px; }
.live-grid.l-1x1 { grid-template-columns: 1fr; }
.live-grid.l-2x2 { grid-template-columns: repeat(2, 1fr); }
.live-grid.l-3x3 { grid-template-columns: repeat(3, 1fr); }
.live-grid.l-4x4 { grid-template-columns: repeat(4, 1fr); }
.live-grid.l-spotlight { grid-template-columns: 3fr 1fr; grid-auto-rows: min-content; }
.live-grid.l-spotlight .tile:first-child { grid-row: span 4; }

.tile {
    position: relative; aspect-ratio: 16 / 9; background: #05070d; border-radius: var(--r);
    overflow: hidden; border: 1px solid var(--hairline); box-shadow: var(--shadow-sm); cursor: pointer;
    transition: transform .2s var(--ease), box-shadow .2s var(--ease);
}
.tile:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; background: #05070d; }
.tile-overlay { position: absolute; inset: 0; display: grid; place-items: center; color: rgba(255,255,255,.55); font-size: .85rem; pointer-events: none; }

/* Frosted floating label/control bar, iOS-style */
.tile-bar {
    position: absolute; left: 10px; right: 10px; bottom: 10px;
    display: flex; justify-content: space-between; align-items: center; gap: 8px;
    padding: 8px 10px; border-radius: 14px; color: #fff; font-size: .8rem;
    background: rgba(10, 12, 20, .42); backdrop-filter: blur(14px) saturate(160%); -webkit-backdrop-filter: blur(14px) saturate(160%);
    border: 1px solid rgba(255,255,255,.12);
    opacity: 0; transform: translateY(6px); transition: opacity .2s, transform .2s;
}
.tile:hover .tile-bar, .tile:focus-within .tile-bar { opacity: 1; transform: none; }
.l-1x1 .tile-bar, .tile.always-bar .tile-bar { opacity: 1; transform: none; }
.tile-name { font-weight: 600; display: flex; align-items: center; gap: 7px; text-shadow: 0 1px 3px rgba(0,0,0,.5); }
.tile-stats { font-variant-numeric: tabular-nums; opacity: .8; font-size: .72rem; }
.tile-ctrls { display: flex; gap: 5px; }
.tile-ctrls button { background: rgba(255,255,255,.16); border: none; color: #fff; width: 30px; height: 30px; border-radius: 9px; cursor: pointer; display: grid; place-items: center; transition: background .15s; }
.tile-ctrls button:hover { background: rgba(255,255,255,.3); }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #ff3b30; display: inline-block; box-shadow: 0 0 0 3px rgba(255,59,48,.25); animation: pulse 2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(255,59,48,0); } }

/* ----------------------------------------------------------------------------
   Misc
---------------------------------------------------------------------------- */
.spin { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
hr { border: none; border-top: 1px solid var(--hairline); margin: 18px 0; }

/* ----------------------------------------------------------------------------
   Responsive
---------------------------------------------------------------------------- */
@media (max-width: 860px) {
    .admin-shell { grid-template-columns: 1fr; padding: 0; gap: 0; }
    .sidebar { position: sticky; top: 0; height: auto; flex-direction: row; flex-wrap: nowrap; overflow-x: auto; gap: 6px; border-radius: 0; border-bottom: 1px solid var(--hairline); padding: 12px; -webkit-overflow-scrolling: touch; }
    .sidebar .brand, .sidebar .grow, .sidebar .stack:last-child { display: none; }
    .sidebar nav { flex-direction: row !important; }
    .side-link { white-space: nowrap; padding: 9px 13px; }
    .side-link.active { background: rgba(var(--accent-rgb), .14); }
    .admin-main { padding: 16px; }
    .live-grid.l-3x3, .live-grid.l-4x4 { grid-template-columns: repeat(2, 1fr); }
    .live-grid.l-spotlight { grid-template-columns: 1fr; }
    .live-grid.l-spotlight .tile:first-child { grid-row: auto; }
    .card { padding: 18px; }
}
@media (max-width: 520px) {
    .live-grid.l-2x2, .live-grid.l-3x3, .live-grid.l-4x4 { grid-template-columns: 1fr; }
    h1 { font-size: 1.45rem; }
}

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