/* NovaStream - Dark UI
   Inspired by BunnyCDN / Cloudflare dashboards. */

/* Some components set an explicit `display` on elements that are also
   toggled via the `hidden` attribute from JS (speed menu, upload result
   box, icon swaps, etc). Author CSS always wins over the browser's
   built-in `[hidden]{display:none}` UA rule, so without this override
   those elements never actually hide. Keep this above everything else. */
[hidden] { display: none !important; }

:root {
    --ns-accent: #6366f1;
    --ns-accent-hover: #7c7ff5;
    --ns-bg: #0b0e14;
    --ns-bg-2: #11151f;
    --ns-surface: #161b26;
    --ns-surface-2: #1c2230;
    --ns-border: #262d3d;
    --ns-text: #e6e9ef;
    --ns-muted: #8b93a7;
    --ns-danger: #ef4444;
    --ns-success: #22c55e;
    --ns-radius: 14px;
    --ns-radius-sm: 9px;
    --ns-shadow: 0 8px 30px rgba(0, 0, 0, .35);
    --ns-font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--ns-bg);
    color: var(--ns-text);
    font-family: var(--ns-font);
    line-height: 1.55;
    font-size: 15px;
}

a { color: var(--ns-accent); text-decoration: none; }
a:hover { color: var(--ns-accent-hover); }

h1, h2, h3 { margin: 0 0 .4em; font-weight: 650; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }

code { font-family: "SFMono-Regular", ui-monospace, Menlo, Consolas, monospace; font-size: .85em; }

.ns-muted { color: var(--ns-muted); }
.ns-text-center { text-align: center; }
.ns-hint { font-size: .8rem; margin-top: .75rem; }

/* ---------- Buttons ---------- */
.ns-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    border: 1px solid var(--ns-border);
    background: var(--ns-surface-2);
    color: var(--ns-text);
    padding: .6rem 1rem;
    border-radius: var(--ns-radius-sm);
    font-size: .9rem;
    font-weight: 550;
    cursor: pointer;
    transition: background .15s ease, border-color .15s ease, transform .05s ease;
    text-decoration: none;
}
.ns-btn:hover { background: #232b3b; }
.ns-btn:active { transform: translateY(1px); }
.ns-btn-primary { background: var(--ns-accent); border-color: var(--ns-accent); color: #fff; }
.ns-btn-primary:hover { background: var(--ns-accent-hover); color: #fff; }
.ns-btn-danger { background: transparent; border-color: rgba(239, 68, 68, .5); color: #fca5a5; }
.ns-btn-danger:hover { background: rgba(239, 68, 68, .12); }
.ns-btn-ghost { background: transparent; }
.ns-btn-sm { padding: .38rem .7rem; font-size: .8rem; }
.ns-btn-block { width: 100%; }

/* ---------- Alerts ---------- */
.ns-alert {
    padding: .75rem 1rem;
    border-radius: var(--ns-radius-sm);
    margin-bottom: 1rem;
    font-size: .9rem;
    border: 1px solid transparent;
}
.ns-alert-error { background: rgba(239, 68, 68, .12); border-color: rgba(239, 68, 68, .3); color: #fca5a5; }
.ns-alert-success { background: rgba(34, 197, 94, .12); border-color: rgba(34, 197, 94, .3); color: #86efac; }

/* ---------- Forms ---------- */
.ns-form { display: flex; flex-direction: column; gap: 1rem; }
.ns-field { display: flex; flex-direction: column; gap: .35rem; font-size: .85rem; }
.ns-field > span { color: var(--ns-muted); font-weight: 550; }
.ns-field input, .ns-field select, .ns-field textarea {
    background: var(--ns-bg-2);
    border: 1px solid var(--ns-border);
    color: var(--ns-text);
    padding: .65rem .8rem;
    border-radius: var(--ns-radius-sm);
    font-size: .9rem;
    font-family: inherit;
    width: 100%;
}
.ns-field input:focus, .ns-field select:focus, .ns-field textarea:focus {
    outline: none;
    border-color: var(--ns-accent);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, .18);
}
.ns-field input[type="color"] { height: 44px; padding: .2rem; cursor: pointer; }
.ns-field input[type="file"] { padding: .5rem; }
.ns-form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.ns-check { display: flex; align-items: center; gap: .6rem; font-size: .9rem; cursor: pointer; }
.ns-check input { width: 18px; height: 18px; accent-color: var(--ns-accent); }
.ns-subhead { margin-top: .6rem; color: var(--ns-text); font-size: .95rem; border-top: 1px solid var(--ns-border); padding-top: 1rem; }

/* ---------- Centered pages (install / login / 404) ---------- */
.ns-center-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: radial-gradient(1200px 600px at 50% -10%, rgba(99, 102, 241, .12), transparent), var(--ns-bg);
}
.ns-auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--ns-surface);
    border: 1px solid var(--ns-border);
    border-radius: var(--ns-radius);
    padding: 2rem;
    box-shadow: var(--ns-shadow);
}
.ns-auth-head { text-align: center; margin-bottom: 1.5rem; }
.ns-auth-head h1 { margin: .6rem 0 .2rem; }
.ns-detected { text-align: center; font-size: .8rem; margin-bottom: 1rem; word-break: break-all; }
.ns-404 { font-size: 3rem; margin: .5rem 0; }

.ns-logo-mark {
    width: 46px; height: 46px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--ns-accent), #4338ca);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 750;
    letter-spacing: .5px;
    margin: 0 auto;
}

/* ---------- Admin layout ---------- */
.ns-admin { display: block; }
.ns-nav-toggle { display: none; }

.ns-sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 250px;
    background: var(--ns-bg-2);
    border-right: 1px solid var(--ns-border);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    z-index: 40;
}
.ns-brand { display: flex; align-items: center; gap: .7rem; margin-bottom: 1.75rem; }
.ns-brand .ns-logo-mark { width: 38px; height: 38px; font-size: .85rem; }
.ns-brand-name { font-weight: 650; font-size: 1.05rem; }
.ns-logo-img { height: 34px; width: auto; border-radius: 8px; }

