:root {
    --gm-primary: #2f7d4f;
    --gm-primary-dark: #235f3c;
    --gm-sidebar-bg: #1f2d24;
    --gm-sidebar-width: 240px;
    --gm-topbar-height: 60px;
}

/* Piège classique : sans min-width:0 sur les conteneurs flex, un texte
   non cassable garde sa largeur de contenu et pousse toute la page. */
html, body {
    overflow-x: hidden;
    min-width: 0;
}

* {
    min-width: 0;
}

body {
    background: #f4f6f5;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

a {
    text-decoration: none;
}

/* ----------------------------- Layout général ---------------------------- */

.app-shell {
    display: flex;
    min-height: 100vh;
    min-width: 0;
}

.sidebar {
    width: var(--gm-sidebar-width);
    flex-shrink: 0;
    background: var(--gm-sidebar-bg);
    color: #fff;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1030;
    transition: transform 0.2s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 1.1rem 1.2rem;
    font-size: 1.15rem;
    font-weight: 700;
    color: #fff;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    padding: 0.75rem 0;
    overflow-y: auto;
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: rgba(255, 255, 255, 0.75);
    padding: 0.65rem 1.2rem;
    font-size: 0.94rem;
    border-left: 3px solid transparent;
}

.sidebar-nav .nav-link i {
    width: 1.1rem;
    text-align: center;
}

.sidebar-nav .nav-link:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
}

.sidebar-nav .nav-link.active {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border-left-color: var(--gm-primary);
}

.sidebar-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.08);
    margin: 0.6rem 1.2rem;
}

.app-main {
    flex: 1 1 auto;
    min-width: 0;
    margin-left: var(--gm-sidebar-width);
    display: flex;
    flex-direction: column;
}

.topbar {
    height: var(--gm-topbar-height);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0 1.25rem;
    background: #fff;
    border-bottom: 1px solid #e4e7e5;
    position: sticky;
    top: 0;
    z-index: 1020;
    min-width: 0;
}

.sidebar-toggle {
    display: none;
    border: none;
    background: transparent;
    font-size: 1.2rem;
    padding: 0.25rem 0.5rem;
}

.household-switch select {
    max-width: 200px;
}

.household-name {
    color: #555;
    font-weight: 500;
}

.main-content {
    flex: 1 1 auto;
    min-width: 0;
    padding: 1.5rem;
}

/* ----------------------------- Auth pages -------------------------------- */

.auth-body {
    background: linear-gradient(135deg, var(--gm-primary), var(--gm-primary-dark));
    min-height: 100vh;
}

.auth-main {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 1.5rem;
}

.auth-main .alert {
    width: 100%;
    max-width: 420px;
}

.auth-card {
    background: #fff;
    border-radius: 0.75rem;
    padding: 2rem;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

/* ----------------------------- Composants -------------------------------- */

.card {
    border: 1px solid #e4e7e5;
    border-radius: 0.6rem;
}

.kpi-card {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 1rem 1.1rem;
    min-width: 0;
}

.kpi-card .kpi-icon {
    flex-shrink: 0;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(47, 125, 79, 0.12);
    color: var(--gm-primary);
    font-size: 1.1rem;
}

.kpi-card .kpi-text {
    min-width: 0;
}

.kpi-card .kpi-value {
    font-size: 1.35rem;
    font-weight: 700;
    line-height: 1.1;
}

.kpi-card .kpi-label {
    color: #6b7570;
    font-size: 0.82rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.text-truncate-cell {
    max-width: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Chaque tableau doit défiler horizontalement dans son propre cadre,
   jamais faire bouger toute la page. */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.badge-slot {
    text-transform: capitalize;
}

.recipe-thumb {
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    border-radius: 0.5rem 0.5rem 0 0;
    background: #e9ece9;
}

.week-grid {
    display: grid;
    grid-template-columns: 90px repeat(7, minmax(150px, 1fr));
    gap: 0.5rem;
    min-width: 900px;
}

.week-grid-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.week-day-header {
    font-weight: 600;
    text-align: center;
    padding: 0.4rem;
    border-radius: 0.4rem;
    background: #eef3ef;
}

.week-slot-label {
    display: flex;
    align-items: center;
    font-size: 0.82rem;
    color: #6b7570;
    text-transform: capitalize;
}

.meal-cell {
    background: #fff;
    border: 1px dashed #d7ddda;
    border-radius: 0.4rem;
    padding: 0.4rem;
    min-height: 64px;
    font-size: 0.82rem;
}

.meal-entry {
    background: #eef3ef;
    border-radius: 0.35rem;
    padding: 0.3rem 0.45rem;
    margin-bottom: 0.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.3rem;
}

.shopping-item.checked .item-label {
    text-decoration: line-through;
    color: #9aa39d;
}

/* ----------------------------- Terminal (tests SMTP) ---------------------- */

.terminal-window {
    background: #1b1e23;
    border-radius: 0.6rem;
    overflow: hidden;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    position: sticky;
    top: calc(var(--gm-topbar-height) + 1rem);
}

.terminal-header {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.6rem 0.9rem;
    background: #262a31;
    border-bottom: 1px solid #33383f;
}

.terminal-dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    flex-shrink: 0;
}

.dot-red { background: #ff5f56; }
.dot-yellow { background: #ffbd2e; }
.dot-green { background: #27c93f; }

.terminal-title {
    margin-left: 0.5rem;
    color: #9aa0a8;
    font-size: 0.82rem;
}

.terminal-body {
    margin: 0;
    padding: 0.9rem;
    min-height: 320px;
    max-height: 520px;
    overflow-y: auto;
    color: #8b94a3;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 0.82rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

.terminal-line {
    color: #d4d8de;
}

.terminal-line.terminal-ok {
    color: #4ade80;
}

.terminal-line.terminal-error {
    color: #f87171;
}

/* ----------------------------- Install banner ---------------------------- */

.install-banner {
    position: fixed;
    left: 1rem;
    right: 1rem;
    bottom: 1rem;
    z-index: 1050;
    background: var(--gm-primary-dark);
    color: #fff;
    padding: 0.75rem 1rem;
    border-radius: 0.6rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

/* ----------------------------- Responsive -------------------------------- */

@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .app-main {
        margin-left: 0;
    }

    .sidebar-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .week-grid {
        min-width: 700px;
    }
}

@media (max-width: 575.98px) {
    .main-content {
        padding: 1rem 0.75rem;
    }

    .auth-card {
        padding: 1.5rem;
    }
}
