/*
 * Pancho SaaS — Core Design System
 * Premium, modern visual language. Not cookie-cutter.
 * Font: Inter. Accent: Indigo. Radius: Soft. Motion: Purposeful.
 */

/* ── Theme Variables ──────────────────────────────────── */

:root {
    /* Accent palette */
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --accent-soft: rgba(99, 102, 241, 0.08);
    --accent-muted: rgba(99, 102, 241, 0.16);

    /* Surface palette */
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --bg-card: #ffffff;
    --bg-elevated: #ffffff;
    --bg-hover: #f1f5f9;
    --bg-input: #f8fafc;
    --bg-overlay: rgba(15, 23, 42, 0.4);

    /* Text palette */
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-tertiary: #64748b;
    --text-muted: #94a3b8;
    --text-inverse: #ffffff;

    /* Border & shadow */
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --ring: rgba(99, 102, 241, 0.3);
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.07), 0 1px 3px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 8px 28px rgba(0, 0, 0, 0.1), 0 2px 8px rgba(0, 0, 0, 0.06);
    --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.12), 0 4px 16px rgba(0, 0, 0, 0.08);

    /* Status colors */
    --success: #10b981;
    --success-soft: rgba(16, 185, 129, 0.1);
    --warning: #f59e0b;
    --warning-soft: rgba(245, 158, 11, 0.1);
    --danger: #ef4444;
    --danger-soft: rgba(239, 68, 68, 0.1);
    --info: #3b82f6;
    --info-soft: rgba(59, 130, 246, 0.1);

    /* Layout */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;
    --nav-height: 72px;
    --sidebar-width: 260px;
    --sidebar-collapsed: 72px;
    --header-height: 64px;

    /* Motion */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --duration-fast: 150ms;
    --duration-normal: 250ms;
    --duration-slow: 400ms;
}

/* ── Dark Theme ───────────────────────────────────────── */

[data-theme="dark"] {
    --accent: #818cf8;
    --accent-hover: #6366f1;
    --accent-soft: rgba(129, 140, 248, 0.1);
    --accent-muted: rgba(129, 140, 248, 0.18);

    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --bg-card: #1e293b;
    --bg-elevated: #1e293b;
    --bg-hover: #334155;
    --bg-input: #1e293b;
    --bg-overlay: rgba(0, 0, 0, 0.6);

    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-tertiary: #64748b;
    --text-muted: #475569;
    --text-inverse: #0f172a;

    --border: #334155;
    --border-strong: #475569;
    --ring: rgba(129, 140, 248, 0.3);
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.35), 0 1px 3px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 8px 28px rgba(0, 0, 0, 0.4), 0 2px 8px rgba(0, 0, 0, 0.25);
    --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.5), 0 4px 16px rgba(0, 0, 0, 0.3);

    --success: #34d399;
    --success-soft: rgba(52, 211, 153, 0.12);
    --warning: #fbbf24;
    --warning-soft: rgba(251, 191, 36, 0.12);
    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, 0.12);
    --info: #60a5fa;
    --info-soft: rgba(96, 165, 250, 0.12);
}

/* ── Base Reset & Typography ──────────────────────────── */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-text-size-adjust: 100%;
}

html.theme-transition,
html.theme-transition * {
    transition: background-color var(--duration-normal) var(--ease-out),
                color var(--duration-normal) var(--ease-out),
                border-color var(--duration-normal) var(--ease-out),
                box-shadow var(--duration-normal) var(--ease-out) !important;
}

body {
    min-height: 100vh;
    background: var(--bg-secondary);
    overflow-x: hidden;
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: color var(--duration-fast);
}
a:not(.btn):hover { color: var(--accent-hover); }

/* ── Buttons ──────────────────────────────────────────── */

.btn,
.btn-primary,
.btn-secondary,
.btn-ghost,
.btn-danger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    line-height: 1;
    padding: 0 20px;
    min-height: 48px;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
    white-space: nowrap;
    position: relative;
    overflow: hidden;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.btn:disabled,
.btn-primary:disabled,
.btn-secondary:disabled,
.btn-ghost:disabled,
.btn-danger:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.btn:active:not(:disabled),
.btn-primary:active:not(:disabled),
.btn-secondary:active:not(:disabled),
.btn-ghost:active:not(:disabled),
.btn-danger:active:not(:disabled) {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--accent);
    color: var(--text-inverse);
    box-shadow: 0 1px 3px rgba(99, 102, 241, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}
.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) {
    background: var(--bg-hover);
    border-color: var(--border-strong);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}
