/* Styles communs à toutes les pages */

/* ========================================
   CSS VARIABLES FOR THEMING
   ======================================== */
:root {
    /* Light theme (default) */
    --bg-primary: #FFFFFF;
    --bg-secondary: #F9FAFB;
    --bg-tertiary: #F3F4F6;
    --bg-card: #FFFFFF;
    --bg-input: #FFFFFF;
    --bg-hover: #F3F4F6;
    
    --text-primary: #1F2937;
    --text-secondary: #374151;
    --text-tertiary: #4B5563;
    --text-muted: #6B7280;
    --text-light: #9CA3AF;
    
    --border-primary: #E5E7EB;
    --border-secondary: #D1D5DB;
    
    --shadow-color: rgba(0, 0, 0, 0.1);
}

html.dark {
    /* Dark theme */
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #242424;
    --bg-card: #1a1a1a;
    --bg-input: #242424;
    --bg-hover: #2d2d2d;
    
    --text-primary: #F3F4F6;
    --text-secondary: #E5E7EB;
    --text-tertiary: #D1D5DB;
    --text-muted: #9CA3AF;
    --text-light: #6B7280;
    
    --border-primary: #2d2d2d;
    --border-secondary: #3d3d3d;
    
    --shadow-color: rgba(0, 0, 0, 0.4);
}

html {
    overflow-x: hidden;
}

body {
    font-family: 'Montserrat', sans-serif;
    background-color: var(--bg-primary) !important;
    color: var(--text-primary) !important;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* ========================================
   DARK THEME OVERRIDES
   ======================================== */

/* Sidebar */
html.dark .sidebar {
    background-color: var(--bg-secondary) !important;
    border-right-color: var(--border-primary) !important;
}

html.dark .sidebar li {
    color: var(--text-primary) !important;
}

html.dark .sidebar li:not(.bg-amber-500):hover {
    background-color: var(--bg-hover) !important;
}

html.dark .sidebar .text-gray-800,
html.dark .sidebar .text-gray-700 {
    color: var(--text-primary) !important;
}

html.dark .sidebar .text-gray-500 {
    color: var(--text-muted) !important;
}

html.dark .sidebar .text-gray-400 {
    color: var(--text-light) !important;
}

/* Mobile header */
html.dark .mobile-header {
    background-color: var(--bg-secondary) !important;
    border-bottom-color: var(--border-primary) !important;
}

/* Cards and containers */
html.dark .bg-white {
    background-color: var(--bg-card) !important;
}

html.dark .bg-gray-50 {
    background-color: var(--bg-tertiary) !important;
}

html.dark .bg-gray-100 {
    background-color: var(--bg-hover) !important;
}

/* Borders */
html.dark .border-gray-200,
html.dark .border-gray-300 {
    border-color: var(--border-primary) !important;
}

html.dark .border-t,
html.dark .border-b,
html.dark .border {
    border-color: var(--border-primary) !important;
}

html.dark .divide-y > * + *,
html.dark .divide-gray-200 > * + * {
    border-color: var(--border-primary) !important;
}

/* Text colors */
html.dark .text-gray-800,
html.dark .text-gray-900 {
    color: var(--text-primary) !important;
}

html.dark .text-gray-700 {
    color: var(--text-secondary) !important;
}

html.dark .text-gray-600 {
    color: var(--text-tertiary) !important;
}

html.dark .text-gray-500 {
    color: var(--text-muted) !important;
}

html.dark .text-gray-400 {
    color: var(--text-light) !important;
}

/* Form elements */
html.dark input,
html.dark select,
html.dark textarea {
    background-color: var(--bg-input) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-secondary) !important;
}

html.dark input::placeholder,
html.dark textarea::placeholder {
    color: var(--text-light) !important;
}

html.dark input:focus,
html.dark select:focus,
html.dark textarea:focus {
    border-color: #FFC107 !important;
    box-shadow: 0 0 0 3px rgba(255, 193, 7, 0.2) !important;
}

html.dark input:disabled,
html.dark select:disabled,
html.dark textarea:disabled {
    background-color: var(--bg-secondary) !important;
    color: var(--text-light) !important;
}

html.dark input[type="checkbox"],
html.dark input[type="radio"] {
    accent-color: #FFC107;
}

/* Tables */
html.dark table th {
    background-color: var(--bg-tertiary) !important;
    color: var(--text-muted) !important;
    border-bottom-color: var(--border-primary) !important;
}

html.dark table td {
    border-bottom-color: var(--border-primary) !important;
    color: var(--text-secondary) !important;
}

html.dark table tr:hover td {
    background-color: var(--bg-tertiary) !important;
}

/* Alerts */
html.dark .bg-red-50 {
    background-color: rgba(220, 38, 38, 0.15) !important;
}

