/* Security & SSO Page Styles */

.sso-page {
    max-width: 1200px;
    margin: 0 auto;
}

/* Page Header */
.page-header {
    margin-bottom: 32px;
}

.page-header-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 16px;
}

.page-title h1 {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.page-title p {
    font-size: 14px;
    color: var(--text-muted);
    margin: 0;
}

/* Section Title */
.section-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Active SSO Card */
.active-sso-card {
    background: white;
    border-radius: 16px;
    border: 2px solid var(--color-success-light);
    overflow: hidden;
    margin-bottom: 24px;
}

.sso-card-header {
    padding: 20px;
    display: flex;
    align-items: flex-start;
    gap: 16px;
    border-bottom: 1px solid var(--bg-tertiary);
}

.sso-icon {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 24px;
}

.sso-icon.azure { background: linear-gradient(135deg, #0078d4, #00bcf2); color: white; }
.sso-icon.adfs { background: linear-gradient(135deg, #00188f, #0078d4); color: white; }
.sso-icon.duo { background: linear-gradient(135deg, #6dc04b, #4fa94d); color: white; }
.sso-icon.okta { background: linear-gradient(135deg, #00297a, #0066cc); color: white; }

.sso-info {
    flex: 1;
    min-width: 0;
}

.sso-name {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.sso-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 4px;
}

.sso-badge.active {
    background: var(--color-success-bg);
    color: var(--color-success-text);
}

.sso-description {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.5;
}

.sso-status {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    flex-shrink: 0;
}

.sso-status.connected {
    background: var(--color-success-bg);
    color: var(--color-success-text);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
}

.sso-card-body {
    padding: 20px;
}

.sso-details {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
}

.detail-label {
    color: var(--text-muted);
}

.detail-value {
    color: #1f2937;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
}

.detail-value code {
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
}

.detail-value.success { color: var(--color-success-light); }

.sso-card-footer {
    padding: 16px 20px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--bg-tertiary);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.config-date {
    font-size: 12px;
    color: var(--text-placeholder);
}

.footer-actions {
    display: flex;
    gap: 8px;
}

/* SSO Providers Grid */
.sso-providers-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.sso-provider-card {
    background: white;
    border: 2px dashed var(--border-primary);
    border-radius: 16px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    cursor: pointer;
    transition: all 0.15s;
}

.sso-provider-card:hover {
    border-color: var(--color-primary);
    background: var(--color-primary-bg);
}

.sso-provider-card .sso-icon {
    margin-bottom: 16px;
}

.provider-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.provider-info h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.protocol-badge {
    font-size: 11px;
    font-weight: 500;
    padding: 3px 8px;
    border-radius: 4px;
    background: var(--bg-tertiary);
    color: var(--text-muted);
}

.sso-provider-card p {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 16px;
    line-height: 1.4;
}

.sso-provider-card .btn {
    width: 100%;
    justify-content: center;
}

/* Security Settings Card */
.security-settings-card {
    background: white;
    border-radius: 16px;
    border: 1px solid var(--border-primary);
    padding: 24px;
}

.setting-group {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 0;
    border-bottom: 1px solid var(--bg-tertiary);
}

.setting-group:last-child {
    border-bottom: none;
}

.setting-info h4 {
    font-size: 14px;
    font-weight: 500;
    color: #1f2937;
    margin-bottom: 2px;
}

.setting-info p {
    font-size: 12px;
    color: var(--text-muted);
    margin: 0;
}

/* Toggle */
.toggle {
    width: 44px;
    height: 24px;
    background: var(--border-primary);
    border-radius: 12px;
    position: relative;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.toggle::after {
    content: "";
    position: absolute;
    width: 18px;
    height: 18px;
    background: white;
    border-radius: 50%;
    top: 3px;
    left: 3px;
    transition: all 0.2s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.toggle.active {
    background: var(--color-primary);
}

.toggle.active::after {
    left: 23px;
}

/* Buttons — see design-tokens.css for canonical button rules. */

.btn-icon {
    width: 32px;
    height: 32px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    border: 1px solid var(--border-primary);
    background: white;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
}

.btn-icon:hover {
    background: var(--bg-secondary);
    color: var(--text-secondary);
}

.btn-icon.danger:hover {
    background: var(--color-danger-bg);
    color: #ef4444;
    border-color: #ef4444;
}

.btn-copy {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.15s;
}

.btn-copy:hover {
    background: var(--border-primary);
    color: var(--text-secondary);
}

/* Modal */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
}

.modal.show {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border-radius: 20px;
    width: 600px;
    max-width: 90vw;
    max-height: 90vh;
    overflow: hidden;
    z-index: 1001;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
}

.modal-header {
    padding: 24px;
    border-bottom: 1px solid var(--border-primary);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title {
    display: flex;
    align-items: center;
    gap: 14px;
}

.modal-title h2 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.modal-close {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: none;
    background: var(--bg-tertiary);
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.modal-close:hover {
    background: var(--border-primary);
    color: var(--text-secondary);
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.form-section {
    margin-bottom: 24px;
}

.form-section:last-child {
    margin-bottom: 0;
}

.form-section-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-label .required {
    color: #ef4444;
}

.form-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    font-size: 14px;
    transition: all 0.15s;
    font-family: inherit;
}

.form-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Scoped to .sso-page — the certificate paste boxes want monospace. Previously unscoped, this
   leaked app-wide (textarea.form-input outranks .form-input) and forced every textarea in the app
   to monospace 12px, e.g. the clause editor's Description field. */
.sso-page textarea.form-input {
    resize: vertical;
    min-height: 100px;
    font-family: monospace;
    font-size: 12px;
}

.form-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 6px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.readonly-field {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-secondary);
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid var(--border-primary);
}

.readonly-field code {
    flex: 1;
    font-size: 12px;
    color: var(--text-secondary);
    word-break: break-all;
}

.toggle-group {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--bg-tertiary);
}

.toggle-group:last-child {
    border-bottom: none;
}

.toggle-info h4 {
    font-size: 14px;
    font-weight: 500;
    color: #1f2937;
    margin-bottom: 2px;
}

.toggle-info p {
    font-size: 12px;
    color: var(--text-muted);
    margin: 0;
}

.modal-footer {
    padding: 20px 24px;
    border-top: 1px solid var(--border-primary);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-secondary);
}

.test-connection {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-tertiary);
    cursor: pointer;
    transition: color 0.15s;
}

.test-connection:hover {
    color: var(--color-primary);
}

.modal-actions {
    display: flex;
    gap: 12px;
}

/* Toast Notification */
.toast-notification {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 16px 20px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    font-weight: 500;
    z-index: 2000;
    animation: slideIn 0.3s ease;
}

.toast-notification.success {
    background: var(--color-success-bg);
    color: var(--color-success-text);
    border: 1px solid var(--color-success-light);
}

.toast-notification.error {
    background: var(--color-danger-bg);
    color: var(--color-danger-dark);
    border: 1px solid #ef4444;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Settings Loading */
.settings-loading {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 20px;
    color: var(--text-muted);
    font-size: 14px;
    border-top: 1px solid var(--bg-tertiary);
}

.settings-loading .spinner-border-sm {
    width: 16px;
    height: 16px;
    border-width: 2px;
}

/* Responsive */
@media (max-width: 768px) {
    .sso-providers-grid {
        grid-template-columns: 1fr;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .modal.show {
        width: 95vw;
    }

    .sso-card-header {
        flex-wrap: wrap;
    }

    .sso-card-footer {
        flex-direction: column;
        gap: 12px;
    }

    .footer-actions {
        width: 100%;
        justify-content: flex-end;
    }
}

/* ===== Security tabs (SSO config / Audit logs) ===== */
.security-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid #e5e7eb;
    margin: 4px 0 24px;
}

.security-tab {
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 500;
    color: #6b7280;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.security-tab:hover {
    color: #374151;
}

.security-tab.active {
    color: #2563eb;
    border-bottom-color: #2563eb;
}

/* ===== Audit log table ===== */
.audit-log-table-wrap {
    overflow-x: auto;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
}

.audit-log-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.audit-log-table thead th {
    text-align: left;
    background: #f9fafb;
    color: #6b7280;
    font-weight: 600;
    padding: 10px 12px;
    border-bottom: 1px solid #e5e7eb;
    white-space: nowrap;
}

.audit-log-table tbody td {
    padding: 10px 12px;
    border-bottom: 1px solid #f3f4f6;
    color: #111827;
    vertical-align: top;
}

.audit-log-table tbody tr:last-child td {
    border-bottom: none;
}

.audit-when {
    white-space: nowrap;
    color: #6b7280;
}

.audit-ip {
    white-space: nowrap;
    font-family: monospace;
    color: #6b7280;
}

.audit-action {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    background: #eef2ff;
    color: #4338ca;
    font-weight: 500;
    font-size: 12px;
    white-space: nowrap;
}

.audit-details {
    color: #374151;
}

.audit-pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-top: 16px;
    flex-wrap: wrap;
}

.audit-pager-info {
    color: #6b7280;
    font-size: 13px;
}

.audit-pager-buttons {
    display: flex;
    gap: 8px;
}

.audit-pager-buttons .btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
