:root {
    --primary: #1e3a8a;
    --primary-light: #3b82f6;
    --primary-dark: #172554;
    --surface: #ffffff;
    --background: #f8fafc;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --success: #16a34a;
    --success-bg: #dcfce7;
    --warning: #d97706;
    --warning-bg: #fef3c7;
    --danger: #dc2626;
    --danger-bg: #fee2e2;
    --radius: 8px;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --primary: #2563eb;
        --primary-light: #60a5fa;
        --primary-dark: #93c5fd;
        --surface: #1e293b;
        --background: #0f172a;
        --text: #f1f5f9;
        --text-muted: #94a3b8;
        --border: #334155;
        --success: #4ade80;
        --success-bg: rgba(34, 197, 94, 0.2);
        --warning: #fbbf24;
        --warning-bg: rgba(245, 158, 11, 0.2);
        --danger: #f87171;
        --danger-bg: rgba(239, 68, 68, 0.2);
    }
}

html[data-theme="dark"] {
    --primary: #2563eb;
    --primary-light: #60a5fa;
    --primary-dark: #93c5fd;
    --surface: #1e293b;
    --background: #0f172a;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #334155;
    --success: #4ade80;
    --success-bg: rgba(34, 197, 94, 0.2);
    --warning: #fbbf24;
    --warning-bg: rgba(245, 158, 11, 0.2);
    --danger: #f87171;
    --danger-bg: rgba(239, 68, 68, 0.2);
}

html[data-theme="light"] {
    --primary: #1e3a8a;
    --primary-light: #3b82f6;
    --primary-dark: #172554;
    --surface: #ffffff;
    --background: #f8fafc;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --success: #16a34a;
    --success-bg: #dcfce7;
    --warning: #d97706;
    --warning-bg: #fef3c7;
    --danger: #dc2626;
    --danger-bg: #fee2e2;
}

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

html, body {
    min-height: 100%;
    overscroll-behavior-y: auto;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--background);
    color: var(--text);
    line-height: 1.5;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    background-color: var(--primary);
    color: #ffffff;
    padding: 0.85rem 1.5rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
    z-index: 100;
    position: sticky;
    top: 0;
}

.header-container {
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.header-logo {
    height: 32px;
    width: auto;
    max-width: 210px;
    object-fit: contain;
    display: block;
}

.header-title-divider {
    color: rgba(255, 255, 255, 0.35);
    font-size: 1.25rem;
    font-weight: 300;
    user-select: none;
}

.header-title {
    font-size: 1.15rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    white-space: nowrap;
}

.header-agent-id {
    font-size: 0.95rem;
    font-weight: 600;
    color: #ffffff;
    background: rgba(255, 255, 255, 0.15);
    padding: 0.25rem 0.75rem;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    letter-spacing: 0.02em;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

/* PWA Install Button */
.pwa-install-btn {
    display: none !important;
}

@media (max-width: 768px) {
    .pwa-install-btn.can-install {
        display: inline-flex !important;
        align-items: center;
        background: rgba(255, 255, 255, 0.2);
        color: #ffffff;
        border: 1px solid rgba(255, 255, 255, 0.4);
        padding: 0.25rem 0.65rem;
        border-radius: 6px;
        font-size: 0.825rem;
        font-weight: 600;
        cursor: pointer;
        transition: background 0.15s ease, border-color 0.15s ease;
    }

    .pwa-install-btn.can-install:hover {
        background: rgba(255, 255, 255, 0.3);
        border-color: rgba(255, 255, 255, 0.6);
    }
}

/* Telegram Button */
.telegram-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    text-decoration: none;
    transition: transform 0.15s ease, filter 0.15s ease;
    flex-shrink: 0;
    cursor: pointer;
}

.telegram-icon-btn:hover {
    transform: scale(1.12);
    filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.25));
}

/* Theme Toggle Button */
.theme-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.35);
    cursor: pointer;
    transition: all 0.15s ease;
    flex-shrink: 0;
    padding: 0;
}

.theme-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.32);
    border-color: rgba(255, 255, 255, 0.6);
    transform: scale(1.12);
}

.theme-icon-sun { display: none; }
.theme-icon-moon { display: block; }

@media (prefers-color-scheme: dark) {
    html:not([data-theme="light"]) .theme-icon-sun { display: block; }
    html:not([data-theme="light"]) .theme-icon-moon { display: none; }
}

html[data-theme="dark"] .theme-icon-sun { display: block; }
html[data-theme="dark"] .theme-icon-moon { display: none; }
html[data-theme="light"] .theme-icon-sun { display: none; }
html[data-theme="light"] .theme-icon-moon { display: block; }

/* Responsive Header */
@media (max-width: 640px) {
    header {
        padding: 0.65rem 1rem;
    }

    .header-container {
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 0.5rem;
    }

    .header-brand {
        flex-direction: column;
        align-items: center;
        gap: 0.25rem;
    }

    .header-logo {
        height: 26px;
    }

    .header-title-divider {
        display: none;
    }

    .header-title {
        font-size: 1.05rem;
        white-space: normal;
    }

    .header-actions {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        width: 100%;
        gap: 0.45rem;
    }
}

/* Main Layout & Cards */
.main-content {
    flex: 1;
    max-width: 1100px;
    width: 100%;
    margin: 0 auto;
    padding: 1.5rem 1rem;
}

.card {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 9999px;
    text-transform: uppercase;
}

