/**
 * SyncPBX - Asterisk Configuration Management System
 * Copyright (c) 2025 Synchresis Solutions
 * https://www.synchresis.net
 * Modern Responsive UI with Full Screen Reader Accessibility
 */

:root {
    --primary: #2563eb;
    --primary-dark: #1e40af;
    --secondary: #64748b;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #06b6d4;
    --light: #f8fafc;
    --dark: #0f172a;
    --border: #e2e8f0;
    --shadow: rgba(0, 0, 0, 0.1);
    --radius: 8px;
    --radius-lg: 16px;
    --transition: 0.2s ease;
    --focus-ring: 0 0 0 3px rgba(37, 99, 235, 0.3);

    /* Semantic theme colors - Light mode (default) */
    --background: #f8fafc;
    --surface: #ffffff;
    --text: #0f172a;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --shadow-color: rgba(0, 0, 0, 0.1);
}

/* Dark mode - Auto-switches based on OS preference */
@media (prefers-color-scheme: dark) {
    :root {
        --primary: #60a5fa;
        --primary-dark: #3b82f6;
        --secondary: #cbd5e1;
        --success: #4ade80;
        --danger: #fb7185;
        --warning: #fcd34d;
        --info: #67e8f9;
        --light: #1e293b;
        --dark: #f1f5f9;
        --border: #334155;
        --shadow: rgba(0, 0, 0, 0.3);

        /* Semantic theme colors - Dark mode */
        --background: #0f172a;
        --surface: #111827;
        --text: #f1f5f9;
        --text-muted: #cbd5e1;
        --border-color: #1f2937;
        --shadow-color: rgba(0, 0, 0, 0.3);
    }
}

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

/* Skip to main content link for screen readers */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--primary);
    color: white;
    padding: 8px 16px;
    text-decoration: none;
    z-index: 9999;
    border-radius: 0 0 4px 0;
}

.skip-link:focus {
    top: 0;
}

/* Screen reader only text */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Focus styles for keyboard navigation */
*:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

*:focus:not(:focus-visible) {
    outline: none;
}

*:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--background);
    color: var(--text);
    line-height: 1.6;
    font-size: 16px;
}

/* Layout */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
}

.wrapper {
    display: flex;
    min-height: 100vh;
}

/* Header */
.header {
    background: var(--surface);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 4px var(--shadow-color);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.9rem;
    color: var(--secondary);
}

.header-user #go-live-btn {
    margin-left: 0.75rem;
}

.header-user__name strong {
    color: var(--primary-dark);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    text-decoration: none;
}

.logo:focus {
    outline: 2px solid var(--primary);
    outline-offset: 4px;
}

.logo-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
}

/* Sidebar Navigation */
.sidebar {
    width: 260px;
    background: var(--surface);
    border-right: 1px solid var(--border-color);
    padding: 2rem 0;
    overflow-y: auto;
    position: fixed;
    height: calc(100vh - 73px);
    top: 73px;
}

.nav-menu {
    list-style: none;
}

.nav-item {
    margin: 0.25rem 1rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0.75rem 1rem;
    color: var(--secondary);
    text-decoration: none;
    border-radius: var(--radius);
    transition: all var(--transition);
    font-weight: 500;
}

.nav-link:hover {
    background: var(--light);
    color: var(--primary);
}

.nav-link:focus {
    box-shadow: var(--focus-ring);
}

.nav-link[aria-current="page"] {
    background: var(--primary);
    color: white;
}

.nav-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: 260px;
    padding: 2rem;
    background: var(--light);
}

/* Page Header */
.page-header {
    margin-bottom: 2rem;
}

.page-title {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.page-description {
    color: var(--secondary);
}

/* Cards */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: 0 1px 3px var(--shadow-color);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

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

.card-title {
    font-size: 1.25rem;
    font-weight: 600;
}

.card-body {
    padding: 0;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0.625rem 1.25rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

.btn:focus {
    box-shadow: var(--focus-ring);
}

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

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

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

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

.btn-success:hover:not(:disabled) {
    background: #059669;
}

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

.btn-danger:hover:not(:disabled) {
    background: #dc2626;
}

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

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

.btn-warning:hover:not(:disabled) {
    background: #d97706;
}

.btn-link {
    background: transparent;
    color: var(--primary);
    padding: 0;
    font-weight: 600;
    text-decoration: underline;
}

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

.btn-full {
    width: 100%;
}

/* Authentication Layout */
.auth-body {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.1), rgba(59, 130, 246, 0.05));
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.auth-container {
    width: 100%;
    max-width: 480px;
    padding: 2rem;
}

.auth-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: 0 25px 50px -12px var(--shadow-color);
    padding: 2.5rem;
}

