/* Common Styles - Unified Design for All Pages */
:root {
    --primary: #6366f1;
    --primary-rgb: 99, 102, 241;
    --secondary: #06b6d4;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --dark: #0f172a;
    --light: #f8fafc;
    --surface: #ffffff;
    --muted: #94a3b8;
    --text-primary: #0f172a;
    --text-color: #0f172a;
    --bg-color: #f8fafc;
    --text-on-dark: #f8fafc;
    --card-bg: rgba(255, 255, 255, 0.85);
    --border-color: rgba(99, 102, 241, 0.12);
    --shadow: 0 4px 12px -4px rgba(15, 23, 42, 0.12);
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: 1px solid rgba(255, 255, 255, 0.3);
    --primary-gradient: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
    --secondary-gradient: linear-gradient(135deg, #06b6d4 0%, #22d3ee 100%);
    --danger-gradient: linear-gradient(135deg, #ef4444 0%, #f87171 100%);
}

[data-bs-theme="dark"] {
    --card-bg: rgba(15, 23, 42, 0.8);
    --border-color: rgba(99, 102, 241, 0.2);
    --light: #020617;
    --text-color: #f1f5f9;
    --bg-color: #0f172a;
    --text-primary: #f1f5f9;
    --muted: #94a3b8;
    --text-muted: #94a3b8;
    color: #f1f5f9;
    --shadow: 0 4px 12px -4px rgba(0, 0, 0, 0.2);
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: 1px solid rgba(255, 255, 255, 0.05);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--text-primary);
    background: var(--light);
    transition: color 0.25s ease, background 0.25s ease;
    min-height: 100vh;
    line-height: 1.5;
}

.app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.shell-header {
    position: sticky;
    top: 0;
    z-index: 1020;
    background: rgba(255, 255, 255, 0.97);
    border-bottom: 1px solid rgba(15, 23, 42, 0.08);
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

.app-shell main,
.app-shell .shell-body {
    padding-top: 1rem;
}

[data-bs-theme="dark"] .shell-header {
    background: rgba(15, 23, 42, 0.97);
    border-color: rgba(255, 255, 255, 0.08);
}

.shell-header .brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.shell-header .brand i {
    font-size: 1.8rem;
    color: var(--primary);
}

.shell-header .brand h1 {
    font-size: clamp(1.1rem, 2vw, 1.4rem);
    margin: 0;
    font-weight: 700;
}

.shell-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 0;
}

.shell-toolbar .filter-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    width: 100%;
}

@media (min-width: 768px) {
    .shell-toolbar .filter-group {
        width: auto;
    }
}

.quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.quick-actions .btn {
    border-radius: 999px;
    padding-inline: 1rem;
}

/* Navbar */
.navbar-custom {
    background: rgba(var(--primary-rgb), 0.95);
    padding: 0.75rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    position: sticky;
    top: 0;
    z-index: 1000;
}

/* Cards */
.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 1.5rem;
    height: 100%;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}

.stat-card:hover {
    border-color: rgba(var(--primary-rgb), 0.3);
}

.glass-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

/* Icons */
.stat-icon {
    width: 54px;
    height: 54px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    margin-bottom: 1rem;
}

.bg-icon-primary {
    background: rgba(99, 102, 241, 0.12);
    color: var(--primary);
}

.bg-icon-success {
    background: rgba(16, 185, 129, 0.12);
    color: var(--success);
}

.bg-icon-warning {
    background: rgba(245, 158, 11, 0.12);
    color: var(--warning);
}

.bg-icon-danger {
    background: rgba(239, 68, 68, 0.12);
    color: var(--danger);
}

/* Typography */
.stat-value {
    font-size: 2.25rem;
    font-weight: 800;
    letter-spacing: -0.025em;
    margin-bottom: 0.25rem;
    color: var(--text-primary);
}

