/**
 * Centralized UI Components Styles
 * Dialogs, notifications, and reusable UI elements
 */

/* ========================================
   NOTIFICATIONS (Toast Messages)
   ======================================== */

.ui-notification {
    position: fixed;
    top: 70px;  /* sit below the page header */
    right: 20px;
    z-index: 10000;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 24px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    font-size: 15.5px;
    font-weight: 500;
    opacity: 0;
    transform: translateX(100%);
    transition: all 0.3s ease;
    max-width: 460px;
}

.ui-notification-visible {
    opacity: 1;
    transform: translateX(0);
}

.ui-notification-hiding {
    opacity: 0;
    transform: translateX(100%);
}

.ui-notification-icon {
    font-size: 21px;
    flex-shrink: 0;
}

.ui-notification-message {
    flex: 1;
    line-height: 1.4;
}

.ui-notification-close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    opacity: 0.6;
    padding: 0;
    line-height: 1;
    transition: opacity 0.2s;
}

.ui-notification-close:hover {
    opacity: 1;
}

/* Notification Types */
.ui-notification-success {
    background: #10b981;
    color: white;
}

.ui-notification-success .ui-notification-close {
    color: white;
}

.ui-notification-error {
    background: #ef4444;
    color: white;
}

.ui-notification-error .ui-notification-close {
    color: white;
}

.ui-notification-warning {
    background: #f59e0b;
    color: white;
}

.ui-notification-warning .ui-notification-close {
    color: white;
}

.ui-notification-info {
    background: #3b82f6;
    color: white;
}

.ui-notification-info .ui-notification-close {
    color: white;
}

/* Loading toast (persistent, spinner instead of icon) */
.ui-notification-loading {
    color: white;
}

/* Reads (entry load, boot, source switch) — slate */
.ui-notification-loading-loading {
    background: #334155;
}

/* Writes (saving an entry) — indigo, distinct from reads */
.ui-notification-loading-saving {
    background: #4f46e5;
}

.ui-notification-spinner {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: #ffffff;
    border-radius: 50%;
    /* GPU-composite the rotation so it stays fluid while the toast slides in.
       The translateZ lives inside the keyframes (not as a static base) so it
       doesn't fight the rotate(). */
    will-change: transform;
    animation: ui-notification-spin 0.8s linear infinite;
}

@keyframes ui-notification-spin {
    from { transform: translateZ(0) rotate(0deg); }
    to   { transform: translateZ(0) rotate(360deg); }
}

/* ========================================
   DIALOGS
   ======================================== */

.ui-dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200000;
    animation: ui-fadeIn 0.2s ease;
}

.ui-dialog-overlay.ui-dialog-hiding {
    animation: ui-fadeOut 0.2s ease forwards;
}

.ui-dialog {
    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 480px;
    width: 90%;
    animation: ui-slideUp 0.3s ease;
    overflow: hidden;
}

.ui-dialog-hiding .ui-dialog {
    animation: ui-slideDown 0.2s ease forwards;
}

.ui-dialog-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 24px 16px;
    border-bottom: 1px solid #e2e8f0;
}

.ui-dialog-icon {
    font-size: 24px;
}

.ui-dialog-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #1e293b;
}

.ui-dialog-body {
    padding: 20px 24px;
}

.ui-dialog-body p {
    margin: 0 0 12px 0;
    color: #475569;
    line-height: 1.5;
}

.ui-dialog-body p:last-child {
    margin-bottom: 0;
}

.ui-dialog-details {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 12px 16px;
    margin: 12px 0;
    font-family: monospace;
    font-size: 13px;
    color: #64748b;
    max-height: 150px;
    overflow-y: auto;
}

.ui-dialog-details > div {
    padding: 4px 0;
    border-bottom: 1px solid #e2e8f0;
}

.ui-dialog-details > div:last-child {
    border-bottom: none;
}

/* "Changed by someone else in the meantime" (bibliography save): field, the value
   now on the server, the value being saved. Wider than a plain confirm, and the
   list is allowed to be tall: every contested field has to be readable without
   scrolling a 150px box, because the answer overwrites someone's work. */
