/* ServiceAlert.ai — Certificate Lifecycle Monitor Styles */

/* Page container */
.cert-page {
    max-width: 1280px;
}

/* ========== Summary Bar ========== */
.cert-summary {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 24px;
}

.cert-summary-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 14px;
    transition: border-color 0.2s;
}

.cert-summary-card:hover {
    border-color: rgba(255, 255, 255, 0.15);
}

.cert-summary-card.cert-summary-warning .cert-summary-value {
    color: var(--status-degraded);
}

.cert-summary-card.cert-summary-danger .cert-summary-value {
    color: var(--status-major);
}

.cert-summary-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary);
    flex-shrink: 0;
}

.cert-summary-card.cert-summary-warning .cert-summary-icon {
    background: rgba(232, 163, 23, 0.1);
    color: var(--status-degraded);
}

.cert-summary-card.cert-summary-danger .cert-summary-icon {
    background: rgba(229, 72, 77, 0.1);
    color: var(--status-major);
}

.cert-summary-data {
    min-width: 0;
}

.cert-summary-value {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.cert-summary-label {
    font-size: 0.72rem;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-top: 2px;
    white-space: nowrap;
}

/* ========== Controls (Filters + Sort) ========== */
.cert-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.cert-filters {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.cert-filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 14px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: inherit;
}

.cert-filter-chip:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.cert-filter-chip.active {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-subtle, rgba(59, 130, 246, 0.08));
}

.cert-sort select {
    padding: 7px 32px 7px 12px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-family: inherit;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%23A0A0A8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    transition: border-color 0.15s;
}

.cert-sort select:hover,
.cert-sort select:focus {
    border-color: var(--accent);
    outline: none;
}

/* ========== Table Header ========== */
.cert-table-header {
    display: grid;
    grid-template-columns: 40px 1fr 60px 100px 1fr 60px 100px 90px;
    gap: 12px;
    align-items: center;
    padding: 8px 16px;
    font-size: 0.68rem;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 4px;
}

/* ========== Table Body / Rows ========== */
.cert-table-body {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.cert-row {
    display: grid;
    grid-template-columns: 40px 1fr 60px 100px 1fr 60px 100px 90px;
    gap: 12px;
    align-items: center;
    padding: 14px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.cert-row:hover {
    border-color: var(--accent);
    box-shadow: 0 1px 8px rgba(0, 0, 0, 0.15);
}

/* Status dot column */
.cert-col-status {
    display: flex;
    align-items: center;
    justify-content: center;
}

.cert-status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.cert-status-dot.valid {
    background: var(--status-operational);
    box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.15);
}

.cert-status-dot.expiring {
    background: var(--status-degraded);
    box-shadow: 0 0 0 3px rgba(232, 163, 23, 0.15);
    animation: pulse-warning 2s infinite;
}

.cert-status-dot.critical {
    background: var(--status-major);
    box-shadow: 0 0 0 3px rgba(229, 72, 77, 0.15);
    animation: pulse-critical 1.5s infinite;
}

.cert-status-dot.expired {
    background: var(--status-major);
}

.cert-status-dot.unknown {
    background: var(--text-tertiary);
}

@keyframes pulse-warning {
    0%, 100% { box-shadow: 0 0 0 3px rgba(232, 163, 23, 0.15); }
    50% { box-shadow: 0 0 0 6px rgba(232, 163, 23, 0); }
}

@keyframes pulse-critical {
    0%, 100% { box-shadow: 0 0 0 3px rgba(229, 72, 77, 0.15); }
    50% { box-shadow: 0 0 0 6px rgba(229, 72, 77, 0); }
}

/* Domain column */
.cert-col-domain {
    overflow: hidden;
    min-width: 0;
}

.cert-domain-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
    text-decoration: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
    transition: color 0.15s;
}

.cert-domain-name:hover {
    color: var(--accent);
}

