:root {
    --bg-main: #121212;       /* Bardzo ciemne tło (nie czarne) */
    --bg-card: #1e1e1e;       /* Tło kart */
    --bg-input: #2d2d2d;
    --primary: #bb86fc;       /* Fioletowy akcent (klasyk dark mode) */
    --primary-dim: rgba(187, 134, 252, 0.1);
    --accent-green: #03dac6;
    --accent-red: #cf6679;
    --text-main: #e0e0e0;     /* Złamana biel */
    --text-muted: #a0a0a0;
    --border: #333333;
    
    --header-height: 60px;
    --nav-height: 70px;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    padding-top: var(--header-height);
    padding-bottom: var(--nav-height);
    -webkit-tap-highlight-color: transparent;
}

/* --- NAGŁÓWEK --- */
.app-header {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--header-height);
    background-color: rgba(18, 18, 18, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    z-index: 1000;
    display: flex;
    align-items: center;
    padding: 0 16px;
}
.header-content {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.header-content h1 { font-size: 1.2rem; font-weight: 600; }

.icon-btn {
    background: none; border: none; color: var(--text-main); cursor: pointer; padding: 8px;
}

/* --- LISTA SPRAW (DASHBOARD) --- */
.app-container { padding: 16px; }

.case-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
    transition: transform 0.1s, background-color 0.2s;
}
.case-card:active { transform: scale(0.98); background-color: #252525; }

.card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 8px; }
.card-title { font-size: 1rem; font-weight: 600; margin-bottom: 4px; color: #fff; }
.card-meta { font-size: 0.85rem; color: var(--text-muted); display: flex; flex-direction: column; gap: 4px; }

/* Status Badges */
.status-badge {
    font-size: 0.75rem; padding: 4px 8px; border-radius: 4px; font-weight: 600; text-transform: uppercase;
}
.status-new { background: rgba(3, 218, 198, 0.15); color: var(--accent-green); }
.status-warn { background: rgba(207, 102, 121, 0.15); color: var(--accent-red); }

.deadline-info {
    margin-top: 12px; display: flex; align-items: center; font-size: 0.85rem;
    color: var(--primary);
}

/* --- TIMELINE (CZAT) --- */
.timeline-container { display: flex; flex-direction: column; gap: 16px; padding-bottom: 20px; }

.msg {
    max-width: 85%; padding: 12px 16px; border-radius: 16px; position: relative; font-size: 0.95rem; line-height: 1.4;
}
.msg-meta {
    font-size: 0.75rem; opacity: 0.7; margin-bottom: 4px; display: block;
}

/* Przychodzące (Od Urzędu) */
.msg-in {
    align-self: flex-start;
    background-color: #2c2c2c;
    border-bottom-left-radius: 4px;
    border: 1px solid var(--border);
}

/* Wychodzące (My) */
.msg-out {
    align-self: flex-end;
    background-color: var(--primary-dim);
    color: #e2d3f5;
    border: 1px solid rgba(187, 134, 252, 0.3);
    border-bottom-right-radius: 4px;
}

/* Notatki */
.msg-note {
    align-self: center;
    background-color: transparent;
    border: 1px dashed var(--border);
    color: var(--text-muted);
    font-style: italic;
    width: 100%;
    text-align: center;
    font-size: 0.85rem;
}

/* --- AKCJE (Action Bar) --- */
.action-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 20px;
}
.btn {
    padding: 12px; border: none; border-radius: 8px; font-weight: 600; cursor: pointer;
    font-size: 0.9rem; display: flex; justify-content: center; align-items: center; gap: 8px;
}
.btn-primary { background-color: var(--primary); color: #000; }
.btn-secondary { background-color: var(--bg-input); color: var(--text-main); border: 1px solid var(--border); }

/* --- DOLNE MENU --- */
.bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0;
    height: var(--nav-height);
    background-color: #1a1a1a;
    border-top: 1px solid var(--border);
    display: flex; justify-content: space-around; align-items: center;
    z-index: 1000;
}
.nav-item {
    background: none; border: none; color: var(--text-muted);
    display: flex; flex-direction: column; align-items: center; gap: 4px;
    font-size: 0.75rem; width: 60px;
}
.nav-item.active { color: var(--primary); }

.fab-container { position: relative; top: -20px; }
.fab-btn {
    width: 56px; height: 56px; border-radius: 50%;
    background-color: var(--primary); color: #000;
    border: none; box-shadow: 0 4px 10px rgba(0,0,0,0.5);
    display: flex; align-items: center; justify-content: center;
}

