/* ===== SnusVikings Portal - Design System ===== */

:root {
    --bg-primary: #0f1117;
    --bg-secondary: #161822;
    --bg-tertiary: #1c1f2e;
    --bg-elevated: #222538;
    --bg-hover: #282b3d;

    --border: #2a2d3e;
    --border-light: #353849;

    --text-primary: #e8eaf0;
    --text-secondary: #9598a6;
    --text-muted: #6b6e7d;

    --accent: #6c5ce7;
    --accent-hover: #7c6ff0;
    --accent-subtle: rgba(108, 92, 231, 0.12);

    --success: #2ecc71;
    --success-subtle: rgba(46, 204, 113, 0.12);
    --danger: #e74c3c;
    --danger-subtle: rgba(231, 76, 60, 0.12);
    --warning: #f39c12;

    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 2px 8px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);

    --sidebar-width: 220px;
    --topbar-height: 56px;

    --transition: 150ms ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ===== Topbar ===== */
.app-topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 100;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
}

.sidebar-toggle:hover { color: var(--text-primary); background: var(--bg-hover); }

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 15px;
    color: var(--text-primary);
}

.brand-icon { color: var(--accent); }

.topbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
}

.user-role {
    font-size: 11px;
    background: var(--accent-subtle);
    color: var(--accent);
    padding: 2px 8px;
    border-radius: 10px;
    text-transform: capitalize;
}

.topbar-logout {
    color: var(--text-muted);
    display: flex;
    padding: 6px;
    border-radius: 6px;
    transition: var(--transition);
}

.topbar-logout:hover { color: var(--danger); background: var(--danger-subtle); }

/* ===== Layout ===== */
.app-layout {
    display: flex;
    padding-top: var(--topbar-height);
    min-height: 100vh;
}

.app-sidebar {
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    padding: 16px 12px;
    overflow-y: auto;
    z-index: 90;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    transition: var(--transition);
}

.nav-item:hover { color: var(--text-primary); background: var(--bg-hover); }

.nav-item.active {
    color: var(--text-primary);
    background: var(--accent-subtle);
}

.nav-item.active svg { color: var(--accent); }

.app-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 28px 32px;
    max-width: 1200px;
}

/* ===== Page Header ===== */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 24px;
}

.page-header h1 {
    font-size: 22px;
    font-weight: 600;
}

.page-subtitle {
    color: var(--text-secondary);
    font-size: 13px;
    margin-top: 2px;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-danger {
    background: var(--danger-subtle);
    color: var(--danger);
}
.btn-danger:hover { background: var(--danger); color: #fff; }

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.btn-ghost:hover { border-color: var(--border-light); color: var(--text-primary); background: var(--bg-hover); }

.btn-sm { padding: 5px 10px; font-size: 12px; }

.btn-full { width: 100%; justify-content: center; }

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== Preview Strip ===== */
.preview-strip {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 20px;
    margin-bottom: 24px;
}

.preview-strip-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.preview-strip-slides {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
}

.preview-thumb {
    flex: 0 0 auto;
    width: 120px;
    height: 48px;
    border-radius: 6px;
    overflow: hidden;
    border: 2px solid transparent;
    position: relative;
    cursor: pointer;
    transition: var(--transition);
}

.preview-thumb.active { border-color: var(--accent); }
.preview-thumb.inactive { opacity: 0.4; }

.preview-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.preview-thumb-label {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 2px 6px;
    background: rgba(0,0,0,0.7);
    font-size: 10px;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.preview-thumb-placeholder {
    width: 100%;
    height: 100%;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 10px;
}

.preview-thumb-order {
    position: absolute;
    top: 2px;
    left: 4px;
    font-size: 9px;
    font-weight: 700;
    color: #fff;
    background: rgba(0,0,0,0.6);
    padding: 0 4px;
    border-radius: 3px;
}

/* ===== Slide Cards ===== */
.slides-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.slide-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    cursor: grab;
    transition: var(--transition);
    user-select: none;
}

.slide-card:hover { border-color: var(--border-light); }

.slide-card.dragging {
    opacity: 0.5;
    border-color: var(--accent);
}

.slide-card.drag-over {
    border-color: var(--accent);
    background: var(--accent-subtle);
}

.slide-drag-handle {
    color: var(--text-muted);
    cursor: grab;
    flex-shrink: 0;
}

.slide-thumb {
    width: 80px;
    height: 45px;
    border-radius: 6px;
    overflow: hidden;
    flex-shrink: 0;
    background: var(--bg-tertiary);
}

.slide-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.slide-thumb-empty {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 10px;
}

.slide-info {
    flex: 1;
    min-width: 0;
}

.slide-heading {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.slide-subheading {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.slide-meta {
    display: flex;
    gap: 12px;
    margin-top: 4px;
}

.slide-meta-item {
    font-size: 11px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 4px;
}

.slide-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.slide-status {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.slide-status.active { background: var(--success); box-shadow: 0 0 6px var(--success); }
.slide-status.inactive { background: var(--text-muted); }

.slide-edit-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    transition: var(--transition);
}

.slide-edit-btn:hover { color: var(--text-primary); background: var(--bg-hover); }

/* ===== Modal ===== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.open { display: flex; }

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 680px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-sm { max-width: 440px; }

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 { font-size: 16px; font-weight: 600; }

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    line-height: 1;
}

.modal-close:hover { color: var(--text-primary); background: var(--bg-hover); }

.modal-body { padding: 24px; }

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    margin-top: 20px;
}

/* ===== Forms ===== */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="email"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    transition: var(--transition);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-subtle);
}

.form-group input::placeholder { color: var(--text-muted); }

.form-hint {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
    display: block;
}

.form-row { }
.form-row.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* Toggle switch */
.toggle-label {
    display: flex !important;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    text-transform: none !important;
    font-size: 14px !important;
    font-weight: 500 !important;
    color: var(--text-primary) !important;
}

.toggle-label input { display: none; }

.toggle-switch {
    width: 40px;
    height: 22px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 11px;
    position: relative;
    transition: var(--transition);
    flex-shrink: 0;
}

.toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: var(--transition);
}

.toggle-label input:checked + .toggle-switch {
    background: var(--accent);
    border-color: var(--accent);
}

.toggle-label input:checked + .toggle-switch::after {
    transform: translateX(18px);
    background: #fff;
}

/* Image upload */
.image-upload {
    position: relative;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: var(--transition);
    aspect-ratio: 16/9;
}

.image-upload:hover { border-color: var(--accent); }

.file-input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    z-index: 2;
}

