/*
 * Admin Panel Styles
 * Re-skinned on the site design tokens (styles.css :root). Only layout and
 * admin-specific components live here; palette, radii and typography come
 * from the shared tokens so the admin panel tracks the rest of the site.
 */

/* --- App shell: admin is a fixed-height app, not a scrolling page --- */
html {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
}

body {
    margin: 0;
    padding: 0;
    height: 100vh;
    overflow: hidden;
    /* background / color / font inherit from styles.css */
}

.container {
    height: 100vh;
    width: 100vw;
    display: flex;
    flex-direction: column;
    padding: 0;
    margin: 0;
    max-width: none;
    min-height: 0;
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
}

/* --- Header (mirrors the site's .topbar) --- */
.header {
    padding: 14px 30px;
    background: rgba(10, 7, 16, 0.82);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 18px;
}

/* Same cap as the rest of the site (was max-height: 80px) */
.header img {
    height: 40px;
    max-height: 52px;
    width: auto;
    display: block;
    filter: drop-shadow(0 0 8px var(--accent-glow));
}

/* Solid near-white title, no gradient text */
.header h1 {
    font-family: 'CustomTitle', 'Chakra Petch', 'Roboto Mono', monospace;
    color: var(--text);
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: 1px;
    margin: 0;
    text-align: left;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* One size for all header buttons. The margin reset matters: styles.css
   carries legacy bottom margins on #logout-button / #refresh-shares, which
   is why Clear Cache rendered taller. */
#logout-button,
#refresh-shares,
#clear-cache {
    margin: 0;
    height: 36px;
    padding: 0 14px;
}

/* Danger ghost for logout (matches site button.danger) */
#logout-button {
    background: transparent;
    color: #ff6b6b;
    border-color: rgba(255, 107, 107, 0.3);
}
#logout-button:hover {
    background: rgba(255, 107, 107, 0.1);
    border-color: rgba(255, 107, 107, 0.5);
    color: #ff8585;
}

/* --- Layout panes --- */
#admin-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    width: 100%;
}

.admin-content-wrapper {
    flex: 1;
    padding: 20px;
    overflow: hidden;
    display: flex;
}

.admin-2pane {
    display: flex;
    gap: 20px;
    height: 100%;
    width: 100%;
}

.admin-pane {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

/* --- Sections: neutral site surface, no sheen/lift --- */
.admin-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 15px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3),
                inset 0 1px 0 rgba(255, 255, 255, 0.05);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
    max-height: 100%;
}

.admin-section h2 {
    color: var(--text);
    font-size: 0.95rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin: 0 0 12px 0;
    flex-shrink: 0;
}

/* Form pane scrolls when tall; table pane scrolls internally */
.admin-section:has(.grid-form) {
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-gutter: stable;
}

.admin-section:has(table) > table {
    display: block;
    overflow-y: auto;
    overflow-x: hidden;
    max-height: calc(100% - 40px);
}

/* --- Tabs: quiet until active, active = surface + accent underline --- */
.tab-header {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 15px;
    flex-shrink: 0;
}

.tab-btn {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    border-radius: var(--r-sm) var(--r-sm) 0 0;
    color: var(--text-mute);
    padding: 10px 16px;
    margin-bottom: -1px;
    cursor: pointer;
}

.tab-btn:hover {
    color: var(--text);
    background: var(--accent-tint);
    transform: none;
}

.tab-btn.active {
    color: var(--text);
    background: var(--surface-2);
    border-bottom-color: var(--accent);
    box-shadow: none;
}

.tab-content {
    flex: 1 1 0;
    min-height: 0;
    min-width: 0;
    overflow-y: auto;
    padding-bottom: 10px;
}

