/* ═══════════════════════════════════════════════════════════
   🌴 VILLA SUN — Dark Theme Design System v4.1
   Matching daily-checklist.html & rules.html dark palette
   ═══════════════════════════════════════════════════════════ */

:root {
    /* Dark Theme — matches checklist & rules */
    --bg: #0F1923;
    --bg2: #1A2332;
    --card: #1E2D3D;
    --gold: #D4A843;
    --gold-light: #E8D7AE;
    --gold-dark: #8B7355;
    --gold-metallic: linear-gradient(135deg, #D4A843 0%, #E8D7AE 50%, #D4A843 100%);
    --green: #5C8D6F;
    --green-light: #7DBF8E;
    --ocean: #2C5F77;
    --ocean-teal: #4A9FB1;
    --ocean-light: #7EC8E3;
    --red: #DC2626;
    --purple: #7C3AED;
    --cyan: #0891B2;
    --coral: #D89B7C;
    --coral-light: #E8C0B0;
    --terracotta: #D4A574;
    --terracotta-light: #E8C5A0;
    --txt: #FFFFFF;
    --txt2: rgba(255,255,255,0.75);
    --txt3: rgba(255,255,255,0.5);
    --border: rgba(255,255,255,0.08);

    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
    --shadow-md: 0 8px 24px rgba(0,0,0,0.4);
    --shadow-lg: 0 16px 48px rgba(0,0,0,0.5);
    --shadow-xl: 0 24px 64px rgba(0,0,0,0.6);
    --shadow-gold: 0 4px 20px rgba(212,168,67,0.15);

    /* Glass */
    --glass-bg: rgba(30,45,61,0.85);
    --glass-border: rgba(212,168,67,0.15);
}

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

body {
    font-family: 'Montserrat', 'Noto Sans Khmer', sans-serif;
    background: var(--bg);
    color: var(--txt);
    line-height: 1.6;
    overflow-x: hidden;
    position: relative;
    min-height: 100vh;
}

/* Villa Sun Background Images — dynamisch via backgrounds.js */
body::before {
    content: '';
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(135deg, var(--bg) 0%, var(--bg2) 100%);
    z-index: -1;
    pointer-events: none;
}

#villa-bg {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: -2;
    pointer-events: none;
}

body::after {
    content: '';
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background-image:
        repeating-linear-gradient(45deg, transparent, transparent 100px, rgba(212,168,67,0.015) 100px, rgba(212,168,67,0.015) 200px),
        repeating-linear-gradient(-45deg, transparent, transparent 100px, rgba(92,141,111,0.015) 100px, rgba(92,141,111,0.015) 200px);
    z-index: -1;
    pointer-events: none;
}

/* ── Typography ── */
h1, h2, h3, h4, h5, h6 {
    font-family: 'Playfair Display', 'Noto Sans Khmer', serif;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--txt);
}

.font-display { font-family: 'Playfair Display', serif; }

/* Bilingual */
.bilingual {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.bilingual .km {
    font-family: 'Noto Sans Khmer', sans-serif;
    font-weight: 700;
    font-size: 1.1em;
    color: var(--gold);
    line-height: 1.4;
}
.bilingual .en {
    font-family: 'Montserrat', sans-serif;
    font-weight: 500;
    font-size: 0.7em;
    color: var(--txt3);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    line-height: 1.2;
}
.km {
    font-family: 'Noto Sans Khmer', sans-serif;
    color: var(--gold);
}

/* ── Glass Cards ── */
.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-lg);
    border-radius: 24px;
    position: relative;
    overflow: hidden;
}
.glass-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: var(--gold-metallic);
}

/* ── E-Cards (dark cards — matching rules.html) ── */
.e-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 20px;
    overflow: hidden;
    transition: all 0.3s;
    position: relative;
}

/* ── Header ── */
header {
    background: linear-gradient(135deg, rgba(15,25,35,0.98), rgba(26,35,50,0.98)) !important;
    backdrop-filter: blur(10px);
    border: none !important;
    border-bottom: 3px solid var(--gold) !important;
    box-shadow: var(--shadow-xl);
    position: relative;
    overflow: hidden;
}
header::before {
    content: '';
    position: absolute;
    top: 0; left: -100%;
    width: 100%; height: 100%;
    background: linear-gradient(90deg, transparent, rgba(212,168,67,0.08), transparent);
    animation: shimmer 4s infinite;
}
@keyframes shimmer {
    0% { left: -100%; }
    100% { left: 100%; }
}
header h1 {
    color: #FFFFFF !important;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
    font-weight: 800;
    letter-spacing: -0.03em;
}
header button {
    background: rgba(255,255,255,0.08) !important;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.15) !important;
    color: white !important;
    font-weight: 600;
    transition: all 0.3s ease;
}
header button:hover {
    background: rgba(212,168,67,0.2) !important;
    border-color: var(--gold) !important;
    transform: translateY(-1px);
}

