/* ═══════════════════════════════════════════════════════════════
   UNIFIED OVERLAY SYSTEM — SIMP-04
   3 patterns: Sheet, Dialog, Bottom Sheet
   Shared backdrop, consistent timing, unified z-index layer
   ═══════════════════════════════════════════════════════════════ */

/* ── Shared Backdrop ──────────────────────────────────────────── */

.overlay-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--duration-slow) var(--ease),
                visibility var(--duration-slow) var(--ease);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.overlay-backdrop.show {
    opacity: 1;
    visibility: visible;
}

/* ── Pattern 1: Sheet (side panel) ────────────────────────────── */

.sheet-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 420px;
    max-width: 100%;
    background: var(--bg-primary);
    box-shadow: -4px 0 32px rgba(0, 0, 0, 0.12);
    transform: translateX(100%);
    transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
    z-index: 2001;
    display: flex;
    flex-direction: column;
}

.overlay-backdrop.show .sheet-panel {
    transform: translateX(0);
}

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

.sheet-header h2 {
    font-size: var(--text-lg);
    font-weight: var(--font-bold);
    letter-spacing: -0.02em;
}

.sheet-close {
    width: var(--touch-target);
    height: var(--touch-target);
    border: none;
    background: var(--bg-secondary);
    border-radius: 50%;
    font-size: 16px;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--duration), color var(--duration);
}

.sheet-close:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.sheet-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-lg);
}

/* ── Pattern 2: Dialog (centered card) ────────────────────────── */

.dialog-card {
    background: var(--bg-tertiary);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    width: 90%;
    max-width: 400px;
    transform: scale(0.92) translateY(10px);
    transition: transform var(--duration-slow) cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

.overlay-backdrop.show .dialog-card {
    transform: scale(1) translateY(0);
}

.dialog-header {
    text-align: center;
    padding: var(--space-xl) var(--space-xl) var(--space-md);
}

.dialog-icon {
    font-size: 2.5rem;
    margin-bottom: var(--space-sm);
    line-height: 1;
}

.dialog-title {
    font-size: var(--text-lg);
    font-weight: var(--font-bold);
    margin-bottom: var(--space-xs);
}

.dialog-desc {
    font-size: var(--text-body);
    color: var(--text-secondary);
    line-height: 1.5;
}

.dialog-body {
    padding: 0 var(--space-xl) var(--space-lg);
}

.dialog-footer {
    display: flex;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-xl) var(--space-xl);
}

.dialog-btn {
    flex: 1;
    padding: 14px;
    border: none;
    border-radius: var(--radius-md);
    font-size: var(--text-body);
    font-weight: var(--font-semibold);
    cursor: pointer;
    transition: all var(--duration);
    font-family: inherit;
    min-height: var(--touch-target);
}

.dialog-btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-secondary);
}

.dialog-btn-secondary:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.dialog-btn-primary {
    background: var(--primary);
    color: white;
}

.dialog-btn-primary:hover {
    filter: brightness(1.08);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 113, 227, 0.3);
}

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

.dialog-btn-danger:hover {
    filter: brightness(1.1);
}

.dialog-btn:active {
    transform: scale(0.97);
}

.dialog-input {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: var(--text-body);
    font-family: inherit;
    outline: none;
    transition: border-color var(--duration);
    box-sizing: border-box;
}

.dialog-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.15);
}

.dialog-error {
    display: none;
    font-size: var(--text-small);
    color: var(--danger);
    margin-top: var(--space-xs);
}

/* ── Pattern 3: Bottom Sheet (mobile) ─────────────────────────── */

.bottom-sheet-container {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-tertiary);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.15);
    transform: translateY(100%);
    transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
    z-index: 2001;
    max-height: 85vh;
    overflow-y: auto;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.overlay-backdrop.show .bottom-sheet-container {
    transform: translateY(0);
}

.bottom-sheet-handle {
    width: 36px;
    height: 5px;
    background: var(--border-medium);
    border-radius: 2.5px;
    margin: 8px auto 0;
}

.bottom-sheet-header {
    padding: var(--space-md) var(--space-xl);
    text-align: center;
    border-bottom: 1px solid var(--border-light);
}

.bottom-sheet-title {
    font-size: var(--text-body);
    font-weight: var(--font-semibold);
}

.bottom-sheet-body {
    padding: var(--space-sm) 0;
}

.bottom-sheet-option {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: 14px var(--space-xl);
    cursor: pointer;
    transition: background var(--duration);
    border: none;
    background: none;
    width: 100%;
    font-family: inherit;
    font-size: var(--text-body);
    color: var(--text-primary);
    text-align: left;
}

.bottom-sheet-option:hover {
    background: var(--bg-secondary);
}

.bottom-sheet-option:active {
    background: var(--bg-secondary);
}

.bottom-sheet-option.danger {
    color: var(--danger);
}

.bottom-sheet-icon {
    font-size: 1.1rem;
    width: 24px;
    text-align: center;
    flex-shrink: 0;
}

.bottom-sheet-cancel {
    display: block;
    width: calc(100% - 2 * var(--space-xl));
    margin: var(--space-sm) auto var(--space-md);
    padding: 14px;
    border: none;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border-radius: var(--radius-md);
    font-size: var(--text-body);
    font-weight: var(--font-semibold);
    cursor: pointer;
    font-family: inherit;
    transition: all var(--duration);
}

.bottom-sheet-cancel:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* ── Dark mode overrides ──────────────────────────────────────── */

[data-theme="dark"] .sheet-panel {
    box-shadow: -4px 0 32px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .dialog-card {
    border: 1px solid var(--border-light);
}

[data-theme="dark"] .bottom-sheet-container {
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.4);
}

/* ── Reduced motion ───────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
    .sheet-panel,
    .dialog-card,
    .bottom-sheet-container,
    .overlay-backdrop {
        transition-duration: 0.01ms !important;
    }
}
