/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --blue: #4A90D9;
    --blue-dark: #3570B0;
    --blue-light: #EBF3FC;
    --green: #27AE60;
    --green-light: #E8F8EF;
    --yellow: #F2994A;
    --yellow-light: #FEF3E6;
    --red: #EB5757;
    --red-light: #FDE8E8;
    --gray-50: #F9FAFB;
    --gray-100: #F3F4F6;
    --gray-200: #E5E7EB;
    --gray-300: #D1D5DB;
    --gray-400: #9CA3AF;
    --gray-500: #6B7280;
    --gray-600: #4B5563;
    --gray-700: #374151;
    --gray-800: #1F2937;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--gray-50);
    color: var(--gray-800);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* === Navbar === */
.navbar {
    background: white;
    border-bottom: 1px solid var(--gray-200);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
}

.nav-brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--blue);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-icon {
    width: 32px;
    height: 32px;
    background: var(--blue);
    color: white;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 300;
}

.nav-links {
    display: flex;
    gap: 1.5rem;
    align-items: center;
}

.nav-links a {
    color: var(--gray-600);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9rem;
    transition: color 0.2s;
}

.nav-links a:hover { color: var(--blue); }

.nav-logout {
    color: var(--red) !important;
}

.nav-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    flex-direction: column;
    gap: 4px;
}

.nav-toggle span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--gray-600);
    border-radius: 1px;
    transition: 0.2s;
}

/* === Container === */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem 1rem;
    flex: 1;
}

/* === Flash Messages === */
.flash-messages { margin-bottom: 1rem; }

.flash {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.flash-success { background: var(--green-light); color: #1B7A3D; border: 1px solid #A7E8C0; }
.flash-error { background: var(--red-light); color: #C53030; border: 1px solid #FCA5A5; }
.flash-info { background: var(--blue-light); color: #2563EB; border: 1px solid #93C5FD; }

/* === Cards === */
.card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    border: 1px solid var(--gray-200);
}

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

.card-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--gray-800);
}

/* === Page Header === */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gray-800);
}

/* === Grid Layouts === */
.grid-3 {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1rem;
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
    gap: 1rem;
}

/* === Family Member Cards === */
.member-card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--gray-200);
    padding: 1.25rem;
    display: flex;
    gap: 1rem;
    cursor: pointer;
    transition: box-shadow 0.2s, transform 0.2s;
    text-decoration: none;
    color: inherit;
}

.member-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.member-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--blue-light);
    color: var(--blue);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    font-weight: 700;
    flex-shrink: 0;
}

.member-info { flex: 1; min-width: 0; }

.member-name {
    font-weight: 600;
    font-size: 1rem;
    color: var(--gray-800);
    margin-bottom: 0.15rem;
}

.member-relationship {
    font-size: 0.8rem;
    color: var(--gray-500);
    text-transform: capitalize;
    margin-bottom: 0.5rem;
}

.member-badges {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.badge {
    font-size: 0.7rem;
    padding: 0.15rem 0.5rem;
    border-radius: 99px;
    font-weight: 500;
    white-space: nowrap;
}

.badge-green { background: var(--green-light); color: #1B7A3D; }
.badge-yellow { background: var(--yellow-light); color: #92400E; }
.badge-red { background: var(--red-light); color: #C53030; }
.badge-blue { background: var(--blue-light); color: #2563EB; }
.badge-gray { background: var(--gray-100); color: var(--gray-600); }

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    border: none;
    cursor: pointer;
    transition: 0.2s;
    white-space: nowrap;
}

.btn-primary { background: var(--blue); color: white; }
.btn-primary:hover { background: var(--blue-dark); }

.btn-success { background: var(--green); color: white; }
.btn-success:hover { background: #219A52; }

.btn-danger { background: var(--red); color: white; }
.btn-danger:hover { background: #D04040; }

.btn-outline {
    background: white;
    color: var(--gray-700);
    border: 1px solid var(--gray-300);
}
.btn-outline:hover { background: var(--gray-50); border-color: var(--gray-400); }

.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }

/* === Forms === */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-700);
    margin-bottom: 0.35rem;
}

.form-control {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    color: var(--gray-800);
    background: white;
    transition: border-color 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(74, 144, 217, 0.15);
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236B7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2rem;
}

textarea.form-control { resize: vertical; min-height: 80px; }

/* === Tabs === */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--gray-200);
    margin-bottom: 1.5rem;
    overflow-x: auto;
}

.tab {
    padding: 0.75rem 1.25rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--gray-500);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    white-space: nowrap;
    transition: 0.2s;
}

.tab:hover { color: var(--gray-700); }

.tab.active {
    color: var(--blue);
    border-bottom-color: var(--blue);
}

/* === Tables === */
.table-wrap { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 0.65rem 0.75rem;
    text-align: left;
    font-size: 0.875rem;
}

th {
    font-weight: 600;
    color: var(--gray-600);
    border-bottom: 2px solid var(--gray-200);
}

td { border-bottom: 1px solid var(--gray-100); }

tr:hover td { background: var(--gray-50); }

/* === File Upload === */
.upload-area {
    border: 2px dashed var(--gray-300);
    border-radius: var(--radius);
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: 0.2s;
    background: var(--gray-50);
}

