/* =====================================================================
   app-design.css — Shared design system for the household platform
   Phase 1 of the UI overhaul. Unifies the whole app on the calendar's
   green "household" aesthetic.

   Contents:
     1. Design tokens (light + dark)
     2. Base / body
     3. Bootstrap refinements (low-risk, visual only)
     4. app-* component library (opt-in, used as pages are converted)
     5. Utilities
     6. Responsive

   Loaded globally via partials/theme-head.ejs AFTER Bootstrap so these
   rules win. Nothing here changes page behaviour — visual only.
   ===================================================================== */

/* ------------------------------------------------------------------ */
/* 1. DESIGN TOKENS                                                    */
/* ------------------------------------------------------------------ */
:root {
    --app-radius-sm: 12px;
    --app-radius: 16px;
    --app-radius-lg: 24px;
    --app-radius-xl: 28px;
    --app-radius-pill: 999px;

    --app-space-1: 0.35rem;
    --app-space-2: 0.65rem;
    --app-space-3: 1rem;
    --app-space-4: 1.5rem;
    --app-space-5: 2rem;

    --app-focus-ring: 0 0 0 3px rgba(53, 110, 253, 0.28);
    --app-transition: 0.16s ease;
}

body.theme-light {
    --app-bg: #f5f8f1;
    --app-surface: #ffffff;
    --app-surface-2: #fcfdf9;
    --app-surface-muted: #edf5e5;
    --app-border: rgba(18, 34, 12, 0.10);
    --app-border-strong: rgba(18, 34, 12, 0.18);

    --app-text: #1c2b15;
    --app-text-muted: #5d774a;
    --app-heading: #142114;

    --app-primary: #3a7a2b;
    --app-primary-strong: #2c5d20;
    --app-primary-soft: #e7f2df;
    --app-primary-contrast: #ffffff;
    --app-accent: #5ca248;
    --app-deep: #162218;

    --app-shadow-sm: 0 6px 16px rgba(33, 52, 22, 0.06);
    --app-shadow: 0 14px 32px rgba(33, 52, 22, 0.08);
    --app-shadow-lg: 0 24px 60px rgba(33, 52, 22, 0.10);
}

body.theme-dark {
    --app-bg: #10160f;
    --app-surface: #161e14;
    --app-surface-2: #1b2418;
    --app-surface-muted: #202b1c;
    --app-border: rgba(255, 255, 255, 0.10);
    --app-border-strong: rgba(255, 255, 255, 0.20);

    --app-text: #e8efe3;
    --app-text-muted: #9db390;
    --app-heading: #f1f6ee;

    --app-primary: #58a83f;
    --app-primary-strong: #6cbf52;
    --app-primary-soft: rgba(88, 168, 63, 0.16);
    --app-primary-contrast: #0f160e;
    --app-accent: #6cbf52;
    --app-deep: #d6e6cd;

    --app-shadow-sm: 0 6px 16px rgba(0, 0, 0, 0.30);
    --app-shadow: 0 14px 32px rgba(0, 0, 0, 0.38);
    --app-shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.46);
}

/* ------------------------------------------------------------------ */
/* 2. BASE                                                            */
/* ------------------------------------------------------------------ */
body.theme-light,
body.theme-dark {
    background-color: var(--app-bg);
    color: var(--app-text);
    -webkit-font-smoothing: antialiased;
}

body.theme-light h1, body.theme-light h2, body.theme-light h3,
body.theme-light h4, body.theme-light h5, body.theme-light h6,
body.theme-dark h1, body.theme-dark h2, body.theme-dark h3,
body.theme-dark h4, body.theme-dark h5, body.theme-dark h6 {
    color: var(--app-heading);
    letter-spacing: -0.01em;
}

/* ------------------------------------------------------------------ */
/* 3. BOOTSTRAP REFINEMENTS (visual only, low risk)                   */
/* ------------------------------------------------------------------ */

/* Cards pick up the soft rounded household look everywhere */
body.theme-light .card,
body.theme-dark .card {
    background-color: var(--app-surface);
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius-lg);
    box-shadow: var(--app-shadow-sm);
    color: var(--app-text);
}

/* Buttons: pill, calm motion */
body.theme-light .btn,
body.theme-dark .btn {
    border-radius: var(--app-radius-pill);
    font-weight: 600;
    transition: filter var(--app-transition), background-color var(--app-transition),
        border-color var(--app-transition), box-shadow var(--app-transition);
}

body.theme-light .btn:focus-visible,
body.theme-dark .btn:focus-visible,
body.theme-light .form-control:focus,
body.theme-dark .form-control:focus,
body.theme-light .form-select:focus,
body.theme-dark .form-select:focus {
    box-shadow: var(--app-focus-ring);
    border-color: var(--app-accent);
}

