/* ==========================================================================
   KeepYoga Design System — foundations and component styles
   ========================================================================== */

:root {
    /* ---- Palette ---- */
    --color-primary:       #4f46e5;
    --color-primary-light: #eef2ff;
    --color-primary-hover: #4338ca;
    --color-success:       #059669;
    --color-success-light: #ecfdf5;
    --color-warning:       #d97706;
    --color-warning-light: #fffbeb;
    --color-danger:        #e11d48;
    --color-danger-light:  #fff1f2;
    --color-info:          #2563eb;
    --color-info-light:    #eff6ff;

    --color-bg:            #f8fafc;
    --color-surface:       #ffffff;
    --color-border:        #e2e8f0;
    --color-border-light:  #f1f5f9;

    --color-text:          #0f172a;
    --color-text-secondary:#475569;
    --color-text-muted:    #94a3b8;

    /* ---- Spacing ---- */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;

    /* ---- Radius ---- */
    --radius-sm: 0.375rem;
    --radius:    0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;

    /* ---- Shadows ---- */
    --shadow-sm: 0 1px 2px rgba(0,0,0,.04);
    --shadow:    0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,.06), 0 2px 4px -2px rgba(0,0,0,.04);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.08), 0 4px 6px -4px rgba(0,0,0,.04);

    /* ---- Typography ---- */
    --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
    --font-mono: "JetBrains Mono", "Fira Code", ui-monospace, "Cascadia Code", Consolas, monospace;

    /* ---- Transitions ---- */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-in:  cubic-bezier(0.4, 0, 1, 1);
    --duration-fast: 150ms;
    --duration:       200ms;
}

/* ---- Reset ---- */
body {
    font-family: var(--font-sans);
    color: var(--color-text);
    background: var(--color-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ==========================================================================
   Card
   ========================================================================== */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm);
}
.card-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: var(--space-5) var(--space-6);
    border-bottom: 1px solid var(--color-border-light);
}
.card-body { padding: var(--space-5) var(--space-6); }
.card-footer {
    padding: var(--space-4) var(--space-6);
    border-top: 1px solid var(--color-border-light);
    background: #fafbfc;
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.875rem; font-weight: 500;
    border-radius: var(--radius);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
    white-space: nowrap;
    user-select: none;
    line-height: 1.25rem;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

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

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

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

.btn-ghost {
    background: transparent; color: var(--color-text-secondary);
    border-color: var(--color-border);
}
.btn-ghost:hover:not(:disabled) { background: #f8fafc; color: var(--color-text); }

.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.8125rem; }
.btn-lg { padding: 0.625rem 1.25rem; font-size: 0.9375rem; }

.btn-icon {
    padding: 0.5rem; width: 2.25rem; height: 2.25rem;
}

/* ==========================================================================
   Badges / Status Pills
   ========================================================================== */
.badge {
    display: inline-flex; align-items: center; gap: 0.25rem;
    padding: 0.125rem 0.625rem;
    font-size: 0.75rem; font-weight: 500;
    border-radius: 9999px;
    line-height: 1.25rem;
}
.badge-success { background: var(--color-success-light); color: var(--color-success); }
.badge-warning { background: var(--color-warning-light); color: var(--color-warning); }
.badge-danger  { background: var(--color-danger-light);  color: var(--color-danger); }
.badge-info    { background: var(--color-info-light);    color: var(--color-info); }
.badge-neutral { background: #f1f5f9; color: #64748b; }
.badge-dot::before {
    content: ''; width: 0.375rem; height: 0.375rem;
    border-radius: 50%; background: currentColor;
}

/* ==========================================================================
   Form Controls
   ========================================================================== */
.form-input, .form-select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem; font-family: var(--font-sans);
    color: var(--color-text);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
    outline: none;
}
.form-input:focus, .form-select:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,.12);
}
.form-input::placeholder { color: var(--color-text-muted); }
.form-input.mono { font-family: var(--font-mono); font-size: 0.8125rem; }
.form-label {
    display: block; margin-bottom: 0.375rem;
    font-size: 0.8125rem; font-weight: 500; color: var(--color-text-secondary);
}
.form-hint {
    margin-top: 0.25rem;
    font-size: 0.75rem; color: var(--color-text-muted);
}

/* Checkbox toggle switch */
.toggle {
    position: relative; display: inline-flex; align-items: center; gap: 0.5rem; cursor: pointer;
}
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle-track {
    width: 2.5rem; height: 1.375rem;
    background: #cbd5e1; border-radius: 9999px;
    transition: background var(--duration-fast);
    position: relative;
}
.toggle-track::after {
    content: ''; position: absolute; top: 2px; left: 2px;
    width: 1.125rem; height: 1.125rem;
    background: #fff; border-radius: 50%;
    box-shadow: var(--shadow-sm);
    transition: transform var(--duration-fast) var(--ease-out);
}
.toggle input:checked + .toggle-track { background: var(--color-primary); }
.toggle input:checked + .toggle-track::after { transform: translateX(1.125rem); }

