/* ╔══════════════════════════════════════════════════╗
   ║  SSL Certificate Monitor — Premium Dark Theme    ║
   ╚══════════════════════════════════════════════════╝ */

/* ──────────── Design Tokens ──────────── */
:root {
    /* Base palette */
    --bg-primary: #0a0e1a;
    --bg-secondary: #111827;
    --bg-card: #1a1f35;
    --bg-card-hover: #222845;
    --bg-elevated: #1e2440;
    --bg-input: #151b30;

    /* Borders */
    --border-subtle: rgba(255,255,255,0.06);
    --border-medium: rgba(255,255,255,0.1);
    --border-accent: rgba(6,182,212,0.3);

    /* Text */
    --text-primary: #f0f4f8;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --text-inverse: #0f172a;

    /* Status colors */
    --color-ok: #10b981;
    --color-ok-soft: rgba(16,185,129,0.12);
    --color-info: #3b82f6;
    --color-info-soft: rgba(59,130,246,0.12);
    --color-warning: #f59e0b;
    --color-warning-soft: rgba(245,158,11,0.12);
    --color-critical: #ef4444;
    --color-critical-soft: rgba(239,68,68,0.12);
    --color-error: #6b7280;
    --color-error-soft: rgba(107,114,128,0.12);

    /* Accent */
    --accent-cyan: #06b6d4;
    --accent-purple: #8b5cf6;
    --accent-gradient: linear-gradient(135deg, #06b6d4, #8b5cf6);

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.4);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.5);
    --shadow-glow-cyan: 0 0 30px rgba(6,182,212,0.15);
    --shadow-glow-purple: 0 0 30px rgba(139,92,246,0.15);

    /* Radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    /* Transitions */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --transition-fast: 0.15s var(--ease-out);
    --transition-normal: 0.3s var(--ease-out);
    --transition-slow: 0.5s var(--ease-out);
}

/* ──────────── Reset & Base ──────────── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 14px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Subtle grid background */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse 80% 60% at 50% -10%, rgba(6,182,212,0.08), transparent),
        radial-gradient(ellipse 60% 40% at 80% 100%, rgba(139,92,246,0.06), transparent);
    pointer-events: none;
    z-index: 0;
}

/* ──────────── Header ──────────── */
#main-header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 28px;
    background: rgba(10,14,26,0.85);
    backdrop-filter: blur(20px) saturate(1.4);
    -webkit-backdrop-filter: blur(20px) saturate(1.4);
    border-bottom: 1px solid var(--border-subtle);
}

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

.logo {
    display: flex;
    align-items: center;
    gap: 14px;
}

.logo-icon {
    display: flex;
    align-items: center;
    filter: drop-shadow(0 0 8px rgba(6,182,212,0.4));
    animation: logo-float 4s ease-in-out infinite;
}

@keyframes logo-float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}

.logo h1 {
    font-size: 1.35rem;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
}

.logo .subtitle {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 400;
}

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

/* ──────────── Buttons ──────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 9px 18px;
    border: none;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
    line-height: 1;
}

.btn-primary {
    background: var(--accent-gradient);
    color: white;
    box-shadow: 0 2px 12px rgba(6,182,212,0.3);
}
.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 20px rgba(6,182,212,0.4);
}
.btn-primary:active { transform: translateY(0); }

.btn-primary.scanning {
    background: linear-gradient(135deg, #374151, #4b5563);
    cursor: not-allowed;
    box-shadow: none;
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-medium);
}
.btn-ghost:hover {
    background: var(--bg-card);
    color: var(--text-primary);
    border-color: var(--border-accent);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
}

.btn-danger {
    background: rgba(239,68,68,0.15);
    color: var(--color-critical);
    border: 1px solid rgba(239,68,68,0.3);
}
.btn-danger:hover {
    background: rgba(239,68,68,0.25);
}

/* ──────────── Progress Bar ──────────── */
.progress-container {
    position: relative;
    z-index: 50;
    padding: 12px 28px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-subtle);
    animation: slideDown 0.3s var(--ease-out);
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.progress-bar {
    height: 6px;
    background: var(--bg-card);
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    border-radius: 3px;
    background: var(--accent-gradient);
    transition: width 0.5s var(--ease-out);
    position: relative;
}

.progress-fill::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    from { transform: translateX(-100%); }
    to { transform: translateX(100%); }
}

.progress-text {
    margin-top: 6px;
    font-size: 0.78rem;
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
}