.btn-ghost:hover:not(:disabled) {
    background: var(--bg-hover);
    color: var(--text-primary);
}

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

.btn-sm {
    min-height: 36px;
    padding: 0 14px;
    font-size: 13px;
    border-radius: var(--radius-sm);
}

.btn-lg {
    min-height: 56px;
    padding: 0 28px;
    font-size: 16px;
    border-radius: var(--radius-lg);
}

.btn-full { width: 100%; }

.btn-icon {
    width: 44px;
    height: 44px;
    min-height: auto;
    padding: 0;
    border-radius: var(--radius-md);
}

/* ── Cards ────────────────────────────────────────────── */

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    transition: box-shadow var(--duration-normal) var(--ease-out),
                border-color var(--duration-normal) var(--ease-out);
}

.card-interactive {
    cursor: pointer;
}
.card-interactive:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-md);
}
.card-interactive:active {
    transform: scale(0.985);
    transition: transform 0.1s;
}

.card-flush {
    border-left: none;
    border-right: none;
    border-radius: 0;
}

/* ── Form Inputs ──────────────────────────────────────── */

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.01em;
}

.form-input {
    font-family: inherit;
    font-size: 15px;
    min-height: 48px;
    padding: 0 14px;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    outline: none;
    transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
    -webkit-appearance: none;
}
.form-input::placeholder {
    color: var(--text-tertiary);
}
.form-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--ring);
    background: var(--bg-card);
}
.form-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.form-hint {
    font-size: 12px;
    color: var(--text-tertiary);
}

.form-error {
    font-size: 12px;
    color: var(--danger);
}

textarea.form-input {
    min-height: 100px;
    padding: 12px 14px;
    resize: vertical;
}

select.form-input {
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='m4.5 5.7 3.5 4 3.5-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

/* PIN Input */
.pin-container {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.pin-box {
    width: 52px;
    height: 60px;
    text-align: center;
    font-size: 24px;
    font-weight: 700;
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-input);
    color: var(--text-primary);
    outline: none;
    -webkit-text-security: disc;
    caret-color: var(--accent);
    transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
}
.pin-box:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--ring);
}

/* ── Badges ───────────────────────────────────────────── */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    font-size: 12px;
    font-weight: 600;
    border-radius: var(--radius-full);
    white-space: nowrap;
    letter-spacing: 0.01em;
}

.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger  { background: var(--danger-soft); color: var(--danger); }
.badge-info    { background: var(--info-soft); color: var(--info); }
.badge-neutral { background: var(--bg-tertiary); color: var(--text-secondary); }
.badge-accent  { background: var(--accent-soft); color: var(--accent); }

/* ── Toast Notifications ──────────────────────────────── */

.ps-toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    padding: 12px 24px;
    border-radius: var(--radius-full);
    font-size: 14px;
    font-weight: 500;
    color: #fff;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: var(--shadow-lg);
    transition: opacity var(--duration-normal), transform var(--duration-normal);
    pointer-events: none;
    max-width: calc(100vw - 32px);
    text-align: center;
    animation: toast-in var(--duration-normal) var(--ease-spring);
}
.ps-toast.success { background: rgba(16, 185, 129, 0.92); }
.ps-toast.error   { background: rgba(239, 68, 68, 0.92); }
.ps-toast.warning { background: rgba(245, 158, 11, 0.92); }
.ps-toast.info    { background: rgba(59, 130, 246, 0.92); }