/* --- Buttons: ghost style, matching the site --- */
button {
    font-family: 'CustomButton', 'Chakra Petch', 'Roboto Mono', monospace;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: var(--surface-2);
    color: var(--text-mute);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    padding: 8px 16px;
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    cursor: pointer;
    box-shadow: none;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

button::before {
    content: none;
}

button:hover {
    background: var(--accent-tint);
    color: var(--accent);
    border-color: var(--border-accent);
    box-shadow: none;
    transform: none;
}

button:active {
    transform: translateY(1px);
}

button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Primary accent fill: one per form (Share / Login / Save) */
button[type="submit"],
#save-edit-button,
#save-edit-tag-button {
    background: var(--accent);
    color: #fff;
    border-color: transparent;
}
button[type="submit"] {
    width: 100%;
    padding: 10px 16px;
    margin-top: 5px;
}
button[type="submit"]:hover,
#save-edit-button:hover,
#save-edit-tag-button:hover {
    background: var(--accent-soft);
    color: #fff;
    border-color: transparent;
}

/* Table action buttons: small ghosts */
.copy-button, .edit-button, .edit-tag-button,
.delete-button, .delete-tag-button {
    padding: 4px 8px;
    font-size: 0.7rem;
    margin: 0 2px;
    background: transparent;
}
.copy-button:hover, .edit-button:hover, .edit-tag-button:hover {
    background: var(--surface-2);
    color: var(--text);
    border-color: var(--border-accent);
}
.delete-button, .delete-tag-button {
    color: #ff6b6b;
    border-color: rgba(255, 107, 107, 0.3);
}
.delete-button:hover, .delete-tag-button:hover {
    background: rgba(255, 107, 107, 0.1);
    border-color: rgba(255, 107, 107, 0.5);
    color: #ff8585;
}

/* --- Forms --- */
.grid-form {
    display: grid;
    gap: 10px;
}

.grid-form label {
    color: var(--text-mute);
    font-size: 0.8rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: -6px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.login-form label {
    color: var(--text-mute);
    font-size: 0.8rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0;
}

.grid-form input[type="text"],
.grid-form input[type="number"],
.grid-form input[type="password"],
.grid-form select,
.login-form input[type="text"],
.login-form input[type="password"] {
    background: var(--bg);
    border: 1px solid var(--border-accent);
    color: var(--text-dim);
    padding: 10px 12px;
    border-radius: var(--r-sm);
    font-size: 0.9rem;
    width: 100%;
    box-sizing: border-box;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.grid-form input:focus,
.grid-form select:focus,
.login-form input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-tint);
    background: var(--surface-2);
}

/* Site-style select with chevron (appearance:none removes the native arrow) */
.grid-form select {
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
    padding-right: 38px;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23ff6ec7' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
}

.input-group {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    width: 100%;
}
.input-group input {
    width: 100%;
}
.input-group button {
    white-space: nowrap;
    width: auto;
}

/* --- Toggle switches --- */
.grid-form input[type="checkbox"] {
    display: none;
}

.checkbox-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 5px;
}

.toggle-switch {
    position: relative;
    width: 44px;
    height: 22px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 11px;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease;
    flex-shrink: 0;
}
.toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: var(--text-mute);
    border-radius: 50%;
    transition: transform 0.2s ease, background 0.2s ease;
}
input[type="checkbox"]:checked + .toggle-switch {
    background: var(--accent-tint);
    border-color: var(--border-accent);
}
input[type="checkbox"]:checked + .toggle-switch::after {
    transform: translateX(24px);
    background: var(--accent);
}
.checkbox-label {
    color: var(--text-dim);
    font-size: 0.85rem;
    cursor: pointer;
}

/* --- Messages --- */
.success-message {
    color: var(--accent-soft);
    font-size: 0.85rem;
    margin-top: 10px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}
.error-message {
    color: #ff4458;
    font-size: 0.85rem;
    margin-top: 10px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* --- Tables --- */
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    table-layout: fixed;
}

th {
    background: var(--surface);
    color: var(--text-dim);
    padding: 10px 8px;
    text-align: left;
    text-transform: uppercase;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 1px;
    position: sticky;
    top: 0;
    z-index: 10;
    border-bottom: 1px solid var(--border-accent);
}

