/* ==========================================
   FÄRGER & VARIABLER (Grunden för UI:t)
========================================== */
:root {
    --primary-color: #4F46E5;
    --primary-hover: #4338CA;
    --bg-color: #F9FAFB;
    --surface-color: #FFFFFF;
    --text-main: #111827;
    --text-muted: #6B7280;
    --border-color: #E5E7EB;
    --radius-md: 8px;
    --radius-lg: 12px;
}

/* =========================================================
   1. MODAL BASE (Baserad på Så-tid)
========================================================= */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.modal.hidden {
    display: none !important;
}

.modal-content {
    background: #FFFFFF;
    padding: 24px;
    border-radius: 18px;
    width: 92%;
    max-width: 550px; /* Ändrad från 430px för att rymma tvåkolumns-layouten */
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2);
    position: relative;
    animation: modalFadeIn 0.25s ease-out;
    font-family: inherit;
    max-height: 88vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

@keyframes modalFadeIn {
    from { 
        opacity: 0; 
        transform: scale(0.96) translateY(8px); 
    }
    to { 
        opacity: 1; 
        transform: scale(1) translateY(0); 
    }
}

/* =========================================================
   2. MODAL TITLES
========================================================= */
.modal-title {
    margin-bottom: 20px;
    padding-right: 36px;
    font-size: 1.35rem;
    font-weight: 600;
    color: #1E3A8A !important; /* AniMate Mörkblå istället för mörkgrön */
    line-height: 1.2;
    margin-top: 0;
}

.modal-subtitle {
    color: #1E3A8A !important;
    margin-top: 15px;
    margin-bottom: 20px;
    font-size: 0.9rem;
}

/* =========================================================
   3. STÄNG-KNAPP / KRYSSET
========================================================= */
.modal-close {
    position: absolute;
    top: 18px;
    right: 18px;
    
    /* Perfekt rund blå knapp */
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #0056b3; /* AniMate Blå istället för grön */
    color: #FFFFFF;
    
    border: none;
    outline: none;
    padding: 0;
    margin: 0;
    
    display: inline-flex;
    align-items: center;
    justify-content: center;
    
    font-size: 1.1rem;
    font-weight: bold;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
    transition: background 0.2s ease, transform 0.15s ease;
    z-index: 5;
}

.modal-close:hover {
    background: #004494 !important; /* Mörkare blå vid hover */
    color: #FFFFFF !important;
    transform: scale(1.08);
}

.modal-close:active {
    transform: scale(0.92);
}

/* =========================================================
   4. MODAL BODY & FORMULÄR
========================================================= */
.modal-body {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.modal-body label {
    font-weight: 600;
    font-size: 0.9rem;
    color: #333333;
    display: block;      /* Tvingar labeln att ligga på en egen rad ovanför fältet */
    margin-bottom: 6px;  /* Skapar luften ner till inmatningsfältet */
}

.modal-body input,
.modal-body select,
.modal-body textarea {
    width: 100%;
    padding: 8px 12px;
    border-radius: 10px;
    border: 1px solid #E3E3E3;
    font-size: 1rem;
    background: #FAFAFA;
    color: #222222;
    transition: border-color 0.2s, background 0.2s;
    box-sizing: border-box;
}

.modal-body input:focus,
.modal-body select:focus,
.modal-body textarea:focus {
    border-color: #80bdff; /* Ljusblå fokus-ram */
    background: #FFFFFF;
    outline: none;
}

.modal-body textarea {
    min-height: 90px;
    resize: vertical;
}

/* Låt Flatpickr-kalendern synas utanför rutor inuti modalen */
fieldset, .cw-row, .cw-col {
    overflow: visible !important;
}

/* =========================================================
   5. FIELDSET & LEGEND
========================================================= */
fieldset {
    border: 1px solid #E3E3E3; /* Tunn, snygg grå linje */
    border-radius: 12px;       /* De rundade hörnen */
    padding: 20px;             /* Luften mellan ramen och fälten inuti */
    margin-bottom: 20px;       /* Luft till nästa sektion nedanför */
}

legend {
    font-weight: 600;
    color: #1E3A8A;            /* Matchar din nya AniMate-blå titel */
    padding: 0 10px;           /* Skapar lite snygg luft exakt där texten bryter ramen */
    font-size: 1.05rem;
}

/* =========================================================
   FLIK-SYSTEM (TABS)
========================================================= */
.cw-tabs-nav {
    display: flex;
    border-bottom: 1px solid var(--border-color); /* Kan ändras till transperent */
    background: var(--surface-color);
    padding: 0 16px;
}

.cw-tab-btn {
    background: transparent;
    border: none;
    padding: 16px 20px;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: all 0.2s ease;
}

.cw-tab-btn:hover { color: var(--text-main); }
.cw-tab-btn.active {
    color: var(--primary-color);
    border-bottom: 3px solid var(--primary-color);
}

.cw-tab-content {
    display: none;
    padding: 20px 0;
}
.cw-tab-content.active { display: block; }

/* =========================================================
   UI KOMPONENTER (Foto & Badges)
========================================================= */
.animal-photo {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: #f0f4f8;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    overflow: hidden;
    flex-shrink: 0;
    border: 2px solid var(--border-color);
}

.animal-photo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.cw-badge-status, .cw-badge-link {
    padding: 4px 10px;
    border-radius: 100px;
    font-size: 0.75rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.status-green { background: #dcfce7; color: #15803d; }
.status-yellow { background: #fef3c7; color: #b45309; }
.status-red { background: #fee2e2; color: #b91c1c; }
.status-blue { background: #e0f2fe; color: #0369a1; }

/* =========================================================
   ANIMATIONER
========================================================= */
@keyframes modalFadeIn {
    from { opacity: 0; transform: scale(0.96) translateY(8px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

/* =========================================================
   HÄLSOJOURNAL - HEADER LAYOUT
========================================================= */
.journal-header-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 16px;
    gap: 15px;
}

.journal-title-box h2 {
    margin: 0 0 4px 0;
    font-size: 1.5rem;
    color: var(--text-main);
}

.journal-title-box p {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.95rem;
}

.journal-status-box {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    min-width: 200px;
}

.journal-status-box label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 4px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Mobil-anpassning: Stapla rubrik och dropdown */
@media (max-width: 768px) {
    .journal-header-top {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }
    
    .journal-status-box {
        width: 100%;
        min-width: unset;
    }
}