.stat-label {
    color: #64748b;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

[data-bs-theme="dark"] .stat-label {
    color: #94a3b8;
}

/* Tables */
.table-custom th {
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.1em;
    background: transparent;
    border-bottom: 2px solid var(--border-color);
    color: var(--text-muted);
    padding: 1.25rem 0.75rem;
}

.table-custom td {
    vertical-align: middle;
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 0.75rem;
    color: var(--text-primary);
}

.table-custom tr:last-child td {
    border-bottom: none;
}

/* Progress Bars */
.progress-thin {
    height: 8px;
    border-radius: 10px;
    background-color: rgba(0,0,0,0.05);
    margin-top: 1rem;
    overflow: hidden;
    border: 1px solid rgba(0,0,0,0.02);
}

[data-bs-theme="dark"] .progress-thin {
    background-color: rgba(255,255,255,0.05);
}

/* Badges */
.badge-live {
    background: #ef4444;
    color: white;
    padding: 0.35rem 0.65rem;
    border-radius: 8px;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
}

/* Status Dot */
.status-dot {
    height: 10px;
    width: 10px;
    background-color: #94a3b8;
    border-radius: 50%;
    display: inline-block;
    margin-right: 8px;
    position: relative;
}

.status-dot.online {
    background-color: #10b981;
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}

/* Search */
.search-container {
    position: relative;
    margin: 2rem 0;
    width: 100%;
}

.search-container i {
    position: absolute;
    left: 1.25rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 1.1rem;
}

.search-input {
    padding: 1rem 1rem 1rem 3.5rem;
    border-radius: 16px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    box-shadow: var(--shadow);
    width: 100%;
    font-size: 1rem;
    color: var(--text-primary);
}

.search-input:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
    color: var(--text-primary);
}

/* Buttons */
.btn-glass {
    background: rgba(255,255,255,0.2);
    border: 1px solid rgba(255,255,255,0.3);
    color: white;
}

.btn-glass:hover {
    background: rgba(255,255,255,0.3);
    color: white;
}

/* Mobile Adjustments */
@media (max-width: 768px) {
    .navbar-custom .container {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }

    .navbar-custom .d-flex {
        width: 100%;
        justify-content: center;
    }

    .stat-card {
        padding: 1.25rem;
    }

    .stat-value {
        font-size: 1.75rem;
    }

    .hide-mobile {
        display: none !important;
    }

    .table-custom th, .table-custom td {
        padding: 0.75rem 0.5rem;
        font-size: 0.8rem;
    }

    .search-input {
        padding: 0.75rem 0.75rem 0.75rem 2.5rem;
        font-size: 0.9rem;
    }

    .search-container i {
        left: 1rem;
    }
}

/* Channel Grid */
.channel-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

.channel-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 18px;
    border: 1px solid rgba(15,23,42,0.08);
    box-shadow: var(--shadow);
    cursor: grab;
    transition: border-color 0.2s ease;
    color: var(--text-primary);
    contain: layout style paint;
}

.channel-card:hover {
    border-color: rgba(99,102,241,0.35);
}

.channel-card.active-proxy {
    border-color: rgba(16, 185, 129, 0.6);
}

.channel-card.inactive-proxy {
    opacity: 0.85;
}

[data-bs-theme="dark"] .channel-card {
    border-color: rgba(255,255,255,0.08);
}

[data-bs-theme="dark"] .channel-card:hover {
    border-color: rgba(99,102,241,0.5);
}

[data-bs-theme="dark"] .hero-card {
    border-color: rgba(255,255,255,0.08);
}

/* EPG Progress */
.progress-epg {
    height: 2px;
    border-radius: 2px;
    background: rgba(0,0,0,0.1);
    margin-top: 6px;
    overflow: hidden;
}

.progress-epg .bar {
    height: 100%;
    background: var(--primary);
    width: 0%;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
}

.toast {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    border-radius: 12px;
    padding: 12px 16px;
    margin-bottom: 10px;
    min-width: 250px;
    animation: slideIn 0.2s ease;
}

.toast.success {
    border-left: 4px solid #10b981;
}

.toast.error {
    border-left: 4px solid #ef4444;
}

.toast.info {
    border-left: 4px solid #3b82f6;
}