/* ──────────── Stats Bar ──────────── */
.stats-bar {
    position: relative;
    z-index: 10;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 16px;
    padding: 20px 28px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 20px 22px;
    text-align: center;
    transition: all var(--transition-normal);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.stat-card[data-status="total"]::before { background: var(--accent-gradient); }
.stat-card[data-status="ok"]::before { background: var(--color-ok); }
.stat-card[data-status="warning"]::before { background: var(--color-warning); }
.stat-card[data-status="critical"]::before { background: var(--color-critical); }
.stat-card[data-status="error"]::before { background: var(--color-error); }

.stat-card:hover {
    transform: translateY(-3px);
    border-color: var(--border-accent);
    box-shadow: var(--shadow-md);
}

.stat-number {
    font-size: 2.2rem;
    font-weight: 800;
    font-family: 'JetBrains Mono', monospace;
    letter-spacing: -0.03em;
    line-height: 1.1;
}

.stat-card[data-status="total"] .stat-number { color: var(--accent-cyan); }
.stat-card[data-status="ok"] .stat-number { color: var(--color-ok); }
.stat-card[data-status="warning"] .stat-number { color: var(--color-warning); }
.stat-card[data-status="critical"] .stat-number { color: var(--color-critical); }
.stat-card[data-status="error"] .stat-number { color: var(--color-error); }

.stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 4px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* ──────────── Toolbar ──────────── */
.toolbar {
    position: relative;
    z-index: 10;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 28px 16px;
    flex-wrap: wrap;
    gap: 12px;
}

.toolbar-left, .toolbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    gap: 4px;
    background: var(--bg-card);
    padding: 4px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
}

.filter-btn {
    padding: 6px 14px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.filter-btn:hover { color: var(--text-primary); background: var(--bg-elevated); }
.filter-btn.active { background: var(--accent-gradient); color: white; }

.search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-input);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 7px 14px;
    transition: border-color var(--transition-fast);
}

.search-box:focus-within { border-color: var(--accent-cyan); }
.search-box svg { color: var(--text-muted); flex-shrink: 0; }

.search-box input {
    background: none;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.85rem;
    width: 180px;
}

.search-box input::placeholder { color: var(--text-muted); }

.action-btns { display: flex; gap: 6px; }

/* ──────────── Table ──────────── */
main {
    position: relative;
    z-index: 10;
    padding: 0 28px 40px;
}

.table-section {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.table-container {
    overflow-x: auto;
}

#certs-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

#certs-table thead {
    background: var(--bg-elevated);
    position: sticky;
    top: 0;
    z-index: 5;
}

#certs-table th {
    padding: 13px 16px;
    text-align: left;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-size: 0.72rem;
    letter-spacing: 0.06em;
    border-bottom: 1px solid var(--border-medium);
    white-space: nowrap;
}

.sortable { cursor: pointer; user-select: none; }
.sortable:hover { color: var(--accent-cyan); }
.sort-icon { opacity: 0.4; font-size: 0.7rem; margin-left: 3px; }
.sortable.sort-asc .sort-icon, .sortable.sort-desc .sort-icon { opacity: 1; color: var(--accent-cyan); }

#certs-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-subtle);
    vertical-align: middle;
}

#certs-table tbody tr {
    transition: background var(--transition-fast);
}

#certs-table tbody tr:hover {
    background: var(--bg-card-hover);
}

/* Domain column */
.domain-cell {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-primary);
}

/* Status badge */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.status-badge[data-status="OK"] { background: var(--color-ok-soft); color: var(--color-ok); }
.status-badge[data-status="INFO"] { background: var(--color-info-soft); color: var(--color-info); }
.status-badge[data-status="WARNING"] { background: var(--color-warning-soft); color: var(--color-warning); }
.status-badge[data-status="CRITICAL"] {
    background: var(--color-critical-soft);
    color: var(--color-critical);
    animation: pulse-critical 2s ease-in-out infinite;
}
.status-badge[data-status="EXPIRED"] {
    background: var(--color-critical-soft);
    color: var(--color-critical);
    animation: pulse-critical 1.5s ease-in-out infinite;
}
.status-badge[data-status="ERROR"] { background: var(--color-error-soft); color: #9ca3af; }

@keyframes pulse-critical {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.3); }
    50% { box-shadow: 0 0 0 6px rgba(239,68,68,0); }
}

/* Days left */
.days-cell {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
    font-size: 0.9rem;
}

.days-ok { color: var(--color-ok); }
.days-info { color: var(--color-info); }
.days-warning { color: var(--color-warning); }
.days-critical { color: var(--color-critical); }
.days-error { color: var(--color-error); }