.auth-header h1 {
    font-size: 1.75rem;
    margin-bottom: 0.5rem;
}

.auth-subtitle {
    margin: 0;
    color: var(--secondary);
}

.auth-footer {
    margin-top: 1.5rem;
    font-size: 0.85rem;
    color: var(--secondary);
}

.auth-footer code {
    background: rgba(15, 118, 110, 0.1);
    color: var(--primary-dark);
    padding: 0.1rem 0.3rem;
    border-radius: 4px;
}

.btn-secondary:hover:not(:disabled) {
    background: #475569;
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
}

/* Forms */
.form-group {
    margin-bottom: 1.5rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--dark);
}

.form-hint {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.875rem;
    color: var(--secondary);
}

.form-control {
    width: 100%;
    padding: 0.625rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 0.95rem;
    transition: border-color var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--focus-ring);
}

.form-control:disabled {
    background: var(--light);
    cursor: not-allowed;
}

.form-control[aria-invalid="true"] {
    border-color: var(--danger);
}

.form-error {
    color: var(--danger);
    font-size: 0.875rem;
    margin-top: 0.25rem;
    display: block;
}

.form-control-sm {
    padding: 0.375rem;
    font-size: 0.875rem;
}

.form-select {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 16px 12px;
    padding-right: 2.5rem;
    appearance: none;
}

.form-check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.form-check-input {
    width: 18px;
    height: 18px;
    cursor: pointer;
    flex-shrink: 0;
}

.form-check-input:focus {
    box-shadow: var(--focus-ring);
}

textarea.form-control {
    min-height: 100px;
    resize: vertical;
}

/* Required field indicator */
.required-indicator {
    color: var(--danger);
    font-weight: bold;
    margin-left: 0.25rem;
}

/* Table */
.table-container {
    overflow-x: auto;
}

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

.table caption {
    caption-side: top;
    text-align: left;
    font-weight: 600;
    padding: 0.75rem;
    font-size: 1.125rem;
}

.table th,
.table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.table th {
    background: var(--light);
    font-weight: 600;
    color: var(--dark);
}

.table tbody tr:hover {
    background: var(--light);
}

.table tbody tr:focus-within {
    background: var(--light);
    outline: 2px solid var(--primary);
}

.admin-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.admin-actions form {
    display: inline;
}

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

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

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

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

.badge-info {
    background: #cffafe;
    color: #164e63;
}

.badge-secondary {
    background: #e2e8f0;
    color: #475569;
}

/* Alerts */
.alert {
    padding: 1rem;
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
    border-left: 4px solid;
}

.alert[role="alert"] {
    position: relative;
}

.alert-success {
    background: #d1fae5;
    color: #065f46;
    border-left-color: var(--success);
}

.alert-danger {
    background: #fee2e2;
    color: #991b1b;
    border-left-color: var(--danger);
}

.alert-warning {
    background: #fef3c7;
    color: #92400e;
    border-left-color: var(--warning);
}

.alert-info {
    background: #cffafe;
    color: #164e63;
    border-left-color: var(--info);
}

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

.modal[aria-hidden="false"] {
    display: flex;
}

.modal-content {
    background: var(--surface);
    border-radius: var(--radius);
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

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

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

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--secondary);
    padding: 0.25rem;
    line-height: 1;
}

.modal-close:focus {
    box-shadow: var(--focus-ring);
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
}

/* Mobile Menu Toggle */
.mobile-menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--dark);
    padding: 0.5rem;
}

.mobile-menu-toggle:focus {
    box-shadow: var(--focus-ring);
}

.mobile-menu-toggle[aria-expanded="true"] + .sidebar {
    transform: translateX(0);
}