@keyframes slideIn {
    from { transform: translateX(400px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes slideOut {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(400px); opacity: 0; }
}

.toast.hiding {
    animation: slideOut 0.3s ease;
}

/* Loading Spinner */
.loading-spinner {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10000;
    display: none;
}

.loading-spinner.active {
    display: block;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(99, 102, 241, 0.2);
    border-top-color: #6366f1;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Log Console */
.log-console {
    background: #0f172a;
    color: #34d399;
    font-family: 'Fira Code', 'Courier New', monospace;
    font-size: 0.8rem;
    padding: 1.5rem;
    border-radius: 0 0 16px 16px;
    height: 400px;
    overflow-y: auto;
}

/* EPG Guide Items */
.epg-guide-item {
    padding: 0.75rem;
    border-bottom: 1px solid rgba(0,0,0,0.05);
    cursor: pointer;
    color: var(--text-primary);
}

.epg-guide-item:hover {
    background: rgba(99, 102, 241, 0.05);
}

.epg-guide-item.current {
    background: rgba(99, 102, 241, 0.1);
    border-left: 3px solid var(--primary);
}

.epg-guide-item.current .epg-time {
    color: var(--primary);
    font-weight: 600;
}

.epg-time {
    color: var(--muted);
    font-weight: 500;
    margin-right: 0.5rem;
}

.epg-cat {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
}

.epg-desc {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.2s ease;
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--text-primary);
}

.epg-guide-item.expanded .epg-desc {
    max-height: 500px;
    margin-top: 0.5rem;
}

[data-bs-theme="dark"] .epg-guide-item {
    border-bottom-color: rgba(255,255,255,0.05);
}

[data-bs-theme="dark"] .epg-guide-item:hover {
    background: rgba(99, 102, 241, 0.1);
}

/* Log Container */
.log-container {
    background: #0f172a;
    color: #34d399;
    font-family: 'Courier New', monospace;
    font-size: 0.8rem;
    padding: 1.5rem;
    border-radius: 16px;
    height: 300px;
    overflow-y: auto;
    border: 1px solid rgba(255,255,255,0.05);
}

.log-entry {
    margin-bottom: 4px;
    border-bottom: 1px solid rgba(255,255,255,0.02);
    padding-bottom: 2px;
}

.log-ts {
    color: var(--text-muted);
    margin-right: 10px;
}

/* Device Icon */
.device-icon {
    font-size: 1.2rem;
    margin-right: 8px;
    color: var(--primary);
}

/* Responsive table helper */
.table-modern {
    width: 100%;
}

@media (max-width: 768px) {
    .table-modern thead {
        display: none;
    }
    .table-modern tbody tr {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.25rem 0.5rem;
        padding: 1rem;
        border: 1px solid rgba(15,23,42,0.08);
        border-radius: 12px;
        margin-bottom: 0.75rem;
        background: var(--card-bg);
    }
    .table-modern td {
        border: none;
        padding: 0;
        color: var(--text-color);
    }
    .table-modern td[data-label]::before {
        content: attr(data-label);
        font-size: 0.75rem;
        letter-spacing: 0.08em;
        text-transform: uppercase;
        color: var(--text-muted);
        display: block;
        margin-bottom: 0.2rem;
    }
}

[data-bs-theme="dark"] .action-pill {
    background: rgba(15,23,42,0.6);
    border-color: rgba(255,255,255,0.1);
    color: #f1f5f9;
}

.action-pill i {
    margin-right: 0.35rem;
}

/* Mobile dock */
.mobile-dock {
    position: fixed;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 23, 42, 0.95);
    color: #fff;
    border-radius: 999px;
    padding: 0.4rem 1rem;
    display: flex;
    gap: 0.5rem;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.2);
    z-index: 1080;
}

.mobile-dock .btn {
    color: inherit;
    border: none;
    background: transparent;
}

@media (min-width: 768px) {
    .mobile-dock {
        display: none;
    }
}

/* Mobile Landscape Optimization */
@media (max-height: 500px) and (orientation: landscape) {
    .shell-header {
        padding: 0.15rem 0;
    }
    .shell-header .brand {
        gap: 0.35rem;
    }
    .shell-header .brand h1 {
        font-size: 0.85rem;
        margin: 0;
    }
    .shell-header .brand small {
        display: none;
    }
    .shell-header .brand i {
        font-size: 1rem;
    }
    .shell-header .container {
        padding-top: 0.15rem !important;
        padding-bottom: 0.15rem !important;
        gap: 0.5rem !important;
    }
    .shell-toolbar {
        padding: 0.2rem 0;
    }
    .shell-toolbar .filter-group {
        flex-wrap: nowrap;
        gap: 0.25rem;
    }
    .quick-actions {
        flex-wrap: nowrap;
        gap: 0.15rem;
    }
    .quick-actions .btn {
        padding-inline: 0.4rem;
        font-size: 0.7rem;
        padding: 0.15rem 0.4rem;
    }
    .action-pill {
        padding: 0.15rem 0.4rem !important;
        font-size: 0.7rem !important;
    }
    .shell-body,
    main {
        padding-top: 0.25rem !important;
    }
    .mobile-dock {
        display: none !important;
    }
    .hero-grid {
        gap: 0.35rem;
        grid-template-columns: repeat(4, 1fr);
    }
    .hero-card {
        padding: 0.4rem;
    }
    .hero-card strong {
        font-size: 0.85rem;
    }
    .hero-card small {
        font-size: 0.6rem;
    }
    .glass-card {
        padding: 0.5rem;
    }
    .stat-card {
        padding: 0.5rem;
    }
    .channel-grid {
        gap: 0.35rem;
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    }
    .channel-card {
        padding: 8px;
    }
    section.container {
        margin-top: 0.25rem !important;
    }
    .pb-5 {
        padding-bottom: 0.25rem !important;
    }
    .offcanvas {
        max-width: 60vw;
    }
}

