/* Mobile-first Basis-Styles für PlanB.
   4 Themes (siehe includes/theme.php) setzen je eigene Farb-/Schrift-
   Variablen über [data-theme] auf <html>; jeder Nutzer wählt seines in
   settings.php. Alle Komponenten unten nutzen nur diese Variablen. */

:root,
:root[data-theme="warm"] {
    --color-bg: #fbf3ea;
    --color-surface: #ffffff;
    --color-text: #3a2e26;
    --color-muted: #8a7968;
    --color-primary: #b9582f;
    --color-primary-contrast: #fff7ee;
    --color-accent: #b9582f;
    --color-danger: #c0392b;
    --color-border: #f1e3d2;
    --radius: 16px;
    --button-radius: 24px;
    --card-shadow: 0 2px 8px rgba(58, 46, 38, 0.06);
    --font-body: 'Nunito Sans', system-ui, sans-serif;
    --font-heading: 'Fraunces', serif;
}

:root[data-theme="material"] {
    --color-bg: #f3f2f7;
    --color-surface: #ffffff;
    --color-text: #1c1b1f;
    --color-muted: #5c5a66;
    --color-primary: #3f51b5;
    --color-primary-contrast: #ffffff;
    --color-accent: #3f51b5;
    --color-danger: #c0392b;
    --color-border: #e3e1ea;
    --radius: 6px;
    --button-radius: 24px;
    --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.16);
    --font-body: 'Roboto', system-ui, sans-serif;
    --font-heading: 'Roboto', system-ui, sans-serif;
}

:root[data-theme="pastel"] {
    --color-bg: #f4f1fb;
    --color-surface: #ffffff;
    --color-text: #3d3a52;
    --color-muted: #8f8aab;
    --color-primary: #b8a9f3;
    --color-primary-contrast: #ffffff;
    --color-accent: #b8a9f3;
    --color-danger: #c0392b;
    --color-border: #e7e2f7;
    --radius: 20px;
    --button-radius: 24px;
    --card-shadow: none;
    --font-body: 'Quicksand', system-ui, sans-serif;
    --font-heading: 'Quicksand', system-ui, sans-serif;
}

:root[data-theme="dark"] {
    --color-bg: #14161b;
    --color-surface: #1b1e25;
    --color-text: #f1f2f4;
    --color-muted: #8c92a0;
    --color-primary: #5eead4;
    --color-primary-contrast: #0b1413;
    --color-accent: #5eead4;
    --color-danger: #e0575f;
    --color-border: #343a46;
    --radius: 14px;
    --button-radius: 24px;
    --card-shadow: none;
    --font-body: 'Space Grotesk', system-ui, sans-serif;
    --font-heading: 'Space Grotesk', system-ui, sans-serif;
}

:root[data-theme="nature"] {
    --color-bg: #f6f3ea;
    --color-surface: #eceade;
    --color-text: #1f2e22;
    --color-muted: #6f7c67;
    --color-primary: #4b7a51;
    --color-primary-contrast: #f6f3ea;
    --color-accent: #4b7a51;
    --color-danger: #c0392b;
    --color-border: #c9cfb8;
    --radius: 12px;
    --button-radius: 24px;
    --card-shadow: none;
    --font-body: 'Source Sans 3', system-ui, sans-serif;
    --font-heading: 'Lora', serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--font-body, system-ui), -apple-system, "Segoe UI", sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
}

h1, h2, h3 {
    font-family: var(--font-heading, inherit);
}

a {
    color: var(--color-primary);
}

/* --- Kopfzeile / Navigation ------------------------------------------- */

.app-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    /* Verdunkelt die Theme-Farbe etwas, damit der helle Text auch bei
       hellen Theme-Farben (z. B. Pastell) gut lesbar bleibt. */
    background: linear-gradient(rgba(0, 0, 0, 0.18), rgba(0, 0, 0, 0.18)), var(--color-primary);
    color: var(--color-primary-contrast);
}

.app-title {
    color: var(--color-primary-contrast);
    text-decoration: none;
    font-weight: 700;
    font-size: 1.1rem;
}

.app-nav {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.85rem;
    flex-wrap: wrap;
}

.app-nav a {
    color: var(--color-primary-contrast);
    text-decoration: none;
    opacity: 0.9;
}

.app-nav a:hover {
    text-decoration: underline;
}

