/* ========================================================== */
/* 1. VARIABLEN UND GRUNDLAGEN */
/* ========================================================== */

:root {
    /* Farben (Light Mode) */
    --primary-color: #7B68EE; /* Helles Lila (Accent) */
    --primary-dark: #6A5ACD; /* Dunkleres Lila */
    --accent-color: #6A5ACD; /* Primäre Akzentfarbe */
    --text-color: #333;
    --text-color-light: #666;
    --background-color: #f7f7f7;
    --card-bg: #fff;
    --input-bg: #fff;
    --border-color: #e0e0e0;
    --shadow-color: rgba(0, 0, 0, 0.1);
    
    /* Dark Mode Farben (Überschrieben durch [data-theme="dark"]) */
    --text-color-dark: #f0f0f0;
    --background-color-dark: #121212;
    --card-bg-dark: #1e1e1e;
    --input-bg-dark: #2c2c2c;
    --border-color-dark: #444;
    --shadow-color-dark: rgba(255, 255, 255, 0.1);

    /* Abstände und Radien */
    --spacing-unit: 15px;
    --border-radius: 10px;
    --button-radius: 8px;
    
    /* Schriftarten */
    --main-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}

/* Dark Mode Umschaltung */
body[data-theme="dark"] {
    --text-color: var(--text-color-dark);
    --text-color-light: #aaa;
    --background-color: var(--background-color-dark);
    --card-bg: var(--card-bg-dark);
    --input-bg: var(--input-bg-dark);
    --border-color: var(--border-color-dark);
    --shadow-color: rgba(255, 255, 255, 0.05);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--main-font);
    background-color: var(--background-color);
    color: var(--text-color);
    transition: background-color 0.3s, color 0.3s;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    padding: 0;
}

#main-wrapper {
    width: 100%;
    max-width: 450px; /* Typische Smartphone-Breite */
    background: var(--card-bg); /* Hintergrund für die App-Fläche */
    box-shadow: 0 0 20px var(--shadow-color);
    min-height: 100vh;
    position: relative;
    display: flex;
    flex-direction: column;
}

/* ========================================================== */
/* 2. HEADER UND NAVIGATION */
/* ========================================================== */

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px var(--spacing-unit);
    border-bottom: 1px solid var(--border-color);
    background-color: var(--card-bg);
    position: sticky;
    top: 0;
    z-index: 10;
}

.header-date {
    font-weight: 600;
    color: var(--text-color);
    font-size: 0.9em;
}

.header-actions {
    display: flex;
    gap: 10px;
}

.icon-button {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 1.2em;
    padding: 5px;
    border-radius: 50%;
    transition: background-color 0.2s;
    color: var(--text-color);
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-button:hover {
    background-color: var(--border-color);
}

.view-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px var(--spacing-unit);
    border-bottom: 1px solid var(--border-color);
    background-color: var(--card-bg);
    position: sticky;
    top: 0;
    z-index: 10;
}

.view-header h2 {
    font-size: 1.4em;
    font-weight: 800; /* Konsistent mit Home-Header */
    text-align: center;
    flex-grow: 1;
    margin-left: -60px; /* Ausgleich für Back-Button */
}

/* Button-Styling (Generell) */
.action-button {
    padding: 8px 15px;
    border: none;
    border-radius: var(--button-radius);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9em;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.primary-gradient {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 2px 5px rgba(123, 104, 238, 0.4);
}

.primary-gradient:hover {
    background: var(--primary-dark);
}

.secondary-color-button {
    background: var(--border-color);
    color: var(--text-color);
}

body[data-theme="dark"] .secondary-color-button {
    background: var(--input-bg);
    color: var(--text-color);
}

.secondary-color-button:hover {
    background: #ccc;
}

body[data-theme="dark"] .secondary-color-button:hover {
    background: #3a3a3a;
}

.back-button {
    background: var(--border-color);
    color: var(--text-color);
    padding: 6px 10px;
}

/* ========================================================== */
/* 3. HOME VIEW (JOIN-LISTEN) */
/* ========================================================== */

#home-view {
    display: flex;
    flex-direction: column;
}