/* Loader */
.loader-container { text-align: center; margin-top: 50px; color: var(--text-muted); }
.loader {
    border: 3px solid #333; border-top: 3px solid var(--primary);
    border-radius: 50%; width: 40px; height: 40px;
    animation: spin 1s linear infinite; margin: 0 auto 10px;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }


/* --- WIDOK SPRAWY (CHAT LAYOUT) --- */

/* Główny kontener widoku sprawy - zajmuje całą wysokość minus nagłówek i dolne menu */
.case-view-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--header-height) - var(--nav-height) - 20px);
    overflow: hidden; /* Ukrywamy scroll strony, scrollujemy tylko wiadomości */
}

/* Nagłówek sprawy (Tytuł i info) */
.case-info-header {
    padding: 0 0 15px 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0;
    flex-shrink: 0;
}
.case-title { font-size: 1.1rem; font-weight: 700; color: #fff; margin-bottom: 5px; }
.case-institution { font-size: 0.85rem; color: var(--accent-green); display: flex; align-items: center; gap: 6px; }

/* Obszar przewijania wiadomości */
.chat-scroll-area {
    flex-grow: 1;
    overflow-y: auto;
    padding: 15px 5px; /* Lekki padding boczny */
    display: flex;
    flex-direction: column;
    gap: 20px;
    scroll-behavior: smooth;
}

/* Pojedyncza wiadomość (Wiersz) */
.msg-row {
    display: flex;
    gap: 10px;
    max-width: 90%;
}

/* Wiadomości przychodzące (Urząd) */
.msg-row.incoming { align-self: flex-start; }
.msg-row.incoming .msg-bubble { 
    background-color: #2c2c2c; 
    border-top-left-radius: 2px;
    color: #e0e0e0;
}

/* Wiadomości wychodzące (My) */
.msg-row.outgoing { align-self: flex-end; flex-direction: row-reverse; }
.msg-row.outgoing .msg-bubble { 
    background-color: var(--primary); 
    color: #000; /* Czarny tekst na fioletowym tle dla kontrastu */
    border-top-right-radius: 2px;
}
.msg-row.outgoing .msg-meta { color: rgba(0,0,0,0.6); }

/* Notatki (Środek) */
.msg-row.note {
    align-self: center;
    max-width: 100%;
    width: 100%;
    justify-content: center;
}
.msg-row.note .msg-bubble {
    background: transparent;
    border: 1px dashed var(--border);
    color: var(--text-muted);
    font-style: italic;
    text-align: center;
    padding: 8px 20px;
    border-radius: 20px;
    font-size: 0.85rem;
}

/* Avatar (Kółko z ikoną) */
.msg-avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    font-size: 0.8rem;
    background-color: #333;
    color: #fff;
    border: 1px solid var(--border);
}
.incoming .msg-avatar { background-color: #2c2c2c; }
.outgoing .msg-avatar { background-color: #fff; color: var(--primary); }

/* Dymek z tekstem */
.msg-bubble {
    padding: 12px 16px;
    border-radius: 18px;
    position: relative;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    font-size: 0.95rem;
    line-height: 1.4;
    word-wrap: break-word;
}

/* Metadane (Data, Autor) */
.msg-meta {
    font-size: 0.7rem;
    margin-bottom: 4px;
    opacity: 0.7;
    display: block;
    font-weight: 600;
}

/* Panel akcji na dole (Sticky) */
.case-actions-footer {
    padding-top: 15px;
    border-top: 1px solid var(--border);
    background-color: var(--bg-main); /* Przykrywa content pod spodem */
    flex-shrink: 0;
    display: grid;
    grid-template-columns: 1fr 2fr; /* Mały przycisk notatki, duży pisma */
    gap: 10px;
}

/* --- Dodaj to na końcu style.css --- */

/* Ramka na treść maila HTML */
.email-frame {
    width: 100%;
    min-height: 300px; /* Domyślna wysokość */
    border: none;
    background-color: #ffffff; /* Ważne: maile zazwyczaj mają czarny tekst, więc tło musi być białe */
    display: block;
    margin-top: 10px;
    border-radius: 4px;
}

/* W dymkach notatek nie chcemy ramki, tylko tekst */
.note-content {
    white-space: pre-wrap; /* Zachowuje entery */
}

/* --- Sekcja Załączników --- */
.attachments-area {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid rgba(255,255,255,0.1);
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.attachment-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background-color: #333;
    border: 1px solid #444;
    color: #e0e0e0;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    text-decoration: none;
    transition: background 0.2s;
    max-width: 100%;
}

.attachment-btn:hover {
    background-color: #444;
    color: #fff;
}

.attachment-icon {
    opacity: 0.7;
}