.cert-domain-san {
    font-size: 0.72rem;
    color: var(--text-tertiary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-top: 2px;
}

/* Grade badge */
.cert-col-grade {
    display: flex;
    align-items: center;
    justify-content: center;
}

.cert-grade {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.8rem;
    letter-spacing: -0.02em;
    flex-shrink: 0;
}

.cert-grade.a-plus,
.cert-grade.a {
    background: rgba(52, 211, 153, 0.15);
    color: #34D399;
}

.cert-grade.b {
    background: rgba(59, 130, 246, 0.15);
    color: #3B82F6;
}

.cert-grade.c {
    background: rgba(232, 163, 23, 0.15);
    color: #E8A317;
}

.cert-grade.d {
    background: rgba(232, 116, 44, 0.15);
    color: #E8742C;
}

.cert-grade.f {
    background: rgba(229, 72, 77, 0.15);
    color: #E5484D;
}

.cert-grade.unknown {
    background: var(--bg-tertiary);
    color: var(--text-tertiary);
}

/* Expiry column */
.cert-col-expiry {
    white-space: nowrap;
}

.cert-expiry {
    font-size: 0.85rem;
    font-weight: 600;
}

.cert-expiry.safe {
    color: var(--status-operational);
}

.cert-expiry.warning {
    color: var(--status-degraded);
}

.cert-expiry.danger {
    color: var(--status-partial);
}

.cert-expiry.critical {
    color: var(--status-major);
}

.cert-expiry-date {
    font-size: 0.7rem;
    color: var(--text-tertiary);
    margin-top: 1px;
}

/* Issuer column */
.cert-col-issuer {
    font-size: 0.82rem;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

/* Chain status column */
.cert-col-chain {
    display: flex;
    align-items: center;
    justify-content: center;
}

.cert-chain-status {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
}

.cert-chain-status.ok {
    color: var(--status-operational);
    background: rgba(52, 211, 153, 0.1);
}

.cert-chain-status.warning {
    color: var(--status-partial);
    background: rgba(232, 116, 44, 0.1);
}

.cert-chain-status.unknown {
    color: var(--text-tertiary);
    background: var(--bg-tertiary);
}

/* Last checked column */
.cert-col-checked {
    font-size: 0.78rem;
    color: var(--text-tertiary);
    white-space: nowrap;
}

/* Actions column */
.cert-col-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

.cert-check-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
    white-space: nowrap;
}

.cert-check-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-subtle, rgba(59, 130, 246, 0.08));
}

.cert-check-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.cert-check-btn .spinner-sm {
    width: 12px;
    height: 12px;
    border: 2px solid rgba(255, 255, 255, 0.15);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* ========== Empty State ========== */
.cert-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-tertiary);
}

.cert-empty svg {
    margin-bottom: 16px;
    opacity: 0.4;
}

.cert-empty h3 {
    font-size: 1.15rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-weight: 600;
}

.cert-empty p {
    font-size: 0.9rem;
    margin-bottom: 20px;
    max-width: 400px;
    margin-left: auto;
    margin-right: auto;
}

/* ========== Auth Gate ========== */
.cert-auth-gate {
    text-align: center;
    padding: 100px 20px;
}

.cert-auth-gate svg {
    color: var(--text-tertiary);
    opacity: 0.4;
    margin-bottom: 20px;
}

.cert-auth-gate h2 {
    font-size: 1.4rem;
    color: var(--text-primary);
    margin-bottom: 10px;
    font-weight: 700;
}

.cert-auth-gate p {
    font-size: 0.95rem;
    color: var(--text-tertiary);
    margin-bottom: 28px;
    max-width: 420px;
    margin-left: auto;
    margin-right: auto;
}

/* ========== Skeleton Loading ========== */
.cert-skeleton {
    pointer-events: none;
}

.skeleton-text {
    color: var(--text-tertiary);
    opacity: 0.5;
}

.skeleton-line {
    height: 14px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    animation: skeleton-pulse 1.5s ease-in-out infinite;
}

.skeleton-circle {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    animation: skeleton-pulse 1.5s ease-in-out infinite;
}

.skeleton-circle-sm {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    animation: skeleton-pulse 1.5s ease-in-out infinite;
}

@keyframes skeleton-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ========== Mobile Card Layout ========== */
.cert-row-mobile-label {
    display: none;
}

/* ========== Loading overlay for the page ========== */
.loading {
    text-align: center;
    padding: 80px 20px;
    color: var(--text-tertiary);
}

.loading .spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    margin: 0 auto 16px;
}

/* ========== Error toast ========== */
.cert-toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    z-index: 9999;
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s ease;
    max-width: 400px;
}

.cert-toast.visible {
    transform: translateY(0);
    opacity: 1;
}

.cert-toast.error {
    background: rgba(229, 72, 77, 0.95);
    color: #fff;
    border: 1px solid rgba(229, 72, 77, 0.5);
}

.cert-toast.success {
    background: rgba(52, 211, 153, 0.95);
    color: #0F0F11;
    border: 1px solid rgba(52, 211, 153, 0.5);
}

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

