/* ============================================ */
/* GLOBAL THEME & CSS VARIABLES                 */
/* Apple Design Style - Clean & Minimal        */
/* ============================================ */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Kanit', sans-serif;
    transition: background-color 0.3s ease, color 0.3s ease;
    height: 100dvh;
    overflow: hidden;
    padding: 20px 20px 0 20px;
    display: flex;
    justify-content: center;
    min-height: 0;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#app {
    max-width: 500px;
    width: 100%;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

/* ========== DARK MODE (Default) ========== */
:root,
body.dark {
    --bg-primary: #000000;
    --bg-secondary: #0d0d10;
    --bg-card: #111114;
    --text-primary: #f5f3f7;
    --text-secondary: #aaa5ae;
    --text-muted: #716c75;
    --border-color: #29262e;
    --border-light: rgba(255,255,255,0.045);
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.48);
    --shadow-hover: 0 8px 24px rgba(0, 0, 0, 0.62);
    --danger: #ff453a;
    --danger-bg: rgba(255, 69, 58, 0.12);
    --warning: #ff9f0a;
    --warning-bg: rgba(255, 159, 10, 0.1);
    --success: #30d158;
    --success-bg: rgba(48, 209, 88, 0.1);
    --primary: #a78bfa;
    --primary-dark: #8b72df;
    --modal-overlay: rgba(0, 0, 0, 0.5);
    /* Glassmorphism - Dark */
    --glass-bg: rgba(14, 14, 17, 0.78);
    --glass-surface: rgba(22, 21, 26, 0.86);
    --glass-border: rgba(255, 255, 255, 0.055);
    --glass-border-strong: rgba(255, 255, 255, 0.10);
    --glass-shadow: 0 12px 32px rgba(0, 0, 0, 0.62);
    --glass-blur: blur(24px);
    --glass-edge: rgba(31, 29, 36, 0.88);
}

/* ========== LIGHT MODE (switch via class) ========== */
body.light {
    --bg-primary: #e8ecf1;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --text-primary: #1c1c1e;
    --text-secondary: #8e8e93;
    --text-muted: #787882;
    --border-color: #d1d1d6;
    --border-light: rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-hover: 0 4px 14px rgba(0, 0, 0, 0.08);
    --danger: #ff3b30;
    --danger-bg: rgba(255, 59, 48, 0.1);
    --warning: #ff9500;
    --warning-bg: rgba(255, 149, 0, 0.1);
    --success: #34c759;
    --success-bg: rgba(52, 199, 89, 0.1);
    --primary: #007aff;
    --primary-dark: #0066d6;
    --modal-overlay: rgba(0, 0, 0, 0.25);
    /* Glassmorphism - Light */
    --glass-bg: rgba(255, 255, 255, 0.78);
    --glass-surface: rgba(255, 255, 255, 0.92);
    --glass-border: rgba(0, 0, 0, 0.08);
    --glass-border-strong: rgba(0, 0, 0, 0.12);
    --glass-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    --glass-blur: blur(20px);
    --glass-edge: rgba(255, 255, 255, 0.65);
}

/* ========== LATTE PASTEL ========== */
body.latte {
    --bg-primary: #fff5ed;
    --bg-secondary: #fffaf6;
    --bg-card: #ffffff;
    --text-primary: #4f3b38;
    --text-secondary: #8f7470;
    --text-muted: #b09a94;
    --border-color: #efdcd2;
    --border-light: rgba(121, 79, 69, 0.08);
    --shadow: 0 3px 12px rgba(157, 111, 96, 0.10);
    --shadow-hover: 0 9px 24px rgba(157, 111, 96, 0.16);
    --danger: #cd4448;
    --danger-bg: #fff0ef;
    --warning: #d2a136;
    --warning-bg: #fff6e7;
    --success: #73a980;
    --success-bg: #eef8ed;
    --primary: #e98131;
    --primary-dark: #cf6011;
    --modal-overlay: rgba(254, 246, 238, 0.427);
    --glass-bg: rgba(255, 250, 246, 0.78);
    --glass-surface: rgba(255, 255, 255, 0.85);
    --glass-border: rgba(178, 121, 104, 0.14);
    --glass-border-strong: rgba(178, 121, 104, 0.22);
    --glass-shadow: 0 12px 32px rgba(159, 105, 91, 0.14);
    --glass-blur: blur(20px);
    --glass-edge: rgba(255, 238, 229, 0.85);
}

