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

:root {
    --primary-color: #4CAF50;
    --primary-hover: #45a049;
    --secondary-color: #2196F3;
    --success-color: #4CAF50;
    --danger-color: #d32f2f;
    --warning-color: #FF9800;
    --bg-color: #1a1a1a;
    --card-bg: #242424;
    --text-primary: #e0e0e0;
    --text-secondary: #888;
    --border-color: #333;
    --shadow: 0 1px 3px rgba(0,0,0,0.5);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.7);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

/* ==========================================
   Login Screen
   ========================================== */

.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1a1a1a 0%, #2a2a2a 100%);
}

.login-box {
    background: #242424;
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    width: 100%;
    max-width: 400px;
    border: 1px solid #333;
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-header .login-icon {
    width: 48px;
    height: 48px;
    color: #4CAF50;
    margin-bottom: 16px;
}

.login-header h1 {
    font-size: 24px;
    margin-bottom: 8px;
    color: #e0e0e0;
}

.login-header p {
    color: #888;
    font-size: 14px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

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

.form-group label {
    font-size: 13px;
    font-weight: 600;
    color: #aaa;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-group input {
    padding: 12px 16px;
    background: #2a2a2a;
    border: 1px solid #444;
    border-radius: 6px;
    color: #e0e0e0;
    font-size: 14px;
    transition: all 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: #4CAF50;
    background: #333;
}

.form-group input::placeholder {
    color: #666;
}

.login-btn {
    padding: 14px;
    background: #4CAF50;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 8px;
}

.login-btn:hover {
    background: #45a049;
    transform: translateY(-1px);
}

.login-btn:active {
    transform: translateY(0);
}

.error-message {
    background: #d32f2f;
    color: white;
    padding: 12px;
    border-radius: 6px;
    font-size: 13px;
    text-align: center;
}

.error-message.hidden {
    display: none;
}

.dashboard-container.hidden {
    display: none;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-left .header-icon {
    width: 24px;
    height: 24px;
    color: #4CAF50;
}

.logout-btn {
    padding: 8px 16px;
    background: #d32f2f;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

.logout-btn:hover {
    background: #c62828;
}

.logout-btn svg {
    width: 16px;
    height: 16px;
}

.container {
    max-width: 1800px;
    margin: 0 auto;
    padding: 0 40px;
}

header {
    background: #242424;
    padding: 20px 40px;
    border-bottom: 2px solid #333;
    border-radius: 0;
    box-shadow: none;
    margin: 0 -40px 0 -40px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

header h1 {
    font-size: 20px;
    font-weight: 600;
    color: #e0e0e0;
    margin-bottom: 0;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 16px;
}

.header-controls {
    display: flex;
    gap: 12px;
    align-items: center;
}

.debug-indicator {
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
}

.debug-indicator.active {
    background: var(--warning-color);
    color: white;
}

.debug-indicator.inactive {
    background: var(--border-color);
    color: var(--text-secondary);
}

.btn-primary {
    background: #4CAF50;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}

.btn-primary:hover {
    background: #45a049;
    transform: translateY(-1px);
}

.btn-secondary {
    background: #2a2a2a;
    color: #e0e0e0;
    border: 1px solid #444;
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: #333;
    border-color: #555;
}

.btn-secondary-sm {
    background: var(--card-bg);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.btn-danger {
    background: var(--danger-color);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.btn-success {
    background: var(--success-color);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.action-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.action-bar-left {
    display: flex;
    gap: 12px;
    align-items: center;
}

.action-bar button {
    display: flex;
    align-items: center;
    gap: 6px;
}

.device-count {
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
}

.device-count span {
    color: #4CAF50;
    font-weight: 700;
}

.devices-container {
    background: var(--card-bg);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 20px;
    min-height: 400px;
}

.device-card {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 16px;
    transition: all 0.2s;
}

.device-card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.device-card.inactive {
    opacity: 0.6;
    border-color: var(--danger-color);
}

.device-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 16px;
}

.device-info h3 {
    font-size: 18px;
    margin-bottom: 4px;
}

.device-info .user-email {
    color: var(--text-secondary);
    font-size: 14px;
}

.device-status {
    display: flex;
    gap: 8px;
    align-items: center;
}

.status-badge {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

.status-badge.active {
    background: #d1fae5;
    color: #065f46;
}

.status-badge.inactive {
    background: #fee2e2;
    color: #991b1b;
}

.status-badge.expiring {
    background: #fef3c7;
    color: #92400e;
}

.device-details {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.detail-item {
    font-size: 13px;
}

.detail-item label {
    display: block;
    color: var(--text-secondary);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.detail-item span {
    font-weight: 600;
}

.device-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
}

.empty-icon {
    font-size: 64px;
    margin-bottom: 16px;
}

.empty-state h3 {
    font-size: 20px;
    margin-bottom: 8px;
}

.empty-state p {
    color: var(--text-secondary);
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.hidden {
    display: none !important;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: #2a2a2a;
    border: 1px solid #444;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-large {
    max-width: 800px;
}

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

.modal-header h2 {
    font-size: 22px;
}

.close-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}

.close-btn:hover {
    background: var(--bg-color);
}

.modal-body {
    padding: 24px;
}

.registration-step.hidden {
    display: none;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 14px;
}

.form-group input {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
}

.device-code-container {
    text-align: center;
}

.code-display {
    margin: 24px 0;
    padding: 32px;
    background: #1a1a1a;
    border-radius: 8px;
    border: 1px solid #333;
}

.user-code {
    font-size: 36px;
    font-weight: 700;
    letter-spacing: 8px;
    color: var(--primary-color);
    font-family: 'Courier New', monospace;
}

.instructions {
    text-align: left;
    margin: 24px 0;
    padding: 16px;
    background: #eff6ff;
    border-left: 4px solid var(--primary-color);
    border-radius: 4px;
}

.instructions p {
    margin-bottom: 8px;
    font-size: 14px;
}

.instructions a {
    color: var(--primary-color);
    font-weight: 600;
    text-decoration: none;
}

.polling-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin: 24px 0;
    color: var(--text-secondary);
}

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

@keyframes spin {
    to { transform: rotate(360deg); }
}

.success-message {
    text-align: center;
    padding: 32px;
}

.success-icon {
    width: 80px;
    height: 80px;
    background: var(--success-color);
    color: white;
    font-size: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 24px;
}

.success-message h3 {
    font-size: 22px;
    margin-bottom: 8px;
}

.success-message p {
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.debug-console {
    background: #1e293b;
    color: #e2e8f0;
    border-radius: 8px;
    margin-top: 24px;
    box-shadow: var(--shadow-lg);
    font-family: 'Courier New', monospace;
    font-size: 12px;
}

.debug-console.hidden {
    display: none;
}

.debug-header {
    padding: 12px 16px;
    border-bottom: 1px solid #334155;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.debug-header h3 {
    font-size: 14px;
}

.debug-log {
    padding: 16px;
    max-height: 400px;
    overflow-y: auto;
}

.debug-entry {
    padding: 6px 0;
    border-bottom: 1px solid #334155;
}

.debug-timestamp {
    color: #94a3b8;
    font-size: 11px;
}

.debug-message {
    color: #e2e8f0;
    margin-top: 2px;
}

.debug-message.error {
    color: #fca5a5;
}

.debug-message.success {
    color: #86efac;
}

.debug-message.warning {
    color: #fcd34d;
}

.cookie-format-selector {
    margin-bottom: 16px;
}

.cookie-format-selector label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
}

.cookie-format-selector select {
    width: 100%;
    padding: 10px;
    border: 1px solid #444;
    border-radius: 6px;
    font-size: 14px;
    background: #2a2a2a;
    color: #e0e0e0;
}

.cookie-output {
    margin-bottom: 16px;
}

.cookie-output textarea {
    width: 100%;
    min-height: 300px;
    padding: 16px;
    border: 1px solid #444;
    border-radius: 6px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 12px;
    resize: vertical;
    background: #1a1a1a;
    color: #e0e0e0;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

.cookie-actions {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}

.cookie-instructions {
    background: #1e3a5f;
    border: 1px solid #2c5282;
    border-radius: 8px;
    padding: 16px;
    font-size: 13px;
}

.cookie-instructions h4 {
    margin-bottom: 12px;
    font-size: 14px;
    color: #90cdf4;
    font-weight: 600;
}

.cookie-instructions p {
    margin-bottom: 8px;
    line-height: 1.5;
    color: #cbd5e0;
}

.sso-status {
    padding: 12px 16px;
    background: #1e3a5f;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: #90cdf4;
}

.sso-step {
    margin-top: 16px;
}

.sso-step h3 {
    margin-bottom: 8px;
    color: var(--text-primary);
}

.sso-step p {
    margin-bottom: 8px;
    color: var(--text-secondary);
    font-size: 14px;
}

.sso-step ol {
    margin: 8px 0 16px 24px;
    font-size: 14px;
    color: var(--text-secondary);
}

.sso-actions {
    display: flex;
    gap: 12px;
    margin-top: 12px;
}

.sso-device-info {
    font-family: monospace;
}

@media (max-width: 768px) {
    .device-details {
        grid-template-columns: 1fr;
    }

    .device-header {
        flex-direction: column;
        gap: 12px;
    }

    .modal-content {
        width: 95%;
    }

    .devices-table {
        font-size: 12px;
    }

    .devices-table th,
    .devices-table td {
        padding: 8px 6px;
    }

    .action-buttons {
        flex-wrap: wrap;
    }

    .action-btn {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }

    .pagination-controls {
        flex-wrap: wrap;
        justify-content: center;
    }
}

.devices-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card-bg);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow);
    font-size: 14px;
}

.devices-table thead {
    background: #2a2a2a;
    border-bottom: 1px solid var(--border-color);
}

.devices-table th {
    padding: 16px 20px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #888;
    border-bottom: 1px solid #333;
}

.devices-table th:last-child {
    text-align: center;
}

.devices-table tbody tr {
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.15s;
}

.devices-table tbody tr:hover {
    background-color: #2a2a2a;
}

.devices-table tbody tr.inactive {
    background-color: #2a1818;
    opacity: 0.7;
}

.devices-table tbody tr.inactive:hover {
    background-color: #3a2020;
}

.devices-table td {
    padding: 12px 16px;
    vertical-align: middle;
}

.device-cell .device-name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 14px;
    margin-bottom: 2px;
}

.device-cell .device-email {
    color: var(--text-secondary);
    font-size: 12px;
}

.device-type-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 3px;
    vertical-align: middle;
    margin-left: 6px;
    cursor: help;
}

.device-type-badge.broker {
    background: #1e3a5f;
    color: #60a5fa;
    border: 1px solid #2563eb;
}

.device-type-badge.broker-noazure {
    background: #422006;
    color: #fbbf24;
    border: 1px solid #d97706;
    cursor: pointer;
}

.device-type-badge.office {
    background: #7c2d12;
    color: #fb923c;
    border: 1px solid #c2410c;
}

.user-cell {
    color: var(--text-primary);
    font-size: 13px;
}

.search-bar {
    position: relative;
    margin-bottom: 20px;
    max-width: 400px;
}

.search-bar input {
    width: 100%;
    padding: 8px 12px 8px 36px;
    border: 1px solid #444;
    border-radius: 4px;
    font-size: 14px;
    transition: all 0.2s;
    background: #2a2a2a;
    color: #e0e0e0;
    box-sizing: border-box;
}

.search-bar input:focus {
    outline: none;
    border-color: #2196F3;
}

.search-bar input::placeholder {
    color: #888;
}

.search-bar .search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: #888;
    pointer-events: none;
}

.no-search-results {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
    font-size: 14px;
}

.notes-cell {
    max-width: 200px;
}

.notes-display {
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 6px;
    transition: all 0.2s ease;
    min-height: 20px;
    word-break: break-word;
}

.notes-display:hover {
    background-color: #2a2a2a;
}

.notes-empty {
    color: #888;
    font-style: italic;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.status-pill.active {
    background: #1B5E20;
    color: #4CAF50;
}

.status-pill.inactive {
    background: #7f1d1d;
    color: #f87171;
}

.status-pill.expiring {
    background: #713f12;
    color: #fbbf24;
}

.status-pill.token-stale {
    background: #4a3728;
    color: #e0a858;
    border: 1px solid #b8860b;
}

.status-pill.password-changed {
    background: #7c2d12;
    color: #fb923c;
    border: 1px solid #c2410c;
}

.date-cell {
    color: var(--text-secondary);
    font-size: 13px;
    white-space: nowrap;
}

.expiry-cell .expiry-time {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
}

.expiry-cell .expiry-time.urgent {
    color: var(--danger-color);
    font-weight: 600;
}

.actions-cell {
    text-align: center;
}

.action-buttons {
    display: flex;
    gap: 6px;
    justify-content: center;
}

.action-btn {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    background: transparent;
    padding: 0;
}

.action-btn:hover {
    transform: scale(1.1);
}

.action-btn svg {
    display: block;
}

.action-btn.sso {
    background: #1B5E20;
    color: #4CAF50;
}

.action-btn.sso:hover {
    background: #15803d;
}

.action-btn.refresh-token {
    background: #1a3a4a;
    color: #4dd0e1;
}

.action-btn.refresh-token:hover {
    background: #1a4a5a;
}

.action-btn.mail {
    background: #1e3a8a;
    color: #60a5fa;
}

.action-btn.mail:hover {
    background: #1e40af;
}

.action-btn.reset {
    background: #27272a;
    color: #a1a1aa;
}

.action-btn.reset:hover {
    background: #3f3f46;
}

.action-btn.delete {
    background: #d32f2f;
    color: white;
}

.action-btn.delete:hover {
    background: #c62828;
}

.pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    background: var(--card-bg);
    border-radius: 0 0 8px 8px;
    border-top: 1px solid var(--border-color);
    font-size: 13px;
}

.pagination-info {
    color: var(--text-secondary);
}

.pagination-controls {
    display: flex;
    gap: 4px;
    align-items: center;
}

.page-btn {
    padding: 6px 12px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text-primary);
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    min-width: 32px;
    transition: all 0.15s;
}

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

.page-btn.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

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

.page-ellipsis {
    padding: 6px 8px;
    color: var(--text-secondary);
    font-size: 13px;
}

.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: #94a3b8;
}

.loading-spinner .spinner {
    width: 36px;
    height: 36px;
    border: 3px solid #334155;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.loading-spinner p {
    margin-top: 14px;
    font-size: 14px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}