.ns-nav { display: flex; flex-direction: column; gap: .25rem; }
.ns-nav-link {
    color: var(--ns-muted);
    padding: .65rem .8rem;
    border-radius: var(--ns-radius-sm);
    font-weight: 550;
    font-size: .92rem;
    transition: background .15s ease, color .15s ease;
}
.ns-nav-link:hover { background: var(--ns-surface); color: var(--ns-text); }
.ns-nav-link.is-active { background: var(--ns-accent); color: #fff; }
.ns-nav-logout { margin-top: auto; color: #fca5a5; }

.ns-main { margin-left: 250px; min-height: 100vh; display: flex; flex-direction: column; }
.ns-topbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--ns-border);
    background: var(--ns-bg-2);
    position: sticky;
    top: 0;
    z-index: 30;
}
.ns-page-title { font-size: 1.2rem; margin: 0; }
.ns-topbar-right { margin-left: auto; font-size: .85rem; }
.ns-content { padding: 1.5rem; display: flex; flex-direction: column; gap: 1.5rem; max-width: 1200px; width: 100%; }

.ns-hamburger { display: none; flex-direction: column; gap: 4px; cursor: pointer; padding: .3rem; }
.ns-hamburger span { width: 22px; height: 2px; background: var(--ns-text); border-radius: 2px; }

/* ---------- Cards ---------- */
.ns-card {
    background: var(--ns-surface);
    border: 1px solid var(--ns-border);
    border-radius: var(--ns-radius);
    padding: 1.25rem 1.35rem;
}
.ns-card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.ns-card-head h2 { margin: 0; }
.ns-empty { padding: 2rem 0; text-align: center; }

/* ---------- Stats ---------- */
.ns-stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; }
.ns-stat { display: flex; flex-direction: column; gap: .4rem; }
.ns-stat-label { color: var(--ns-muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; }
.ns-stat-value { font-size: 1.9rem; font-weight: 700; }

/* ---------- Thumbnails / recent ---------- */
.ns-recent-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; }
.ns-recent-item { display: flex; flex-direction: column; gap: .5rem; color: var(--ns-text); }
.ns-recent-meta { display: flex; flex-direction: column; gap: .1rem; }
.ns-recent-id { font-weight: 600; font-size: .9rem; }

.ns-thumb {
    position: relative;
    aspect-ratio: 16 / 9;
    background: var(--ns-bg-2);
    border-radius: var(--ns-radius-sm);
    overflow: hidden;
    border: 1px solid var(--ns-border);
}
.ns-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ns-thumb-fallback { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--ns-muted); font-size: .8rem; }
.ns-thumb-duration {
    position: absolute; bottom: 6px; right: 6px;
    background: rgba(0, 0, 0, .8);
    color: #fff; font-size: .72rem;
    padding: .1rem .35rem; border-radius: 4px;
}

/* ---------- Dropzone ---------- */
.ns-dropzone {
    border: 2px dashed var(--ns-border);
    border-radius: var(--ns-radius);
    padding: 2.5rem 1.5rem;
    text-align: center;
    background: var(--ns-bg-2);
    transition: border-color .15s ease, background .15s ease;
}
.ns-dropzone.is-drag { border-color: var(--ns-accent); background: rgba(99, 102, 241, .08); }
.ns-dropzone-inner { display: flex; flex-direction: column; align-items: center; gap: .5rem; }
.ns-dropzone-icon { color: var(--ns-accent); }
.ns-dropzone-title { font-size: 1.1rem; font-weight: 600; margin: 0; }