/* Primary => brand green (the unify goal) */
body.theme-light .btn-primary,
body.theme-dark .btn-primary {
    --bs-btn-bg: var(--app-primary);
    --bs-btn-border-color: var(--app-primary);
    --bs-btn-hover-bg: var(--app-primary-strong);
    --bs-btn-hover-border-color: var(--app-primary-strong);
    --bs-btn-active-bg: var(--app-primary-strong);
    --bs-btn-active-border-color: var(--app-primary-strong);
    --bs-btn-disabled-bg: var(--app-primary);
    --bs-btn-disabled-border-color: var(--app-primary);
    --bs-btn-color: var(--app-primary-contrast);
    --bs-btn-hover-color: var(--app-primary-contrast);
    --bs-btn-active-color: var(--app-primary-contrast);
}

body.theme-light .btn-outline-primary,
body.theme-dark .btn-outline-primary {
    --bs-btn-color: var(--app-primary);
    --bs-btn-border-color: var(--app-primary);
    --bs-btn-hover-bg: var(--app-primary);
    --bs-btn-hover-border-color: var(--app-primary);
    --bs-btn-active-bg: var(--app-primary);
    --bs-btn-active-border-color: var(--app-primary);
    --bs-btn-hover-color: var(--app-primary-contrast);
    --bs-btn-active-color: var(--app-primary-contrast);
}

/* Links adopt the brand green — but never anchors styled as buttons, whose
   text colour must come from the .btn variant (otherwise green-on-green). */
body.theme-light a:not(.btn):not(.nav-link):not(.dropdown-item) {
    color: var(--app-primary);
}
body.theme-dark a:not(.btn):not(.nav-link):not(.dropdown-item) {
    color: var(--app-primary-strong);
}

/* Inputs */
body.theme-light .form-control,
body.theme-light .form-select,
body.theme-light textarea {
    border-radius: var(--app-radius-sm);
    border-color: var(--app-border);
}
body.theme-dark .form-control,
body.theme-dark .form-select,
body.theme-dark textarea {
    border-radius: var(--app-radius-sm);
    background-color: var(--app-surface-2) !important;
    border-color: var(--app-border) !important;
    color: var(--app-text) !important;
}

/* Tables: cleaner separators, rounded container when wrapped in .app-card */
body.theme-light .table,
body.theme-dark .table {
    --bs-table-color: var(--app-text);
    --bs-table-border-color: var(--app-border);
}
body.theme-dark .table {
    --bs-table-bg: transparent;
    --bs-table-striped-color: var(--app-text);
    --bs-table-striped-bg: rgba(255, 255, 255, 0.03);
    --bs-table-hover-color: var(--app-text);
    --bs-table-hover-bg: rgba(255, 255, 255, 0.05);
}

/* Modals + dropdowns + list groups in dark mode */
body.theme-dark .modal-content,
body.theme-dark .dropdown-menu,
body.theme-dark .list-group-item {
    background-color: var(--app-surface);
    border-color: var(--app-border);
    color: var(--app-text);
}

/* Muted text token */
body.theme-light .text-muted { color: var(--app-text-muted) !important; }
body.theme-dark .text-muted { color: var(--app-text-muted) !important; }

/* ------------------------------------------------------------------ */
/* 4. APP COMPONENT LIBRARY (opt-in: class names prefixed app-)        */
/* ------------------------------------------------------------------ */

/* Page wrapper — consistent max width + breathing room */
.app-page {
    padding: 1.25rem 0 6rem;
}

.app-container {
    max-width: 1040px;
    margin: 0 auto;
    padding-left: 1rem;
    padding-right: 1rem;
}

.app-container-narrow {
    max-width: 720px;
}

.app-container-wide {
    max-width: 1240px;
}

/* Page header — title block + actions, responsive */
.app-page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.app-kicker {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-weight: 700;
    color: var(--app-text-muted);
    margin-bottom: 0.3rem;
}

.app-page-title {
    margin: 0;
    font-size: clamp(1.5rem, 3vw, 2rem);
    font-weight: 800;
    color: var(--app-heading);
}

.app-page-subtitle {
    margin: 0.4rem 0 0;
    color: var(--app-text-muted);
    max-width: 46rem;
}

.app-page-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

/* Surfaces */
.app-card {
    background: var(--app-surface);
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius-lg);
    box-shadow: var(--app-shadow-sm);
    padding: 1.35rem;
    color: var(--app-text);
}

.app-card-lg {
    border-radius: var(--app-radius-xl);
    box-shadow: var(--app-shadow);
    padding: 1.6rem;
}

.app-card-flush { padding: 0; overflow: hidden; }

.app-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.app-card-title {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--app-heading);
}

.app-card-link {
    font-size: 0.92rem;
    font-weight: 600;
    text-decoration: none;
}

/* Hero — soft green gradient header block */
.app-hero {
    border-radius: var(--app-radius-xl);
    border: 1px solid var(--app-border);
    padding: 1.6rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--app-shadow);
    background:
        radial-gradient(circle at top right, var(--app-primary-soft), transparent 42%),
        var(--app-surface);
}

/* Stat strip / cards */
.app-stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.9rem;
}

