/* ===================================
   Database Administrator — Custom CSS
   Dark theme overrides & custom styles
   =================================== */

/* Import Google Font */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* Base */
* {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

body {
    background: #0f172a;
    color: #e2e8f0;
    min-height: 100vh;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: #1e293b;
}
::-webkit-scrollbar-thumb {
    background: #475569;
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: #64748b;
}

/* Card Style */
.card {
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -2px rgba(0, 0, 0, 0.2);
    transition: box-shadow 0.2s ease;
}
.card:hover {
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -4px rgba(0, 0, 0, 0.3);
}

/* Input Styles */
.input-field {
    background: #0f172a;
    border: 1px solid #334155;
    color: #e2e8f0;
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    width: 100%;
}
.input-field:focus {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}
.input-field::placeholder {
    color: #64748b;
}
.input-field.error {
    border-color: #ef4444;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15);
}

/* Select Styles */
select.input-field {
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%2364748b' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.5rem center;
    background-repeat: no-repeat;
    background-size: 1.5em 1.5em;
    padding-right: 2.5rem;
}

/* Checkbox */
input[type="checkbox"] {
    appearance: none;
    width: 1.25rem;
    height: 1.25rem;
    border: 2px solid #475569;
    border-radius: 4px;
    background: #0f172a;
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
}
input[type="checkbox"]:checked {
    background: #6366f1;
    border-color: #6366f1;
}
input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    left: 3px;
    top: 0px;
    width: 6px;
    height: 10px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

/* Button Base */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-weight: 500;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.15s ease;
    border: none;
    outline: none;
}
.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: white;
}
.btn-primary:hover:not(:disabled) {
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
    transform: translateY(-1px);
}

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

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

.btn-success {
    background: linear-gradient(135deg, #059669, #10b981);
    color: white;
}
.btn-success:hover:not(:disabled) {
    background: linear-gradient(135deg, #047857, #059669);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
    transform: translateY(-1px);
}

.btn-ghost {
    background: transparent;
    color: #94a3b8;
    padding: 0.375rem;
}
.btn-ghost:hover:not(:disabled) {
    background: #1e293b;
    color: #e2e8f0;
}

/* Header */
.app-header {
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    border-bottom: 1px solid #334155;
    backdrop-filter: blur(10px);
}

/* Login Card */
.login-card {
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

/* Form Table */
.form-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}
.form-table th {
    background: #1e293b;
    color: #94a3b8;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid #334155;
    position: sticky;
    top: 0;
    z-index: 1;
}
.form-table td {
    padding: 0.5rem;
    border-bottom: 1px solid rgba(51, 65, 85, 0.5);
}
.form-table tr:hover td {
    background: rgba(99, 102, 241, 0.03);
}

/* Status Messages */
.status-success {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.1), rgba(5, 150, 105, 0.05));
    border: 1px solid rgba(16, 185, 129, 0.3);
    color: #6ee7b7;
    border-radius: 12px;
}
.status-error {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.1), rgba(220, 38, 38, 0.05));
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #fca5a5;
    border-radius: 12px;
}