.user-widget {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.user-icon-circle {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    line-height: 1;
    text-decoration: none;
    overflow: hidden;
}

.user-icon-circle:active {
    background: rgba(255, 255, 255, 0.35);
}

.user-icon-glyph {
    font-size: 1rem;
    line-height: 1;
}

.user-icon-initials {
    font-size: 0.48rem;
    font-weight: 700;
    letter-spacing: 0.3px;
    line-height: 1.4;
    /* Immer schwarz auf einem eigenen hellen Chip - damit die Initialen
       unabhängig vom Hintergrund (dunkle Kopfzeile, buntes Emoji, …)
       lesbar bleiben, statt sich in die Kontext-Textfarbe einzufügen. */
    color: #000000;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 3px;
    padding: 0 3px;
    opacity: 1;
}

.user-logout {
    font-size: 0.7rem;
    color: var(--color-primary-contrast);
    opacity: 0.85;
    text-decoration: none;
}

.user-logout:hover {
    text-decoration: underline;
}

/* --- Allgemeines Layout ------------------------------------------------ */

.app-main {
    padding: 1rem;
    max-width: 640px;
    margin: 0 auto;
}

.app-footer {
    padding: 1.5rem 1rem 2rem;
    font-size: 0.75rem;
    color: var(--color-muted);
    text-align: center;
}

.hint {
    color: var(--color-muted);
    font-size: 0.9rem;
}

.error {
    color: var(--color-danger);
    font-weight: 600;
}

.success {
    color: var(--color-accent);
    font-weight: 600;
}

.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--card-shadow, none);
    padding: 1rem;
    margin: 1rem 0;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.5rem;
}

.card-actions {
    display: flex;
    gap: 0.75rem;
    font-size: 0.85rem;
}

.plain-list {
    list-style: none;
    margin: 0.5rem 0 0;
    padding: 0;
}

.template-list {
    list-style: none;
    margin: 1rem 0;
    padding: 0;
}

.plain-list li {
    padding: 0.25rem 0;
}

/* --- Formulare ---------------------------------------------------------- */

form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

label {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.9rem;
}

input[type="text"],
input[type="password"],
textarea,
select {
    font-size: 1rem;
    padding: 0.6rem;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    font-family: inherit;
}

textarea {
    resize: vertical;
}

input[type="checkbox"] {
    accent-color: var(--color-accent);
}

button {
    font-size: 1rem;
    padding: 0.65rem 1rem;
    border: none;
    border-radius: var(--button-radius, 8px);
    background: var(--color-primary);
    color: var(--color-primary-contrast);
    cursor: pointer;
    font-family: inherit;
}

button:active {
    opacity: 0.85;
}

button.danger,
.button.danger {
    background: var(--color-danger);
}

.link-button {
    background: none;
    color: var(--color-primary);
    padding: 0;
    text-decoration: underline;
    font-size: 0.85rem;
}

.link-button.danger {
    background: none;
    color: var(--color-danger);
    text-decoration: none;
}

.link-button.danger:hover,
.link-button.danger:focus-visible {
    text-decoration: underline;
}

.checkbox-line {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
}

.template-item-line.already-in-project {
    opacity: 0.6;
}

.template-item-line.already-in-project .hint {
    font-size: 0.8rem;
}

.inline-form {
    display: inline;
}

fieldset {
    border: 1px solid var(--color-border);
    border-radius: 8px;
    margin: 0.5rem 0;
}

.button {
    display: inline-block;
    background: var(--color-primary);
    color: var(--color-primary-contrast);
    text-decoration: none;
    padding: 0.5rem 0.9rem;
    border-radius: 8px;
    font-size: 0.9rem;
}

.hidden {
    display: none !important;
}

/* --- Login-Seite --------------------------------------------------------- */

.auth-page {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

.auth-page .app-footer {
    padding: 0;
}

.auth-box {
    width: 100%;
    max-width: 360px;
    padding: 1.5rem;
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--card-shadow, none);
    text-align: center;
}

.auth-hint {
    color: var(--color-muted);
    font-size: 0.9rem;
}

.auth-footnote {
    margin-top: 1rem;
    font-size: 0.8rem;
    color: var(--color-muted);
}

/* --- Projektliste --------------------------------------------------------- */

.list-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}

.search-field {
    width: 100%;
    margin: 0.75rem 0;
    -webkit-appearance: none;
    appearance: none;
    border: 1px solid var(--color-border);
    border-radius: 999px;
    background: var(--color-surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23999999' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E") no-repeat 0.9rem center;
    background-size: 18px 18px;
    padding: 0.65rem 1rem 0.65rem 2.6rem;
    font-size: 1rem;
    box-shadow: var(--card-shadow, none);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.search-field:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.06);
}

.search-field::-webkit-search-cancel-button {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    margin-left: 0.4rem;
    background: var(--color-muted);
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round'%3E%3Cline x1='18' y1='6' x2='6' y2='18'/%3E%3Cline x1='6' y1='6' x2='18' y2='18'/%3E%3C/svg%3E") center / contain no-repeat;
    cursor: pointer;
}

.search-hidden {
    display: none !important;
}

