/* ============================================
   MELODIA — Care Record System
   Warm · Cute · Friendly · Modern Theme
   Colors: #A20104 · #7D435B · #CDAB07 · #BDA77F
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;500;600;700;800&display=swap');

:root {
    /* ---- Core Palette ---- */
    --red: #A20104;
    --red-dark: #7a0103;
    --red-light: #fdf0f0;
    --red-muted: #d4787a;

    --plum: #7D435B;
    --plum-dark: #5e2f42;
    --plum-light: #f6edf1;
    --plum-muted: #b08a9a;

    --gold: #CDAB07;
    --gold-dark: #9e8405;
    --gold-light: #fdf8e3;
    --gold-muted: #e2cf6a;

    --tan: #BDA77F;
    --tan-dark: #9a855e;
    --tan-light: #f8f3ec;
    --tan-muted: #d5c8ac;

    /* ---- Semantic ---- */
    --primary: var(--red);
    --primary-dark: var(--red-dark);
    --primary-light: var(--red-light);
    --primary-muted: var(--red-muted);

    --surface: #ffffff;
    --surface-alt: #fdfaf6;
    --bg: #faf6f0;
    --border: #e8dfd4;
    --border-light: #f0ebe3;

    --text: #2d2019;
    --text-secondary: #5e4d3e;
    --text-muted: #a3937f;

    --danger: #A20104;
    --danger-bg: #fdf0f0;
    --info-bg: var(--plum-light);
    --info: var(--plum);
    --success: #6bbd7b;
    --success-bg: #eef8f0;

    --radius: 16px;
    --radius-sm: 12px;
    --radius-lg: 24px;
    --shadow-sm: 0 2px 8px rgba(45,32,25,0.05);
    --shadow: 0 4px 20px rgba(45,32,25,0.07);
    --shadow-lg: 0 8px 40px rgba(45,32,25,0.10);
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.65;
    -webkit-font-smoothing: antialiased;
    padding-bottom: 90px;
    min-height: 100dvh;
}

/* ---- Decorative BG blobs ---- */
body::before,
body::after {
    content: '';
    position: fixed;
    border-radius: 50%;
    z-index: -1;
    opacity: 0.18;
    filter: blur(90px);
    pointer-events: none;
}

body::before {
    width: 320px;
    height: 320px;
    background: var(--plum);
    top: -80px;
    right: -60px;
}

body::after {
    width: 260px;
    height: 260px;
    background: var(--gold);
    bottom: 60px;
    left: -40px;
}

/* ---- App Header ---- */
.app-header {
    background: linear-gradient(170deg, var(--tan-light) 0%, var(--bg) 100%);
    padding: 2rem 1.5rem 1.5rem;
    position: relative;
    overflow: hidden;
}

.app-header::before {
    content: '🎵';
    position: absolute;
    top: 1rem;
    right: 1.2rem;
    font-size: 2rem;
    opacity: 0.12;
    animation: floatNote 4s ease-in-out infinite;
}

@keyframes floatNote {
    0%, 100% { transform: translateY(0) rotate(-5deg); }
    50% { transform: translateY(-8px) rotate(5deg); }
}

.app-header .brand {
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 3.5px;
    text-transform: uppercase;
    color: var(--red);
    margin-bottom: 0.4rem;
}

.app-header .greeting {
    font-size: 1.45rem;
    font-weight: 800;
    color: var(--text);
    line-height: 1.3;
    margin-bottom: 0.8rem;
}

.app-header .date-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.45rem 1.1rem;
    background: rgba(255,255,255,0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--border);
    border-radius: 50px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.app-header .date-pill::before {
    content: '📅';
    font-size: 0.85rem;
}

/* ---- Layout ---- */
main {
    max-width: 480px;
    margin: 0 auto;
    padding: 1.25rem;
}

.grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

/* ---- Cards ---- */
.card {
    background: var(--surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition), box-shadow var(--transition);
}

.card:hover {
    box-shadow: var(--shadow);
}

/* ---- Section Title ---- */
.section-title {
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px dashed var(--border-light);
}

.section-title span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: linear-gradient(135deg, var(--red), var(--plum));
    color: #fff;
    border-radius: 8px;
    font-size: 0.72rem;
    font-weight: 800;
    margin-right: 0.5rem;
    vertical-align: middle;
}

/* ---- Typography ---- */
h2 {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--text);
    margin-bottom: 0.75rem;
}