/* ---------- Upload list ---------- */
.ns-upload-list { list-style: none; margin: 1.25rem 0 0; padding: 0; display: flex; flex-direction: column; gap: 1rem; }
.ns-upload-row { background: var(--ns-bg-2); border: 1px solid var(--ns-border); border-radius: var(--ns-radius-sm); padding: 1rem; }
.ns-upload-row-head { display: flex; justify-content: space-between; gap: 1rem; font-size: .88rem; margin-bottom: .6rem; }
.ns-upload-name { font-weight: 600; word-break: break-all; }
.ns-upload-status { color: var(--ns-muted); white-space: nowrap; }
.ns-upload-row.is-done .ns-upload-status { color: var(--ns-success); }
.ns-upload-row.is-error .ns-upload-status { color: #fca5a5; }

.ns-progress { height: 8px; background: var(--ns-surface-2); border-radius: 99px; overflow: hidden; }
.ns-progress-bar { height: 100%; width: 0; background: var(--ns-accent); border-radius: 99px; transition: width .2s ease; }
.ns-upload-result { margin-top: 1rem; display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: .6rem; }

/* ---------- Copy fields ---------- */
.ns-copy-field { display: flex; flex-direction: column; gap: .25rem; }
.ns-copy-field label { font-size: .72rem; color: var(--ns-muted); text-transform: uppercase; letter-spacing: .04em; }
.ns-copy-field { position: relative; }
.ns-copy-field input {
    background: var(--ns-bg);
    border: 1px solid var(--ns-border);
    color: var(--ns-text);
    padding: .5rem 4rem .5rem .6rem;
    border-radius: var(--ns-radius-sm);
    font-size: .8rem;
    width: 100%;
}
.ns-copy, .ns-copy-input {
    position: absolute;
    right: 5px; bottom: 5px;
    padding: .3rem .55rem;
    font-size: .72rem;
}

/* ---------- Video manager ---------- */
.ns-video-list { display: flex; flex-direction: column; gap: 1rem; }
.ns-video-item {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: 1.25rem;
    background: var(--ns-bg-2);
    border: 1px solid var(--ns-border);
    border-radius: var(--ns-radius);
    padding: 1rem;
}
.ns-video-thumb { position: relative; aspect-ratio: 16 / 9; border-radius: var(--ns-radius-sm); overflow: hidden; border: 1px solid var(--ns-border); background: var(--ns-surface); }
.ns-video-thumb img { width: 100%; height: 100%; object-fit: cover; }
.ns-video-body { display: flex; flex-direction: column; gap: .8rem; min-width: 0; }
.ns-video-top { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.ns-video-id { margin: 0; font-size: 1.05rem; }
.ns-copy-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .6rem; }
.ns-video-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: auto; }
.ns-inline-form { display: inline; margin: 0; }

/* ---------- Settings ---------- */
.ns-settings-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.5rem; }
.ns-span-2 { grid-column: 1 / -1; }

/* ---------- Code block ---------- */
.ns-code {
    background: var(--ns-bg);
    border: 1px solid var(--ns-border);
    border-radius: var(--ns-radius-sm);
    padding: 1rem;
    overflow-x: auto;
    font-size: .82rem;
    color: #cbd5e1;
    white-space: pre;
    margin: .4rem 0 1rem;
}

/* ---------- Watch / player pages ---------- */
.ns-watch { background: var(--ns-bg); min-height: 100vh; }
.ns-watch-header { padding: 1rem 1.5rem; border-bottom: 1px solid var(--ns-border); }
.ns-watch-header .ns-brand { margin: 0; }
.ns-watch-main { max-width: 1000px; margin: 0 auto; padding: 1.5rem; }
.ns-player-wrap { width: 100%; }
.ns-ad { max-width: 1000px; margin: 0 auto; padding: .5rem 1.5rem; text-align: center; }