.search-mark {
    background: var(--color-accent);
    color: #ffffff;
    border-radius: 3px;
    padding: 0 2px;
}

.empty-state {
    color: var(--color-muted);
    text-align: center;
    padding: 2rem 0;
}

.project-list {
    list-style: none;
    margin: 1rem 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.project-row-main {
    cursor: pointer;
}

.project-name {
    font-weight: 600;
    font-size: 1.05rem;
}

.project-meta {
    color: var(--color-muted);
    font-size: 0.85rem;
    margin-top: 0.25rem;
}

.project-shared-with {
    color: var(--color-muted);
    font-size: 0.78rem;
    margin-top: 0.15rem;
}

.archive-toggle {
    text-align: center;
    font-size: 0.85rem;
}

.badge {
    display: inline-block;
    background: var(--color-border);
    color: var(--color-text);
    border-radius: 999px;
    padding: 0.1rem 0.6rem;
    font-size: 0.75rem;
}

/* --- Projekt-Checkliste --------------------------------------------------- */

.project-title-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.item-list-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    margin: 0.5rem 0 1rem;
}

.show-done-toggle {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--color-muted);
    margin: 0;
}

#toggle-reorder {
    font-size: 0.85rem;
}

.selection-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
    background: var(--color-primary);
    color: var(--color-primary-contrast);
    border-radius: var(--radius);
    padding: 0.6rem 0.9rem;
    margin: 0 0 0.75rem;
    position: sticky;
    top: 0.5rem;
    z-index: 3;
}

.selection-count {
    font-size: 0.9rem;
    font-weight: 600;
}

.selection-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.selection-actions button {
    font-size: 0.8rem;
    padding: 0.4rem 0.7rem;
    background: rgba(255, 255, 255, 0.2);
    color: var(--color-primary-contrast);
}

.selection-actions button.danger {
    background: var(--color-danger);
}

.selection-actions .link-button {
    background: none;
    color: var(--color-primary-contrast);
    text-decoration: underline;
    padding: 0.4rem 0.3rem;
}

.item-list.selection-mode .swipe-icon {
    display: none;
}

.item-list.selection-mode .reorder-buttons {
    display: none !important;
}

.item-row.is-selected .item-row-main {
    background: rgba(37, 99, 235, 0.12);
    outline: 2px solid #2563eb;
    outline-offset: -2px;
}

.item-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.item-list.hide-done .item-row.is-checked {
    display: none;
}

/* "order" erst nach kurzer Verzögerung (siehe app.js) auf "is-settled"
   gesetzt, nicht direkt auf "is-checked" - so bleibt ein erledigter
   Punkt kurz an seinem Platz, falls man ihn versehentlich abgehakt hat
   und direkt wieder zurücknehmen möchte. */
.item-row.is-settled {
    order: 1;
}

.item-list.reorder-mode .item-row.is-settled {
    order: 0;
}

.item-row {
    position: relative;
    overflow: hidden;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--card-shadow, none);
}

.item-row.is-checked {
    opacity: 0.6;
}

.item-row.is-checked .item-headline {
    text-decoration: line-through;
}

.item-row-main {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    background: var(--color-surface);
    padding: 0.7rem;
    touch-action: pan-y;
    transition: transform 0.15s ease, background-color 0.1s ease;
}

.toggle-form {
    margin: 0;
}

.checkbox-button {
    width: 28px;
    height: 28px;
    min-width: 28px;
    border-radius: 50%;
    border: 2px solid var(--color-primary);
    background: var(--color-surface);
    color: var(--color-accent);
    font-weight: 700;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.checkbox-button:disabled {
    opacity: 0.4;
}

.item-text-slot {
    flex: 1;
    min-width: 0;
}

.item-headline {
    font-size: 1.05rem;
    font-weight: 600;
    word-break: break-word;
}

.item-subline {
    font-size: 0.8rem;
    color: var(--color-muted);
    word-break: break-word;
}

.checked-by-icon {
    flex: none;
    display: flex;
    align-items: center;
    gap: 0.2rem;
    font-size: 1rem;
    opacity: 0.85;
}

.checked-by-initials {
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--color-muted);
    letter-spacing: 0.5px;
}

.reorder-buttons {
    display: none;
    flex-direction: column;
    gap: 2px;
    flex: none;
}

.item-list.reorder-mode .reorder-buttons {
    display: flex;
}

.reorder-button {
    width: 22px;
    height: 20px;
    padding: 0;
    font-size: 0.6rem;
    line-height: 1;
    background: var(--color-border);
    color: var(--color-text);
    border-radius: 4px;
}

.reorder-button:disabled {
    opacity: 0.25;
}

