/* ===========================
   CSS Variables & Reset
   =========================== */
:root {
    --primary: #667eea;
    --primary-dark: #5a67d8;
    --secondary: #764ba2;
    --success: #10b981;
    --success-dark: #059669;
    --danger: #ef4444;
    --danger-dark: #dc2626;
    --warning: #f59e0b;
    --background: #0f0f23;
    --surface: #1a1a2e;
    --surface-light: #252542;
    --text: #ffffff;
    --text-muted: #94a3b8;
    --border: rgba(255, 255, 255, 0.1);
    --gradient: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    --radius: 16px;
    --radius-sm: 8px;
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Segoe UI', 'Noto Sans Thai', Tahoma, sans-serif;
    background: var(--background);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
}

/* ===========================
   Container
   =========================== */
.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 20px;
    padding-bottom: 40px;
}

/* ===========================
   Header
   =========================== */
.header {
    text-align: center;
    padding: 40px 20px;
    background: var(--gradient);
    border-radius: var(--radius);
    margin-bottom: 24px;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}

.header::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.1) 0%, transparent 70%);
    animation: pulse 4s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
        opacity: 0.5;
    }

    50% {
        transform: scale(1.1);
        opacity: 0.3;
    }
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    position: relative;
    z-index: 1;
}

.logo-icon {
    font-size: 48px;
    animation: ring 2s ease-in-out infinite;
}

@keyframes ring {

    0%,
    100% {
        transform: rotate(0deg);
    }

    10% {
        transform: rotate(15deg);
    }

    20% {
        transform: rotate(-15deg);
    }

    30% {
        transform: rotate(10deg);
    }

    40% {
        transform: rotate(-10deg);
    }

    50% {
        transform: rotate(0deg);
    }
}

.header h1 {
    font-size: 28px;
    font-weight: 700;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

.subtitle {
    margin-top: 8px;
    opacity: 0.9;
    font-size: 16px;
    position: relative;
    z-index: 1;
}

/* ===========================
   Cards
   =========================== */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 20px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 15px 50px rgba(0, 0, 0, 0.4);
}

.card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.card-icon {
    font-size: 28px;
}

.card-header h2 {
    font-size: 20px;
    font-weight: 600;
}

.card-description {
    color: var(--text-muted);
    margin-bottom: 16px;
    font-size: 14px;
}

/* ===========================
   Status Card
   =========================== */
.status-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    background: var(--surface-light);
    border-radius: var(--radius-sm);
}

.status-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
}

.status-badge.pending {
    background: rgba(245, 158, 11, 0.2);
    color: var(--warning);
}

.status-badge.subscribed {
    background: rgba(16, 185, 129, 0.2);
    color: var(--success);
}

.status-badge.not-subscribed {
    background: rgba(239, 68, 68, 0.2);
    color: var(--danger);
}

.status-badge.denied {
    background: rgba(239, 68, 68, 0.2);
    color: var(--danger);
}