.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-neutral { background: var(--border); color: var(--text-muted); }
/* Login Page Styles */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: calc(75vh - 80px);
    padding: 1.5rem 1rem;
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2.5rem 2rem;
    max-width: 440px;
    width: 100%;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
    text-align: center;
}

.login-title {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 0.5rem;
    letter-spacing: -0.01em;
}

.login-subtitle {
    font-size: 0.925rem;
    color: var(--text-muted);
    margin-bottom: 1.75rem;
    line-height: 1.45;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    text-align: left;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.form-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text);
}

.form-input {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 1.1rem;
    font-family: inherit;
    border: 1.5px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-input:focus {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.btn-primary {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    padding: 0.85rem 1.5rem;
    background: var(--primary);
    color: #ffffff;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease;
}

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

.btn-primary:active {
    transform: scale(0.99);
}

.login-error {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid rgba(220, 38, 38, 0.3);
    padding: 0.75rem 1rem;
    border-radius: 6px;
    font-size: 0.875rem;
    margin-bottom: 1.25rem;
    text-align: left;
    font-weight: 500;
}
/* Numeric Input - hide all stepper arrows/spinners */
.numeric-input,
input[type=number] {
    -moz-appearance: textfield;
    appearance: textfield;
}

.numeric-input::-webkit-outer-spin-button,
.numeric-input::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Success Alert Card */
.login-success {
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid rgba(22, 163, 74, 0.3);
    padding: 0.85rem 1rem;
    border-radius: 6px;
    font-size: 0.875rem;
    margin-bottom: 1.25rem;
    text-align: left;
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    line-height: 1.4;
}

.login-success .success-icon {
    font-size: 1.1rem;
    font-weight: bold;
    flex-shrink: 0;
}
/* Success Confirmation Screen on Login */
.login-success-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 1.25rem 0.25rem 0.25rem 0.25rem;
}

.success-icon-circle {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background-color: var(--success-bg);
    color: var(--success);
    border: 2px solid var(--success);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 0.85rem;
}

.success-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 0.45rem;
}

.success-desc {
    font-size: 0.95rem;
    color: var(--text);
    line-height: 1.5;
    margin-bottom: 1.25rem;
}

.success-footer-note {
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.5;
    border-top: 1px solid var(--border);
    padding-top: 1.15rem;
    width: 100%;
}

.success-close-hint {
    display: inline-block;
    background: var(--background);
    border: 1px solid var(--border);
    padding: 0.35rem 0.85rem;
    border-radius: 6px;
    font-weight: 600;
    color: var(--text);
    margin-top: 0.25rem;
}
/* Notifications Menu & Dropdown */
.notif-dropdown-wrapper {
    position: relative;
    display: inline-block;
}

.notif-menu-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.4rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    transition: all 0.15s ease;
    line-height: 1;
}

.notif-menu-btn:hover {
    background: var(--background);
    border-color: var(--primary);
    color: var(--primary);
}

.notif-btn-label {
    font-size: 0.82rem;
}

.notif-dropdown-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 320px;
    max-width: calc(100vw - 1.5rem);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.18), 0 8px 10px -6px rgba(0, 0, 0, 0.12);
    z-index: 1000;
    overflow: hidden;
    box-sizing: border-box;
}

/* Ensure dropdown menu stays strictly within screen limits on mobile/tablets */
@media (max-width: 768px) {
    .notif-dropdown-wrapper {
        position: static;
    }

    .notif-dropdown-menu {
        left: 0.75rem;
        right: 0.75rem;
        width: auto;
        max-width: 340px;
        margin-left: auto;
        margin-right: auto;
        top: calc(100% + 8px);
    }
}

.notif-dropdown-body {
    padding: 0.5rem 1rem;
}

.notif-channel-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
}

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

.notif-channel-info {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    flex: 1;
    margin-right: 0.75rem;
    min-width: 0;
}

.notif-channel-name {
    font-weight: 600;
    font-size: 0.86rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--text);
}

.notif-email-text {
    display: block;
    max-width: 175px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.notif-channel-desc {
    font-size: 0.76rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.status-badge-active {
    color: var(--success);
    font-weight: 500;
}

.status-badge-inactive {
    color: var(--text-muted);
}

/* Toggle Switch Styles */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 42px;
    height: 24px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--border);
    transition: 0.2s ease;
    border-radius: 24px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.2s ease;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

.toggle-switch input:checked + .toggle-slider {
    background-color: var(--primary);
}

.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(18px);
}

.notif-badge-disabled {
    font-size: 0.72rem;
    color: var(--text-muted);
    background: var(--background);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    border: 1px solid var(--border);
}

/* Telegram Action Buttons */
.btn-action-tg {
    padding: 0.35rem 0.75rem;
    border-radius: 6px;
    font-size: 0.78rem;
    font-weight: 600;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
    white-space: nowrap;
}

.btn-link-tg {
    background: #229ED9;
    color: #ffffff !important;
    border: 1px solid #229ED9;
}

.btn-link-tg:hover {
    background: #1e8dc2;
}

.btn-unlink-tg {
    background: transparent;
    border: 1px solid rgba(220, 38, 38, 0.3);
    color: #dc2626;
}

.btn-unlink-tg:hover {
    background: rgba(220, 38, 38, 0.08);
    border-color: #dc2626;
}

.notif-dropdown-footer {
    padding: 0.35rem 1rem;
    background: var(--background);
    border-top: 1px solid var(--border);
    min-height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.notif-status-msg {
    font-size: 0.75rem;
    color: var(--success);
    font-weight: 500;
    min-height: 1rem;
    text-align: center;
}