/* Loading state */
.loading {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.6s linear infinite;
}

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

/* Live region for announcements */
.sr-live-region {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Responsive Design */
@media (max-width: 968px) {
    .header-content {
        flex-wrap: wrap;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .header-user {
        width: 100%;
        flex-wrap: wrap;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .header-user__name {
        width: 100%;
    }

    .header-user .btn-link {
        padding-left: 0;
    }

    .header-user #go-live-btn {
        margin-left: 0;
    }

    .sidebar {
        transform: translateX(-100%);
        transition: transform var(--transition);
        z-index: 200;
    }

    .sidebar[data-visible="true"] {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }

    .mobile-menu-toggle {
        display: block;
    }
}

@media (max-width: 640px) {
    .header-user #go-live-btn {
        width: 100%;
    }

    .page-title {
        font-size: 1.5rem;
    }

    .card {
        padding: 1rem;
    }

    .btn {
        padding: 0.5rem 1rem;
        font-size: 0.875rem;
    }

    .table th,
    .table td {
        padding: 0.5rem;
        font-size: 0.875rem;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .btn {
        border: 2px solid currentColor;
    }

    .form-control {
        border-width: 2px;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Print styles */
@media print {
    .sidebar,
    .mobile-menu-toggle,
    .btn,
    .skip-link {
        display: none;
    }

    .main-content {
        margin-left: 0;
    }
}

/* Utilities */
.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.d-flex { display: flex; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.justify-between { justify-content: space-between; }
.align-center { align-items: center; }

/* ==================== AGENT STATUS POPOVER ==================== */

/* Agent status container in header */
.agent-status-container {
    position: relative;
    margin-right: 1rem;
}

/* Agent status button - minimal styling, inherits from .btn .btn-success */
.agent-status-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Status badge within button */
.status-badge {
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius);
    font-size: 0.8rem;
    font-weight: 600;
}

.status-badge.status-available {
    background: var(--success-bg, #d4edda);
    color: var(--success, #28a745);
}

.status-badge.status-paused {
    background: var(--warning-bg, #fff3cd);
    color: var(--warning, #ffc107);
}

.status-badge.status-logged-out {
    background: var(--secondary-bg, #e9ecef);
    color: var(--secondary, #6c757d);
}

/* Agent popover container */
.agent-popover {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    width: 400px;
    max-width: 90vw;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1000;
}

.agent-popover[hidden] {
    display: none;
}

/* Popover header */
.agent-popover-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}

.agent-popover-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
}

.agent-popover-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    color: var(--secondary);
    cursor: pointer;
    padding: 0;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.agent-popover-close:hover {
    color: var(--text);
}

.agent-popover-close:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-radius: var(--radius);
}

/* Popover body */
.agent-popover-body {
    padding: 1rem;
    max-height: 400px;
    overflow-y: auto;
}

/* Loading state */
.agent-loading {
    text-align: center;
    padding: 2rem;
    color: var(--secondary);
}

/* No queues message */
.agent-no-queues {
    text-align: center;
    padding: 2rem;
    color: var(--secondary);
}

/* Queue item */
.agent-queue-item {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}

.agent-queue-item:last-child {
    border-bottom: none;
}

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

.agent-queue-controls {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.agent-pause-reason {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
    color: var(--secondary);
    font-style: italic;
}

/* Dark mode adjustments */
@media (prefers-color-scheme: dark) {
    .agent-popover {
        background: var(--surface-dark, #2c2c2c);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    }

    .status-badge.status-available {
        background: rgba(40, 167, 69, 0.2);
        color: #5cd67f;
    }

    .status-badge.status-paused {
        background: rgba(255, 193, 7, 0.2);
        color: #ffd54f;
    }

    .status-badge.status-logged-out {
        background: rgba(108, 117, 125, 0.2);
        color: #adb5bd;
    }
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .agent-status-container {
        margin-right: 0.5rem;
    }

    .agent-popover {
        width: 320px;
        right: auto;
        left: 50%;
        transform: translateX(-50%);
    }

    .agent-status-btn {
        padding: 0.4rem 0.75rem;
        font-size: 0.85rem;
    }
}
.w-100 { width: 100%; }