/* ---------- Custom player ---------- */
.ns-player {
    position: relative;
    background: #000;
    border-radius: var(--ns-radius);
    overflow: hidden;
    aspect-ratio: 16 / 9;
    width: 100%;
}
.ns-video { width: 100%; height: 100%; display: block; background: #000; object-fit: contain; }

.ns-player-loading {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    background: rgba(0, 0, 0, .35);
    opacity: 0; pointer-events: none; transition: opacity .2s ease;
}
.ns-player.is-loading .ns-player-loading { opacity: 1; }
.ns-spinner {
    width: 44px; height: 44px;
    border: 3px solid rgba(255, 255, 255, .25);
    border-top-color: #fff;
    border-radius: 50%;
    animation: ns-spin .8s linear infinite;
}
@keyframes ns-spin { to { transform: rotate(360deg); } }

.ns-big-play {
    position: absolute; top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 74px; height: 74px;
    border: none; border-radius: 50%;
    background: rgba(99, 102, 241, .92);
    color: #fff; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: transform .15s ease, opacity .2s ease;
}
.ns-big-play:hover { transform: translate(-50%, -50%) scale(1.06); }
.ns-player.is-playing .ns-big-play { opacity: 0; pointer-events: none; }

.ns-branding { position: absolute; max-height: 85px; opacity: .85; pointer-events: none; z-index: 5; }
.ns-branding-top-left { top: 12px; left: 12px; }
.ns-branding-top-right { top: 12px; right: 12px; }
.ns-branding-bottom-left { bottom: 60px; left: 12px; }
.ns-branding-bottom-right { bottom: 60px; right: 12px; }

.ns-controls {
    position: absolute; left: 0; right: 0; bottom: 0;
    padding: .5rem .75rem .6rem;
    background: linear-gradient(transparent, rgba(0, 0, 0, .8));
    display: flex; flex-direction: column; gap: .4rem;
    opacity: 0; transform: translateY(8px);
    transition: opacity .2s ease, transform .2s ease;
}
.ns-player:hover .ns-controls,
.ns-player.is-paused .ns-controls,
.ns-player.show-controls .ns-controls { opacity: 1; transform: translateY(0); }

.ns-seek { position: relative; height: 16px; display: flex; align-items: center; cursor: pointer; }
.ns-seek-buffer, .ns-seek-progress {
    position: absolute; left: 0; top: 50%; transform: translateY(-50%);
    height: 5px; border-radius: 99px; pointer-events: none;
}
.ns-seek-buffer { width: 0; background: rgba(255, 255, 255, .35); }
.ns-seek-progress { width: 0; background: var(--ns-accent); z-index: 2; }
.ns-seek::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; transform: translateY(-50%); height: 5px; background: rgba(255, 255, 255, .18); border-radius: 99px; }
.ns-seek-input { position: absolute; inset: 0; width: 100%; margin: 0; opacity: 0; cursor: pointer; z-index: 3; }

.ns-controls-row { display: flex; align-items: center; gap: .5rem; color: #fff; }
.ns-ctrl {
    background: transparent; border: none; color: #fff;
    cursor: pointer; padding: .35rem; border-radius: 6px;
    display: inline-flex; align-items: center; justify-content: center;
    transition: background .15s ease;
}
.ns-ctrl:hover { background: rgba(255, 255, 255, .15); }
.ns-time { font-size: .8rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ns-controls-spacer { flex: 1; }

.ns-volume { display: flex; align-items: center; gap: .2rem; }
.ns-volume-input { width: 0; opacity: 0; transition: width .2s ease, opacity .2s ease; accent-color: var(--ns-accent); }
.ns-volume:hover .ns-volume-input { width: 70px; opacity: 1; }

.ns-speed { position: relative; }
.ns-speed-toggle { font-size: .8rem; font-weight: 600; min-width: 34px; }
.ns-speed-menu {
    position: absolute; bottom: 110%; right: 0;
    background: rgba(20, 24, 34, .97);
    border: 1px solid var(--ns-border);
    border-radius: 8px; padding: .3rem;
    display: flex; flex-direction: column; gap: 2px;
    min-width: 70px;
}
.ns-speed-option { background: transparent; border: none; color: #fff; padding: .35rem .5rem; text-align: left; cursor: pointer; border-radius: 5px; font-size: .8rem; }
.ns-speed-option:hover, .ns-speed-option.is-active { background: var(--ns-accent); }

.ns-player-ad { margin-top: 1rem; text-align: center; }

/* ---------- Toast ---------- */
.ns-toast {
    position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px);
    background: var(--ns-surface-2); color: var(--ns-text);
    border: 1px solid var(--ns-border);
    padding: .7rem 1.1rem; border-radius: 99px;
    font-size: .85rem; box-shadow: var(--ns-shadow);
    opacity: 0; pointer-events: none;
    transition: opacity .2s ease, transform .2s ease;
    z-index: 100;
}
.ns-toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    .ns-settings-grid { grid-template-columns: 1fr; }
    .ns-video-item { grid-template-columns: 1fr; }
    .ns-video-thumb { max-width: 320px; }
}

@media (max-width: 720px) {
    .ns-sidebar { transform: translateX(-100%); transition: transform .25s ease; }
    .ns-nav-toggle:checked ~ .ns-sidebar { transform: translateX(0); }
    .ns-main { margin-left: 0; }
    .ns-hamburger { display: flex; }
    .ns-form-row { grid-template-columns: 1fr; }
}
