:root {
    --bg:           #f5f6f8;
    --panel:        #ffffff;
    --border:       #e3e5ea;
    --text:         #1a1d22;
    --muted:        #6a7280;
    --accent:       #2563eb;
    --accent-hover: #1d4ed8;
    --danger:       #dc2626;
    --success:      #16a34a;
    --warn:         #d97706;
    --radius:       6px;
    --shadow:       0 1px 2px rgba(0,0,0,.04), 0 1px 3px rgba(0,0,0,.06);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button, .btn {
    appearance: none;
    border: 1px solid var(--border);
    background: var(--panel);
    color: var(--text);
    padding: .55rem 1rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
    line-height: 1.2;
    transition: background .12s, border-color .12s;
}
button:hover, .btn:hover { border-color: #c5c9d2; }
button:disabled { opacity: .55; cursor: not-allowed; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: white; }
button.primary:hover, .btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button.danger { background: white; border-color: var(--danger); color: var(--danger); }
button.danger:hover { background: var(--danger); color: white; }

input, select, textarea {
    appearance: none;
    border: 1px solid var(--border);
    background: white;
    border-radius: var(--radius);
    padding: .55rem .7rem;
    font-size: 14px;
    width: 100%;
    color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }

label { display: block; font-weight: 600; margin: .8rem 0 .35rem; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }

.boot { padding: 3rem; text-align: center; color: var(--muted); }

/* ---------------- Login ---------------- */
.login-wrap { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 1rem; }
.login-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 2rem; width: 100%; max-width: 380px; }
.login-card h1 { margin: 0 0 .25rem; font-size: 22px; }
.login-card .sub { color: var(--muted); margin-bottom: 1.25rem; font-size: 13px; }

/* ---------------- App shell ---------------- */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--border); padding: 1.2rem 1rem; display: flex; flex-direction: column; }
.sidebar .brand { font-weight: 700; font-size: 16px; margin-bottom: 1.5rem; }
.sidebar .brand .sub { font-weight: 400; font-size: 11px; color: var(--muted); display: block; }
.sidebar nav a { display: block; padding: .6rem .75rem; border-radius: var(--radius); color: var(--text); margin-bottom: .15rem; }
.sidebar nav a:hover { background: var(--bg); text-decoration: none; }
.sidebar nav a.active { background: var(--accent); color: white; }
.sidebar .user-info { margin-top: auto; padding-top: 1rem; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); }
.sidebar .user-info .who { color: var(--text); font-weight: 600; margin-bottom: .25rem; }
.sidebar .user-info button { width: 100%; margin-top: .5rem; font-size: 12px; padding: .4rem; }