.upload-area:hover, .upload-area.drag-over {
    border-color: var(--blue);
    background: var(--blue-light);
}

.upload-area p {
    color: var(--gray-500);
    margin-top: 0.5rem;
    font-size: 0.9rem;
}

.upload-area input[type="file"] { display: none; }

/* === Status Indicators === */
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 0.4rem;
}

.status-green { background: var(--green); }
.status-yellow { background: var(--yellow); }
.status-red { background: var(--red); }
.status-gray { background: var(--gray-400); }

/* === Empty State === */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--gray-500);
}

.empty-state h3 { margin-bottom: 0.5rem; color: var(--gray-600); }

/* === Login Page === */
.login-container {
    max-width: 400px;
    margin: 4rem auto;
}

.login-card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 2rem;
    border: 1px solid var(--gray-200);
}

.login-header {
    text-align: center;
    margin-bottom: 1.5rem;
}

.login-header h1 {
    font-size: 1.5rem;
    color: var(--gray-800);
    margin-top: 0.75rem;
}

.login-header .nav-icon {
    width: 48px;
    height: 48px;
    font-size: 2rem;
    margin: 0 auto;
}

/* === Footer === */
.footer {
    text-align: center;
    padding: 1.5rem 1rem;
    color: var(--gray-400);
    font-size: 0.8rem;
    border-top: 1px solid var(--gray-200);
    margin-top: 2rem;
}

.disclaimer {
    font-style: italic;
    margin-top: 0.25rem;
}

/* === Stat Cards === */
.stat-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: white;
    border-radius: var(--radius-sm);
    padding: 1rem;
    border: 1px solid var(--gray-200);
    text-align: center;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--blue);
}

.stat-label {
    font-size: 0.75rem;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 0.15rem;
}

/* === Utility === */
.text-muted { color: var(--gray-500); }
.text-sm { font-size: 0.8rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.inline-form { display: inline; }

/* === Chat === */
.chat-card {
    padding: 0;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 200px);
    min-height: 400px;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.chat-bubble {
    max-width: 80%;
    padding: 0.75rem 1rem;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.5;
    word-wrap: break-word;
}

.chat-user {
    background: var(--blue);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.chat-assistant {
    background: var(--gray-100);
    color: var(--gray-800);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.chat-text { white-space: pre-wrap; }

.chat-meta {
    font-size: 0.7rem;
    color: var(--gray-400);
    margin-top: 0.25rem;
}

.chat-image-preview {
    max-height: 150px;
    max-width: 250px;
    border-radius: 8px;
    margin-bottom: 0.5rem;
    display: block;
}

.chat-input-area {
    border-top: 1px solid var(--gray-200);
    padding: 0.75rem 1rem;
    background: white;
    border-radius: 0 0 var(--radius) var(--radius);
}

.chat-input-row {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    resize: none;
    min-height: 44px !important;
    max-height: 120px;
    padding: 0.6rem 0.75rem;
}

.chat-upload-btn {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gray-100);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 1.25rem;
    flex-shrink: 0;
    transition: background 0.2s;
}

.chat-upload-btn:hover { background: var(--gray-200); }

.chat-send-btn {
    height: 44px;
    flex-shrink: 0;
}

#image-preview-container {
    align-items: center;
    margin-bottom: 0.5rem;
}

.typing-indicator {
    display: none;
    align-items: center;
    gap: 0.3rem;
    padding: 0.5rem 1rem;
    color: var(--gray-400);
    font-style: italic;
    font-size: 0.85rem;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    background: var(--gray-400);
    border-radius: 50%;
    animation: typing-bounce 1.4s ease-in-out infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

.chat-welcome {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--gray-500);
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.chat-welcome h3 { color: var(--gray-700); margin-bottom: 0.5rem; }

.chat-suggestions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 1rem;
    max-width: 400px;
}

.chat-suggestion {
    padding: 0.5rem 1rem;
    background: var(--blue-light);
    color: var(--blue-dark);
    border: 1px solid rgba(74, 144, 217, 0.2);
    border-radius: 99px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: 0.2s;
    text-align: left;
}

.chat-suggestion:hover { background: var(--blue); color: white; }

/* === Responsive === */
@media (max-width: 768px) {
    .nav-links { display: none; }
    .nav-container.open .nav-links {
        display: flex;
        flex-direction: column;
        position: absolute;
        top: 60px;
        left: 0;
        right: 0;
        background: white;
        padding: 1rem;
        border-bottom: 1px solid var(--gray-200);
        box-shadow: var(--shadow-md);
        gap: 0.75rem;
    }
    .nav-toggle { display: flex; }

    .grid-3 { grid-template-columns: 1fr; }
    .grid-2 { grid-template-columns: 1fr; }

    .page-header { flex-direction: column; align-items: flex-start; }
    .page-header h1 { font-size: 1.25rem; }

    .container { padding: 1rem 0.75rem; }

    .stat-row { grid-template-columns: repeat(2, 1fr); }

    .tabs { gap: 0; }
    .tab { padding: 0.6rem 0.75rem; font-size: 0.8rem; }
}