.ui-dialog.bib-conflict-dialog {
    max-width: 760px;
}

.bib-conflict-dialog .ui-dialog-details {
    max-height: 50vh;
    font-family: inherit;
    color: #334155;
}

.ui-dialog-details .bib-conflict-table {
    width: 100%;
    border-collapse: collapse;
    font-family: inherit;
}

.ui-dialog-details .bib-conflict-table th,
.ui-dialog-details .bib-conflict-table td {
    text-align: left;
    vertical-align: top;
    padding: 4px 8px 4px 0;
    border-bottom: 1px solid #e2e8f0;
}

.ui-dialog-details .bib-conflict-table small {
    color: #94a3b8;
}

.ui-dialog-link {
    text-align: center;
    margin: 16px 0 8px 0;
}

.ui-dialog-link-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #3b82f6;
    text-decoration: none;
    font-size: 13px;
    padding: 8px 16px;
    background: #eff6ff;
    border-radius: 6px;
    border: 1px solid #bfdbfe;
    transition: all 0.2s;
}

.ui-dialog-link-btn:hover {
    background: #dbeafe;
    border-color: #93c5fd;
    text-decoration: none;
}

.ui-dialog-link-btn::before {
    content: "🔍";
}

.ui-dialog-footer {
    padding: 16px 24px;
    border-top: 1px solid #e2e8f0;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.ui-dialog-footer-multi {
    flex-wrap: wrap;
    gap: 10px;
}

.ui-dialog-btn {
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid #e2e8f0;
    background: white;
    color: #1e293b;
}

.ui-dialog-btn:hover {
    background: #f8fafc;
}

.ui-dialog-btn:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.3);
}

.ui-dialog-btn:active {
    transform: translateY(1px);
}

/* Button Types */
.ui-dialog-btn-warning {
    background: #f59e0b;
    border-color: #f59e0b;
    color: white;
}

.ui-dialog-btn-warning:hover {
    background: #d97706;
    border-color: #d97706;
}

.ui-dialog-btn-danger {
    background: #ef4444;
    border-color: #ef4444;
    color: white;
}

.ui-dialog-btn-danger:hover {
    background: #dc2626;
    border-color: #dc2626;
}

.ui-dialog-btn-info {
    background: #3b82f6;
    border-color: #3b82f6;
    color: white;
}

.ui-dialog-btn-info:hover {
    background: #2563eb;
    border-color: #2563eb;
}

.ui-dialog-btn-success {
    background: #10b981;
    border-color: #10b981;
    color: white;
}

.ui-dialog-btn-success:hover {
    background: #059669;
    border-color: #059669;
}

/* ========================================
   DIALOG TYPE THEMES
   ======================================== */

/* Danger/Delete Dialog Theme - subtle red styling */
.ui-dialog-danger {
    border-top: 4px solid #ef4444;
}