/* Error message tooltip */
.error-msg {
    font-size: 0.75rem;
    color: #9ca3af;
    max-width: 200px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 60px 20px !important;
    color: var(--text-muted);
}

.empty-icon {
    font-size: 3rem;
    margin-bottom: 12px;
    opacity: 0.5;
}

/* Row action buttons */
.row-actions {
    display: flex;
    gap: 6px;
}

.row-btn {
    background: none;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    padding: 4px 8px;
    cursor: pointer;
    font-size: 0.72rem;
    font-family: inherit;
    transition: all var(--transition-fast);
}

.row-btn:hover {
    border-color: var(--accent-cyan);
    color: var(--accent-cyan);
    background: rgba(6,182,212,0.08);
}

.row-btn.delete-btn:hover {
    border-color: var(--color-critical);
    color: var(--color-critical);
    background: rgba(239,68,68,0.08);
}

/* ──────────── Charts ──────────── */
.charts-row {
    display: grid;
    grid-template-columns: 1fr 2fr 1fr;
    gap: 20px;
    margin-top: 24px;
}

.chart-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 22px;
    box-shadow: var(--shadow-sm);
}

.chart-card h3 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.chart-wrapper {
    position: relative;
    height: 240px;
}

.chart-wrapper-wide {
    height: 240px;
}

/* ──────────── Modals ──────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

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

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-xl);
    width: 90%;
    max-width: 520px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: modalSlide 0.3s var(--ease-out);
}

.modal-lg { max-width: 720px; }

@keyframes modalSlide {
    from { opacity: 0; transform: translateY(20px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

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

.modal-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    transition: color var(--transition-fast);
}
.modal-close:hover { color: var(--text-primary); }

.modal-body { padding: 24px; }

/* Form elements */
.form-group { margin-bottom: 18px; }
.form-group label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.input-row {
    display: flex;
    gap: 8px;
}

.form-group input,
.form-group textarea {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-md);
    padding: 10px 14px;
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    outline: none;
    transition: border-color var(--transition-fast);
}

.form-group input:focus,
.form-group textarea:focus {
    border-color: var(--accent-cyan);
    box-shadow: 0 0 0 3px rgba(6,182,212,0.1);
}

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

.form-divider {
    display: flex;
    align-items: center;
    gap: 16px;
    margin: 20px 0;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.form-divider::before, .form-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-subtle);
}

/* Settings env table */
.settings-info h4 {
    font-size: 0.95rem;
    margin-bottom: 6px;
}

.settings-info > p {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-bottom: 18px;
}

.env-table {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.env-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    gap: 12px;
}

.env-row:nth-child(odd) { background: var(--bg-card); }

.env-row code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.78rem;
    color: var(--accent-cyan);
    white-space: nowrap;
}

.env-row span {
    font-size: 0.78rem;
    color: var(--text-muted);
    text-align: right;
}

/* History table */
.history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

.history-table th {
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.06em;
    border-bottom: 1px solid var(--border-medium);
    background: var(--bg-elevated);
}

.history-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-subtle);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.78rem;
}

/* ──────────── Toasts ──────────── */
#toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.85rem;
    box-shadow: var(--shadow-lg);
    animation: toastIn 0.3s var(--ease-out);
    min-width: 280px;
}

.toast.success { border-left: 4px solid var(--color-ok); }
.toast.error { border-left: 4px solid var(--color-critical); }
.toast.info { border-left: 4px solid var(--accent-cyan); }

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

.toast-out {
    animation: toastOut 0.3s var(--ease-out) forwards;
}

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

/* ──────────── Scrollbar ──────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.1);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ──────────── Responsive ──────────── */
@media (max-width: 1100px) {
    .charts-row {
        grid-template-columns: 1fr 1fr;
    }
    .charts-row .chart-card:nth-child(2) {
        grid-column: span 2;
    }
}

@media (max-width: 768px) {
    #main-header { padding: 12px 16px; }
    .stats-bar {
        grid-template-columns: repeat(3, 1fr);
        padding: 14px 16px;
        gap: 10px;
    }
    .toolbar { padding: 8px 16px 12px; }
    main { padding: 0 16px 30px; }
    .charts-row {
        grid-template-columns: 1fr;
    }
    .charts-row .chart-card:nth-child(2) {
        grid-column: span 1;
    }
    .filter-group { overflow-x: auto; }
    .search-box input { width: 120px; }
    .stat-number { font-size: 1.6rem; }
}

@media (max-width: 480px) {
    .stats-bar { grid-template-columns: repeat(2, 1fr); }
    .header-right .btn span { display: none; }
    .action-btns { display: none; }
}