#joins-container {
    flex-grow: 1;
    padding-bottom: 80px; /* Platz für FAB */
}

.view-content-padding {
    padding: var(--spacing-unit);
}

.section-divider {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 20px var(--spacing-unit);
}

.join-list-section h2 {
    font-size: 1.2em;
    font-weight: 800;
    padding: 0 var(--spacing-unit);
    margin-bottom: 15px;
}

/* Basiskarte/Listen-Item-Styling */
.join-item {
    background: var(--card-bg);
    padding: 15px;
    border-radius: var(--border-radius);
    box-shadow: 0 1px 3px var(--shadow-color);
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s ease;
    border: 1px solid var(--border-color);
}

/* LISTENANSICHT (Standard) */
.joins-list .join-item {
    display: flex;
    flex-direction: row;
    align-items: center;
}

.joins-list .join-info {
    flex-grow: 1;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 5px;
}

.joins-list .join-title {
    font-weight: 600;
    margin-right: 10px;
}

.joins-list .join-organizer, .joins-list .join-detail {
    font-size: 0.9em;
    color: var(--text-color-light);
}


/* KACHELANSICHT (WIRD AKTIVIERT DURCH data-join-view="card") */
body[data-join-view="card"] .joins-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 10px;
}

body[data-join-view="card"] .joins-grid .join-item {
    flex-direction: column;
    align-items: flex-start;
    height: 120px;
    padding: 12px;
    margin-bottom: 0;
}

body[data-join-view="card"] .joins-grid .join-info {
    flex-direction: column;
    align-items: flex-start;
    flex-grow: 1;
    gap: 2px;
    margin-bottom: 10px;
}

body[data-join-view="card"] .joins-grid .join-title {
    font-size: 1em;
    margin-right: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

body[data-join-view="card"] .joins-grid .join-organizer {
    font-size: 0.8em;
}

/* Join- und Chat-Buttons */
.join-item .action-button {
    padding: 5px 10px;
    font-size: 0.85em;
    flex-shrink: 0;
}

.join-item .chat-button {
    background-color: #6DC24D; /* Grün */
    color: white;
}

.join-item .join-button {
    background-color: var(--primary-color);
    color: white;
}

/* Floating Action Button (FAB) */
.floating-action-button {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    font-size: 2em;
    line-height: 50px;
    text-align: center;
    z-index: 20;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

/* ========================================================== */
/* 4. CHAT VIEW */
/* ========================================================== */

#chat-view {
    display: flex;
    flex-direction: column;
}

.chat-content {
    flex-grow: 1;
    padding: var(--spacing-unit);
    display: flex;
    flex-direction: column;
}

#chat-messages {
    flex-grow: 1;
    overflow-y: auto;
    margin-bottom: 10px;
}

.message {
    padding: 8px 12px;
    border-radius: 18px;
    margin-bottom: 8px;
    max-width: 80%;
    word-wrap: break-word;
}

.system-message {
    text-align: center;
    font-style: italic;
    color: var(--text-color-light);
    background: transparent;
}

.incoming-message {
    background-color: var(--border-color);
    align-self: flex-start;
    color: var(--text-color);
}

.outgoing-message {
    background-color: var(--primary-color);
    color: white;
    align-self: flex-end;
    margin-left: auto;
}

.chat-input-container {
    display: flex;
    gap: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
    background: var(--card-bg);
    padding: 10px 0;
}

#chat-input {
    flex-grow: 1;
    padding: 10px 15px;
    border: 1px solid var(--border-color);
    border-radius: var(--button-radius);
    font-size: 1em;
    background: var(--input-bg);
    color: var(--text-color);
}

/* ========================================================== */
/* 5. VIEW-SCREEN FIX & PROFILBILD-STYLING */
/* ========================================================== */

.view-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    min-height: 100%;
    background: var(--background-color);
    z-index: 15;
    display: none;
    flex-direction: column;
}