/* ── Balance Bar ── */
.balance-bar {
    height: 150px;
    border-radius: 28px;
    position: relative;
    overflow: hidden;
    background: linear-gradient(135deg, #1A2332 0%, #0F1923 100%);
    box-shadow: var(--shadow-lg), inset 0 2px 8px rgba(0,0,0,0.3);
    border: 3px solid var(--gold);
    transition: all 0.4s ease;
}
.balance-bar::before {
    content: '';
    position: absolute; inset: 0;
    background: radial-gradient(circle at 30% 30%, rgba(212,168,67,0.1) 0%, transparent 60%);
    pointer-events: none;
}
.balance-bar-fill {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    background: linear-gradient(to top, var(--green) 0%, var(--green-light) 50%, #A8E6B7 100%);
    transition: height 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 -8px 32px rgba(92,141,111,0.4);
    overflow: hidden;
}
.balance-bar-fill::before {
    content: '';
    position: absolute; inset: 0;
    background: linear-gradient(-45deg, transparent 30%, rgba(255,255,255,0.15) 50%, transparent 70%);
    animation: flow 3s linear infinite;
}
@keyframes flow {
    0% { transform: translateX(-100%) translateY(-100%); }
    100% { transform: translateX(100%) translateY(100%); }
}
.balance-bar-fill.low {
    background: linear-gradient(to top, #DC2626 0%, #F87171 50%, #FCA5A5 100%);
    box-shadow: 0 -8px 32px rgba(220,38,38,0.4);
}
.balance-bar-fill.medium {
    background: linear-gradient(to top, var(--terracotta) 0%, var(--terracotta-light) 50%, #F2DEC8 100%);
    box-shadow: 0 -8px 32px rgba(212,165,116,0.4);
}
.balance-bar-fill.high {
    background: linear-gradient(to top, var(--green) 0%, var(--green-light) 50%, #A8E6B7 100%);
    box-shadow: 0 -8px 32px rgba(92,141,111,0.4);
}
.balance-percentage {
    font-size: 4rem;
    font-weight: 900;
    font-family: 'Playfair Display', serif;
    color: white;
    text-shadow: 0 4px 8px rgba(0,0,0,0.5), 0 0 40px rgba(255,255,255,0.2);
    z-index: 10;
    letter-spacing: -0.05em;
    position: relative;
}

/* ── Task Tiles ── */
.task-tile {
    background: var(--card);
    border-radius: 20px;
    padding: 24px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    color: var(--txt);
}
.task-tile::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: var(--gold-metallic);
    opacity: 0;
    transition: opacity 0.3s ease;
}
.task-tile:hover::before { opacity: 1; }
.task-tile:hover {
    transform: translateY(-8px) scale(1.02);
    box-shadow: var(--shadow-lg), 0 0 40px rgba(212,168,67,0.15);
    border-color: rgba(212,168,67,0.3);
}
.task-tile .text-5xl, .task-tile .text-3xl {
    font-size: 3rem !important;
    color: var(--gold);
    filter: drop-shadow(0 4px 8px rgba(212,168,67,0.3));
    transition: all 0.3s ease;
}
.task-tile:hover .text-5xl, .task-tile:hover .text-3xl {
    transform: scale(1.1);
}

/* ── Quick Action Buttons ── */
.bg-gradient-to-br {
    position: relative;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.1);
    box-shadow: var(--shadow-md);
    transition: all 0.3s ease;
}
.bg-gradient-to-br:hover {
    transform: translateY(-6px) scale(1.03);
    box-shadow: var(--shadow-lg);
    border-color: rgba(255,255,255,0.2);
}
.bg-gradient-to-br i { transition: all 0.3s ease; }
.bg-gradient-to-br:hover i { transform: scale(1.15); }

/* ── Buttons ── */
button, .btn {
    font-family: 'Montserrat', sans-serif;
    font-weight: 600;
    letter-spacing: 0.03em;
    font-size: 0.875rem;
    padding: 14px 32px;
    border-radius: 12px;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    color: white;
}
button:hover { transform: translateY(-1px); }

.bg-indigo-600, .bg-blue-600, .bg-blue-500 {
    background: linear-gradient(135deg, var(--ocean), var(--ocean-teal)) !important;
    box-shadow: 0 8px 24px rgba(44,95,119,0.3);
    color: white !important;
}
.bg-indigo-600:hover, .bg-blue-600:hover, .bg-blue-500:hover {
    box-shadow: 0 12px 32px rgba(44,95,119,0.4);
}
.bg-green-600, .bg-green-500 {
    background: linear-gradient(135deg, var(--green), #4A7A5E) !important;
    box-shadow: 0 8px 24px rgba(92,141,111,0.3);
    color: white !important;
}
.bg-red-600, .bg-red-500 {
    background: linear-gradient(135deg, #DC2626, #B91C1C) !important;
    box-shadow: 0 8px 24px rgba(220,38,38,0.3);
    color: white !important;
}
.bg-yellow-500, .bg-orange-600 {
    background: linear-gradient(135deg, var(--gold), var(--gold-dark)) !important;
    box-shadow: 0 8px 24px rgba(212,168,67,0.3);
    color: white !important;
}
.bg-purple-600, .bg-purple-500 {
    background: linear-gradient(135deg, #7C3AED, #5B21B6) !important;
    box-shadow: 0 8px 24px rgba(124,58,237,0.3);
    color: white !important;
}
.bg-cyan-600, .bg-cyan-500 {
    background: linear-gradient(135deg, var(--ocean-teal), var(--ocean)) !important;
    box-shadow: 0 8px 24px rgba(74,159,177,0.3);
    color: white !important;
}

/* ── Status Badges ── */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border: 1px solid;
}
.status-badge::before {
    content: '';
    width: 6px; height: 6px;
    border-radius: 50%;
    background: currentColor;
    box-shadow: 0 0 6px currentColor;
}
.status-assigned { background: rgba(74,159,177,0.12); color: var(--ocean-teal); border-color: rgba(74,159,177,0.3); }
.status-accepted { background: rgba(212,168,67,0.12); color: var(--gold); border-color: rgba(212,168,67,0.3); }
.status-completed { background: rgba(92,141,111,0.12); color: var(--green-light); border-color: rgba(92,141,111,0.3); }
.status-evaluated { background: rgba(212,168,67,0.12); color: var(--gold-light); border-color: rgba(212,168,67,0.3); }
.status-open { background: rgba(216,155,124,0.12); color: var(--coral-light); border-color: rgba(216,155,124,0.3); }
.status-in_progress { background: rgba(245,158,11,0.12); color: #FBBF24; border-color: rgba(245,158,11,0.3); }
.status-resolved { background: rgba(92,141,111,0.12); color: var(--green-light); border-color: rgba(92,141,111,0.3); }

/* ── Item Cards ── */
.item-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 24px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-md);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    color: var(--txt);
}
.item-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: var(--gold-metallic);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.4s ease;
}
.item-card:hover { border-color: rgba(212,168,67,0.25); }
.item-card:hover::before { transform: scaleX(1); }

/* ── Photo Preview ── */
.photo-preview {
    width: 120px; height: 120px;
    object-fit: cover;
    border-radius: 16px;
    border: 2px solid rgba(212,168,67,0.3);
    box-shadow: var(--shadow-md);
    transition: all 0.3s ease;
    cursor: pointer;
}
.photo-preview:hover {
    transform: scale(1.08);
    border-color: var(--gold);
    box-shadow: var(--shadow-lg);
}

/* ── Modal ── */
.modal {
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(8px);
    animation: fadeIn 0.3s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-content,
.modal .bg-white {
    background: var(--bg2) !important;
    border: 1px solid rgba(212,168,67,0.15);
    border-radius: 20px;
    box-shadow: var(--shadow-xl);
    animation: modalSlideUp 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    color: var(--txt) !important;
}
@keyframes modalSlideUp {
    from { opacity: 0; transform: translateY(40px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Input Fields ── */
input, textarea, select {
    font-family: 'Montserrat', 'Noto Sans Khmer', sans-serif;
    border: 1px solid rgba(255,255,255,0.12) !important;
    border-radius: 12px !important;
    transition: all 0.3s ease !important;
    background: rgba(255,255,255,0.06) !important;
    color: var(--txt) !important;
}
/* Select option elements need dark text for browser dropdown */
select option {
    background: #1E2D3D !important;
    color: #FFFFFF !important;
}
input:focus, textarea:focus, select:focus {
    border-color: var(--gold) !important;
    box-shadow: 0 0 0 3px rgba(212,168,67,0.12) !important;
    outline: none !important;
}
input::placeholder, textarea::placeholder { color: var(--txt3) !important; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gold-dark); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--gold); }

/* ── Spinner ── */
.spinner {
    width: 50px; height: 50px;
    border: 3px solid rgba(255,255,255,0.1);
    border-top: 3px solid var(--gold);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* ── BG White override for dark theme ── */
.bg-white {
    background: var(--card) !important;
    box-shadow: var(--shadow-md) !important;
    color: var(--txt) !important;
}

/* ── Additional Tailwind class overrides for dark theme ── */
.bg-gray-50 { background: var(--bg) !important; }
.bg-gray-100 { background: rgba(255,255,255,0.04) !important; }
.bg-gray-200 { background: rgba(255,255,255,0.06) !important; }
.bg-gray-300 { background: rgba(255,255,255,0.1) !important; }
.border-gray-100, .border-gray-200, .border-gray-300 { border-color: var(--border) !important; }
.shadow-sm { box-shadow: 0 2px 8px rgba(0,0,0,0.3) !important; }

/* Header overrides for module pages */
header.bg-white {
    background: linear-gradient(135deg, rgba(15,25,35,0.98), rgba(26,35,50,0.98)) !important;
    border-bottom: 3px solid var(--gold) !important;
}

/* ── Icons ── */
.fas, .far, .fab {
    -webkit-text-fill-color: initial;
    background: none;
    filter: none;
}

/* Header icons get gold */
header .fas, header .far { color: var(--gold-light); }

/* ── Text color overrides for dark theme ── */
.text-gray-600, .text-gray-500, .text-gray-700, .text-gray-800, .text-gray-900 {
    color: var(--txt2) !important;
}
.text-gray-400, .text-gray-300 { color: var(--txt3) !important; }

/* Force dark text colors on typical light-theme patterns */
[style*="color: #2C3E50"], [style*="color:#2C3E50"] { color: var(--txt) !important; }
[style*="color: #8B7355"], [style*="color:#8B7355"] { color: var(--gold) !important; }

/* ── Nav (bottom navigation) ── */
.bnav {
    background: linear-gradient(135deg, rgba(15,25,35,0.98), rgba(26,35,50,0.98));
    border-top: 1px solid rgba(212,168,67,0.15);
    backdrop-filter: blur(10px);
}
.bnav a { color: var(--txt3); transition: color 0.2s; }
.bnav a.active, .bnav a:hover { color: var(--gold); }

/* ── Toast ── */
.toast {
    position: fixed; bottom: 100px; left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--green); color: white;
    padding: 10px 24px; border-radius: 12px;
    font-weight: 600; font-size: 13px;
    z-index: 2100; opacity: 0;
    transition: all 0.3s; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Animations ── */
@keyframes fadeUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
.anim { animation: fadeUp 0.5s ease forwards; }

@keyframes subtlePulse {
    0%, 100% { box-shadow: 0 4px 20px rgba(44,95,119,0.2); }
    50% { box-shadow: 0 4px 30px rgba(44,95,119,0.35); }
}

/* ── Responsive ── */
@media (max-width: 768px) {
    .balance-bar { height: 100px; border-radius: 16px; border-width: 2px; }
    .balance-percentage { font-size: 2rem; }
    .task-tile { padding: 12px; border-radius: 16px; }
    .task-tile:hover { transform: translateY(-4px) scale(1.01); }
    .task-tile .text-5xl, .task-tile .text-3xl { font-size: 2rem !important; }
    .glass-card { border-radius: 16px; }
    .item-card { padding: 16px; border-radius: 14px; margin-bottom: 12px; }
    header h1 { font-size: 1.1rem !important; }
    .modal-content, .modal .bg-white { border-radius: 16px; margin: 8px; max-height: 90vh; overflow-y: auto; }
    button, .btn { padding: 10px 16px; font-size: 0.75rem; }
    input, textarea, select { font-size: 16px !important; padding: 12px !important; }
    .photo-preview { width: 80px; height: 80px; }
}

@media (max-width: 375px) {
    .balance-bar { height: 90px; }
    .balance-percentage { font-size: 1.8rem; }
    .task-tile { padding: 8px; }
    .task-tile .text-3xl { font-size: 1.5rem !important; }
}

@media (min-width: 768px) and (max-width: 1024px) {
    .balance-bar { height: 130px; }
}

/* Modal mobile fix */
.modal {
    position: fixed; inset: 0;
    display: flex; align-items: center; justify-content: center;
    z-index: 50; padding: 16px;
}

/* Safe area */
@supports (padding: env(safe-area-inset-top)) {
    header { padding-top: env(safe-area-inset-top); }
    body { padding-bottom: env(safe-area-inset-bottom); }
}

/* Touch */
@media (hover: none) {
    .task-tile:active { transform: scale(0.97); opacity: 0.9; }
    button:active { opacity: 0.8; }
    .item-card:active { opacity: 0.9; }
    .task-tile:hover { transform: none; box-shadow: var(--shadow-md); }
    .bg-gradient-to-br:hover { transform: none; }
}

/* Print */
@media print {
    body { background: white; color: #000; }
    .no-print { display: none !important; }
}