/* ==========================================================================
   Toast Notification
   ========================================================================== */
.toast {
    position: fixed; bottom: 5rem; left: 50%; transform: translateX(-50%);
    z-index: 100;
    padding: 0.75rem 1.25rem;
    font-size: 0.875rem; font-weight: 500;
    color: #fff; background: var(--color-text);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    animation: toast-in 0.3s var(--ease-out);
    pointer-events: none;
}
.toast-success { background: var(--color-success); }
.toast-error   { background: var(--color-danger); }
@media (min-width: 768px) {
    .toast { left: auto; right: 1.5rem; bottom: 1.5rem; transform: none; }
}

@keyframes toast-in {
    from { opacity: 0; transform: translateX(-50%) translateY(0.75rem); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}
@media (min-width: 768px) {
    @keyframes toast-in {
        from { opacity: 0; transform: translateY(0.75rem); }
        to   { opacity: 1; transform: translateY(0); }
    }
}

/* ==========================================================================
   Modal / Overlay
   ========================================================================== */
.modal-overlay {
    position: fixed; inset: 0; z-index: 60;
    background: rgba(15,23,42,.35);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center;
    padding: 1rem;
    animation: fade-in .2s var(--ease-out);
}
.modal-panel {
    background: var(--color-surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-height: 85vh;
    display: flex; flex-direction: column;
    animation: modal-up .25s var(--ease-out);
}
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: var(--space-5) var(--space-6);
    border-bottom: 1px solid var(--color-border-light);
}
.modal-body { padding: var(--space-5) var(--space-6); overflow-y: auto; flex: 1; }
.modal-footer {
    padding: var(--space-4) var(--space-6);
    border-top: 1px solid var(--color-border-light);
    display: flex; justify-content: flex-end; gap: var(--space-3);
}

@keyframes fade-in  { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-up { from { opacity: 0; transform: translateY(1rem) scale(.97); } to { opacity: 1; transform: translateY(0) scale(1); } }

/* Full-screen modal on mobile */
@media (max-width: 767px) {
    .modal-overlay { padding: 0; align-items: flex-end; }
    .modal-panel {
        max-height: 92vh;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        animation: modal-up-mobile .3s var(--ease-out);
    }
    @keyframes modal-up-mobile {
        from { transform: translateY(100%); }
        to   { transform: translateY(0); }
    }
}

/* ==========================================================================
   Responsive Table → Card Pattern
   ========================================================================== */
.responsive-table { width: 100%; border-collapse: collapse; }
.responsive-table thead { display: none; }
.responsive-table tbody { display: flex; flex-direction: column; gap: 0.75rem; }
.responsive-table tr {
    display: flex; flex-direction: column;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 0; overflow: hidden;
    transition: box-shadow var(--duration-fast);
}
.responsive-table tr:hover { box-shadow: var(--shadow); }
.responsive-table td {
    display: flex; align-items: flex-start; gap: 0.75rem;
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--color-border-light);
}
.responsive-table td:last-child { border-bottom: none; }
.responsive-table td::before {
    content: attr(data-label);
    flex-shrink: 0; width: 4.5rem;
    font-size: 0.75rem; font-weight: 500;
    color: var(--color-text-muted);
    text-transform: uppercase; letter-spacing: 0.025em;
    padding-top: 0.0625rem;
}
.responsive-table td[data-label=""]::before { display: none; }

/* Highlight row */
.responsive-table tr.row-highlight { border-left: 3px solid var(--color-warning); }

/* Row with primary action */
.responsive-table td.cell-action {
    justify-content: flex-end; padding: 0.75rem 1rem;
    background: #fafbfc;
    border-bottom: none;
}
.responsive-table td.cell-action::before { display: none; }

/* Desktop: revert to normal table */
@media (min-width: 768px) {
    .responsive-table { display: table; }
    .responsive-table thead { display: table-header-group; }
    .responsive-table tbody { display: table-row-group; }
    .responsive-table tr {
        display: table-row;
        background: none; border: none; border-radius: 0;
        box-shadow: none;
    }
    .responsive-table tr:hover { box-shadow: none; background: #f8fafc; }
    .responsive-table th {
        padding: 0.625rem 1rem;
        font-size: 0.75rem; font-weight: 500;
        color: var(--color-text-muted);
        text-transform: uppercase; letter-spacing: 0.05em;
        text-align: left;
        border-bottom: 1px solid var(--color-border);
        background: #f8fafc;
        white-space: nowrap;
    }
    .responsive-table td {
        display: table-cell;
        padding: 0.75rem 1rem;
        font-size: 0.875rem;
        border-bottom: 1px solid var(--color-border-light);
        vertical-align: middle;
    }
    .responsive-table td::before { display: none; }
    .responsive-table td.cell-action {
        text-align: right; background: none;
    }
    .responsive-table tr.row-highlight { border-left: none; background: #fffdf5; }
}

/* ==========================================================================
   Empty State
   ========================================================================== */
.empty-state {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 3rem 1.5rem;
    text-align: center;
    color: var(--color-text-muted);
}
.empty-state-icon { font-size: 2.5rem; margin-bottom: 0.75rem; opacity: 0.6; }
.empty-state-title { font-size: 0.9375rem; font-weight: 500; color: var(--color-text-secondary); margin-bottom: 0.25rem; }
.empty-state-desc { font-size: 0.8125rem; }

/* ==========================================================================
   Section Header
   ========================================================================== */
.section-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 1rem;
}
.section-title {
    font-size: 1rem; font-weight: 600; color: var(--color-text);
}

/* ==========================================================================
   Sidebar (refined)
   ========================================================================== */
.sidebar-link {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.5rem 0.75rem; margin-bottom: 0.125rem;
    border-radius: var(--radius);
    font-size: 0.875rem; font-weight: 450;
    color: var(--color-text-secondary);
    text-decoration: none;
    transition: all var(--duration-fast) var(--ease-out);
    position: relative;
}
.sidebar-link:hover { background: #f1f5f9; color: var(--color-text); }
.sidebar-link.active {
    background: var(--color-primary-light); color: var(--color-primary); font-weight: 550;
}
.sidebar-link.active::before {
    content: ''; position: absolute; left: 0; top: 50%; transform: translateY(-50%);
    width: 3px; height: 1.25rem;
    background: var(--color-primary);
    border-radius: 0 2px 2px 0;
}
.sidebar-link .nav-icon { width: 1.25rem; height: 1.25rem; flex-shrink: 0; opacity: 0.7; }
.sidebar-link.active .nav-icon { opacity: 1; }

/* ==========================================================================
   Mobile Bottom Tab Bar
   ========================================================================== */
.mobile-tab-bar {
    position: fixed; bottom: 0; left: 0; right: 0;
    z-index: 40;
    display: flex; justify-content: space-around; align-items: flex-end;
    background: rgba(255,255,255,.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--color-border);
    padding: 0.375rem 0.25rem max(0.375rem, env(safe-area-inset-bottom));
}
.mobile-tab {
    display: flex; flex-direction: column; align-items: center; gap: 0.125rem;
    padding: 0.375rem 0.5rem;
    min-width: 3rem; max-width: 5rem;
    text-decoration: none;
    color: var(--color-text-muted);
    border-radius: var(--radius);
    transition: color var(--duration-fast);
    position: relative;
}
.mobile-tab.active { color: var(--color-primary); }
.mobile-tab.active::after {
    content: '';
    position: absolute; top: 0; left: 50%; transform: translateX(-50%);
    width: 1.25rem; height: 3px;
    background: var(--color-primary);
    border-radius: 0 0 2px 2px;
}
.mobile-tab svg { width: 1.375rem; height: 1.375rem; flex-shrink: 0; }
.mobile-tab-label { font-size: 0.625rem; font-weight: 500; line-height: 1; }

/* Only show on mobile */
@media (min-width: 768px) {
    .mobile-tab-bar { display: none; }
}

/* ==========================================================================
   Mobile Top Bar
   ========================================================================== */
.mobile-topbar {
    position: fixed; top: 0; left: 0; right: 0; z-index: 30;
    height: 3.25rem;
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 1rem;
    background: rgba(255,255,255,.9);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--color-border);
}
@media (min-width: 768px) {
    .mobile-topbar { display: none; }
}

/* ==========================================================================
   Status Pulse Animation
   ========================================================================== */
@keyframes pulse-ring {
    0% { box-shadow: 0 0 0 0 rgba(16,185,129,.4); }
    70% { box-shadow: 0 0 0 6px rgba(16,185,129,0); }
    100% { box-shadow: 0 0 0 0 rgba(16,185,129,0); }
}
.pulse-dot {
    width: 0.5rem; height: 0.5rem; border-radius: 50%;
    background: var(--color-success);
    animation: pulse-ring 2s infinite;
}

/* ==========================================================================
   Utility helpers that the self-hosted tailwind.css might miss
   ========================================================================== */
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.min-w-0 { min-width: 0; }
.whitespace-nowrap { white-space: nowrap; }
.overflow-x-auto { overflow-x: auto; }

/* Alpine.js */
[x-cloak] { display: none !important; }