.swipe-icon {
    position: absolute;
    top: 50%;
    z-index: 2;
    transform: translateY(-50%) scale(0.7);
    opacity: 0;
    /* Unsichtbar UND nicht klickbar, solange keine Wisch-Geste läuft -
       sonst fängt das (unsichtbare) Icon Taps ab, die eigentlich dem
       darunterliegenden Abhaken-Kreis galten. */
    pointer-events: none;
    transition: opacity 0.15s, transform 0.15s;
    font-size: 1.2rem;
    cursor: pointer;
    background: none;
    border: none;
    padding: 6px;
    line-height: 1;
}

.swipe-icon-edit {
    left: 16px;
    color: #2563eb;
}

.swipe-icon-delete {
    right: 16px;
    color: #dc3545;
}

.swipe-icon.is-active {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(-50%) scale(1.35);
    color: #ffffff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

.edit-item-form {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.edit-item-form textarea {
    font-size: 0.95rem;
    padding: 0.4rem;
}

.edit-item-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.edit-item-actions button[type="submit"] {
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
}

/* --- Vorlagen-Auswahl bei neuem Projekt ----------------------------------- */

.template-pick {
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 0.6rem 0.8rem;
    margin-bottom: 0.6rem;
}

.template-pick-toggle {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
}

.template-pick-details {
    margin-top: 0.4rem;
}

.template-pick-details summary {
    font-size: 0.85rem;
    color: var(--color-muted);
    cursor: pointer;
}

.template-pick-items {
    list-style: none;
    margin: 0.5rem 0 0;
    padding: 0;
    opacity: 0.4;
}

.template-pick-items.is-active {
    opacity: 1;
}

.template-pick-items li {
    padding: 0.2rem 0;
    font-size: 0.9rem;
}

/* --- Benutzerverwaltung ---------------------------------------------------- */

.user-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.user-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--color-border);
    flex-wrap: wrap;
}

.user-edit-form {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    flex-wrap: wrap;
}

.user-icon {
    font-size: 1.3rem;
}

.user-name {
    font-weight: 600;
    margin-right: auto;
}

.icon-input {
    width: 3.5rem;
}

.password-input {
    width: 10rem;
}

/* --- Account-Seite (settings.php) ---------------------------------------- */

.account-summary {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.user-icon-circle-large {
    width: 56px;
    height: 56px;
    background: var(--color-border);
    color: var(--color-text);
    flex: none;
}

.user-icon-circle-large .user-icon-glyph {
    font-size: 1.5rem;
}

.user-icon-circle-large .user-icon-initials {
    font-size: 0.6rem;
}

.account-name {
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

/* --- Kompaktere Account-Seite --------------------------------------------- */

.settings-page .account-summary.compact {
    margin-bottom: 1rem;
}

.settings-page .account-summary.compact .user-icon-circle-large {
    width: 44px;
    height: 44px;
}

.settings-page .account-summary.compact .user-icon-circle-large .user-icon-glyph {
    font-size: 1.15rem;
}

.settings-page .account-summary.compact .user-icon-circle-large .user-icon-initials {
    font-size: 0.5rem;
}

.settings-page .account-summary.compact .account-name {
    font-size: 1rem;
    margin-bottom: 0.3rem;
}

.button.small {
    display: inline-block;
    padding: 0.35rem 0.7rem;
    font-size: 0.8rem;
}

.install-button {
    display: block;
    width: 100%;
    text-align: center;
    margin-bottom: 1rem;
}

.settings-section {
    margin: 1.1rem 0;
}

.settings-section h3 {
    margin: 0 0 0.4rem;
    font-size: 0.95rem;
}

.inline-settings-form {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.inline-settings-form input {
    flex: 1;
    min-width: 8rem;
}

.inline-settings-form button {
    flex: none;
}

/* --- Design-Auswahl (settings.php) --------------------------------------- */

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

.theme-picker.compact {
    gap: 0.5rem;
}

.theme-option {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem;
    border: 2px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
}

.theme-picker.compact .theme-option {
    padding: 0.5rem;
    gap: 0.3rem;
}

.theme-option.is-selected {
    border-color: var(--color-primary);
}

.theme-option input[type="radio"] {
    position: absolute;
    top: 0.6rem;
    right: 0.6rem;
    margin: 0;
}

.theme-swatch {
    width: 100%;
    height: 72px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-picker.compact .theme-swatch {
    height: 48px;
}

.theme-swatch-card {
    width: 70%;
    height: 60%;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-swatch-dot {
    width: 20px;
    height: 20px;
    border-radius: 50%;
}

.theme-name {
    font-size: 0.85rem;
    font-weight: 600;
    text-align: center;
}

/* --- Größere Bildschirme ---------------------------------------------------- */

@media (min-width: 600px) {
    .app-main {
        padding: 1.5rem;
    }
}