.status-badge.unsupported {
    background: rgba(148, 163, 184, 0.2);
    color: var(--text-muted);
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: currentColor;
    animation: blink 1.5s ease-in-out infinite;
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.subscriber-info {
    text-align: right;
}

.subscriber-info .count {
    font-size: 32px;
    font-weight: 700;
    background: var(--gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subscriber-info .label {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
}

/* ===========================
   Channel Cards
   =========================== */
.channel-card {
    position: relative;
    overflow: hidden;
    padding: 0;
}

.channel-header {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 20px 20px 16px;
}

.channel-indicator {
    width: 4px;
    min-height: 48px;
    border-radius: 4px;
    flex-shrink: 0;
    align-self: stretch;
}

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

.channel-title {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 4px;
}

.channel-icon {
    font-size: 24px;
    flex-shrink: 0;
}

.channel-title h3 {
    font-size: 17px;
    font-weight: 600;
    color: var(--text);
}

.channel-desc {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.5;
}

/* Channel Badge */
.channel-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.5px;
    flex-shrink: 0;
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
    transition: all 0.3s ease;
}

.channel-badge.subscribed {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
}

.badge-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
}

.channel-badge.subscribed .badge-dot {
    animation: blink 1.5s ease-in-out infinite;
}

/* Channel Stats */
.channel-stats {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    margin: 0 20px;
    background: var(--surface-light);
    border-radius: var(--radius-sm);
}

.stat-count {
    font-size: 22px;
    font-weight: 700;
    background: var(--gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.stat-label {
    font-size: 12px;
    color: var(--text-muted);
}

/* Channel Actions */
.channel-actions {
    display: flex;
    gap: 8px;
    padding: 16px 20px 20px;
}

/* Channel Buttons */
.btn-channel-sub,
.btn-channel-unsub,
.btn-channel-test {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    flex: 1;
}

.btn-channel-sub {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
}

.btn-channel-sub:hover:not(:disabled) {
    transform: scale(1.03);
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.4);
}

.btn-channel-unsub {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
}

.btn-channel-unsub:hover:not(:disabled) {
    transform: scale(1.03);
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.4);
}

.btn-closed {
    background: var(--surface-light);
    color: var(--text-muted);
    opacity: 0.6;
    cursor: default;
}

.btn-channel-test {
    background: var(--surface-light);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-channel-test:hover:not(:disabled) {
    border-color: var(--primary);
    background: rgba(102, 126, 234, 0.1);
}

.btn-channel-sub:disabled,
.btn-channel-unsub:disabled,
.btn-channel-test:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

.btn-icon {
    font-size: 16px;
}

/* Spin animation for loading */
.spin {
    display: inline-block;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* ===========================
   Loading Channels
   =========================== */
.loading-channels {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 40px;
    color: var(--text-muted);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top: 3px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* ===========================
   General Buttons
   =========================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    flex: 1;
}

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

.btn-primary {
    background: var(--gradient);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    transform: scale(1.02);
    box-shadow: 0 5px 20px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: var(--surface-light);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--surface);
    border-color: var(--primary);
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-success:hover:not(:disabled) {
    background: var(--success-dark);
    transform: scale(1.02);
    box-shadow: 0 5px 20px rgba(16, 185, 129, 0.4);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background: var(--danger-dark);
}

.btn-block {
    width: 100%;
}

/* ===========================
   Form
   =========================== */
.send-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
}

.label-icon {
    font-size: 16px;
}

.form-group input,
.form-group textarea {
    background: var(--surface-light);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    font-size: 16px;
    color: var(--text);
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

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

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

/* ===========================
   Result Box
   =========================== */
.result-box {
    margin-top: 16px;
    padding: 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.result-box.success {
    background: rgba(16, 185, 129, 0.2);
    border: 1px solid var(--success);
    color: var(--success);
}

.result-box.error {
    background: rgba(239, 68, 68, 0.2);
    border: 1px solid var(--danger);
    color: var(--danger);
}

/* ===========================
   Footer
   =========================== */
.footer {
    text-align: center;
    padding: 20px;
    color: var(--text-muted);
    font-size: 14px;
}

/* ===========================
   Loading State
   =========================== */
.btn.loading {
    pointer-events: none;
}

.btn.loading .btn-icon {
    animation: spin 1s linear infinite;
}

/* ===========================
   Card appear animation
   =========================== */
.channel-card {
    animation: cardSlideUp 0.4s ease forwards;
    opacity: 0;
}

.channel-card:nth-child(1) {
    animation-delay: 0.05s;
}

.channel-card:nth-child(2) {
    animation-delay: 0.15s;
}

.channel-card:nth-child(3) {
    animation-delay: 0.25s;
}

.channel-card:nth-child(4) {
    animation-delay: 0.35s;
}

.channel-card:nth-child(5) {
    animation-delay: 0.45s;
}

@keyframes cardSlideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===========================
   Channel Devices List
   =========================== */
.channel-devices {
    background: var(--surface-light);
    border-radius: var(--radius-sm);
    padding: 12px 0px;
    animation: fadeIn 0.3s ease;
    border-top: 1px dashed rgba(255, 255, 255, 0.1);
    width: 100%;
}

.channel-devices h4 {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 8px;
    font-weight: 600;
}

.channel-devices ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.channel-devices li {
    font-size: 13px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 6px;
    border-bottom: 1px dashed var(--border);
}

.channel-devices li:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.device-name {
    color: var(--text);
    font-weight: 500;
}

.device-date {
    color: var(--text-muted);
    font-size: 12px;
}

/* ===========================
   Responsive
   =========================== */
@media (max-width: 480px) {
    .container {
        padding: 12px;
    }

    .header {
        padding: 30px 16px;
    }

    .header h1 {
        font-size: 24px;
    }

    .card {
        padding: 20px;
    }

    .status-content {
        flex-direction: column;
        gap: 16px;
        text-align: center;
    }

    .subscriber-info {
        text-align: center;
    }

    .channel-header {
        padding: 16px 16px 12px;
    }

    .channel-stats {
        margin: 0 16px;
    }

    .channel-actions {
        flex-direction: column;
        padding: 12px 16px 16px;
    }

    .btn-channel-sub,
    .btn-channel-unsub,
    .btn-channel-test {
        width: 100%;
    }
}