/* ============================================
   PaneApp Shared Components
   Reusable UI component styles
   ============================================ */

/* ── Session Info ── */
.session-info {
    margin-top: 10px;
    padding: 8px 12px;
    background: rgba(var(--color-primary-rgb), 0.1);
    border-radius: 6px;
    font-size: 0.9em;
    color: var(--color-primary);
    font-weight: 600;
}

.session-info.next-day {
    background: rgba(var(--color-orange-rgb), 0.1);
    color: var(--color-orange);
}

[data-theme="dark"] .session-info {
    background: rgba(var(--color-primary-rgb), 0.2);
}

[data-theme="dark"] .session-info.next-day {
    background: rgba(var(--color-orange-rgb), 0.2);
}

/* ── UI States ── */
.ui-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-8) var(--space-5);
    text-align: center;
    gap: var(--space-4);
    min-height: 200px;
}

.ui-state-icon {
    width: 48px;
    height: 48px;
    opacity: 0.5;
    color: var(--text-tertiary);
}

.ui-state-message {
    color: var(--text-secondary);
    font-size: var(--font-size-md);
    max-width: 400px;
    line-height: 1.5;
}

/* Loading State */
.loading-state .ui-state-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--color-primary);
    border-radius: var(--border-radius-circle);
    animation: spin 0.8s linear infinite;
}

/* Error State */
.error-state .ui-state-icon {
    color: var(--color-danger);
    opacity: 0.7;
}

.error-state .ui-state-message {
    color: var(--color-danger-text);
}

.ui-state-retry {
    padding: 8px 20px;
    background: var(--color-gradient-primary);
    color: var(--text-on-primary);
    border: none;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    font-weight: 600;
    font-size: var(--font-size-sm);
    transition: all var(--transition);
}

.ui-state-retry:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-primary-sm);
}

/* Empty State */
.empty-state .ui-state-icon {
    color: var(--text-tertiary);
    opacity: 0.4;
}

/* ── Toast Notifications ── */
.toast-container {
    position: fixed;
    top: 70px;
    right: 20px;
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    pointer-events: none;
    max-width: 400px;
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: var(--font-size-sm);
    pointer-events: auto;
    cursor: pointer;
    animation: toastSlideIn 0.3s ease forwards;
    transition: opacity 0.3s ease, transform 0.3s ease;
    max-width: 100%;
    word-break: break-word;
}

.toast.removing {
    animation: toastSlideOut 0.3s ease forwards;
}

.toast-icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    margin-top: 1px;
}

.toast-body {
    flex: 1;
    line-height: 1.4;
}

.toast-close {
    flex-shrink: 0;
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 0;
    font-size: 18px;
    line-height: 1;
    opacity: 0.6;
    transition: opacity var(--transition-fast);
}

.toast-close:hover {
    opacity: 1;
}

.toast-success {
    border-left: 4px solid var(--color-success);
}

.toast-success .toast-icon {
    color: var(--color-success);
}

.toast-error {
    border-left: 4px solid var(--color-danger);
}

.toast-error .toast-icon {
    color: var(--color-danger);
}

.toast-warning {
    border-left: 4px solid var(--color-warning);
}

.toast-warning .toast-icon {
    color: var(--color-warning);
}

.toast-info {
    border-left: 4px solid var(--color-info);
}

.toast-info .toast-icon {
    color: var(--color-info);
}

@keyframes toastSlideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes toastSlideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

/* ── Confirm Dialog ── */
.confirm-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-overlay);
    z-index: var(--z-modal-backdrop);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
    padding: var(--space-5);
}

.confirm-dialog {
    background: var(--bg-surface);
    border-radius: var(--border-radius-md);
    padding: var(--space-6);
    max-width: 440px;
    width: 100%;
    box-shadow: var(--shadow-xl);
    animation: confirmSlideUp 0.25s ease;
}

.confirm-title {
    font-size: var(--font-size-lg);
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: var(--space-3);
}

.confirm-message {
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
    line-height: 1.5;
    margin-bottom: var(--space-6);
}

.confirm-actions {
    display: flex;
    gap: var(--space-3);
    justify-content: flex-end;
}

.confirm-btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    font-weight: 600;
    font-size: var(--font-size-sm);
    transition: all var(--transition-fast);
}

.confirm-btn-cancel {
    background: var(--bg-surface-secondary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.confirm-btn-cancel:hover {
    background: var(--bg-surface-hover);
}

.confirm-btn-confirm {
    background: var(--color-gradient-primary);
    color: var(--text-on-primary);
}

.confirm-btn-confirm:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-primary-sm);
}

.confirm-btn-danger {
    background: var(--color-danger);
    color: white;
}

.confirm-btn-danger:hover {
    background: var(--color-danger-dark);
    transform: translateY(-1px);
}

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

/* ── Page Toolbar ── */
.page-toolbar {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 1rem;
}

.toolbar-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: var(--bg-surface-secondary);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    flex-wrap: wrap;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.toolbar-nav {
    flex-shrink: 0;
}