/* ========== WORKBENCH ========== */
body.workbench {
    --bg-primary: #f5f3ee;
    --bg-secondary: #e8e5dc;
    --bg-card: #faf9f5;
    --text-primary: #292824;
    --text-secondary: #615e58;
    --text-muted: #918e86;
    --border-color: #cbc7bd;
    --border-light: rgba(41, 40, 36, 0.08);
    --shadow: 0 2px 5px rgba(41, 40, 36, 0.06);
    --shadow-hover: 0 7px 18px rgba(41, 40, 36, 0.10);
    --danger: #b84d43;
    --danger-bg: #faece9;
    --warning: #b97735;
    --warning-bg: #faf1e3;
    --success: #557a5d;
    --success-bg: #edf4ed;
    --primary: #47657c;
    --primary-dark: #304d64;
    --modal-overlay: rgba(34, 33, 29, 0.22);
    --glass-bg: rgba(250, 249, 245, 0.88);
    --glass-surface: rgba(250, 249, 245, 0.96);
    --glass-border: rgba(41, 40, 36, 0.10);
    --glass-border-strong: rgba(41, 40, 36, 0.18);
    --glass-shadow: 0 12px 26px rgba(41, 40, 36, 0.11);
    --glass-blur: blur(16px);
    --glass-edge: #f4f1e9;
}

/* Workbench uses quiet, almost square controls in place of soft app-style pills. */
body.workbench .group-card { border-radius: 8px; border-color: rgba(41, 40, 36, 0.13); }
body.workbench .group-card.expanded { border-radius: 8px 8px 0 0; }
body.workbench .btn-primary,
body.workbench .btn-danger,
body.workbench .btn-outline,
body.workbench .btn-warning,
body.workbench .btn-add-group-inline,
body.workbench .fab-add-group { border-radius: 6px; }
body.workbench .quick-stat-btn { border-radius: 8px; }
body.workbench .bottom-nav { border-radius: 10px; }
body.workbench .modal-content { border-radius: 12px 12px 0 0; }
body.workbench .settings-btn { border-radius: 6px; }

@media (min-width: 768px) {
    body.workbench .modal-content { border-radius: 12px; }
}

/* ========== CYBERPUNK ========== */
body.cyberpunk {
    --bg-primary: #090714;
    --bg-secondary: #100c24;
    --bg-card: #100d20;
    --text-primary: #f4efff;
    --text-secondary: #bab0d9;
    --text-muted: #776e98;
    --border-color: #2a1e54;
    --border-light: rgba(0, 229, 255, 0.10);
    --shadow: 0 3px 14px rgba(0, 0, 0, 0.5);
    --shadow-hover: 0 0 24px rgba(0, 229, 255, 0.18);
    --danger: #fd4649;
    --danger-bg: rgba(255, 77, 141, 0.13);
    --warning: #ffb300;
    --warning-bg: rgba(255, 227, 110, 0.12);
    --success: #3cffb4;
    --success-bg: rgba(60, 255, 180, 0.11);
    --primary: #ae01ff;
    --primary-dark: #00b7d4;
    --modal-overlay: rgba(5, 2, 16, 0.76);
    --glass-bg: rgba(16, 11, 33, 0.82);
    --glass-surface: rgba(22, 15, 47, 0.90);
    --glass-border: rgba(118, 73, 255, 0.34);
    --glass-border-strong: rgba(0, 229, 255, 0.48);
    --glass-shadow: 0 12px 34px rgba(0, 0, 0, 0.6);
    --glass-blur: blur(20px);
    --glass-edge: rgba(41, 26, 82, 0.94);
}