.upload-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 8px;
    color: var(--text-muted);
    font-size: 12px;
    padding: 16px;
    text-align: center;
}

.upload-preview {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: none;
}

.upload-preview.visible { display: block; }
.upload-preview.visible + .upload-placeholder,
.upload-preview.visible ~ .upload-placeholder { display: none; }

/* ===== Data Table ===== */
.users-table-wrap { overflow-x: auto; }

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    text-align: left;
    padding: 10px 16px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

.data-table td {
    padding: 14px 16px;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
}

.data-table td strong { color: var(--text-primary); }

.data-table tr:hover td { background: var(--bg-tertiary); }

.actions-cell { text-align: right; }

.badge {
    font-size: 10px;
    background: var(--accent-subtle);
    color: var(--accent);
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 6px;
}

.role-badge {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    text-transform: capitalize;
}

.role-admin { background: var(--accent-subtle); color: var(--accent); }
.role-editor { background: var(--success-subtle); color: var(--success); }

/* ===== Settings ===== */
.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.settings-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
}

.settings-card h3 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 20px;
}

.connection-status {
    margin-bottom: 20px;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
}

.status-dot.connected { background: var(--success); box-shadow: 0 0 6px var(--success); }
.status-dot.error { background: var(--danger); box-shadow: 0 0 6px var(--danger); }

.connection-details { margin-bottom: 16px; }

.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

.detail-label { color: var(--text-muted); }
.detail-value { color: var(--text-primary); font-weight: 500; }

/* ===== Alerts ===== */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 16px;
}

.alert-error {
    background: var(--danger-subtle);
    color: var(--danger);
    border: 1px solid rgba(231, 76, 60, 0.2);
}

.alert-success {
    background: var(--success-subtle);
    color: var(--success);
    border: 1px solid rgba(46, 204, 113, 0.2);
}

/* ===== Toast ===== */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 13px;
    box-shadow: var(--shadow-lg);
    animation: slideInRight 200ms ease;
    max-width: 360px;
}

.toast-success { background: #1a3a2a; color: var(--success); border: 1px solid rgba(46,204,113,0.3); }
.toast-error { background: #3a1a1a; color: var(--danger); border: 1px solid rgba(231,76,60,0.3); }

@keyframes slideInRight {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ===== Loading ===== */
.loading-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 12px;
}

.spinner-sm {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    vertical-align: middle;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Empty state ===== */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state svg { margin-bottom: 12px; opacity: 0.5; }
.empty-state p { font-size: 14px; margin-bottom: 16px; }

/* ===== Login ===== */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg-primary);
}

.login-container { width: 100%; max-width: 400px; padding: 20px; }

.login-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 36px 32px;
}

.login-header {
    text-align: center;
    margin-bottom: 28px;
}

.login-logo { color: var(--accent); margin-bottom: 12px; }

.login-header h1 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 4px;
}

.login-header p {
    font-size: 13px;
    color: var(--text-secondary);
}

.login-form .form-group { margin-bottom: 18px; }

.login-form .btn { margin-top: 8px; padding: 12px; font-size: 14px; }

.login-footer {
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 20px;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .sidebar-toggle { display: flex; }

    .app-sidebar {
        transform: translateX(-100%);
        transition: transform 200ms ease;
    }

    .app-sidebar.open { transform: translateX(0); }

    .app-main {
        margin-left: 0;
        padding: 20px 16px;
    }

    .form-row.two-col { grid-template-columns: 1fr; }
    .settings-grid { grid-template-columns: 1fr; }

    .page-header {
        flex-direction: column;
        gap: 12px;
    }
}