h3 {
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

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

.form-group label {
    display: block;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 0.4rem;
}

input, select, textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-family: inherit;
    font-size: 0.9rem;
    color: var(--text);
    transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
    outline: none;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--plum);
    box-shadow: 0 0 0 3.5px rgba(125,67,91,0.10);
    background: #fff;
}

input::placeholder, textarea::placeholder {
    color: var(--text-muted);
    opacity: 0.7;
}

textarea { resize: vertical; }
select { cursor: pointer; }

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 0.8rem 1.25rem;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    transition: all var(--transition);
    background: linear-gradient(135deg, var(--red), var(--plum));
    color: #fff;
    box-shadow: 0 4px 14px rgba(162,1,4,0.2);
    position: relative;
    overflow: hidden;
}

.btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.12), transparent);
    opacity: 0;
    transition: opacity var(--transition);
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(162,1,4,0.25);
}

.btn:hover::after { opacity: 1; }

.btn:active {
    transform: translateY(0) scale(0.98);
    box-shadow: 0 2px 8px rgba(162,1,4,0.15);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text-secondary);
    border: 1.5px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.btn-secondary::after { display: none; }

.btn-secondary:hover {
    background: var(--tan-light);
    border-color: var(--tan-muted);
    color: var(--plum-dark);
    box-shadow: var(--shadow);
}

.btn-sm {
    padding: 0.45rem 0.9rem;
    font-size: 0.78rem;
    width: auto;
    border-radius: 10px;
}

/* ---- Badge ---- */
.badge {
    display: inline-block;
    padding: 0.28rem 0.65rem;
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 700;
    background: var(--gold-light);
    color: var(--gold-dark);
}

/* ---- Patient Circles ---- */
.patient-circles {
    display: flex;
    gap: 1rem;
    overflow-x: auto;
    padding: 0.5rem 0 1rem;
    margin-bottom: 1.5rem;
    scrollbar-width: none;
}
.patient-circles::-webkit-scrollbar { display: none; }

.patient-circle-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.45rem;
    min-width: 60px;
    text-decoration: none;
}

.circle {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 1.05rem;
    color: var(--text);
    background: var(--tan-light);
    transition: transform var(--transition), box-shadow var(--transition);
    border: 2.5px solid transparent;
}

.patient-circle-item:hover .circle {
    transform: scale(1.08);
    box-shadow: 0 4px 16px rgba(125,67,91,0.12);
    border-color: var(--plum-muted);
}

.patient-circle-item:active .circle { transform: scale(0.92); }

.patient-circle-item span {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-secondary);
    max-width: 64px;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---- Stats ---- */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    padding: 1.1rem;
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition), box-shadow var(--transition);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--red), var(--plum));
    border-radius: 3px 3px 0 0;
}

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

.stat-label {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.3rem;
}

.stat-value {
    font-size: 1.7rem;
    font-weight: 800;
    color: var(--red);
}

.progress-bar {
    height: 5px;
    background: var(--border-light);
    border-radius: 3px;
    margin-top: 0.6rem;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    border-radius: 3px;
    background: linear-gradient(90deg, var(--red), var(--plum));
    transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---- History Accordion ---- */
.history-card {
    background: var(--surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    margin-bottom: 0.75rem;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition), box-shadow var(--transition);
}

.history-card:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.history-header {
    padding: 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    transition: background var(--transition);
}

.history-header:hover { background: var(--surface-alt); }

.number-circle {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--plum-light), #f0e2ea);
    color: var(--plum);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.85rem;
    flex-shrink: 0;
    border: 2px solid rgba(125,67,91,0.1);
}

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

.history-title {
    font-weight: 700;
    font-size: 0.88rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.status-tag {
    font-size: 0.68rem;
    font-weight: 700;
    padding: 0.25rem 0.55rem;
    border-radius: 8px;
    flex-shrink: 0;
    background: var(--gold-light);
    color: var(--gold-dark);
}

details > summary { list-style: none; outline: none; }
details > summary::-webkit-details-marker { display: none; }

details[open] .history-header {
    border-bottom: 1px solid var(--border-light);
}

.history-content {
    padding: 1rem;
    background: var(--surface-alt);
}

/* ---- Rating ---- */
.rating-group {
    display: flex;
    gap: 6px;
}

.rating-group input[type="radio"] { display: none; }

.rating-group label {
    flex: 1;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-alt);
    border: 1.5px solid var(--border);
    border-radius: 10px;
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition);
}