/* Profilbild-Styling */
.profile-image-container {
    display: flex;
    justify-content: center;
    margin: 20px 0 30px;
}

#profile-picture {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: #fdfd96; /* Leichter gelber Hintergrund */
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 3em;
    position: relative;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

/* Styling für den Edit-Stift (AKTUALISIERT) */
.edit-overlay-button {
    position: absolute;
    bottom: 5px; /* Etwas vom unteren Rand des Bildes nach oben */
    right: 5px; /* Etwas vom rechten Rand des Bildes nach links */
    /* Kleinerer Kreis mit weniger starkem Rahmen */
    background: white; 
    color: var(--primary-dark);
    border: 2px solid var(--primary-color); /* Dünnerer Rand */
    border-radius: 50%;
    width: 26px; /* Kleiner */
    height: 26px; /* Kleiner */
    line-height: 24px; /* Für vertikale Zentrierung des Emojis */
    padding: 0;
    font-size: 0.8em; /* Kleineres Emoji */
    box-shadow: 0 1px 3px rgba(0,0,0,0.15); /* Leichterer Schatten */
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s ease;
}
body[data-theme="dark"] .edit-overlay-button {
    background: var(--card-bg-dark);
    border-color: var(--accent-color);
    color: var(--accent-color);
}
.edit-overlay-button:hover {
    transform: scale(1.1);
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

/* Name unter dem Bild */
#profile-name-display {
    display: block;
    text-align: center;
    font-weight: 600;
    margin-top: 5px;
}

/* ========================================================== */
/* 6. MODALE (POP-UPS) */
/* ========================================================== */

.modal {
    display: none;
    position: fixed;
    z-index: 50;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.7);
    padding: var(--spacing-unit);
    transition: opacity 0.3s ease;
    opacity: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal.is-open {
    opacity: 1;
}

.modal-content {
    background-color: var(--card-bg);
    margin: auto;
    padding: 30px;
    border-radius: var(--border-radius);
    width: 90%;
    max-width: 400px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    position: relative;
    transform: translateY(20px);
    transition: transform 0.3s ease;
}

.modal.is-open .modal-content {
    transform: translateY(0);
}

.modal-content h2 {
    margin-bottom: 20px;
    font-size: 1.3em;
    font-weight: 700;
}

.close-button {
    color: var(--text-color-light);
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 1.5em;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.2s;
}

.close-button:hover {
    color: var(--primary-dark);
}

/* Formular-Styling in Modalen */
.modal-content label {
    display: block;
    margin-top: 15px;
    margin-bottom: 5px;
    font-weight: 600;
    font-size: 0.9em;
}

.modal-content input[type="text"],
.modal-content input[type="date"],
.modal-content input[type="time"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--button-radius);
    background: var(--input-bg);
    color: var(--text-color);
    font-size: 1em;
}

.modal-content .full-width-button {
    margin-top: 25px;
}

/* ========================================================== */
/* 7. FREUNDESLISTEN-VIEW (KACHELN & LISTEN) */
/* ========================================================== */

.list-controls {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
}

.list-controls .action-button {
    padding: 8px 12px;
}

/* Grid/Kachel-Ansicht (Standard) */
.lists-grid {
    display: grid;
    grid-template-columns: 1fr; /* Einzelspalt auf kleinen Screens */
    gap: 12px;
}

@media (min-width: 350px) {
    .lists-grid {
        grid-template-columns: 1fr; /* Bleibt bei Liste für besseren Look */
    }
}

