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

:root {
    --bg: #0e0e10;
    --surface: #18181b;
    --surface2: #1f1f23;
    --surface3: #26262c;
    --border: #2f2f35;
    --border-hover: #3f3f45;
    --accent: #9147ff;
    --accent-hover: #772ce8;
    --accent-soft: rgba(145, 71, 255, 0.15);
    --accent-glow: rgba(145, 71, 255, 0.3);
    --text: #efeff1;
    --text-dim: #adadb8;
    --text-muted: #76768a;
    --success: #00e676;
    --success-soft: rgba(0, 230, 118, 0.12);
    --warning: #ffab00;
    --warning-soft: rgba(255, 171, 0, 0.12);
    --danger: #ff5252;
    --danger-soft: rgba(255, 82, 82, 0.12);
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
    --transition: 0.2s ease;
}

body {
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

/* ── Scrollbar ── */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-dim);
}

/* ── Animations ── */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

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

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-12px);
    }

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

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(12px);
    }

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

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

@keyframes glow {

    0%,
    100% {
        box-shadow: 0 0 8px var(--accent-glow);
    }

    50% {
        box-shadow: 0 0 20px var(--accent-glow);
    }
}

/* ── Login Screen ── */
.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem;
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 3rem;
    width: 100%;
    max-width: 420px;
    text-align: center;
    animation: fadeIn 0.5s ease;
    box-shadow: var(--shadow);
}

.login-card .logo {
    font-size: 2.2rem;
    font-weight: 900;
    background: linear-gradient(135deg, var(--accent), #bf7aff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
    letter-spacing: -0.5px;
    overflow: visible;
}

.login-card .subtitle {
    color: var(--text-dim);
    font-size: 0.95rem;
    margin-bottom: 2.5rem;
    line-height: 1.5;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.7rem 1.25rem;
    border: none;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
}

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

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

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

.btn-twitch {
    background: var(--accent);
    color: white;
    width: 100%;
    padding: 0.9rem 1.25rem;
    font-size: 1rem;
    font-weight: 700;
    border-radius: var(--radius);
    letter-spacing: 0.3px;
}

.btn-twitch:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px var(--accent-glow);
}

.btn-ghost {
    background: transparent;
    color: var(--text-dim);
    border: 1px solid var(--border);
    padding: 0.5rem 0.9rem;
    font-size: 0.82rem;
}

.btn-ghost:hover {
    color: var(--text);
    border-color: var(--border-hover);
    background: var(--surface2);
}

.btn-danger {
    background: var(--danger-soft);
    color: var(--danger);
    border: 1px solid rgba(255, 82, 82, 0.25);
}

.btn-danger:hover {
    background: rgba(255, 82, 82, 0.25);
}

.btn-success {
    background: var(--success-soft);
    color: var(--success);
    border: 1px solid rgba(0, 230, 118, 0.25);
}

.btn-success:hover {
    background: rgba(0, 230, 118, 0.25);
}

.btn-warning {
    background: var(--warning-soft);
    color: var(--warning);
    border: 1px solid rgba(255, 171, 0, 0.25);
}

.btn-warning:hover {
    background: rgba(255, 171, 0, 0.25);
}

.trigger-card.disabled {
    opacity: 0.5;
    filter: grayscale(0.5);
}

.channel-item.paused .channel-name {
    opacity: 0.5;
    text-decoration: line-through;
}

.paused-badge {
    font-size: 0.65rem;
    color: var(--warning);
    background: var(--warning-soft);
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
    margin-left: 0.4rem;
    font-weight: 800;
}

.btn-icon {
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 6px;
    font-size: 1rem;
}

/* ── Dashboard ── */
.dashboard {
    display: none;
    height: 100vh;
    flex-direction: column;
}

.dashboard.active {
    display: flex;
}

.login-screen.active {
    display: flex;
}

.login-screen {
    display: none;
}

/* Header */
.dash-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.65rem 1.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 10;
}

.dash-header .brand {
    font-size: 1.15rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--accent), #bf7aff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

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

.connection-dot.connected {
    background: var(--success);
    animation: pulse 2s ease-in-out infinite;
}

.connection-dot.connecting {
    background: var(--warning);
    animation: pulse 1s ease-in-out infinite;
}

.user-badge {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0.75rem;
    background: var(--surface2);
    border-radius: 20px;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-dim);
}