html.dark .bg-green-50 {
    background-color: rgba(34, 197, 94, 0.15) !important;
}

html.dark .bg-blue-50 {
    background-color: rgba(59, 130, 246, 0.15) !important;
}

html.dark .bg-amber-50 {
    background-color: rgba(245, 158, 11, 0.15) !important;
}

html.dark .bg-amber-100 {
    background-color: rgba(245, 158, 11, 0.2) !important;
}

/* Shadows */
html.dark .shadow-md,
html.dark .shadow-lg {
    box-shadow: 0 4px 6px -1px var(--shadow-color), 0 2px 4px -1px var(--shadow-color) !important;
}

/* Hover states */
html.dark .hover\:bg-gray-50:hover {
    background-color: var(--bg-tertiary) !important;
}

html.dark .hover\:bg-gray-100:hover {
    background-color: var(--bg-hover) !important;
}

html.dark .hover\:bg-gray-200:hover {
    background-color: #3d3d3d !important;
}

/* Details/Summary */
html.dark details pre {
    background-color: var(--bg-tertiary) !important;
    border-color: var(--border-primary) !important;
}

/* Cards in table mobile view */
html.dark .table-card .card {
    background-color: var(--bg-card) !important;
    border-color: var(--border-primary) !important;
}

html.dark .table-card .card-header {
    border-bottom-color: var(--border-primary) !important;
}

html.dark .table-card .card-label {
    color: var(--text-muted) !important;
}

html.dark .table-card .card-value {
    color: var(--text-secondary) !important;
}

/* ========================================
   RICH TEXT (DESCRIPTIONS QUILL)
   ======================================== */

.rich-text-description h1,
.rich-text-description h2,
.rich-text-description h3 {
    font-weight: 700;
    margin-top: 0.5rem;
    margin-bottom: 0.25rem;
}

.rich-text-description h1 {
    font-size: 1.25rem;
}

.rich-text-description h2 {
    font-size: 1.15rem;
}

.rich-text-description h3 {
    font-size: 1.05rem;
}

.rich-text-description p {
    margin-bottom: 0.4rem;
}

.rich-text-description ul,
.rich-text-description ol {
    margin-left: 1.25rem;
    margin-bottom: 0.4rem;
}

.rich-text-description blockquote {
    border-left: 4px solid #E5E7EB;
    padding-left: 0.75rem;
    margin: 0.5rem 0;
    color: #4B5563;
    font-style: italic;
}

html.dark .rich-text-description blockquote {
    border-left-color: var(--border-secondary);
    color: var(--text-tertiary);
}

/* Lore page specific */
html.dark .chapter-quote {
    background: linear-gradient(to right, rgba(245, 158, 11, 0.15), transparent) !important;
}

html.dark .bg-gray-900 {
    background-color: #0a0a0a !important;
}

html.dark .bg-gray-800 {
    background-color: #141414 !important;
}

/* Modal backgrounds */
html.dark .bg-black.bg-opacity-50 {
    background-color: rgba(0, 0, 0, 0.8) !important;
}

/* ========================================
   THEME TOGGLE STYLES
   (version switch avec label + pill)
   ======================================== */
.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    margin: 0.5rem;
    border-radius: 0.5rem;
    background-color: var(--bg-tertiary);
    cursor: pointer;
    transition: all 0.3s ease;
    user-select: none;
}

.theme-toggle:hover {
    background-color: var(--bg-hover);
}

.theme-toggle-label {
    color: var(--text-primary);
}

.theme-toggle-switch {
    position: relative;
    width: 48px;
    height: 24px;
    background-color: #d1d5db;
    border-radius: 12px;
    transition: background-color 0.3s ease;
    cursor: pointer;
}

html.dark .theme-toggle-switch {
    background-color: #FFC107;
}

.theme-toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background-color: white;
    border-radius: 50%;
    transition: transform 0.3s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

html.dark .theme-toggle-switch::after {
    transform: translateX(24px);
}

/* ========================================
   END DARK THEME STYLES
   ======================================== */

/* Mobile-first approach */
body {
    display: block;
    min-height: 100vh;
    min-height: 100dvh;
    padding-bottom: env(safe-area-inset-bottom); /* iOS safe area */
    overflow-x: hidden;
}