/* ========== Responsive: Tablet ========== */
@media (max-width: 960px) {
    .cert-summary {
        grid-template-columns: repeat(2, 1fr);
    }

    .cert-table-header {
        display: none;
    }

    .cert-row {
        grid-template-columns: 32px 1fr auto;
        grid-template-rows: auto auto auto;
        gap: 4px 12px;
        padding: 14px 16px;
    }

    .cert-col-status {
        grid-row: 1 / 3;
        align-self: start;
        padding-top: 4px;
    }

    .cert-col-domain {
        grid-column: 2;
        grid-row: 1;
    }

    .cert-col-grade {
        grid-column: 3;
        grid-row: 1 / 3;
    }

    .cert-col-expiry {
        grid-column: 2;
        grid-row: 2;
    }

    .cert-col-issuer {
        grid-column: 1 / -1;
        grid-row: 3;
        padding-top: 8px;
        border-top: 1px solid var(--border-color);
        margin-top: 6px;
        display: flex;
        align-items: center;
        gap: 12px;
    }

    .cert-col-chain {
        grid-column: 2;
        grid-row: 3;
        display: none;
    }

    .cert-col-checked {
        display: none;
    }

    .cert-col-actions {
        grid-column: 3;
        grid-row: 3;
        display: none;
    }

    /* Show mobile labels */
    .cert-row-mobile-label {
        display: inline;
        font-size: 0.68rem;
        color: var(--text-tertiary);
        text-transform: uppercase;
        letter-spacing: 0.04em;
        margin-right: 6px;
    }
}

/* ========== Responsive: Mobile ========== */
@media (max-width: 768px) {
    .cert-summary {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .cert-summary-card {
        padding: 12px 14px;
        gap: 10px;
    }

    .cert-summary-icon {
        width: 34px;
        height: 34px;
    }

    .cert-summary-icon svg {
        width: 16px;
        height: 16px;
    }

    .cert-summary-value {
        font-size: 1.15rem;
    }

    .cert-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .cert-filters {
        overflow-x: auto;
        flex-wrap: nowrap;
        padding-bottom: 4px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .cert-filters::-webkit-scrollbar {
        display: none;
    }

    .cert-filter-chip {
        flex-shrink: 0;
    }

    .cert-sort {
        align-self: flex-end;
    }

    .cert-sort select {
        width: 100%;
    }

    /* Card layout on mobile */
    .cert-row {
        grid-template-columns: 1fr auto;
        grid-template-rows: auto auto auto;
        gap: 6px 10px;
        padding: 16px;
    }

    .cert-col-status {
        display: none;
    }

    .cert-col-domain {
        grid-column: 1;
        grid-row: 1;
    }

    .cert-col-grade {
        grid-column: 2;
        grid-row: 1 / 3;
        align-self: center;
    }

    .cert-col-expiry {
        grid-column: 1;
        grid-row: 2;
    }

    .cert-col-issuer {
        grid-column: 1 / -1;
        grid-row: 3;
        padding-top: 10px;
        border-top: 1px solid var(--border-color);
        margin-top: 6px;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .cert-col-chain {
        display: none;
    }

    .cert-col-checked {
        display: none;
    }

    .cert-col-actions {
        display: none;
    }

    /* Show check button in issuer row on mobile */
    .cert-row .cert-mobile-actions {
        display: flex;
    }

    .cert-page {
        padding-top: 16px !important;
    }
}

/* ========== Responsive: Small ========== */
@media (max-width: 480px) {
    .cert-summary {
        grid-template-columns: 1fr;
    }

    .cert-summary-card {
        padding: 12px 16px;
    }

    .monitor-page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .cert-grade {
        width: 36px;
        height: 36px;
        font-size: 0.75rem;
    }
}

/* ── Add Certificate Modal ────────────────────── */
.cert-modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 1100;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.cert-modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    width: 100%;
    max-width: 440px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.4);
}

.cert-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 0;
}

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

.cert-modal-close {
    background: none;
    border: none;
    color: var(--text-tertiary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
}

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

.cert-modal-body {
    padding: 20px 24px 24px;
}

.cert-modal-body label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 6px;
    margin-top: 14px;
}

.cert-modal-body label:first-child {
    margin-top: 0;
}

.cert-modal-body input[type="text"] {
    width: 100%;
    padding: 10px 14px;
    font-size: 0.875rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: inherit;
    outline: none;
}

.cert-modal-body input[type="text"]:focus {
    border-color: var(--accent);
}

.cert-modal-hint {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    margin: 4px 0 0;
}

.cert-modal-actions {
    margin-top: 20px;
}

.cert-modal-actions .btn {
    width: 100%;
}

.cert-modal-status {
    margin-top: 12px;
    font-size: 0.8125rem;
    text-align: center;
    min-height: 20px;
}

.cert-modal-status.success { color: var(--status-operational); }
.cert-modal-status.error { color: var(--status-major); }