body.cyberpunk .group-card,
body.cyberpunk .member-row {
    border-color: rgba(118, 73, 255, 0.42);
    border-radius: 2px;
}
body.cyberpunk .group-detail,
body.cyberpunk .desktop-detail-panel,
body.cyberpunk .bottom-nav,
body.cyberpunk .modal-content,
body.cyberpunk .theme-menu,
body.cyberpunk .search-dropdown { border-radius: 2px; }
body.cyberpunk .group-card.expanded { border-radius: 2px 2px 0 0; }
body.cyberpunk .btn-primary,
body.cyberpunk .btn-danger,
body.cyberpunk .btn-outline,
body.cyberpunk .btn-warning,
body.cyberpunk .btn-add-group-inline,
body.cyberpunk .btn-add-member,
body.cyberpunk .btn-renew-solid,
body.cyberpunk .btn-renew-pill,
body.cyberpunk .quick-stat-btn,
body.cyberpunk .fab-add-group,
body.cyberpunk .nav-item,
body.cyberpunk .theme-swatch,
body.cyberpunk .quick-date-btn,
body.cyberpunk .preset-btn,
body.cyberpunk .modal-close,
body.cyberpunk .desktop-detail-close,
body.cyberpunk .custom-select-trigger,
body.cyberpunk .custom-select-menu,
body.cyberpunk .custom-select-option,
body.cyberpunk .notification-help { border-radius: 2px; }
body.cyberpunk .form-group input,
body.cyberpunk .form-group select,
body.cyberpunk .form-group textarea,
body.cyberpunk .member-row .mem-days { border-radius: 2px; }
body.cyberpunk .group-card:hover { box-shadow: 0 0 22px rgba(0, 229, 255, 0.14); }
body.cyberpunk .bottom-nav { box-shadow: 0 0 28px rgba(118, 73, 255, 0.20); }

/* Keep the Workbench member footer connected to its card rather than a separate dark band. */
body.workbench .member-row .mem-bottom {
    background: rgba(41, 40, 36, 0.035);
    border-top: 1px solid rgba(41, 40, 36, 0.07);
}

/* ========== CLARITY ========== */
body.clarity {
    --bg-primary: #f6f6f3;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --text-primary: #070707;
    --text-secondary: #3f3f3f;
    --text-muted: #737373;
    --border-color: #c8c8c2;
    --border-light: rgba(0, 0, 0, 0.07);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-hover: 0 6px 16px rgba(0, 0, 0, 0.10);
    --danger: #d71920;
    --danger-bg: #fff0f0;
    --warning: #b86b00;
    --warning-bg: #fff5df;
    --success: #147a38;
    --success-bg: #edf8f0;
    --primary: #050505;
    --primary-dark: #000000;
    --modal-overlay: rgba(0, 0, 0, 0.30);
    --glass-bg: rgba(255, 255, 255, 0.88);
    --glass-surface: rgba(255, 255, 255, 0.97);
    --glass-border: rgba(0, 0, 0, 0.10);
    --glass-border-strong: rgba(0, 0, 0, 0.20);
    --glass-shadow: 0 10px 24px rgba(0, 0, 0, 0.10);
    --glass-blur: blur(12px);
    --glass-edge: #f0f0ec;
}

body.clarity .group-card,
body.clarity .member-row,
body.clarity .modal-content,
body.clarity .desktop-detail-panel {
    border-color: rgba(0, 0, 0, 0.14);
}

body.clarity .btn-primary,
body.clarity .btn-renew-solid,
body.clarity .fab-add-group {
    color: #ffffff;
}

body.clarity .btn-add-group-inline,
body.clarity .btn-add-member {
    background: #ffffff;
    border-color: var(--primary);
    color: var(--text-primary);
}

