/* ========================================
   My King PWA — Theme System
   Light (default): white bg, green accent #22c55e
   Dark: zinc bg #18181b, gold accent #eab308
   ======================================== */

/* Utility */
.hidden { display: none !important; }

/* ========== Theme Variables ========== */

:root {
    --bg-primary: #f5f5f5;
    --bg-card: #ffffff;
    --card-bg: #ffffff;
    --bg: #f5f5f5;
    --text: #000000;
    --border: #e5e7eb;
    --bg-surface: #ffffff;
    --bg-header: #ffffff;
    --bg-nav: #ffffff;
    --bg-input: #f9fafb;
    --bg-modal: #ffffff;
    --bg-overlay: rgba(0, 0, 0, 0.4);
    --border-color: #e5e7eb;
    --border-light: #f3f4f6;
    --text-primary: #000000;
    --text-secondary: #1f2937;
    --text-muted: #374151;
    --accent: #22c55e;
    --accent-hover: #16a34a;
    --accent-dim: #15803d;
    --accent-bg: rgba(34, 197, 94, 0.10);
    --accent-text: #ffffff;
    --danger: #ef4444;
    --danger-bg: rgba(239, 68, 68, 0.08);
    --success: #22c55e;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.06), 0 2px 4px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.08);
    --skeleton-from: #e5e7eb;
    --skeleton-via: #f3f4f6;
    --icon-action-bg: #f3f4f6;
    --icon-action-hover: #e5e7eb;
    --scrollbar-thumb: #d1d5db;
    --scrollbar-hover: #9ca3af;
}

[data-theme="dark"] {
    --bg-primary: #18181b;
    --bg-card: #27272a;
    --card-bg: #27272a;
    --bg: #18181b;
    --text: #f1f1f1;
    --border: #3f3f46;
    --bg-surface: #1f1f23;
    --bg-header: #0f0f12;
    --bg-nav: #0f0f12;
    --bg-input: #1f1f23;
    --bg-modal: #1c1c20;
    --bg-overlay: rgba(0, 0, 0, 0.7);
    --border-color: #3f3f46;
    --border-light: #27272a;
    --text-primary: #f1f1f1;
    --text-secondary: #d4d4d8;
    --text-muted: #a1a1aa;
    --accent: #eab308;
    --accent-hover: #facc15;
    --accent-dim: #a16207;
    --accent-bg: rgba(234, 179, 8, 0.10);
    --accent-text: #18181b;
    --danger: #ef4444;
    --danger-bg: rgba(239, 68, 68, 0.15);
    --success: #22c55e;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.4);
    --skeleton-from: #27272a;
    --skeleton-via: #3f3f46;
    --icon-action-bg: #3f3f46;
    --icon-action-hover: #52525b;
    --scrollbar-thumb: #3f3f46;
    --scrollbar-hover: #52525b;
}

/* ========== Base ========== */

html, body {
    background-color: var(--bg-primary) !important;
    color: var(--text-primary) !important;
    -webkit-tap-highlight-color: transparent;
}

/* ========== Tab System ========== */

.tab-content {
    display: none;
}
.tab-content.active {
    display: block;
}

/* ========== Header ========== */

header {
    background-color: var(--bg-header) !important;
    border-color: var(--border-color) !important;
    box-shadow: var(--shadow-sm);
}

/* ========== Bottom Navigation ========== */

#bottomNavigation {
    background-color: var(--bg-nav);
    border-color: var(--border-color) !important;
    box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.05);
}

#bottomNavigation button {
    transition: all 0.2s ease;
}

#bottomNavigation button span {
    color: var(--text-muted);
    transition: color 0.2s ease;
}

#bottomNavigation svg.tab-icon {
    stroke: var(--text-muted);
    transition: stroke 0.2s ease;
}

#bottomNavigation button.active span,
#bottomNavigation button.active .tab-icon {
    color: var(--accent) !important;
    stroke: var(--accent) !important;
}

.tab-icon.active {
    stroke: var(--accent) !important;
}

/* ========== iOS Safe Area ========== */

@supports (-webkit-touch-callout: none) {
    .pb-safe {
        padding-bottom: calc(env(safe-area-inset-bottom) + 0.5rem);
    }
    body {
        min-height: -webkit-fill-available;
    }
}

