:root {
    --bg-primary: #111827;
    --bg-secondary: #1f2937;
    --text-primary: #f9fafb;
    --text-secondary: #9ca3af;
    --accent-gradient: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
    --card-gradient: linear-gradient(145deg, #1f2937, #111827);
    --border-color: #374151;
    --success-color: #10b981;
    --font-family: 'Outfit', system-ui, -apple-system, sans-serif;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    background-image:
        radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.15) 0px, transparent 50%),
        radial-gradient(at 100% 0%, rgba(168, 85, 247, 0.15) 0px, transparent 50%);
    background-attachment: fixed;
    font-family: var(--font-family);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    margin: 0;
}

header {
    background: rgba(31, 41, 55, 0.7);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding: 1.5rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 0;
}

h1 i {
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Nav */
.main-nav {
    display: flex;
    gap: 1rem;
}

.nav-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.nav-btn.active {
    background: var(--accent-gradient);
    color: white;
    box-shadow: 0 4px 10px rgba(99, 102, 241, 0.2);
}

main {
    flex: 1;
    max-width: 1000px;
    margin: 0 auto;
    padding: 2rem;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
}

/* Cards */
.card {
    background: rgba(31, 41, 55, 0.6);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    transition: transform 0.2s ease;
}

.card:hover {
    transform: translateY(-2px);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.card-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-value {
    font-size: 2.25rem;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    line-height: 1;
}

.status-text {
    font-size: 0.75rem;
    color: var(--success-color);
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    margin-top: 0.5rem;
}

.status-indicator {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--success-color);
    box-shadow: 0 0 8px var(--success-color);
}

/* Channel List Table */
.channels-container {
    background: rgba(31, 41, 55, 0.6);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    overflow: hidden;
}

.table-header {
    background: rgba(17, 24, 39, 0.8);
    padding: 1rem 1.5rem;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: grid;
    grid-template-columns: 1fr auto 100px;
    gap: 1rem;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
}

.channel-row {
    padding: 1rem 1.5rem;
    display: grid;
    grid-template-columns: 1fr auto 100px;
    gap: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    align-items: center;
    cursor: pointer;
    transition: background 0.2s;
}

.channel-row:hover {
    background: rgba(255, 255, 255, 0.03);
}

.channel-row:last-child {
    border-bottom: none;
}

.channel-meta {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    overflow: hidden;
    min-width: 0;
}

.channel-name {
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.category-tag {
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 12px;
    background: rgba(99, 102, 241, 0.2);
    color: #a5b4fc;
    border: 1px solid rgba(99, 102, 241, 0.3);
    white-space: nowrap;
}

.today-badge {
    background: var(--success-color);
    color: white;
    padding: 0.1rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    white-space: nowrap;
}

.channel-count {
    font-weight: 600;
    text-align: right;
    color: var(--text-primary);
    background: rgba(0, 0, 0, 0.2);
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    justify-self: end;
    min-width: 3rem;
    text-align: center;
}

.edit-btn {
    padding: 4px;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.channel-row:hover .edit-btn {
    opacity: 1;
}

.delete-btn {
    padding: 4px;
    background: none;
    border: none;
    color: #ef4444;
    /* Red for delete */
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.2s;
    margin-left: 0.5rem;
}

.channel-row:hover .delete-btn {
    opacity: 1;
}

.category-edit-form {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.category-input {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
}

/* Controls */
.controls {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 1rem;
    gap: 1rem;
}

select,
input {
    background: rgba(17, 24, 39, 0.8);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-family: inherit;
}

/* Modal Styling */
dialog {
    border: none;
    border-radius: 12px;
    padding: 0;
    box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1);
    background: #1f2937;
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.1);
    max-width: 500px;
    width: 90%;
    margin: auto;
}

dialog::backdrop {
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 700;
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
}

.modal-body {
    padding: 1.5rem;
    max-height: 60vh;
    overflow-y: auto;
}

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

.history-table th,
.history-table td {
    text-align: left;
    padding: 0.75rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.history-table th {
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.875rem;
}

.empty-state {
    padding: 3rem;
    text-align: center;
    color: var(--text-secondary);
    font-style: italic;
}

@media (max-width: 640px) {
    main {
        padding: 1rem;
    }

    /* Stack Header */
    header {
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 0.75rem;
    }

    h1 {
        font-size: 1.25rem;
    }

    /* Full width controls */
    .controls {
        justify-content: center;
        width: 100%;
        margin-bottom: 1rem;
    }

    select {
        width: 100%;
        padding: 0.75rem;
        font-size: 1rem;
    }

    /* Cards - Stack Metrics */
    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .stat-value {
        font-size: 2rem;
    }

    /* Channel List - Mobile Card Style */
    .table-header {
        display: none;
    }

    /* Use simple flex column layout for mobile rows */
    .channel-row {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        /* Stretch full width */
        gap: 0.75rem;
        padding: 1rem;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
        /* Ensure separator */
    }

    /* Top Row in Card: Name + Menu/Actions */
    .channel-meta {
        /* Container for Name and Actions */
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        width: 100%;
        gap: 0.5rem;
        flex-wrap: wrap;
        /* Allow wrapping if name is super long */
    }

    .channel-name {
        font-size: 1rem;
        font-weight: 600;
        white-space: normal;
        /* Allow wrapping */
        overflow: visible;
        text-overflow: clip;
        flex: 1;
        /* Take up space */
        line-height: 1.4;
        min-width: 0;
        /* Enable flex shrinking/wrapping */
        margin-right: 0.5rem;
    }

    /* Action Buttons Container */
    .actions {
        display: flex;
        gap: 0.5rem;
        /* Ensure buttons stay on top right even if name wraps */
        align-self: flex-start;
        flex-shrink: 0;
        /* Prevent buttons from shrinking */
    }

    .edit-btn,
    .delete-btn {
        /* Reset absolute positioning */
        position: static;
        padding: 8px;
        /* Larger touch target */
        margin: 0;
        opacity: 0.8;
        /* Always visible to indicate interactivity */
        border-radius: 4px;
        background: rgba(255, 255, 255, 0.05);
        /* Slight background for button feel */
    }

    .delete-btn {
        color: #ef4444;
    }

    /* Bottom Row in Card: Tags + Count */
    /* Since we can't easily select the parents of these elements cleanly with just CSS
       without strict HTML structure, we rely on flow. The tags are siblings of .actions div now.
    */

    /* Force Category Tag and Today Badge to appear below name area */
    .category-tag {
        display: inline-block;
        margin-top: 0.25rem;
        margin-right: 0.5rem;
        font-size: 0.75rem;
    }

    .today-badge {
        display: inline-block;
        margin-top: 0.25rem;
        font-size: 0.75rem;
    }

    .channel-count {
        align-self: flex-start;
        /* Align left */
        margin-top: 0.5rem;
        /* Space from tags */
        padding: 0;
        background: none;
        color: var(--text-primary);
        font-size: 1.1rem;
        font-weight: 700;
        width: 100%;
        /* Take full width */
        text-align: left;
        /* Explicitly align left */
        border-top: 1px solid rgba(255, 255, 255, 0.05);
        /* Separator */
        padding-top: 0.5rem;
    }

    /* Add label for clarity on mobile */
    .channel-count::before {
        content: "Total Requests: ";
        font-size: 0.9rem;
        color: var(--text-secondary);
        font-weight: normal;
    }
}