/* Aggregation Panel */
.aggregation-panel {
    background: linear-gradient(135deg, #1e293b, #1a2332);
    border: 1px solid #334155;
    border-radius: 12px;
}
.aggregation-value {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    color: #a5b4fc;
}

/* Spinner */
@keyframes spin {
    to { transform: rotate(360deg); }
}
.spinner {
    display: inline-block;
    width: 1.25rem;
    height: 1.25rem;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

/* Fade transitions */
.fade-enter-active, .fade-leave-active {
    transition: opacity 0.3s ease, transform 0.3s ease;
}
.fade-enter, .fade-leave-to {
    opacity: 0;
    transform: translateY(-10px);
}

/* Tooltip */
[data-tooltip] {
    position: relative;
    cursor: help;
}
[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: #0f172a;
    color: #e2e8f0;
    padding: 0.375rem 0.75rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 400;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 10;
    border: 1px solid #334155;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
}
[data-tooltip]:hover::after {
    opacity: 1;
}

/* Responsive stacked cards for mobile */
@media (max-width: 768px) {
    .form-table thead {
        display: none;
    }
    .form-table tr {
        display: block;
        margin-bottom: 1rem;
        background: #1e293b;
        border-radius: 12px;
        border: 1px solid #334155;
        padding: 1rem;
    }
    .form-table td {
        display: block;
        border: none;
        padding: 0.375rem 0;
    }
    .form-table td::before {
        content: attr(data-label);
        display: block;
        font-size: 0.7rem;
        font-weight: 600;
        color: #94a3b8;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        margin-bottom: 0.25rem;
    }
}

/* ===================================
   DB Status Indicator
   =================================== */
.db-status-wrapper {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.db-status-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0.375rem 0.5rem;
    border-radius: 6px;
    transition: background 0.15s ease;
}
.db-status-btn:hover {
    background: rgba(255, 255, 255, 0.06);
}

.db-status-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: #94a3b8;
}

.db-status-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.db-status-dot--ok {
    background: #22c55e;
    box-shadow: 0 0 6px rgba(34, 197, 94, 0.6);
    animation: db-pulse-green 2s ease-in-out infinite;
}
.db-status-dot--err {
    background: #ef4444;
    box-shadow: 0 0 6px rgba(239, 68, 68, 0.6);
    animation: db-pulse-red 1.5s ease-in-out infinite;
}
.db-status-dot--loading {
    background: #94a3b8;
    animation: db-pulse-grey 1s ease-in-out infinite;
}

@keyframes db-pulse-green {
    0%, 100% { box-shadow: 0 0 4px rgba(34, 197, 94, 0.4); }
    50%      { box-shadow: 0 0 10px rgba(34, 197, 94, 0.8); }
}
@keyframes db-pulse-red {
    0%, 100% { box-shadow: 0 0 4px rgba(239, 68, 68, 0.4); }
    50%      { box-shadow: 0 0 10px rgba(239, 68, 68, 0.8); }
}
@keyframes db-pulse-grey {
    0%, 100% { opacity: 0.4; }
    50%      { opacity: 1; }
}

/* Popup */
.db-status-popup {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 260px;
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 10px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    z-index: 50;
    padding: 0.75rem;
    animation: db-popup-in 0.15s ease-out;
}
@keyframes db-popup-in {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.db-status-popup-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.625rem;
    font-size: 0.875rem;
    color: #e2e8f0;
}
.db-status-popup-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    font-size: 0.75rem;
    font-weight: 700;
    flex-shrink: 0;
}
.db-status-popup-icon--ok {
    background: rgba(34, 197, 94, 0.15);
    color: #22c55e;
}
.db-status-popup-icon--err {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

.db-status-popup-body {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}
.db-status-popup-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
    font-size: 0.8rem;
}
.db-status-popup-row--error {
    flex-direction: column;
    gap: 0.125rem;
}
.db-status-popup-label {
    color: #64748b;
    flex-shrink: 0;
}
.db-status-popup-value {
    color: #cbd5e1;
    text-align: right;
    word-break: break-all;
}
.db-status-popup-row--error .db-status-popup-value {
    text-align: left;
    font-size: 0.75rem;
    line-height: 1.4;
}

.db-status-popup-refresh {
    margin-top: 0.5rem;
    width: 100%;
    justify-content: center;
    font-size: 0.75rem;
}

/* ===================================
   Insert History Panel
   =================================== */
.history-panel {
    overflow: hidden;
}

.history-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.75rem 1rem;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: background 0.15s ease;
}
.history-toggle:hover {
    background: rgba(255, 255, 255, 0.03);
}

.history-chevron {
    transition: transform 0.2s ease;
    flex-shrink: 0;
}
.history-chevron.open {
    transform: rotate(90deg);
}

.history-badge {
    font-size: 0.7rem;
    font-weight: 500;
    color: #a5b4fc;
    background: rgba(99, 102, 241, 0.12);
    padding: 0.2rem 0.5rem;
    border-radius: 9999px;
}

.history-body {
    border-top: 1px solid #334155;
}

.history-filters {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.625rem 1rem;
    background: rgba(15, 23, 42, 0.4);
    border-bottom: 1px solid rgba(51, 65, 85, 0.5);
}

.history-date-input {
    max-width: 160px;
    padding: 0.3rem 0.5rem !important;
    font-size: 0.8rem !important;
}

.history-loading,
.history-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 2rem 1rem;
}

.history-entries {
    max-height: 400px;
    overflow-y: auto;
}

.history-entry {
    border-bottom: 1px solid rgba(51, 65, 85, 0.4);
}
.history-entry:last-child {
    border-bottom: none;
}

.history-entry-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.5rem 1rem;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: background 0.15s ease;
}
.history-entry-header:hover {
    background: rgba(99, 102, 241, 0.04);
}

.history-row-badge {
    font-size: 0.7rem;
    color: #94a3b8;
    background: rgba(148, 163, 184, 0.1);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
}