/* Body layout */
.dash-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 1rem 1rem 0.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-header h2 {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-dim);
}

.channel-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 0.5rem;
}

.channel-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    margin-bottom: 2px;
    animation: slideInLeft 0.3s ease;
}

.channel-item:hover {
    background: var(--surface2);
}

.channel-item.active {
    background: var(--accent-soft);
    border: 1px solid rgba(145, 71, 255, 0.25);
}

.channel-item.active .channel-name {
    color: var(--text);
}

.channel-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
}

.channel-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--surface3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--accent);
    flex-shrink: 0;
    text-transform: uppercase;
}

.channel-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.channel-trigger-count {
    font-size: 0.72rem;
    color: var(--text-muted);
    background: var(--surface3);
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    flex-shrink: 0;
}

.channel-remove {
    opacity: 0;
    transition: opacity var(--transition);
}

.channel-item:hover .channel-remove {
    opacity: 1;
}

/* Add channel */
.add-channel-area {
    padding: 0.75rem;
    border-top: 1px solid var(--border);
}

.add-channel-row {
    display: flex;
    gap: 0.5rem;
}

.add-channel-row input {
    flex: 1;
    padding: 0.5rem 0.75rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: inherit;
    font-size: 0.85rem;
    transition: border-color var(--transition);
}

.add-channel-row input:focus {
    outline: none;
    border-color: var(--accent);
}

.add-channel-row input::placeholder {
    color: var(--text-muted);
}

/* Main content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

/* Trigger editor */
.trigger-area {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

.no-channel-selected {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    font-size: 1rem;
    flex-direction: column;
    gap: 0.5rem;
}

.no-channel-selected .icon {
    font-size: 2.5rem;
    opacity: 0.4;
}

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

.triggers-header h2 {
    font-size: 1.15rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.triggers-header h2 .hash {
    color: var(--accent);
    font-weight: 800;
}

.trigger-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    margin-bottom: 0.75rem;
    transition: all var(--transition);
    animation: fadeIn 0.3s ease;
}

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

.trigger-row {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
}

.trigger-field {
    flex: 1;
    min-width: 0;
}

.trigger-field label {
    display: block;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.35rem;
}

.trigger-field input,
.trigger-field textarea {
    width: 100%;
    padding: 0.55rem 0.75rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-family: inherit;
    font-size: 0.88rem;
    transition: border-color var(--transition);
    resize: none;
}

.trigger-field input:focus,
.trigger-field textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.trigger-field input::placeholder,
.trigger-field textarea::placeholder {
    color: var(--text-muted);
}

.trigger-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}