@keyframes toast-in {
    from { opacity: 0; transform: translateX(-50%) translateY(12px) scale(0.95); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

/* ── Bottom Sheet / Modal ─────────────────────────────── */

.sheet-overlay {
    position: fixed;
    inset: 0;
    z-index: 90;
    background: var(--bg-overlay);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 0;
    transition: opacity var(--duration-normal) var(--ease-out);
    display: none;
}
.sheet-overlay.open {
    display: block;
    opacity: 1;
}

.sheet-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 91;
    max-height: 90vh;
    overflow-y: auto;
    background: var(--bg-card);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    box-shadow: var(--shadow-xl);
    transform: translateY(100%);
    transition: transform var(--duration-slow) var(--ease-out);
    padding: 8px 24px 32px;
    overscroll-behavior: contain;
    pointer-events: none;
}
.sheet-panel.open {
    transform: translateY(0);
    pointer-events: auto;
}

.sheet-handle {
    width: 40px;
    height: 4px;
    background: var(--text-muted);
    border-radius: var(--radius-full);
    margin: 8px auto 20px;
}

/* Desktop modal variant */
@media (min-width: 768px) {
    .sheet-panel {
        bottom: auto;
        top: 50%;
        left: 50%;
        right: auto;
        width: 100%;
        max-width: 480px;
        border-radius: var(--radius-xl);
        transform: translate(-50%, -50%) scale(0.95);
        opacity: 0;
        padding: 24px 28px 28px;
        max-height: 85vh;
    }
    .sheet-panel.open {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
    .sheet-handle { display: none; }
}

/* ── Skeleton Loading ─────────────────────────────────── */

.skeleton {
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    animation: shimmer 1.8s ease-in-out infinite;
    background-size: 200% 100%;
    background-image: linear-gradient(
        90deg,
        var(--bg-tertiary) 0%,
        var(--bg-hover) 40%,
        var(--bg-tertiary) 80%
    );
}

@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

/* ── Spinner ──────────────────────────────────────────── */

.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2.5px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
.spinner-dark {
    border-color: rgba(0, 0, 0, 0.1);
    border-top-color: var(--text-primary);
}
.spinner-accent {
    border-color: var(--accent-soft);
    border-top-color: var(--accent);
}
.spinner-lg { width: 32px; height: 32px; border-width: 3px; }

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ── Progress Dots (Wizard) ───────────────────────────── */

.progress-dots {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.progress-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: all var(--duration-normal) var(--ease-spring);
}
.progress-dot.active {
    width: 28px;
    border-radius: var(--radius-full);
    background: var(--accent);
}
.progress-dot.done {
    background: var(--accent);
}

/* ── Empty State ──────────────────────────────────────── */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    text-align: center;
}
.empty-state-icon {
    width: 64px;
    height: 64px;
    color: var(--text-muted);
    margin-bottom: 16px;
}
.empty-state-title {
    font-size: 17px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
}
.empty-state-text {
    font-size: 14px;
    color: var(--text-tertiary);
    margin-bottom: 20px;
    max-width: 280px;
}

/* ── Storage Meter ────────────────────────────────────── */

.storage-meter {
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-full);
    overflow: hidden;
}
.storage-meter-fill {
    height: 100%;
    border-radius: var(--radius-full);
    transition: width var(--duration-slow) var(--ease-out);
}
.storage-meter-fill.green  { background: var(--success); }
.storage-meter-fill.yellow { background: var(--warning); }
.storage-meter-fill.red    { background: var(--danger); }

/* ── Filter Tabs ──────────────────────────────────────── */

.filter-tabs {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    padding: 2px;
}
.filter-tabs::-webkit-scrollbar { display: none; }

.filter-tab {
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    background: transparent;
    border: 1.5px solid transparent;
    border-radius: var(--radius-full);
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--duration-fast);
}
.filter-tab:hover {
    background: var(--bg-hover);
}
.filter-tab.active {
    color: var(--accent);
    background: var(--accent-soft);
    border-color: var(--accent-muted);
}

/* ── Utilities ────────────────────────────────────────── */

.text-primary   { color: var(--text-primary) !important; }
.text-secondary { color: var(--text-secondary) !important; }
.text-tertiary  { color: var(--text-tertiary) !important; }
.text-muted     { color: var(--text-muted) !important; }
.text-accent    { color: var(--accent) !important; }
.text-success   { color: var(--success) !important; }
.text-danger    { color: var(--danger) !important; }
.text-warning   { color: var(--warning) !important; }

.bg-primary   { background: var(--bg-primary) !important; }
.bg-secondary { background: var(--bg-secondary) !important; }
.bg-card      { background: var(--bg-card) !important; }

.no-scrollbar { scrollbar-width: none; }
.no-scrollbar::-webkit-scrollbar { display: none; }

.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Animations ───────────────────────────────────────── */

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

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

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

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.92); }
    to   { opacity: 1; transform: scale(1); }
}

.animate-fade-in  { animation: fadeIn var(--duration-normal) var(--ease-out); }
.animate-slide-up { animation: slideUp var(--duration-normal) var(--ease-out); }
.animate-slide-down { animation: slideDown var(--duration-normal) var(--ease-out); }
.animate-scale-in { animation: scaleIn var(--duration-normal) var(--ease-spring); }

/* Stagger children */
.stagger > * { animation: slideUp var(--duration-normal) var(--ease-out) both; }
.stagger > *:nth-child(1) { animation-delay: 0ms; }
.stagger > *:nth-child(2) { animation-delay: 50ms; }
.stagger > *:nth-child(3) { animation-delay: 100ms; }
.stagger > *:nth-child(4) { animation-delay: 150ms; }
.stagger > *:nth-child(5) { animation-delay: 200ms; }
.stagger > *:nth-child(6) { animation-delay: 250ms; }