.ui-dialog-danger .ui-dialog-header {
    background: linear-gradient(to bottom, #fef2f2, #ffffff);
    border-bottom-color: #fecaca;
}

.ui-dialog-danger .ui-dialog-header h3 {
    color: #b91c1c;
}

.ui-dialog-danger .ui-dialog-body {
    background: #fffbfb;
}

.ui-dialog-danger .ui-dialog-body p {
    color: #7f1d1d;
}

.ui-dialog-danger .ui-dialog-footer {
    background: #fef2f2;
    border-top-color: #fecaca;
}

/* Warning Dialog Theme - subtle amber styling */
.ui-dialog-warning {
    border-top: 4px solid #f59e0b;
}

.ui-dialog-warning .ui-dialog-header {
    background: linear-gradient(to bottom, #fffbeb, #ffffff);
    border-bottom-color: #fde68a;
}

.ui-dialog-warning .ui-dialog-header h3 {
    color: #92400e;
}

.ui-dialog-warning .ui-dialog-body {
    background: #fffef5;
}

.ui-dialog-warning .ui-dialog-footer {
    background: #fffbeb;
    border-top-color: #fde68a;
}

/* Success Dialog Theme - subtle green styling */
.ui-dialog-success {
    border-top: 4px solid #10b981;
}

.ui-dialog-success .ui-dialog-header {
    background: linear-gradient(to bottom, #ecfdf5, #ffffff);
    border-bottom-color: #a7f3d0;
}

.ui-dialog-success .ui-dialog-header h3 {
    color: #065f46;
}

.ui-dialog-success .ui-dialog-body {
    background: #f0fdf9;
}

.ui-dialog-success .ui-dialog-footer {
    background: #ecfdf5;
    border-top-color: #a7f3d0;
}

/* Info Dialog Theme - subtle blue styling */
.ui-dialog-info {
    border-top: 4px solid #3b82f6;
}

.ui-dialog-info .ui-dialog-header {
    background: linear-gradient(to bottom, #eff6ff, #ffffff);
    border-bottom-color: #bfdbfe;
}

.ui-dialog-info .ui-dialog-header h3 {
    color: #1e40af;
}

.ui-dialog-info .ui-dialog-body {
    background: #f8faff;
}

.ui-dialog-info .ui-dialog-footer {
    background: #eff6ff;
    border-top-color: #bfdbfe;
}

/* Options in dialog body */
.ui-dialog-options {
    margin: 16px 0;
    padding: 12px;
    background: #f8fafc;
    border-radius: 6px;
}

.ui-dialog-option {
    padding: 8px 0;
    font-size: 13px;
    color: #475569;
}

.ui-dialog-option:not(:last-child) {
    border-bottom: 1px solid #e2e8f0;
}

.ui-dialog-option strong {
    color: #1e293b;
}

.ui-dialog-option code {
    background: #e2e8f0;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 12px;
    color: #3b82f6;
}

/* ========================================
   ANIMATIONS
   ======================================== */

@keyframes ui-fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes ui-fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

@keyframes ui-slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes ui-slideDown {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(20px);
    }
}

/* ========================================
   RESPONSIVE
   ======================================== */

@media (max-width: 480px) {
    .ui-notification {
        left: 10px;
        right: 10px;
        max-width: none;
    }

    .ui-dialog {
        width: 95%;
        margin: 10px;
    }

    .ui-dialog-footer {
        flex-direction: column;
    }

    .ui-dialog-btn {
        width: 100%;
        justify-content: center;
    }
}

/* ========================================
   LOADING OVERLAY
   ======================================== */

.ui-loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10002;
    animation: ui-fadeIn 0.2s ease;
}

.ui-loading-overlay.ui-loading-hiding {
    animation: ui-fadeOut 0.3s ease forwards;
}

.ui-loading-dialog {
    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 420px;
    width: 90%;
    padding: 24px;
    animation: ui-slideUp 0.3s ease;
}

.ui-loading-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
}

.ui-loading-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #1e293b;
}

.ui-loading-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid #e2e8f0;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: ui-spin 0.8s linear infinite;
}

@keyframes ui-spin {
    to { transform: rotate(360deg); }
}