.friend-list-item {
    background: var(--card-bg);
    padding: 15px;
    border-radius: var(--border-radius);
    box-shadow: 0 1px 3px var(--shadow-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid var(--border-color);
}

.list-icon-name {
    display: flex;
    align-items: center;
}

.list-icon {
    font-size: 1.8em;
    margin-right: 15px;
    width: 30px;
    text-align: center;
    line-height: 1;
}

.list-text-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.list-name {
    font-weight: 700;
    font-size: 1.1em;
}

.list-member-count {
    font-size: 0.85em;
    color: var(--text-color-light);
}

.edit-list-button {
    background: var(--border-color);
    color: var(--text-color);
    padding: 8px 12px;
    font-size: 0.85em;
    flex-shrink: 0;
}

/* Kompakte Listen-Ansicht (Compact View) */
.lists-compact-view .friend-list-item {
    padding: 10px;
    margin-bottom: 8px;
    border-radius: 5px;
}

.lists-compact-view .list-icon {
    font-size: 1.2em;
    margin-right: 10px;
    width: auto;
}

.lists-compact-view .list-name {
    font-size: 1em;
}

.lists-compact-view .list-member-count {
    display: none; /* Mitgliederanzahl in Kompaktansicht verstecken */
}

/* ========================================================== */
/* 8. PROFIL-FORMULAR-FEINHEITEN (AKTUALISIERT) */
/* ========================================================== */

#profile-form label,
#edit-friend-list-view label {
    display: block;
    margin-bottom: 8px; /* Etwas mehr Abstand zum Input-Feld */
    margin-top: 25px; /* Abstand zwischen den Feldern */
    font-weight: 700;
    font-size: 1em; /* Einheitliche Schriftgröße */
    color: inherit; /* Nimmt die Textfarbe des Themes an */
    text-align: left; /* Labels linksbündig */
    padding-left: 5px; /* Kleiner Einzug für Optik */
}

/* Anpassung der Inputs und Textareas im Profil und Edit-View */
#profile-form input[type="text"], 
#profile-form textarea,
#edit-friend-list-view input[type="text"],
#edit-friend-list-view textarea {
    width: 100%; 
    padding: 12px 15px; 
    border: 1px solid var(--border-color); 
    border-radius: var(--border-radius); 
    font-size: 1em; 
    box-sizing: border-box; 
    background: var(--input-bg);
    color: var(--text-color);
    margin-top: 0; /* Kein zusätzlicher Abstand nach dem Label */
    font-family: var(--main-font); 
    font-weight: 500;
}


#profile-form textarea,
#edit-friend-list-view textarea {
    resize: vertical; /* Nur vertikales Resizing erlauben */
    min-height: 80px; /* Mindesthöhe für die Beschreibung */
}

/* Sicherstellen, dass die Überschriften im Profil-View dem globalen Stil folgen */
#profile-view h2,
#profile-view h3,
#edit-friend-list-view h3 {
    font-weight: 800; 
    text-align: center;
    color: inherit;
    padding-top: 0;
    margin-bottom: 0; /* Werden durch den nachfolgenden Container-Padding gesetzt */
}

#profile-view h3 {
    font-size: 1.1em;
    text-align: left; /* H3 der Sektion ist linksbündig */
    padding-left: 5px;
    margin-top: 30px;
    margin-bottom: 10px;
}

/* Freundeslisten-Edit-View */
#edit-list-form .list-details-section {
    padding-bottom: 20px;
    margin-bottom: 30px;
    border-bottom: 1px solid var(--border-color);
}

#edit-list-form h3 {
    text-align: left;
    font-size: 1.1em;
    margin-top: 0;
    margin-bottom: 20px;
}

/* Such- und Member-Sektion */
.friends-manage-section {
    padding-top: 0;
}

.search-input-group {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

#friend-search-input {
    flex-grow: 1;
}

.friends-list-container {
    margin-top: 25px;
}

.friends-list-heading {
    font-size: 0.9em;
    font-weight: 700;
    color: var(--text-color-light);
    margin-bottom: 10px;
    padding-left: 5px;
}

.member-pills-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.member-tag {
    background: var(--primary-color);
    color: white;
    padding: 5px 10px;
    border-radius: 20px;
    font-size: 0.9em;
    display: flex;
    align-items: center;
}

.remove-member {
    margin-left: 5px;
    cursor: pointer;
    font-weight: bold;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.remove-member:hover {
    opacity: 1;
}