/* SIP Phone System Styles */

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--card-bg, #fff);
    border-radius: 8px;
    padding: 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: var(--shadow);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-icon.extensions { background: #dbeafe; color: #2563eb; }
.stat-icon.trunks { background: #d1fae5; color: #059669; }
.stat-icon.ring-groups { background: #fef3c7; color: #d97706; }
.stat-icon.calls { background: #ede9fe; color: #7c3aed; }

.stat-content {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* Tabs */
.sip-tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--border-color, #e5e7eb);
    margin-bottom: 1.5rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.sip-tab {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary, #666);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s;
    white-space: nowrap;
}

.sip-tab:hover {
    color: var(--primary-color);
    background: var(--hover-bg, #f3f4f6);
}

.sip-tab.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.sip-tab svg {
    opacity: 0.7;
}

.sip-tab.active svg {
    opacity: 1;
}

/* Panels */
.sip-panel {
    display: none;
}

.sip-panel.active {
    display: block;
}

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

.panel-header h3 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--text-primary);
}

/* Tables */
.table-container {
    background: var(--card-bg, #fff);
    border-radius: 8px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

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

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

.data-table th {
    background: var(--hover-bg, #f9fafb);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

.data-table tbody tr:hover {
    background: var(--hover-bg, #f9fafb);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.loading-text {
    text-align: center;
    padding: 2rem !important;
    color: var(--text-secondary);
}

.empty-text {
    text-align: center;
    padding: 2rem !important;
    color: var(--text-secondary);
    font-style: italic;
}

/* Status Badges */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.6rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
}

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

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

.status-badge.idle,
.status-badge.pending {
    background: #fef3c7;
    color: #92400e;
}

.status-badge.no-answer {
    background: #f3f4f6;
    color: #4b5563;
}

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

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

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

/* Action Buttons */
.action-btns {
    display: flex;
    gap: 0.5rem;
}

.btn-action {
    padding: 0.35rem 0.6rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    transition: all 0.2s;
}

.btn-action.edit {
    background: var(--hover-bg, #f3f4f6);
    color: var(--text-primary);
}

.btn-action.edit:hover {
    background: #e5e7eb;
}

.btn-action.delete {
    background: #fee2e2;
    color: #991b1b;
}

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

/* Routes Section */
.routes-section {
    display: grid;
    gap: 1.5rem;
}

.route-type {
    background: var(--card-bg, #fff);
    border-radius: 8px;
    padding: 1.25rem;
    box-shadow: var(--shadow);
}

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

.route-header h4 {
    margin: 0;
    font-size: 1rem;
    color: var(--text-primary);
}

.route-type .table-container {
    box-shadow: none;
}

/* CDR Filters */
.cdr-filters {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.cdr-filters input,
.cdr-filters select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.9rem;
    background: var(--input-bg, #fff);
    color: var(--text-primary);
}

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

.modal.active {
    display: flex;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
}

.modal-content {
    position: relative;
    background: var(--card-bg, #fff);
    border-radius: 12px;
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    z-index: 1001;
}

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

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

.modal-header h2 {
    margin: 0;
    font-size: 1.25rem;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    line-height: 1;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
}

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

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    background: var(--hover-bg);
    border-radius: 0 0 12px 12px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.form-section {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.form-section h4 {
    margin: 0 0 1rem 0;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.checkbox-group input[type="checkbox"] {
    width: auto;
}

.checkbox-row {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.checkbox-row label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.9rem;
}

.checkbox-row input[type="checkbox"] {
    width: auto;
}

.input-with-btn {
    display: flex;
    gap: 0.5rem;
}

.input-with-btn input {
    flex: 1;
}

.form-hint {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* IVR Options */
.ivr-option-row {
    display: grid;
    grid-template-columns: 60px 1fr 100px auto;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 0.5rem;
    padding: 0.5rem;
    background: var(--hover-bg);
    border-radius: 6px;
}

.ivr-option-row input,
.ivr-option-row select {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.85rem;
}

.ivr-option-row .btn-remove {
    padding: 0.35rem;
    border: none;
    background: #fee2e2;
    color: #991b1b;
    border-radius: 4px;
    cursor: pointer;
}

/* Extension Info Display */
.ext-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.ext-number {
    font-weight: 600;
    font-size: 1rem;
}

.ext-name {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* Responsive */
@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .sip-tabs {
        flex-wrap: nowrap;
        padding-bottom: 0.5rem;
    }

    .sip-tab {
        padding: 0.6rem 1rem;
        font-size: 0.85rem;
    }

    .sip-tab span {
        display: none;
    }

    .panel-header {
        flex-direction: column;
        gap: 0.75rem;
        align-items: flex-start;
    }

    .data-table {
        font-size: 0.85rem;
    }

    .data-table th,
    .data-table td {
        padding: 0.6rem 0.75rem;
    }

    .action-btns {
        flex-direction: column;
        gap: 0.25rem;
    }

    .cdr-filters {
        flex-direction: column;
    }

    .cdr-filters input,
    .cdr-filters select {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .ivr-option-row {
        grid-template-columns: 1fr;
    }
}

/* Notification Styles */
.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 1rem 1.5rem;
    border-radius: 8px;
    color: #fff;
    font-weight: 500;
    z-index: 10000;
    animation: slideIn 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.notification-success {
    background: #22c55e;
}

.notification-error {
    background: #ef4444;
}

.notification-info {
    background: #3b82f6;
}

.notification.fade-out {
    animation: fadeOut 0.3s ease forwards;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(100px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

/* Button Styles for SIP */
.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
}

.btn-secondary {
    background: var(--hover-bg, #e5e7eb);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

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

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

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

/* Monitor Section Styles */
.monitor-section {
    background: var(--card-bg, #fff);
    border-radius: 8px;
    padding: 1.25rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
}

.monitor-section h4 {
    margin: 0 0 1rem 0;
    font-size: 1rem;
    color: var(--text-primary);
}

.notice-box {
    padding: 1rem 1.25rem;
    border-radius: 8px;
    border: 1px solid;
}

.notice-box.warning {
    background: #fef3c7;
    border-color: #fcd34d;
    color: #92400e;
}

.notice-box h4 {
    margin: 0 0 0.5rem 0;
    font-size: 1rem;
}

.notice-box p {
    margin: 0;
    font-size: 0.9rem;
}

.port-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.75rem;
}

.port-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: var(--hover-bg);
    border-radius: 6px;
}

.port-name {
    font-weight: 500;
    font-size: 0.9rem;
}

.port-status {
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
}

.port-status.checking {
    background: #e0e7ff;
    color: #3730a3;
}

.port-status.open {
    background: #d1fae5;
    color: #065f46;
}

.port-status.closed {
    background: #fee2e2;
    color: #991b1b;
}

.port-status.unknown {
    background: #e5e7eb;
    color: #6b7280;
}

.status-box {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 0.75rem;
}

.status-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: var(--hover-bg);
    border-radius: 6px;
}

.status-item .label {
    font-weight: 500;
}

.status-item .value {
    font-size: 0.9rem;
}

.status-item .value.running {
    color: #059669;
}

.status-item .value.stopped {
    color: #dc2626;
}

.status-item .value.not-installed {
    color: #6b7280;
}

.hint-text {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 0.75rem;
}

.diagnostics-output {
    background: #1e293b;
    color: #e2e8f0;
    padding: 1rem;
    border-radius: 6px;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    max-height: 300px;
    overflow-y: auto;
    white-space: pre-wrap;
}

.diagnostics-output .success {
    color: #4ade80;
}

.diagnostics-output .error {
    color: #f87171;
}

.diagnostics-output .warning {
    color: #fbbf24;
}

.diagnostics-output .info {
    color: #60a5fa;
}

.test-form {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.test-form input {
    flex: 1;
    min-width: 150px;
    padding: 0.6rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.9rem;
}

.test-results {
    margin-top: 1rem;
    padding: 1rem;
    background: var(--hover-bg);
    border-radius: 6px;
    font-size: 0.9rem;
}

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

.test-results.error {
    background: #fee2e2;
    color: #991b1b;
}

/* Section Header with button */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.section-header h4 {
    margin: 0;
}

/* Firewall Result */
.firewall-result {
    margin-top: 1rem;
    padding: 1rem;
    background: var(--hover-bg);
    border-radius: 6px;
    font-size: 0.9rem;
    line-height: 1.6;
}

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

.firewall-result.error {
    background: #fee2e2;
    color: #991b1b;
}

.firewall-result .success {
    color: #059669;
}

.firewall-result .error {
    color: #dc2626;
}

.firewall-result .info {
    color: #2563eb;
}

/* Sync result */
.sync-result {
    margin-top: 1rem;
    padding: 1rem;
    background: var(--hover-bg);
    border-radius: 6px;
    font-size: 0.9rem;
    line-height: 1.6;
}

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

.sync-result.error {
    background: #fee2e2;
    color: #991b1b;
}

.sync-result .success { color: #059669; }
.sync-result .error { color: #dc2626; }
.sync-result .info { color: #2563eb; }
.sync-result .warning { color: #d97706; }

.sync-result ul {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
}

.sync-result li {
    margin: 0.25rem 0;
}

/* Config preview */
.config-preview {
    margin-top: 1rem;
    padding: 1rem;
    background: var(--hover-bg);
    border-radius: 6px;
    font-size: 0.9rem;
    overflow-x: auto;
}

.config-preview table {
    width: 100%;
}

.config-preview code {
    background: #1e293b;
    color: #e2e8f0;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-size: 0.8rem;
}

/* Loading spinner */
.loading-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid #e5e7eb;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    vertical-align: middle;
    margin-right: 0.5rem;
}

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

/* Status value colors */
.status-box .value.running {
    color: #059669;
    font-weight: 600;
}

.status-box .value.stopped {
    color: #d97706;
    font-weight: 600;
}

.status-box .value.not-installed {
    color: #dc2626;
    font-weight: 600;
}

/* Asterisk status specific styles */
.value.status-running {
    color: #059669;
    font-weight: 600;
}

.value.status-stopped {
    color: #d97706;
    font-weight: 600;
}

.value.status-error {
    color: #dc2626;
    font-weight: 600;
}

/* Notice box variations */
.notice-box.success {
    background: #d1fae5;
    border-color: #34d399;
    color: #065f46;
}

.notice-box.error {
    background: #fee2e2;
    border-color: #f87171;
    color: #991b1b;
}

/* Asterisk controls */
.asterisk-controls {
    display: flex;
    gap: 0.5rem;
}

.notification-warning {
    background: #f59e0b;
}

/* Log tabs and output */
.log-tabs {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.log-tab {
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--border-color);
    background: var(--hover-bg);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.log-tab:hover {
    background: var(--border-color);
}

.log-tab.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: #fff;
}

.log-output {
    background: #1e293b;
    color: #e2e8f0;
    padding: 1rem;
    border-radius: 6px;
    font-family: 'Courier New', monospace;
    font-size: 0.8rem;
    max-height: 300px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

.log-output .info {
    color: #60a5fa;
}

.log-output .error {
    color: #f87171;
}

.log-output .warning {
    color: #fbbf24;
}

.log-output .success {
    color: #4ade80;
}

.log-line {
    padding: 0.25rem 0;
    border-bottom: 1px solid #334155;
    line-height: 1.4;
}

.log-line:last-child {
    border-bottom: none;
}

.log-line.error {
    background: rgba(248, 113, 113, 0.1);
}

.log-line.warning {
    background: rgba(251, 191, 36, 0.05);
}

.log-time {
    color: #94a3b8;
    font-size: 0.75rem;
}

.log-line strong.error {
    color: #f87171;
    font-weight: 600;
}

.log-line strong.warning {
    color: #fbbf24;
    font-weight: 600;
}

.log-line strong.success {
    color: #4ade80;
    font-weight: 600;
}


/* Real-time monitoring styles */
.btn-realtime {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: #1e293b;
    color: #94a3b8;
    border: 1px solid #334155;
    transition: all 0.2s;
}

.btn-realtime:hover {
    background: #334155;
    color: #e2e8f0;
}

.btn-realtime.active {
    background: #16a34a;
    color: #fff;
    border-color: #16a34a;
}

.realtime-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #64748b;
    display: inline-block;
}

.realtime-dot.live {
    background: #4ade80;
    animation: pulse-dot 1.5s ease-in-out infinite;
}

.realtime-indicator {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.7rem;
    font-weight: 600;
    color: #16a34a;
    background: rgba(22, 163, 74, 0.15);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    margin-left: 0.5rem;
}

.pulse-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #16a34a;
    animation: pulse-dot 1.5s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.5;
        transform: scale(0.8);
    }
}

/* Improve log output for real-time */
.log-output {
    scroll-behavior: smooth;
}

.log-output .log-line:first-child {
    animation: highlight-new 2s ease-out;
}

@keyframes highlight-new {
    0% {
        background: rgba(96, 165, 250, 0.2);
    }
    100% {
        background: transparent;
    }
}