.ui-loading-steps {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ui-loading-step {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: #f8fafc;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    transition: all 0.3s ease;
}

.ui-loading-step-icon {
    font-size: 18px;
    flex-shrink: 0;
    transition: transform 0.3s ease;
}

.ui-loading-step-text {
    font-size: 14px;
    color: #64748b;
    transition: color 0.3s ease;
    /* Take the slack so the timing detail sits hard against the right edge. */
    flex: 1;
}

/* Per-step timing: a live counter while the step runs, then its final
   "24,938 entries · 12s" once it completes. Tabular figures stop the counter
   jittering as the digits change. */
.ui-loading-step-detail {
    font-size: 12px;
    color: #94a3b8;
    white-space: nowrap;
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}

.ui-loading-step-active .ui-loading-step-detail {
    color: #1e40af;
}

.ui-loading-step-completed .ui-loading-step-detail {
    color: #166534;
}

.ui-loading-step-error .ui-loading-step-detail {
    color: #991b1b;
}

.ui-loading-step-active {
    background: #eff6ff;
    border-color: #bfdbfe;
}

.ui-loading-step-active .ui-loading-step-icon {
    /* Exercise icons cycle via JS - no spin animation needed */
    font-size: 20px;
}

.ui-loading-step-active .ui-loading-step-text {
    color: #1e40af;
    font-weight: 500;
}

.ui-loading-step-completed {
    background: #f0fdf4;
    border-color: #bbf7d0;
}

.ui-loading-step-completed .ui-loading-step-text {
    color: #166534;
}

.ui-loading-step-error {
    background: #fef2f2;
    border-color: #fecaca;
}

.ui-loading-step-error .ui-loading-step-text {
    color: #991b1b;
}

.ui-loading-status {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid #e2e8f0;
    font-size: 13px;
    color: #64748b;
    text-align: center;
    min-height: 20px;
}

.ui-loading-complete .ui-loading-dialog {
    border: 2px solid #10b981;
}

.ui-loading-complete .ui-loading-header h3 {
    color: #166534;
}

/* ========================================
   SUMMARY DIALOG
   ======================================== */

.ui-summary-list {
    margin-top: 16px;
    padding: 12px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
}

.ui-summary-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    margin-bottom: 6px;
    background: white;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
    transition: all 0.2s ease;
}

.ui-summary-item:last-child {
    margin-bottom: 0;
}

.ui-summary-item:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
}

.ui-summary-item-icon {
    font-size: 16px;
    flex-shrink: 0;
}

.ui-summary-item-text {
    flex: 1;
    font-size: 13px;
    color: #475569;
    line-height: 1.4;
}

.ui-summary-item-deleted {
    background: #fef2f2;
    border-color: #fecaca;
}

.ui-summary-item-deleted:hover {
    background: #fee2e2;
}

.ui-summary-item-deleted .ui-summary-item-text {
    color: #991b1b;
}

.ui-summary-item-renamed {
    background: #fefce8;
    border-color: #fef08a;
}

.ui-summary-item-renamed:hover {
    background: #fef9c3;
}

.ui-summary-item-renamed .ui-summary-item-text del {
    color: #92400e;
}

.ui-summary-link {
    color: #2563eb;
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
}

.ui-summary-link:hover {
    color: #1d4ed8;
    text-decoration: underline;
}

/* ========================================
   MISSING FIELDS DIALOG
   ======================================== */

.ui-missing-field-item {
    background: #fffbeb;
    border-color: #fde68a;
}

.ui-missing-field-item:hover {
    background: #fef3c7;
}

.ui-missing-field-item .ui-summary-item-icon {
    color: #d97706;
    font-size: 10px;
}

.ui-missing-field-item .ui-summary-item-text {
    font-weight: 500;
    color: #92400e;
}

.ui-missing-field-fix-btn {
    flex-shrink: 0;
    padding: 4px 12px !important;
    font-size: 12px !important;
    background: #2563eb !important;
    color: white !important;
    border: none !important;
    border-radius: 4px !important;
    cursor: pointer;
    transition: background 0.2s;
}

.ui-missing-field-fix-btn:hover {
    background: #1d4ed8 !important;
}

/* ========================================
   PROMPT INPUT DIALOG
   ======================================== */

.ui-prompt-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    color: #1e293b;
    background: #fff;
    margin-top: 12px;
    transition: border-color 0.15s, box-shadow 0.15s;
    box-sizing: border-box;
}

.ui-prompt-input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.ui-prompt-input::placeholder {
    color: #94a3b8;
}

.ui-dialog-danger .ui-prompt-input:focus {
    border-color: #ef4444;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15);
}

.ui-dialog-warning .ui-prompt-input:focus {
    border-color: #f59e0b;
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.15);
}

/* ========================================
   PASSWORD FIELD GROUP (reuses ui-prompt-input)
   ======================================== */

.ui-password-field {
    margin-bottom: 14px;
}

.ui-password-field:last-child {
    margin-bottom: 0;
}

.ui-password-field label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: #475569;
    margin-bottom: 6px;
}

.ui-password-field .ui-prompt-input {
    margin-top: 0;
}