.history-entry-data {
    padding: 0 1rem 0.75rem 2.25rem;
    animation: db-popup-in 0.15s ease-out;
}

.history-data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.75rem;
}
.history-data-table th {
    text-align: left;
    padding: 0.35rem 0.5rem;
    color: #64748b;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 0.65rem;
    border-bottom: 1px solid #334155;
    background: rgba(15, 23, 42, 0.5);
}
.history-data-table td {
    padding: 0.3rem 0.5rem;
    color: #cbd5e1;
    border-bottom: 1px solid rgba(51, 65, 85, 0.3);
}
.history-data-table tr:last-child td {
    border-bottom: none;
}
.history-data-table tr:hover td {
    background: rgba(99, 102, 241, 0.03);
}

/* ===================================
   Dashboard Panel
   =================================== */
.dashboard-panel {
    margin-bottom: 1.5rem;
}

.dashboard-welcome {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
}
.dashboard-greeting {
    font-size: 1.35rem;
    font-weight: 600;
    color: #e2e8f0;
    margin: 0;
}
.dashboard-user-name {
    background: linear-gradient(135deg, #a5b4fc, #818cf8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.dashboard-date {
    font-size: 0.8rem;
    color: #64748b;
    margin: 0.25rem 0 0;
}
.dashboard-refresh-btn {
    padding: 0.4rem;
    border-radius: 8px;
}

.dashboard-loading,
.dashboard-error,
.dashboard-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 3rem 1rem;
    text-align: center;
}
.dashboard-empty-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    border-radius: 16px;
    background: rgba(51, 65, 85, 0.3);
}

/* Stats Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}
@media (min-width: 640px) {
    .dashboard-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}
@media (min-width: 1024px) {
    .dashboard-grid {
        grid-template-columns: repeat(6, 1fr);
    }
}

/* Stat Card */
.dashboard-stat-card {
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 12px;
    padding: 1.25rem 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    position: relative;
    overflow: hidden;
}
.dashboard-stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    border-radius: 12px 12px 0 0;
}
.dashboard-stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px -5px rgba(0, 0, 0, 0.4);
}

/* Card accent colors */
.dashboard-stat-card--success .dashboard-stat-icon { color: #34d399; }
.dashboard-stat-card--success::before { background: linear-gradient(90deg, #059669, #34d399); }
.dashboard-stat-card--success:hover { border-color: rgba(52, 211, 153, 0.3); }

.dashboard-stat-card--info .dashboard-stat-icon { color: #60a5fa; }
.dashboard-stat-card--info::before { background: linear-gradient(90deg, #2563eb, #60a5fa); }
.dashboard-stat-card--info:hover { border-color: rgba(96, 165, 250, 0.3); }

.dashboard-stat-card--danger .dashboard-stat-icon { color: #f87171; }
.dashboard-stat-card--danger::before { background: linear-gradient(90deg, #dc2626, #f87171); }
.dashboard-stat-card--danger:hover { border-color: rgba(248, 113, 113, 0.3); }

.dashboard-stat-card--warning .dashboard-stat-icon { color: #fbbf24; }
.dashboard-stat-card--warning::before { background: linear-gradient(90deg, #d97706, #fbbf24); }
.dashboard-stat-card--warning:hover { border-color: rgba(251, 191, 36, 0.3); }

.dashboard-stat-card--purple .dashboard-stat-icon { color: #a78bfa; }
.dashboard-stat-card--purple::before { background: linear-gradient(90deg, #7c3aed, #a78bfa); }
.dashboard-stat-card--purple:hover { border-color: rgba(167, 139, 250, 0.3); }

.dashboard-stat-card--teal .dashboard-stat-icon { color: #2dd4bf; }
.dashboard-stat-card--teal::before { background: linear-gradient(90deg, #0d9488, #2dd4bf); }
.dashboard-stat-card--teal:hover { border-color: rgba(45, 212, 191, 0.3); }

.dashboard-stat-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.04);
}
.dashboard-stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: #f1f5f9;
    font-variant-numeric: tabular-nums;
    line-height: 1;
}
.dashboard-stat-label {
    font-size: 0.7rem;
    font-weight: 500;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    text-align: center;
}
.dashboard-stat-detail {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    justify-content: center;
    margin-top: 0.25rem;
}
.dashboard-template-tag {
    font-size: 0.65rem;
    color: #94a3b8;
    background: rgba(148, 163, 184, 0.1);
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
}

.dashboard-footer {
    text-align: center;
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid rgba(51, 65, 85, 0.4);
}