/* ========== Splash Screen ========== */

#splashScreen {
    background-color: var(--bg-primary) !important;
}

#splashScreen p {
    color: var(--text-muted);
}

/* ========== Loader / Spinner ========== */

.loader {
    border: 3px solid var(--border-color);
    border-radius: 50%;
    border-top: 3px solid var(--accent);
    width: 24px;
    height: 24px;
    animation: spin 0.8s linear infinite;
    display: inline-block;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ========== Animations ========== */

.fade-in {
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes slideUp {
    from { transform: translateY(100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ========== Error Notification ========== */

.error-notification {
    position: fixed;
    top: 1rem;
    right: 1rem;
    background-color: #451a1a;
    border-left: 4px solid var(--danger);
    color: #fca5a5;
    padding: 1rem;
    border-radius: 0.75rem;
    box-shadow: var(--shadow-lg);
    z-index: 9999;
    max-width: 90%;
    width: 24rem;
    animation: slideIn 0.3s ease-out;
}

/* ========== iOS Install Banner ========== */

.ios-install-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 16px;
    background-color: var(--bg-card);
    border-top: 1px solid var(--border-color);
    display: none;
    z-index: 1000;
    box-shadow: var(--shadow-md);
}

.ios-install-banner p {
    color: var(--text-secondary);
}

.ios-install-banner .font-semibold {
    color: var(--text-primary);
}

/* ========== Section Headers ========== */

.section-title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary);
    padding: 0.5rem 0.25rem 0.5rem;
    margin-bottom: 0.25rem;
}

.section-group {
    margin-bottom: 1.25rem;
}

.section-items {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* ========== Item Cards (PVR list style — matches old app) ========== */

.item-card {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 0.875rem;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s, transform 0.15s;
    cursor: default;
}

.item-card:active {
    transform: scale(0.99);
}

.item-icon {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}

.item-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.item-content {
    flex: 1;
    min-width: 0;
}

.item-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.3;
}

.item-subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.125rem;
    line-height: 1.3;
}

.item-actions {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    flex-shrink: 0;
}

/* ========== Action Buttons (small circular — old app style) ========== */

.action-icon {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--icon-action-bg);
    border: none;
    cursor: pointer;
    transition: background-color 0.2s;
    text-decoration: none;
    color: inherit;
}

.action-icon:hover {
    background-color: var(--icon-action-hover);
}

.action-icon svg {
    width: 16px;
    height: 16px;
}

/* ========== King Card (generic) ========== */

.king-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    padding: 1rem;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s, box-shadow 0.2s;
}

.king-card:hover {
    box-shadow: var(--shadow);
}

.king-card-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* ========== Primary / Secondary / Ghost Buttons ========== */

.king-btn-primary {
    background-color: var(--accent);
    color: var(--accent-text);
    font-weight: 600;
    padding: 0.5rem 1.25rem;
    border-radius: 0.75rem;
    border: none;
    cursor: pointer;
    transition: background-color 0.2s;
}

.king-btn-primary:hover {
    background-color: var(--accent-hover);
}

.king-btn-secondary {
    background-color: transparent;
    color: var(--accent);
    font-weight: 500;
    padding: 0.5rem 1.25rem;
    border-radius: 0.75rem;
    border: 1px solid var(--accent);
    cursor: pointer;
    transition: background-color 0.2s;
}

.king-btn-secondary:hover {
    background-color: var(--accent-bg);
}

.king-btn-ghost {
    background-color: transparent;
    color: var(--text-secondary);
    padding: 0.5rem 1rem;
    border-radius: 0.75rem;
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.2s;
}

.king-btn-ghost:hover {
    background-color: var(--bg-card);
    color: var(--text-primary);
}

/* ========== Staff Card ========== */

.staff-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    padding: 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: var(--shadow-sm);
}

.staff-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background-color: var(--accent-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent);
}

/* ========== Chat ========== */

.chat-bubble {
    max-width: 80%;
    padding: 0.75rem 1rem;
    border-radius: 1rem;
    margin-bottom: 0.5rem;
    animation: fadeIn 0.2s ease;
}

.chat-bubble.sent {
    background-color: var(--accent);
    color: var(--accent-text);
    margin-left: auto;
    border-bottom-right-radius: 0.25rem;
}

