/* ========== CARNET MEDICAMENTS v1.0 - PREMIUM APP DESIGN ========== */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
    --blue-deep: #0D47A1;
    --blue-rich: #1565C0;
    --blue-mid: #1976D2;
    --blue-bright: #2196F3;
    --blue-light: #42A5F5;
    --blue-soft: #90CAF9;
    --blue-pale: #E3F2FD;
    --blue-faint: #F0F6FF;

    --primary: #1976D2;
    --primary-bright: #2196F3;
    --primary-light: #42A5F5;
    --primary-soft: rgba(25,118,210,0.1);

    --success: #4CAF50;
    --danger: #EF5350;
    --warning: #FFA726;
    --info: #29B6F6;

    --text: #1a1a2e;
    --text-secondary: #555;
    --text-dim: #999;

    --card-bg: #ffffff;
    --card-shadow: 0 2px 12px rgba(13,71,161,0.06), 0 1px 3px rgba(13,71,161,0.04);
    --input-bg: #f5f7fa;
    --input-border: #dde4ed;
    --border-light: rgba(13,71,161,0.06);

    --shell-max: 500px;
    --header-h: auto;
    --radius-xl: 24px;
    --radius-lg: 18px;
    --radius-md: 14px;
    --radius-sm: 10px;
}

/* ========== BODY ========== */
html { height: 100%; }
body {
    height: 100%;
    background: #c5d0dc;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
    color: var(--text);
    overflow: hidden;
}
@media (min-width: 540px) {
    body {
        background: linear-gradient(145deg, #9cb4d0 0%, #7a9cc0 50%, #5f87b0 100%);
    }
}

/* ========== APP SHELL ========== */
.app-shell {
    position: relative;
    max-width: var(--shell-max);
    height: 100vh;
    height: 100dvh;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    background: #f0f2f5;
    overflow: hidden;
    z-index: 1;
}
@media (min-width: 540px) {
    .app-shell {
        border-radius: 32px;
        height: calc(100vh - 24px);
        height: calc(100dvh - 24px);
        margin: 12px auto;
        box-shadow:
            0 20px 60px rgba(13,47,100,0.25),
            0 4px 16px rgba(13,47,100,0.12);
        overflow: hidden;
    }
}

/* ========== SPLASH ========== */
.splash {
    position: fixed; inset: 0; z-index: 9999;
    background: linear-gradient(135deg, #0D47A1 0%, #1565C0 40%, #1976D2 100%);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    transition: opacity 0.8s, visibility 0.8s;
}
.splash.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.splash-icon {
    width: 80px; height: 80px; margin-bottom: 20px;
    background: rgba(255,255,255,0.15); border-radius: 24px;
    display: flex; align-items: center; justify-content: center;
}
.splash-icon i { font-size: 40px; color: var(--blue-soft); filter: drop-shadow(0 4px 16px rgba(0,0,0,0.2)); }
.splash h1 { font-size: 28px; font-weight: 800; color: #fff; letter-spacing: -0.5px; }
.splash p { font-size: 12px; color: var(--blue-soft); margin-top: 8px; letter-spacing: 2px; font-weight: 300; text-transform: uppercase; }

/* ========== HEADER ========== */
.header {
    flex-shrink: 0;
    background: linear-gradient(135deg, #1565C0 0%, #0D47A1 100%);
    padding: 16px 16px 12px;
    position: relative; z-index: 100;
    box-shadow: 0 2px 12px rgba(13,71,161,0.3);
}
.header-top {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 10px;
}
.header-left { display: flex; align-items: center; gap: 10px; }
.header-logo {
    width: 36px; height: 36px; border-radius: 10px;
    background: rgba(255,255,255,0.15);
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 18px;
}
.header-title { font-size: 18px; font-weight: 800; color: #fff; letter-spacing: -0.3px; }
.header-subtitle { font-size: 11px; color: rgba(255,255,255,0.7); font-weight: 500; }

.header-count {
    background: rgba(255,255,255,0.15); border-radius: 12px;
    padding: 4px 10px; color: #fff; font-size: 13px; font-weight: 700;
}
.header-count small { font-weight: 400; font-size: 11px; opacity: 0.8; }

/* ========== SEARCH ========== */
.search-wrapper { position: relative; margin-bottom: 8px; }
.search-wrapper .search-icon {
    position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
    font-size: 14px; color: #aaa; pointer-events: none;
}
.search-input {
    width: 100%; padding: 10px 40px 10px 36px;
    border-radius: 12px; border: none; outline: none;
    font-size: 14px; font-family: inherit;
    background: rgba(255,255,255,0.95); color: var(--text);
}
.search-input::placeholder { color: #aaa; }
.search-clear {
    position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
    background: #e0e0e0; border: none; border-radius: 50%;
    width: 22px; height: 22px; cursor: pointer; font-size: 12px;
    display: none; align-items: center; justify-content: center;
    color: #666;
}
.search-clear.visible { display: flex; }

/* ========== FILTER TOGGLE ========== */
.filter-toggle-row {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.btn-filter-toggle {
    background: rgba(255,255,255,0.1); color: #fff;
    border: 1px solid rgba(255,255,255,0.3); border-radius: 8px;
    padding: 5px 10px; font-size: 11px; font-weight: 600;
    cursor: pointer; font-family: inherit;
    transition: background 0.2s;
}
.btn-filter-toggle.active { background: rgba(255,255,255,0.25); }
.active-filter-badge {
    display: inline-flex; align-items: center; gap: 4px;
    border: none; border-radius: 8px;
    padding: 5px 10px; font-size: 11px; font-weight: 600;
    cursor: pointer; color: #fff; font-family: inherit;
}

/* ========== FAMILY FILTERS ========== */
.family-filters {
    background: #fff; padding: 12px 16px;
    border-bottom: 1px solid #e0e0e0;
    display: none; flex-wrap: wrap; gap: 6px;
    max-height: 200px; overflow-y: auto;
}
.family-filters.visible { display: flex; }
.family-chip {
    border-radius: 16px; padding: 4px 10px;
    font-size: 11px; font-weight: 600; cursor: pointer;
    font-family: inherit; transition: all 0.15s;
    border-width: 1.5px; border-style: solid;
}
.family-chip .chip-count { opacity: 0.7; }

/* ========== MED LIST ========== */
.med-list {
    flex: 1; overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px 12px 24px;
    display: flex; flex-direction: column; gap: 6px;
    scrollbar-width: none; -ms-overflow-style: none;
}
.med-list::-webkit-scrollbar { display: none; }

/* ========== MED CARD ========== */
.med-card {
    border-radius: 8px; padding: 10px 12px;
    cursor: pointer; transition: transform 0.15s, box-shadow 0.15s;
    border-left: 4px solid #ccc;
}
.med-card:hover, .med-card:active {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.med-card-top {
    display: flex; justify-content: space-between; align-items: flex-start; gap: 8px;
}
.med-card-info { flex: 1; min-width: 0; }
.med-card-dci {
    font-weight: 700; font-size: 14px; color: var(--text); line-height: 1.2;
}
.med-card-nom {
    font-size: 12px; color: var(--text-secondary); margin-top: 2px;
}
.med-card-right {
    display: flex; flex-direction: column; align-items: flex-end; flex-shrink: 0;
}
.med-card-family {
    font-size: 10px; font-weight: 600; padding: 2px 8px;
    border-radius: 10px; white-space: nowrap;
    display: inline-flex; align-items: center; gap: 3px;
}
.med-card-family i { font-size: 9px; }
.med-card-voie {
    font-size: 10px; color: #888; margin-top: 3px;
    font-family: "SF Mono", "Fira Code", monospace;
}

/* ========== EMPTY STATE ========== */
.empty-state {
    text-align: center; padding: 40px 20px; color: var(--text-dim);
}
.empty-state i { font-size: 40px; margin-bottom: 12px; display: block; color: var(--blue-light); }
.empty-state .empty-title { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.empty-state .empty-sub { font-size: 13px; }

/* ========== DETAIL MODAL (bottom sheet) ========== */
.modal-overlay {
    position: fixed; inset: 0; z-index: 1000;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
    display: flex; align-items: flex-end; justify-content: center;
    opacity: 0; visibility: hidden;
    transition: opacity 0.2s;
}
.modal-overlay.active { opacity: 1; visibility: visible; }

.modal-sheet {
    background: #fff; border-radius: 20px 20px 0 0;
    width: 100%; max-width: 500px;
    max-height: 85vh; overflow-y: auto;
    transform: translateY(100%);
    transition: transform 0.3s ease;
}
.modal-overlay.active .modal-sheet {
    transform: translateY(0);
}

.modal-header {
    padding: 24px 20px 16px;
    position: relative;
}
.modal-header-family {
    font-size: 10px; font-weight: 700; text-transform: uppercase;
    letter-spacing: 1px; display: flex; align-items: center; gap: 6px;
}
.modal-header-family i { font-size: 10px; }
.modal-header h2 {
    margin: 6px 0 2px; font-size: 22px; font-weight: 800;
    color: var(--text); line-height: 1.1;
}
.modal-header .modal-nom { font-size: 15px; color: var(--text-secondary); }

.modal-close {
    position: absolute; top: 16px; right: 16px;
    background: rgba(0,0,0,0.08); border: none; border-radius: 50%;
    width: 32px; height: 32px; cursor: pointer; font-size: 16px;
    display: flex; align-items: center; justify-content: center;
    color: #666; transition: background 0.2s;
}
.modal-close:hover { background: rgba(0,0,0,0.15); }

.modal-body { padding: 20px; }

.modal-section { margin-bottom: 16px; }
.modal-section:last-child { margin-bottom: 0; }
.modal-section-label {
    display: flex; align-items: center; gap: 8px; margin-bottom: 6px;
}
.modal-section-label i { font-size: 14px; }
.modal-section-label span {
    font-weight: 700; font-size: 12px; color: #888;
    text-transform: uppercase; letter-spacing: 0.5px;
}
.modal-section-content {
    border-radius: 8px; padding: 12px 14px;
    font-size: 14px; line-height: 1.5;
}
.modal-section-content.voie {
    background: #f8f9fa; font-weight: 600; color: var(--text);
    font-family: "SF Mono", "Fira Code", monospace; padding: 10px 14px;
}
.modal-section-content.effets {
    background: #e8f5e9; border-left: 3px solid #66bb6a; color: #2e7d32;
}
.modal-section-content.ei {
    background: #fff3e0; border-left: 3px solid #ffa726; color: #e65100;
}

/* ========== TOAST ========== */
.toast {
    position: fixed; top: 16px; left: 50%; transform: translateX(-50%) translateY(-100px);
    padding: 12px 22px; border-radius: var(--radius-md); font-size: 13px; font-weight: 600;
    z-index: 9999; transition: transform 0.35s ease; pointer-events: none;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.success { background: var(--success); color: #fff; }
.toast.info { background: var(--primary); color: #fff; }

/* ========== CREDITS ========== */
.credits {
    text-align: center; padding: 8px 0 16px;
    font-size: 10px; color: var(--text-dim);
}

/* ========== RESPONSIVE ========== */
@media (max-width: 380px) {
    .header-title { font-size: 16px; }
    .med-card-dci { font-size: 13px; }
}