.sidebar {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    background-color: #FFFFFF;
    border-right: 1px solid #E5E7EB;
    z-index: 1000;
    transition: left 0.3s ease;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar.open {
    left: 0;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

.sidebar-overlay.show {
    display: block;
}

.mobile-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background-color: #FFFFFF;
    border-bottom: 1px solid #E5E7EB;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
}

.mobile-menu-btn {
    display: block;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: #FFC107;
    cursor: pointer;
}

main {
    padding-top: 0;
    min-height: 100vh;
}

/* Desktop styles */
@media (min-width: 1024px) {
    body {
        display: block;
        overflow-x: hidden;
    }
    
    .sidebar {
        position: fixed !important;
        left: 0 !important;
        top: 0 !important;
        bottom: 0 !important;
        width: 280px !important;
        height: 100vh !important;
        max-height: 100vh !important;
        overflow-y: auto;
        overflow-x: hidden;
        z-index: 1000;
        flex-shrink: 0;
    }
    
    .sidebar-overlay {
        display: none !important;
    }
    
    .mobile-header {
        display: none;
    }
    
    .mobile-menu-btn {
        display: none;
    }
    
    main {
        margin-left: 280px;
        padding-top: 0;
        min-height: 100vh;
        width: calc(100% - 280px);
    }
}

.btn {
    transition: all 0.3s ease;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

input, select, textarea {
    background-color: #FFFFFF;
    color: #333333;
    border: 1px solid #D1D5DB;
}

input:focus, select:focus, textarea:focus {
    border-color: #FFC107;
    outline: none;
    box-shadow: 0 0 0 3px rgba(255, 193, 7, 0.3);
}

input[type="radio"] {
    accent-color: #FFC107;
}

table {
    border-collapse: separate;
    border-spacing: 0;
}

table th {
    background-color: #F9FAFB;
    color: #4B5563;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 12px 16px;
    border-bottom: 1px solid #E5E7EB;
}

table td {
    padding: 12px 16px;
    border-bottom: 1px solid #E5E7EB;
}

table tr:hover td {
    background-color: #F9FAFB;
}

/* Responsive Tables */
@media (max-width: 768px) {
    .table-responsive {
        display: block;
        width: 100%;
        overflow-x: auto;
        white-space: nowrap;
    }
    
    .table-responsive table {
        min-width: 600px;
    }
    
    .table-card {
        display: none;
    }
    
    .table-card.show {
        display: block;
    }
    
    .table-card .card {
        background: white;
        border-radius: 8px;
        box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
        margin-bottom: 1rem;
        padding: 1rem;
        border: 1px solid #E5E7EB;
    }
    
    .table-card .card-header {
        font-weight: 600;
        color: #FFC107;
        margin-bottom: 0.5rem;
        padding-bottom: 0.5rem;
        border-bottom: 1px solid #E5E7EB;
    }
    
    .table-card .card-row {
        display: flex;
        justify-content: space-between;
        padding: 0.25rem 0;
    }
    
    .table-card .card-label {
        font-weight: 500;
        color: #6B7280;
        font-size: 0.875rem;
    }
    
    .table-card .card-value {
        color: #374151;
        text-align: right;
    }
}

/* Form Improvements */
@media (max-width: 640px) {
    .grid {
        grid-template-columns: 1fr !important;
    }
    
    .md\\:grid-cols-2,
    .md\\:grid-cols-3,
    .md\\:grid-cols-4,
    .md\\:grid-cols-6 {
        grid-template-columns: 1fr !important;
    }
    
    .md\\:col-span-2,
    .md\\:col-span-3,
    .md\\:col-span-6 {
        grid-column: span 1 / span 1 !important;
    }
    
    /* Stack buttons vertically on mobile */
    .flex.gap-2,
    .flex.gap-3 {
        flex-direction: column;
    }
    
    .flex.gap-2 > *,
    .flex.gap-3 > * {
        width: 100%;
        justify-content: center;
    }
}

/* Stats page mobile improvements */
@media (max-width: 768px) {
    .lg\\:grid-cols-2 {
        grid-template-columns: 1fr !important;
    }
    
    .h-\\[320px\\] {
        height: 250px !important;
    }
    
    /* Period buttons mobile */
    .flex.items-center.gap-2 {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .flex.items-center.gap-2 a {
        flex: 1;
        min-width: 80px;
        text-align: center;
    }
}

/* Audit logs mobile improvements */
@media (max-width: 768px) {
    details summary {
        cursor: pointer;
        user-select: none;
    }
    
    .overflow-x-auto {
        -webkit-overflow-scrolling: touch;
    }
}

/* Formulaires inline pour actions sécurisées */
form.inline {
    display: inline;
}

form.inline button {
    background: none;
    border: none;
    padding: inherit;
    margin: inherit;
    color: inherit;
    font: inherit;
    cursor: pointer;
    text-decoration: none;
    display: inline;
}

/* Styles pour boutons qui remplacent les liens */
button.link-style {
    background: none !important;
    border: none !important;
    padding: 0 !important;
    color: inherit !important;
    text-decoration: underline;
    cursor: pointer;
    font: inherit;
}

button.link-style:hover {
    text-decoration: none;
}