.counter-section {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.toggle-wrapper {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.82rem;
    color: var(--text-dim);
    user-select: none;
}

.toggle {
    width: 36px;
    height: 20px;
    background: var(--surface3);
    border-radius: 10px;
    position: relative;
    transition: background var(--transition);
    border: 1px solid var(--border);
    cursor: pointer;
}

.toggle.active {
    background: var(--accent);
    border-color: var(--accent);
}

.toggle::after {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: white;
    top: 2px;
    left: 2px;
    transition: transform var(--transition);
}

.toggle.active::after {
    transform: translateX(16px);
}

.counter-start {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.counter-start label {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.counter-start input {
    width: 65px;
    padding: 0.3rem 0.5rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-family: inherit;
    font-size: 0.82rem;
    text-align: center;
}

.counter-start input:focus {
    outline: none;
    border-color: var(--accent);
}

.counter-current {
    font-size: 0.78rem;
    color: var(--accent);
    font-weight: 600;
    padding: 0.2rem 0.5rem;
    background: var(--accent-soft);
    border-radius: 6px;
}

/* Activity log */
.activity-panel {
    width: 320px;
    background: var(--surface);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

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

.activity-header h3 {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-dim);
}

.activity-log {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.activity-empty {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    line-height: 1.5;
}

.log-entry {
    padding: 0.5rem 0.65rem;
    border-radius: 6px;
    margin-bottom: 4px;
    font-size: 0.82rem;
    animation: slideInRight 0.25s ease;
    line-height: 1.4;
}

.log-entry.match {
    background: var(--accent-soft);
    border-left: 3px solid var(--accent);
}

.log-entry.sent {
    background: var(--success-soft);
    border-left: 3px solid var(--success);
}

.log-entry.error {
    background: var(--danger-soft);
    border-left: 3px solid var(--danger);
}

.log-entry.info {
    background: var(--warning-soft);
    border-left: 3px solid var(--warning);
}

.log-entry.chat {
    background: rgba(255, 255, 255, 0.03);
    border-left: 3px solid var(--border);
    color: var(--text-dim);
    font-size: 0.78rem;
}

.log-time {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-right: 0.4rem;
    font-variant-numeric: tabular-nums;
}

.log-channel {
    color: var(--accent);
    font-weight: 600;
}

.log-user {
    color: var(--warning);
    font-weight: 600;
}

.log-phrase {
    color: var(--text);
    font-weight: 600;
    background: rgba(255, 255, 255, 0.06);
    padding: 0.05rem 0.35rem;
    border-radius: 3px;
}

/* Monitoring status bar */
.monitor-bar {
    padding: 0.8rem 1.25rem;
    background: var(--surface2);
    border-top: 1px solid var(--border);
    font-size: 0.85rem;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-shrink: 0;
    box-shadow: 0 -4px 12px rgba(0,0,0,0.2);
}

.monitor-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 500;
}

.monitor-right {
    flex: 1;
    max-width: 300px;
    display: flex;
    align-items: center;
}

.progress-bar-bg {
    width: 100%;
    height: 6px;
    background: var(--surface3);
    border-radius: 3px;
    overflow: hidden;
    position: relative;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), #bf7aff);
    width: 0%;
    transition: width 0.3s ease;
    box-shadow: 0 0 10px var(--accent-glow);
}

.model-select-compact {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-dim);
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}

.model-select-compact:hover {
    border-color: var(--accent);
    color: var(--text);
}

.model-select-compact:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
}


/* Empty triggers */
.empty-triggers {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

.empty-triggers .icon {
    font-size: 2rem;
    margin-bottom: 0.75rem;
    opacity: 0.4;
}

.empty-triggers p {
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

/* Responsive */
@media (max-width: 900px) {
    .activity-panel {
        display: none;
    }
}

@media (max-width: 650px) {
    .sidebar {
        width: 220px;
    }
}

/* ── Help Modal ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    padding: 2rem;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2rem;
    max-width: 560px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
    transform: translateY(12px);
    transition: transform 0.25s ease;
}

.modal-overlay.active .modal {
    transform: translateY(0);
}

.modal h2 {
    font-size: 1.2rem;
    font-weight: 800;
    margin-bottom: 1rem;
    color: var(--text);
}

.modal h3 {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 1.25rem;
    margin-bottom: 0.4rem;
}

.modal p,
.modal li {
    font-size: 0.88rem;
    color: var(--text-dim);
    line-height: 1.6;
}

.modal ul {
    padding-left: 1.25rem;
    margin-bottom: 0.5rem;
}

.modal li {
    margin-bottom: 0.3rem;
}

.modal code {
    background: var(--surface2);
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    font-size: 0.82rem;
    color: var(--accent);
    font-family: 'Consolas', 'Monaco', monospace;
}

.modal-close {
    float: right;
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1.3rem;
    cursor: pointer;
    padding: 0.2rem 0.5rem;
    border-radius: 6px;
    transition: all var(--transition);
}

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

.help-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid rgba(145, 71, 255, 0.4);
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    margin-left: 0.5rem;
    vertical-align: middle;
}

.help-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-soft);
}

.login-features {
    text-align: left;
    margin: 1.5rem 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.login-feature {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.82rem;
    color: var(--text-dim);
}

.login-feature .feat-icon {
    font-size: 1rem;
    width: 24px;
    text-align: center;
    flex-shrink: 0;
}

/* ── AI Model selection styles ── */
.model-selection-login {
    margin-top: 1.5rem;
    text-align: left;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
}

.model-selection-login label {
    display: block;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.5rem;
}

.model-selection-login select {
    width: 100%;
    padding: 0.7rem 1rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.9rem;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
}

.model-selection-login select:focus {
    outline: none;
    border-color: var(--accent);
}

.model-warning {
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: var(--warning-soft);
    color: var(--warning);
    border: 1px solid rgba(255, 171, 0, 0.2);
    border-radius: var(--radius);
    font-size: 0.8rem;
    line-height: 1.4;
    animation: fadeIn 0.3s ease;
}