.toolbar-info {
    flex: 1;
    min-width: 0;
    text-align: center;
}

.toolbar-actions {
    flex-shrink: 0;
    margin-left: auto;
}

/* ── Responsive Tables ── */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 calc(-1 * var(--space-3));
    padding: 0 var(--space-3);
}

/* ── Mobile Improvements ── */
@media (max-width: 768px) {
    .toast-container {
        left: 10px;
        right: 10px;
        max-width: none;
    }

    .confirm-dialog {
        margin: var(--space-5);
    }

    .confirm-actions {
        flex-direction: column-reverse;
    }

    .confirm-btn {
        width: 100%;
        min-height: var(--touch-target-min);
    }

    /* Toolbar responsive */
    .toolbar-row {
        flex-wrap: wrap;
        gap: 8px;
        padding: 8px 12px;
    }

    .toolbar-info {
        width: 100%;
        order: -1;
    }

    .toolbar-actions {
        margin-left: 0;
        width: 100%;
        justify-content: center;
    }

    /* Touch targets for mobile */
    .btn,
    button,
    .toggle-switch,
    [role="button"] {
        min-height: var(--touch-target-min);
    }

    /* Bottom-sheet style modals on mobile */
    .modal-content {
        width: 95vw;
        max-height: 85vh;
        overflow-y: auto;
        margin: auto;
        border-radius: var(--border-radius-md) var(--border-radius-md) 0 0;
        position: fixed;
        bottom: 0;
        left: 50%;
        transform: translateX(-50%);
    }
}

/* ── Table Sort ── */
th[aria-sort] .sort-indicator {
    font-size: 0.75em;
    opacity: 0.5;
    transition: opacity var(--transition-fast);
}

th[aria-sort]:hover .sort-indicator {
    opacity: 0.9;
}

th.sort-asc .sort-indicator,
th.sort-desc .sort-indicator {
    opacity: 1;
    color: var(--text-on-primary);
}

/* ── Accessibility ── */

/* Focus visible styles */
:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* 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-width: 0;
}

/* Smooth scrolling */
html {
    scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ── Color Bands ── */
/* Reusable 6-color cycling system for visual separation of repeating sections.
 *
 * Usage:
 *   <div data-color-band="0"> ... </div>   (values: 0-5, cycle with index % 6)
 *
 * What it provides (via CSS custom properties on each element):
 *   --cb-rgb          main color as r,g,b
 *   --cb-rgb-end      gradient end-point as r,g,b
 *   --cb-solid        main color as hex (for icon tint, text highlights)
 *   --cb-gradient     ready-made 135deg gradient (header backgrounds)
 *   --cb-border       matching border-color with correct alpha
 *   --cb-accent       left-accent border-color (slightly stronger)
 *
 * Quick classes (optional, apply directly):
 *   .cb-accent-left   3px colored left border on the element
 *   .cb-header        gradient background + bottom border (for section headers)
 *   .cb-icon svg      tints child SVG icons to match band color
 */

/* Per-band token assignment */
[data-color-band="0"] {
    --cb-rgb: var(--band-0);  --cb-rgb-end: var(--band-0-end);  --cb-solid: var(--band-0-solid);
}
[data-color-band="1"] {
    --cb-rgb: var(--band-1);  --cb-rgb-end: var(--band-1-end);  --cb-solid: var(--band-1-solid);
}
[data-color-band="2"] {
    --cb-rgb: var(--band-2);  --cb-rgb-end: var(--band-2-end);  --cb-solid: var(--band-2-solid);
}
[data-color-band="3"] {
    --cb-rgb: var(--band-3);  --cb-rgb-end: var(--band-3-end);  --cb-solid: var(--band-3-solid);
}
[data-color-band="4"] {
    --cb-rgb: var(--band-4);  --cb-rgb-end: var(--band-4-end);  --cb-solid: var(--band-4-solid);
}
[data-color-band="5"] {
    --cb-rgb: var(--band-5);  --cb-rgb-end: var(--band-5-end);  --cb-solid: var(--band-5-solid);
}

/* Derived tokens (computed from --cb-rgb + theme intensities) */
[data-color-band] {
    --cb-gradient: linear-gradient(135deg,
        rgba(var(--cb-rgb), var(--band-gradient-from)) 0%,
        rgba(var(--cb-rgb-end), var(--band-gradient-to)) 100%);
    --cb-border: rgba(var(--cb-rgb), var(--band-border-alpha));
    --cb-accent: rgba(var(--cb-rgb), var(--band-accent-alpha));
}

/* .cb-accent-left — colored left border */
[data-color-band].cb-accent-left,
.cb-accent-left[data-color-band] {
    border-left: 3px solid var(--cb-accent);
}

/* .cb-header — gradient background for section headers */
.cb-header {
    background: var(--cb-gradient);
    border-bottom: 1px solid var(--cb-border);
}

/* .cb-icon — tint child SVG icons */
.cb-icon svg {
    color: var(--cb-solid);
}