.app-stat {
    background: var(--app-surface);
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius);
    padding: 1rem 1.15rem;
    box-shadow: var(--app-shadow-sm);
}

.app-stat-value {
    font-size: 1.7rem;
    font-weight: 800;
    line-height: 1;
    color: var(--app-heading);
}

.app-stat-label {
    margin-top: 0.4rem;
    font-size: 0.85rem;
    color: var(--app-text-muted);
}

/* Chip / pill bar (segmented look from calendar) */
.app-chip-bar {
    display: inline-flex;
    gap: 0.3rem;
    padding: 0.3rem;
    border-radius: var(--app-radius-pill);
    background: var(--app-surface-muted);
    border: 1px solid var(--app-border);
}

.app-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    min-height: 38px;
    padding: 0.4rem 0.95rem;
    border-radius: var(--app-radius-pill);
    font-weight: 600;
    color: var(--app-text-muted);
    text-decoration: none;
    border: none;
    background: transparent;
}

.app-chip.active,
.app-chip:hover {
    color: var(--app-heading);
    background: var(--app-surface);
    box-shadow: var(--app-shadow-sm);
}

/* List rows (recent items / feeds) */
.app-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.85rem 0;
    border-bottom: 1px solid var(--app-border);
}

.app-row:last-child { border-bottom: none; }

.app-row[data-detail-href] {
    cursor: pointer;
    border-radius: var(--app-radius-sm);
    padding-left: 0.6rem;
    padding-right: 0.6rem;
    transition: background-color var(--app-transition), transform var(--app-transition);
}

.app-row[data-detail-href]:hover {
    background-color: var(--app-primary-soft);
    transform: translateX(2px);
}

.app-row[data-detail-href]:focus-visible {
    outline: none;
    box-shadow: var(--app-focus-ring);
}

/* Soft tile (clickable card link) */
.app-tile {
    display: block;
    text-decoration: none;
    color: inherit;
    background: var(--app-surface);
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius-lg);
    box-shadow: var(--app-shadow-sm);
    padding: 1.2rem;
    height: 100%;
    transition: transform var(--app-transition), box-shadow var(--app-transition), border-color var(--app-transition);
}

.app-tile:hover {
    transform: translateY(-3px);
    box-shadow: var(--app-shadow);
    border-color: var(--app-border-strong);
    color: inherit;
}

/* Empty state */
.app-empty {
    text-align: center;
    padding: 2.75rem 1.5rem;
    border: 1px dashed var(--app-border-strong);
    border-radius: var(--app-radius-lg);
    background: var(--app-surface-2);
    color: var(--app-text-muted);
}

.app-empty-icon {
    font-size: 2.4rem;
    color: var(--app-accent);
    margin-bottom: 0.75rem;
}

/* Soft badge / tag */
.app-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.25rem 0.7rem;
    border-radius: var(--app-radius-pill);
    font-size: 0.8rem;
    font-weight: 600;
    background: var(--app-surface-muted);
    color: var(--app-text-muted);
}

.app-tag-primary {
    background: var(--app-primary-soft);
    color: var(--app-primary-strong);
}

/* Section heading */
.app-section-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--app-heading);
    margin-bottom: 1rem;
}

/* Sticky bottom action bar (mobile-friendly CTA dock) */
.app-sticky-bar {
    position: fixed;
    left: 50%;
    bottom: max(1rem, env(safe-area-inset-bottom));
    transform: translateX(-50%);
    z-index: 1040;
    width: min(1000px, calc(100% - 1.2rem));
    display: flex;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: var(--app-radius-lg);
    background: var(--app-surface);
    border: 1px solid var(--app-border);
    box-shadow: var(--app-shadow-lg);
}

.app-sticky-bar .btn {
    flex: 1;
    min-height: 50px;
}

/* ------------------------------------------------------------------ */
/* 5. UTILITIES                                                        */
/* ------------------------------------------------------------------ */
.app-muted { color: var(--app-text-muted) !important; }
.app-surface-muted { background: var(--app-surface-muted) !important; }
.app-rounded { border-radius: var(--app-radius) !important; }
.app-rounded-lg { border-radius: var(--app-radius-lg) !important; }
.app-shadow { box-shadow: var(--app-shadow) !important; }
.app-fcap { font-feature-settings: "tnum"; }

/* ------------------------------------------------------------------ */
/* 6. RESPONSIVE                                                       */
/* ------------------------------------------------------------------ */
@media (max-width: 767.98px) {
    .app-page { padding-bottom: 7rem; }

    .app-page-header { flex-direction: column; }

    .app-page-actions { width: 100%; }

    .app-page-actions .btn { flex: 1; }

    .app-card { padding: 1.1rem; }

    .app-sticky-bar {
        flex-direction: column;
        width: calc(100% - 1rem);
        bottom: 0.5rem;
    }
}

@media (hover: none), (pointer: coarse) {
    .app-tile:hover { transform: none; }
    .app-row[data-detail-href]:hover { transform: none; }
}