main.content { padding: 1.75rem 2rem; overflow: auto; }
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.25rem; }
.page-header h2 { margin: 0; font-size: 22px; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card + .card { margin-top: 1rem; }
.card .body { padding: 1.25rem; }
.card h3 { margin: 0 0 .75rem; font-size: 15px; }

/* ---------------- Tables / lists ---------------- */
.video-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.video-item {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: var(--shadow);
    /* Flex column so .actions can be pinned to the bottom with margin-top:auto.
       Combined with the title's reserved 2-line height, this gives every card
       the same overall height and identical button alignment. */
    display: flex;
    flex-direction: column;
}
.video-item .name {
    font-weight: 600;
    margin-bottom: .35rem;
    line-height: 1.3;
    /* Reserve 2 lines so single-line titles don't produce shorter cards. */
    min-height: calc(1.3em * 2);
    /* Truncate at 2 lines with ellipsis if a title is unusually long. */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    overflow-wrap: anywhere;
    word-break: break-word;
}
.video-item .meta {
    font-size: 12px;
    color: var(--muted);
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0 .35rem;
    overflow-wrap: anywhere;
}
.video-item .meta .dot { opacity: .5; }
.video-item .actions {
    margin-top: auto;            /* pins to bottom of card */
    padding-top: .75rem;
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
}
.video-item .actions button, .video-item .actions .btn { padding: .35rem .65rem; font-size: 12px; }
.video-item .name-input {
    width: 100%;
    margin-bottom: .35rem;
    padding: .35rem .5rem;
    font-size: 14px;
    font-weight: 600;
    /* While editing, match the reserved 2-line space so the layout doesn't jump. */
    min-height: calc(1.3em * 2 + .7rem);
}

.project-list { list-style: none; padding: 0; margin: 0; }
.project-list li { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: .6rem; display: flex; align-items: center; justify-content: space-between; box-shadow: var(--shadow); }
.project-list .pname { font-weight: 600; }
.project-list .pdesc { color: var(--muted); font-size: 12px; margin-top: .15rem; }

.item-list { list-style: none; padding: 0; margin: 0; }
.item-list li { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem 1rem; margin-bottom: .4rem; display: flex; align-items: center; gap: .75rem; box-shadow: var(--shadow); }
.item-list .handle { color: var(--muted); cursor: grab; user-select: none; padding: 0 .25rem; font-size: 18px; line-height: 1; }
.item-list .pos { color: var(--muted); font-size: 12px; min-width: 1.5rem; }
.item-list .vname { flex: 1; }
.item-list li.sortable-ghost { opacity: .4; }
.item-list li.sortable-chosen { background: #f0f4ff; }

/* ---------------- Now playing ---------------- */
.np-card { display: flex; align-items: center; justify-content: space-between; }
.np-info { display: flex; align-items: center; gap: 1rem; }
.np-status { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.np-status.ok    { background: var(--success); }
.np-status.warn  { background: var(--warn); }
.np-status.stale { background: var(--danger); }
.np-screen-name { font-size: 18px; font-weight: 700; }
.np-meta { color: var(--muted); font-size: 12px; }

/* ---------------- Upload: drop zone + queue ---------------- */
.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 2rem 1rem;
    text-align: center;
    cursor: pointer;
    transition: border-color .12s, background .12s;
    background: #fafbfc;
}
.drop-zone:hover, .drop-zone:focus { border-color: var(--accent); outline: none; }
.drop-zone.dragover { border-color: var(--accent); background: #eef4ff; }
.drop-zone-icon { font-size: 28px; color: var(--accent); margin-bottom: .4rem; line-height: 1; }
.drop-zone-text { font-weight: 600; }
.drop-zone-hint { font-size: 12px; margin-top: .3rem; }

.upload-queue { margin-top: 1rem; display: flex; flex-direction: column; gap: .4rem; }
.upload-row {
    display: grid;
    grid-template-columns: 1fr 200px 220px;
    gap: 1rem;
    align-items: center;
    padding: .55rem .75rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
}
.upload-row-name    { word-break: break-word; min-width: 0; }
.upload-row-status  { text-align: right; font-size: 12px; color: var(--muted); }
.upload-row-status.error { color: var(--danger); }
.upload-row.done    { border-color: rgba(22,163,74,.4); background: rgba(22,163,74,.06); }
.upload-row.failed  { border-color: rgba(220,38,38,.4); background: rgba(220,38,38,.05); }
.upload-row.cancelled { opacity: .65; }
.upload-row .bar-track {
    height: 8px;
    background: white;
    border: 1px solid var(--border);
    border-radius: 999px;
    overflow: hidden;
}
.upload-row .bar-fill {
    height: 100%;
    width: 0%;
    background: var(--accent);
    transition: width .15s ease;
}
.upload-row.done .bar-fill   { background: var(--success); }
.upload-row.failed .bar-fill { background: var(--danger); width: 0%; }

.queue-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: .25rem; }
.queue-actions button { font-size: 12px; padding: .35rem .65rem; }

@media (max-width: 700px) {
    .upload-row { grid-template-columns: 1fr; gap: .35rem; }
    .upload-row-status { text-align: left; }
}

/* ---------------- Project preview modal ---------------- */
body.modal-open { overflow: hidden; }
.preview-modal {
    position: fixed; inset: 0;
    background: rgba(10, 12, 15, .92);
    z-index: 1000;
    display: flex;
    flex-direction: column;
}
.preview-close {
    position: absolute; top: .75rem; right: 1rem;
    width: 40px; height: 40px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,.1);
    color: white;
    font-size: 26px; line-height: 1;
    cursor: pointer;
    z-index: 2;
}
.preview-close:hover { background: rgba(255,255,255,.2); }
.preview-content {
    flex: 1; min-height: 0;
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 1rem;
    padding: 1rem;
}
@media (max-width: 800px) {
    .preview-content { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
    .preview-sidebar { max-height: 30vh; }
}
.preview-stage {
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: black;
    border-radius: var(--radius);
    overflow: hidden;
}
/* Double-buffered video stack: both <video> elements occupy the same area,
   only the .active one is visible. No transition — opacity flips instantly so
   we don't get any cross-fade ghost frame. */
.preview-video-wrap { position: relative; flex: 1 1 auto; min-height: 0; background: black; }
.preview-video {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    background: black;
    object-fit: contain;
    opacity: 0;
    pointer-events: none;
}
.preview-video.active { opacity: 1; pointer-events: auto; }

.preview-bottom {
    padding: .8rem 1rem;
    background: #15181c;
    color: white;
    display: flex; align-items: center; justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}
.preview-title   { font-size: 14px; font-weight: 600; }
.preview-counter { font-size: 12px; color: #9aa1ab; margin-top: 2px; }
.preview-hint    { font-size: 11px; color: #6e7681; }
.preview-ctls    { display: flex; gap: .35rem; }
.preview-ctl {
    background: rgba(255,255,255,.08);
    color: white;
    border: 1px solid rgba(255,255,255,.1);
    border-radius: var(--radius);
    padding: .4rem .65rem;
    font-size: 12px;
    cursor: pointer;
    min-width: 38px;
}
.preview-ctl:hover { background: rgba(255,255,255,.16); }

.preview-sidebar {
    background: #15181c;
    color: white;
    border-radius: var(--radius);
    overflow: auto;
    padding: 1rem;
}
.preview-side-header { padding-bottom: .75rem; border-bottom: 1px solid #2a2e34; margin-bottom: .5rem; }
.preview-side-project { font-weight: 700; font-size: 15px; }
.preview-side-meta    { font-size: 12px; color: #9aa1ab; margin-top: 2px; }
.preview-list { list-style: none; padding: 0; margin: 0; }
.preview-list li {
    padding: .5rem .6rem;
    border-radius: var(--radius);
    cursor: pointer;
    display: flex; gap: .5rem; align-items: baseline;
    font-size: 13px;
}
.preview-list li:hover { background: #1d2127; }
.preview-list li.active { background: var(--accent); }
.preview-list-pos  { color: #9aa1ab; font-size: 11px; min-width: 1.75rem; }
.preview-list li.active .preview-list-pos { color: rgba(255,255,255,.85); }
.preview-list-name { flex: 1; word-break: break-word; }

/* ---------------- Folder bar + view toggle ---------------- */
.folder-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .4rem;
    margin-bottom: 1rem;
}
.folder-bar .folder-bar-right { margin-left: auto; display: flex; align-items: center; gap: .5rem; }

.folder-chip, .folder-new {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    background: var(--panel);
    border: 1px solid var(--border);
    color: var(--text);
    padding: .35rem .7rem;
    font-size: 13px;
    border-radius: 999px;
    cursor: pointer;
    line-height: 1.2;
    transition: background .12s, border-color .12s;
}
.folder-chip:hover, .folder-new:hover { border-color: #c5c9d2; }
.folder-chip.active { background: var(--accent); border-color: var(--accent); color: white; }
.folder-chip .fc-count {
    background: rgba(0,0,0,.06);
    color: var(--muted);
    padding: 0 .45rem;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
}
.folder-chip.active .fc-count { background: rgba(255,255,255,.22); color: white; }
.folder-chip .fc-act {
    background: transparent;
    border: none;
    padding: 0 .15rem;
    margin: 0;
    color: inherit;
    opacity: .55;
    font-size: 13px;
    cursor: pointer;
    line-height: 1;
}
.folder-chip .fc-act:hover { opacity: 1; }
.folder-chip .fc-act.danger:hover { color: var(--danger); }
.folder-chip.active .fc-act.danger:hover { color: white; background: rgba(255,255,255,.18); border-radius: 4px; }

.folder-new {
    border-style: dashed;
    color: var(--muted);
    font-weight: 600;
}
.folder-new:hover { color: var(--accent); border-color: var(--accent); }

/* Drag-and-drop visual state */
body.dragging-item { cursor: grabbing; }
body.dragging-item .folder-chip.can-drop {
    outline: 2px dashed var(--accent);
    outline-offset: 2px;
    animation: pulse-target 1.6s ease-in-out infinite;
}
@keyframes pulse-target {
    0%, 100% { outline-color: var(--accent); }
    50%      { outline-color: rgba(37,99,235,.3); }
}
.folder-chip.drop-hover {
    background: var(--accent) !important;
    color: white !important;
    border-color: var(--accent) !important;
    transform: scale(1.04);
}
.folder-chip.drop-hover .fc-count { background: rgba(255,255,255,.22); color: white; }
.folder-chip.drop-flash {
    animation: flash-drop .6s ease;
}
@keyframes flash-drop {
    0%  { background: var(--success); border-color: var(--success); color: white; }
    100%{ }
}
.video-item.dragging,
.list-row.dragging { opacity: .4; }
.video-item, .list-row { cursor: grab; }
.video-item:active, .list-row:active { cursor: grabbing; }
/* Don't let cursor:grab override interactive children */
.video-item button, .video-item a, .video-item input, .video-item select,
.list-row    button, .list-row    a, .list-row    input, .list-row    select { cursor: pointer; }
.video-item input.name-input, .list-row input.name-input { cursor: text; }

/* View toggle */
.view-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.view-toggle-btn {
    background: var(--panel);
    border: none;
    padding: .35rem .55rem;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    color: var(--muted);
    min-width: 34px;
}
.view-toggle-btn + .view-toggle-btn { border-left: 1px solid var(--border); }
.view-toggle-btn:hover { background: var(--bg); }
.view-toggle-btn.active { background: var(--accent); color: white; }

/* Folder selector inside a video/project card */
.folder-row { display: flex; align-items: center; gap: .4rem; margin-top: .5rem; }
.folder-row .folder-label { font-size: 11px; text-transform: uppercase; letter-spacing: .03em; font-weight: 600; }
.move-to {
    padding: .25rem .35rem;
    font-size: 12px;
    border-radius: 4px;
    flex: 1;
    min-width: 0;
}

/* ---------------- List view (rows) ---------------- */
.list-view {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}
.list-row {
    display: grid;
    grid-template-columns: minmax(180px, 2.5fr) 1fr 1fr 1fr 1fr auto;
    gap: 1rem;
    align-items: center;
    padding: .65rem 1rem;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    min-height: 48px;
}
.list-row:last-child { border-bottom: none; }
.list-head {
    background: var(--bg);
    font-weight: 600;
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .03em;
    min-height: 36px;
    padding-top: .45rem;
    padding-bottom: .45rem;
}
.lr-name-text { font-weight: 600; word-break: break-word; overflow-wrap: anywhere; }
.lr-meta-col  { color: var(--muted); font-variant-numeric: tabular-nums; }
.lr-folder    { display: flex; }
.lr-folder .move-to { width: 100%; }
.lr-actions   { display: flex; gap: .35rem; justify-content: flex-end; flex-wrap: wrap; }
.lr-actions button, .lr-actions .btn { padding: .3rem .55rem; font-size: 12px; }
.lr-actions .name-input { width: 100%; }

@media (max-width: 900px) {
    .list-row { grid-template-columns: 1fr; gap: .25rem; min-height: 0; padding: .75rem 1rem; }
    .list-head { display: none; }
    .lr-actions { justify-content: flex-start; margin-top: .25rem; }
}

/* ---------------- Team page ---------------- */
.self-badge {
    display: inline-block;
    margin-left: .5rem;
    padding: .05rem .4rem;
    background: var(--accent);
    color: white;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    border-radius: 999px;
    vertical-align: middle;
}

/* ---------------- Draft / publish ---------------- */
.dirty-badge {
    color: var(--warn);
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
}
.publish-btn:disabled {
    background: var(--bg);
    color: var(--muted);
    border-color: var(--border);
    opacity: 1; /* override the generic disabled fade -- we want a plain "nothing to publish" look, not a faded blue */
}

/* ---------------- Misc ---------------- */
.empty-state { padding: 2.5rem; text-align: center; color: var(--muted); border: 2px dashed var(--border); border-radius: var(--radius); }
.row { display: flex; gap: .5rem; align-items: center; }
.row > * { flex: 0 0 auto; }
.row .grow { flex: 1 1 auto; }
.error  { color: var(--danger); margin-top: .5rem; font-size: 13px; }
.notice { color: var(--success); margin-top: .5rem; font-size: 13px; }
.muted  { color: var(--muted); }
.spacer { height: 1rem; }
.hidden { display: none !important; }