body.clarity .btn-add-group-inline:hover,
body.clarity .btn-add-member:hover {
    background: #f3f3ef;
    color: var(--warning);
    border-color: var(--warning);
}

body.clarity .quick-stat-btn,
body.clarity .btn-outline,
body.clarity .custom-select-trigger,
body.clarity .form-group input,
body.clarity .form-group select,
body.clarity .form-group textarea {
    border-color: rgba(0, 0, 0, 0.18);
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
}

/* ========== UTILITY CLASSES ========== */
.hidden {
    display: none !important;
}

/* ========== SVG Icons Color ========== */
svg {
    stroke: currentColor;
    fill: none;
}

button svg {
    pointer-events: none;
}

/* ========== BUTTONS ========== */
button {
    cursor: pointer;
    font-family: 'Kanit', sans-serif;
    border: none;
    -webkit-tap-highlight-color: transparent;
    transition: all 0.2s ease;
}

button:active {
    transform: scale(0.97);
}

.btn-primary {
    background-color: var(--primary);
    color: #ffffff;
    padding: 14px 20px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    width: 100%;
    transition: all 0.2s ease;
}

.btn-primary:hover {
    background-color: var(--primary-dark);
}

.btn-outline {
    background-color: transparent;
    color: var(--primary);
    border: 1.5px solid var(--primary);
    padding: 4px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s ease;
}

.btn-outline:hover {
    background-color: var(--primary);
    color: #ffffff;
}

.btn-danger {
    background-color: transparent;
    color: var(--danger);
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    border: 1px solid var(--danger);
    transition: all 0.2s ease;
}

.btn-danger:hover {
    background-color: var(--danger-bg);
}

/* ========== DIVIDER ========== */
.divider {
    text-align: center;
    padding: 16px;
    color: var(--text-secondary);
    font-size: 13px;
    position: relative;
}

.divider::before,
.divider::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 35%;
    height: 1px;
    background: var(--border-color);
}
.divider::before { left: 0; }
.divider::after { right: 0; }

/* ========== SCROLLBAR ========== */
::-webkit-scrollbar {
    width: 4px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}



/* ==================== BOTTOM NAVIGATION & VIEWS ==================== */
.view {
    display: none;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

.view.active {
    display: flex;
}

/* Views that scroll themselves (ledger, profile) */
.view.scrollable {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.btn-primary:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.btn-warning {
    background: var(--warning);
    color: #ffffff;
    border: none;
    padding: 14px 24px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(255, 149, 0, 0.2);
}

.btn-warning:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.bottom-nav {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 48px);
    max-width: 400px;
    height: 64px;
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    border-radius: 32px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 1000;
    padding: 0 8px;
    box-shadow: var(--glass-shadow);
}

body.light .bottom-nav {
    border: 1px solid rgba(0,0,0,0.08);
    box-shadow: var(--glass-shadow), 0 1px 0 rgba(255,255,255,0.8) inset;
}

body.dark .bottom-nav {
    border: 1px solid rgba(255,255,255,0.07);
    box-shadow: var(--glass-shadow);
}

.nav-item {
    background: transparent;
    border: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 500;
    padding: 8px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: 'Kanit', sans-serif;
    -webkit-tap-highlight-color: transparent;
    flex: 1;
}

.nav-item svg {
    transition: all 0.2s;
}

.nav-item.active {
    color: var(--primary);
}

.nav-item.active svg {
    transform: translateY(-2px);
    stroke-width: 2.5px;
}

.nav-item .thai-tea-nav-art { display: none; }

body.latte .nav-item > svg { display: none; }
body.latte .thai-tea-nav-art {
    width: 32px;
    height: 29px;
    display: grid;
    place-items: center;
    position: relative;
    flex: 0 0 auto;
}
body.latte .thai-tea-nav-art img {
    width: 32px;
    height: 29px;
    object-fit: contain;
    image-rendering: auto;
    position: absolute;
    transition: opacity .18s ease, transform .22s ease;
}
body.latte .tea-nav-active { opacity: 0; transform: translateY(3px) scale(.86); }
body.latte .nav-item.active .tea-nav-idle { opacity: 0; transform: translateY(-2px) scale(.9); }
body.latte .nav-item.active .tea-nav-active {
    opacity: 1;
    transform: translateY(-2px) scale(1.08);
}

@media (prefers-reduced-motion: reduce) {
    body.latte .thai-tea-nav-art img { transition: none; }
    body.latte .group-card.expanded::after,
    body.latte .group-card.desktop-selected::after { animation: none; }
}

#app {
    /* Removed padding-bottom to allow full scroll behind nav */
}