.rating-group label:hover {
    border-color: var(--plum-muted);
    background: var(--plum-light);
    color: var(--plum);
}

.rating-group input[type="radio"]:checked + label {
    background: linear-gradient(135deg, var(--red), var(--plum));
    border-color: var(--red);
    color: #fff;
    box-shadow: 0 2px 8px rgba(162,1,4,0.2);
}

/* ---- Info Row (view_patient details) ---- */
.info-row {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.info-cell {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border-light);
    padding: 0.65rem 0.85rem;
    border-radius: var(--radius-sm);
}

.info-cell .label {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.info-cell .value {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text);
    margin-top: 2px;
}

/* ---- Note Box ---- */
.note-box {
    padding: 0.85rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 0.75rem;
    font-size: 0.88rem;
}

.note-box .note-label {
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.3rem;
}

.note-box--green {
    background: var(--gold-light);
    border: 1px solid var(--gold-muted);
}
.note-box--green .note-label { color: var(--gold-dark); }

/* ---- Bottom Navigation ---- */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 68px;
    background: rgba(255,255,255,0.88);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    display: flex;
    justify-content: space-around;
    align-items: center;
    border-top: 1px solid var(--border-light);
    z-index: 100;
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -2px 20px rgba(45,32,25,0.04);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.65rem;
    font-weight: 700;
    padding: 0.35rem 0.9rem;
    transition: color var(--transition), transform var(--transition);
    border-radius: 12px;
}

.nav-item:hover {
    color: var(--plum);
}

.nav-item.active {
    color: var(--red);
    background: var(--red-light);
}

.nav-icon {
    width: 22px;
    height: 22px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: transform var(--transition);
}

.nav-item:hover .nav-icon {
    transform: scale(1.1);
}

/* ---- Login Page ---- */
.login-wrap {
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: linear-gradient(160deg, var(--tan-light) 0%, var(--bg) 30%, #faf6f0 60%, var(--plum-light) 100%);
    position: relative;
    overflow: hidden;
}

.login-wrap::before {
    content: '';
    position: absolute;
    width: 350px;
    height: 350px;
    background: radial-gradient(circle, rgba(125,67,91,0.12) 0%, transparent 70%);
    top: -80px;
    right: -60px;
    border-radius: 50%;
    animation: loginBlob1 8s ease-in-out infinite;
}

.login-wrap::after {
    content: '';
    position: absolute;
    width: 280px;
    height: 280px;
    background: radial-gradient(circle, rgba(205,171,7,0.12) 0%, transparent 70%);
    bottom: -50px;
    left: -40px;
    border-radius: 50%;
    animation: loginBlob2 10s ease-in-out infinite;
}

@keyframes loginBlob1 {
    0%, 100% { transform: translate(0, 0) scale(1); }
    50% { transform: translate(-20px, 15px) scale(1.1); }
}

@keyframes loginBlob2 {
    0%, 100% { transform: translate(0, 0) scale(1); }
    50% { transform: translate(15px, -20px) scale(1.05); }
}

.login-card {
    width: 100%;
    max-width: 380px;
    background: rgba(255,255,255,0.82);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(232,223,212,0.6);
    border-radius: var(--radius-lg);
    padding: 2.5rem 2rem;
    box-shadow: var(--shadow-lg);
    position: relative;
    z-index: 1;
    animation: cardAppear 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes cardAppear {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.97);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.login-card .logo-text {
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 3.5px;
    text-transform: uppercase;
    color: var(--red);
    margin-bottom: 0.3rem;
}

.login-card h1 {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text);
    margin-bottom: 0.3rem;
}

.login-card .subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 2rem;
}

/* ---- Animations ---- */
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(14px); }
    to { opacity: 1; transform: translateY(0); }
}

.animate-up { animation: fadeUp 0.4s cubic-bezier(0.4, 0, 0.2, 1); }

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ---- Selection ---- */
::selection {
    background: var(--plum-light);
    color: var(--plum-dark);
}

/* ---- Utility ---- */
.text-center { text-align: center; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }

/* ---- Responsive ---- */
@media (max-width: 400px) {
    main { padding: 1rem; }
    .app-header { padding: 1.5rem 1rem 1rem; }
    .app-header .greeting { font-size: 1.3rem; }
}