.chat-bubble.received {
    background-color: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    margin-right: auto;
    border-bottom-left-radius: 0.25rem;
}

.chat-input-area {
    position: sticky;
    bottom: 0;
    background-color: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    padding: 0.75rem;
}

/* ========== Video / Formazione ========== */

.video-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    overflow: hidden;
    transition: transform 0.2s;
    box-shadow: var(--shadow-sm);
}

.video-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.video-thumbnail {
    width: 100%;
    aspect-ratio: 16/9;
    background-color: var(--bg-surface);
    display: flex;
    align-items: center;
    justify-content: center;
}

.category-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 0;
    cursor: pointer;
    user-select: none;
}

.category-header:hover {
    opacity: 0.8;
}

.category-content {
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.category-content.collapsed {
    max-height: 0;
}

/* ========== Altro / Menu ========== */

.menu-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 0.875rem;
    cursor: pointer;
    transition: background-color 0.2s, box-shadow 0.2s;
    color: var(--text-primary);
    text-decoration: none;
    width: 100%;
    box-shadow: var(--shadow-sm);
}

.menu-item:hover {
    box-shadow: var(--shadow);
}

.menu-item-icon {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.menu-item-chevron {
    color: var(--text-muted);
    flex-shrink: 0;
}

/* ========== Modals ========== */

.modal-overlay {
    background-color: var(--bg-overlay);
}

.modal-content {
    background-color: var(--bg-modal);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    box-shadow: var(--shadow-lg);
    color: var(--text-primary);
}

/* ========== User Dropdown ========== */

#userDropdown {
    background-color: var(--bg-modal) !important;
    border-color: var(--border-color) !important;
    box-shadow: var(--shadow-lg);
}

#userDropdown .border-b {
    border-color: var(--border-color) !important;
}

/* ========== Empty States ========== */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
    text-align: center;
}

.empty-state svg {
    stroke: var(--text-muted);
    margin-bottom: 1rem;
}

.empty-state p {
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* ========== Loading Skeleton ========== */

.skeleton {
    background: linear-gradient(90deg, var(--skeleton-from) 25%, var(--skeleton-via) 50%, var(--skeleton-from) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 0.5rem;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ========== Badge ========== */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.625rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ========== Scrollbar ========== */

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-hover);
}

/* ========== Form Inputs ========== */

input[type="text"],
input[type="email"],
input[type="password"],
input[type="tel"],
textarea,
select {
    background-color: var(--bg-input) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

input::placeholder,
textarea::placeholder {
    color: var(--text-muted) !important;
}

/* ========== Theme Toggle ========== */

.theme-toggle {
    position: relative;
    width: 50px;
    height: 28px;
    border-radius: 14px;
    background-color: var(--border-color);
    border: none;
    cursor: pointer;
    transition: background-color 0.3s;
    flex-shrink: 0;
}

.theme-toggle.active {
    background-color: var(--accent);
}

.theme-toggle::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background-color: #ffffff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    transition: transform 0.3s;
}

.theme-toggle.active::after {
    transform: translateX(22px);
}

/* ========== Responsive ========== */

@media (min-width: 768px) {
    #pvrContainer .section-items,
    #staffContainer,
    #formazioneContainer {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }
}

@media (min-width: 1024px) {
    #pvrContainer .section-items,
    #staffContainer,
    #formazioneContainer {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ========== Toast Notifications ========== */

.toast {
    position: fixed;
    bottom: 5rem;
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.75rem 1.5rem;
    border-radius: 0.75rem;
    font-size: 0.875rem;
    z-index: 9999;
    animation: slideUp 0.3s ease-out;
    box-shadow: var(--shadow-md);
}

.toast.success {
    border-color: var(--success);
}

.toast.error {
    border-color: var(--danger);
}

/* ========== Utility overrides for themed context ========== */

.text-themed { color: var(--text-primary); }
.text-themed-secondary { color: var(--text-secondary); }
.text-themed-muted { color: var(--text-muted); }
.text-themed-accent { color: var(--accent); }
.bg-themed { background-color: var(--bg-primary); }
.bg-themed-card { background-color: var(--bg-card); }
.border-themed { border-color: var(--border-color); }