/* Inline Add Group Button */
.btn-add-group-inline {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: rgba(0, 122, 255, 0.1);
    color: var(--primary);
    border: 1.5px dashed var(--primary);
    border-radius: 10px;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 500;
    font-family: 'Kanit', sans-serif;
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}

body.dark .btn-add-group-inline {
    background: rgba(0, 122, 255, 0.15);
}

.btn-add-group-inline:active {
    transform: scale(0.98);
    background: rgba(0, 122, 255, 0.2);
}

.add-group-label-mobile { display: none; }

/* Thai Tea keeps the compact add action warm instead of the generic cool blue. */
body.latte .btn-add-group-inline {
    background: #fff0e5;
    color: #bd642d;
    border-color: #e78a4d;
    box-shadow: 0 2px 6px rgba(190, 103, 47, 0.10);
}

body.latte .btn-add-group-inline:active {
    background: #ffe2cc;
}


/* ============================================ */
/* DESKTOP MODE (Responsive Layout)             */
/* ============================================ */
@media (min-width: 1024px) {
    body {
        padding: 0;
        align-items: center;
        background-color: var(--bg-primary); /* Use primary on body */
    }

    #app {
        max-width: 100%;
        width: 100%;
        height: 100dvh;
        display: grid;
        grid-template-columns: 240px 1fr;
        grid-template-rows: auto 1fr;
        background-color: var(--bg-primary);
        box-shadow: var(--shadow);
    }

    /* Sidebar Navigation on Desktop */
    .bottom-nav {
        grid-column: 1;
        grid-row: 1 / span 2;
        position: static;
        transform: none;
        width: 240px;
        height: 100%;
        border-radius: 0;
        flex-direction: column;
        justify-content: flex-start;
        align-items: flex-start;
        padding: 24px 16px;
        border-right: 1px solid var(--border-color);
        border-top: none;
        border-left: none;
        border-bottom: none;
        box-shadow: none;
        background: var(--bg-secondary);
        gap: 8px;
    }

    .sidebar-brand {
        display: flex;
        align-items: center;
        gap: 10px;
        width: 100%;
        padding: 4px 8px 20px;
        margin-bottom: 8px;
        border-bottom: 1px solid var(--border-light);
        color: var(--text-primary);
        font-size: 22px;
        font-weight: 700;
        line-height: 1;
    }

    .sidebar-brand-icon {
        object-fit: contain;
        border-radius: 8px;
    }

    .nav-item {
        flex-direction: row;
        width: 100%;
        padding: 12px 16px;
        border-radius: 12px;
        font-size: 15px;
        justify-content: flex-start;
        gap: 16px;
        flex: none;
    }

    .nav-item:hover {
        background: var(--glass-surface);
    }

    .nav-item.active {
        background: var(--primary);
        color: white;
    }

    .nav-item.active svg {
        stroke-width: 2px;
        transform: none;
    }

    .nav-item span {
        display: inline;
    }

    /* Header */
    .header {
        grid-column: 2;
        grid-row: 1;
        justify-content: flex-end;
        min-height: 60px;
        padding: 16px 32px 8px;
        margin-bottom: 0;
    }

    .header-left { display: none; }

    /* Views */
    .view {
        grid-column: 2;
        grid-row: 2;
        padding: 0 32px;
    }
}