td {
    padding: 10px 8px;
    border-bottom: 1px solid var(--border);
    color: var(--text-dim);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

tr {
    transition: background 0.2s ease;
}
tbody tr:hover {
    background: var(--accent-tint);
}

td a {
    color: var(--accent-soft);
    text-decoration: none;
    transition: color 0.2s ease;
}
td a:hover {
    color: var(--accent);
    text-decoration: underline;
}

/* --- Column widths ---
 * table-layout: fixed reads widths from the header row, and the two tables
 * now have different column counts — so each table gets its own nth-child
 * map. Column 1 (Video / Tag Name) is deliberately unset: it absorbs all
 * leftover space. */
#shared-videos-table th:nth-child(2),
#shared-videos-table td:nth-child(2) {   /* Stash ID */
    width: 72px;
}
#shared-videos-table th:nth-child(3),
#shared-videos-table td:nth-child(3) {   /* Hits */
    width: 48px;
    text-align: center;
}
#shared-videos-table th:nth-child(4),
#shared-videos-table td:nth-child(4) {   /* Expires */
    width: 64px;
}
#shared-videos-table th:nth-child(5),
#shared-videos-table td:nth-child(5) {   /* Actions */
    width: 190px;
    text-align: center;
    white-space: nowrap;
}

#shared-tags-table th:nth-child(2),
#shared-tags-table td:nth-child(2) {     /* Hits */
    width: 48px;
    text-align: center;
}
#shared-tags-table th:nth-child(3),
#shared-tags-table td:nth-child(3) {     /* Expires */
    width: 64px;
}
#shared-tags-table th:nth-child(4),
#shared-tags-table td:nth-child(4) {     /* Actions */
    width: 190px;
    text-align: center;
    white-space: nowrap;
}

/* Slugs stay on one line with ellipsis (the full title is the cell tooltip).
   Overrides the white-space:normal on column 1 from styles.css. */
#shared-videos-table td:first-child {
    white-space: nowrap;
    word-break: normal;
}

/* The ∳ password marker */
.password-mark {
    margin-left: 2px;
    color: var(--accent-soft);
}

/* --- Modals (the tag modal was never styled before) --- */
#edit-modal,
#edit-tag-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--surface);
    padding: 30px;
    border-radius: var(--r-md);
    border: 1px solid var(--border-accent);
    z-index: 1000;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(20px);
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-sizing: border-box;
}

#edit-modal h3,
#edit-tag-modal h3 {
    margin-top: 0;
    font-size: 1.1rem;
}

.modal-buttons {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    justify-content: flex-end;
    grid-column: 1 / -1;
}

/* --- Login --- */
#login-section {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    width: 100vw;
}
#login-section .admin-section {
    max-width: 400px;
    width: 90%;
    overflow: visible;
}

/* --- Video title autocomplete --- */
#share-pane,
#tab-content-share-video,
#share-form {
    overflow: visible;
}

.admin-autocomplete {
    grid-column: 1 / -1;
    position: relative;
    width: 100%;
}

.admin-autocomplete-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 50;
    display: none;
    max-height: 260px;
    overflow-y: auto;
    background: var(--surface-2);
    border: 1px solid var(--border-accent);
    border-radius: var(--r-sm);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.video-search-result {
    width: 100%;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    border: 0;
    background: transparent;
    color: var(--text-dim);
    text-align: left;
    font: inherit;
    font-size: 0.85rem;
    text-transform: none;
    letter-spacing: normal;
    box-shadow: none;
    border-radius: 0;
}
.video-search-result::before {
    content: none;
}
.video-search-result:hover,
.video-search-result.active {
    background: var(--accent-tint);
    color: var(--text);
    transform: none;
    box-shadow: none;
}
.video-search-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.video-search-id {
    flex: 0 0 auto;
    color: var(--text-mute);
    font-size: 0.85rem;
}

/* --- Scrollbars (hidden, same as the site) --- */
::-webkit-scrollbar {
    width: 0;
    height: 0;
}

/* --- Responsive --- */
@media (max-width: 1200px) {
    .admin-2pane {
        flex-direction: column;
        gap: 10px;
    }
}

@media (max-width: 768px) {
    .header {
        padding: 10px 15px;
        flex-direction: column;
        gap: 10px;
    }
    .header-left {
        flex-direction: column;
        gap: 10px;
    }
    .header-controls {
        width: 100%;
        justify-content: center;
    }
    .admin-content-wrapper {
        padding: 10px;
    }
    .admin-section {
        padding: 12px;
    }
}