/* Hero cards */
.hero-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
}

.hero-card {
    border-radius: 16px;
    padding: 1.25rem;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.hero-card small {
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    color: var(--muted);
    font-weight: 600;
}

.hero-card strong {
    font-size: clamp(1.3rem, 3vw, 1.8rem);
    color: var(--text-primary);
}

/* Group Tabs */
.group-tabs-container .nav-pills::-webkit-scrollbar {
    height: 4px;
}

.group-tabs-container .nav-pills::-webkit-scrollbar-track {
    background: transparent;
}

.group-tabs-container .nav-pills::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.3);
    border-radius: 2px;
}

.group-tabs-container .nav-pills .nav-link {
    color: var(--text-color);
    border-radius: 20px;
    padding: 6px 16px;
    margin-right: 8px;
    border: 1px solid transparent;
    cursor: pointer;
    white-space: nowrap;
}

.group-tabs-container .nav-pills .nav-link.active {
    background: var(--primary-gradient);
    color: white;
    border-color: transparent;
}

.group-tabs-container .nav-pills .nav-link:hover:not(.active) {
    background: rgba(99, 102, 241, 0.1);
}

/* Offcanvas */
.offcanvas {
    background: var(--bg-color);
    color: var(--text-color);
    border-left: 1px solid var(--border-color);
}

.offcanvas-header {
    border-bottom: 1px solid var(--border-color);
    background: var(--primary);
    color: white;
}

.offcanvas-body .btn {
    width: 100%;
    text-align: left;
    margin-bottom: 8px;
    justify-content: flex-start;
}

/* Form Controls */
.form-control, .form-select {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    color: var(--text-color);
}

.form-control:focus, .form-select:focus {
    background: var(--card-bg);
    border-color: var(--primary);
    color: var(--text-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* Modal */
.modal-content {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
}

/* Card Header */
.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border-color);
}

/* Helper Classes */
.text-gradient {
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.badge-sched {
    font-size: 0.7em;
    background: rgba(99, 102, 241, 0.1);
    color: #6366f1;
    padding: 4px 8px;
    border-radius: 6px;
    margin-right: 4px;
    font-weight: 600;
}

/* Floating Video Player */
.floating-player {
    position: fixed;
    top: 100px;
    right: 20px;
    width: 400px;
    max-width: calc(100vw - 40px);
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    z-index: 9998;
    overflow: hidden;
    min-width: 280px;
    min-height: 180px;
}

.floating-player.minimized {
    height: auto !important;
    min-height: unset;
    resize: none;
}

.floating-player.minimized .floating-player-body {
    display: none;
}

.floating-player-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: rgba(99, 102, 241, 0.1);
    border-bottom: 1px solid var(--border-color);
    cursor: move;
    user-select: none;
}

.floating-player-header span {
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

.floating-player-controls {
    display: flex;
    gap: 0.25rem;
}

.floating-player-controls .btn {
    padding: 0.25rem 0.5rem;
    color: var(--text-primary);
    opacity: 0.7;
}

.floating-player-controls .btn:hover {
    opacity: 1;
    color: var(--primary);
}

.floating-player-body {
    position: relative;
    background: #000;
}

.floating-player video {
    width: 100%;
    height: auto;
    max-height: 60vh;
    display: block;
}

.floating-player-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.8);
}

[data-bs-theme="dark"] .floating-player {
    border-color: rgba(255, 255, 255, 0.1);
    background: rgba(15, 23, 42, 0.95);
}

[data-bs-theme="dark"] .floating-player-header {
    background: rgba(30, 41, 59, 0.8);
}

@media (max-width: 768px) {
    .floating-player {
        width: calc(100vw - 20px);
        max-width: none;
        left: 10px;
        right: 10px;
        top: auto;
        bottom: 90px;
        border-radius: 12px;
        min-width: unset;
    }
    
    .floating-player-header span {
        max-width: 55vw;
    }
    
    .floating-player.minimized {
        width: 200px;
        left: auto;
        right: 10px;
        bottom: 90px;
    }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.3);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(99, 102, 241, 0.5);
}
