/* ganz oben ergänzen, damit box-sizing wirklich überall gilt */
*,
*::before,
*::after {
    box-sizing: border-box;
}

/* Global Styles */
body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
    background-color: #f9f9f9;
    color: #333;
}

/* Container */
#app {
    width: 95%;
    max-width: 700px;
    margin: 20px auto;
    padding: 20px;
    background: #fff;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    border-radius: 10px;
    animation: fadeIn 0.5s ease-in-out;
    overflow-x: hidden; /* verhindert, dass die Tabelle minimal übersteht */
}

/* Header */
h1 {
    text-align: center;
    font-size: 2.2rem;
    margin-bottom: 20px;
    color: #007bff;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Form Styles (oben: Geschäft hinzufügen) – NICHT für das Artikel-Formular */
form:not(#addArticleForm) {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 15px;
    margin-bottom: 20px;
    align-items: center;
}

/* SPEZIELL: Formular auf der Artikelseite */
#addArticleForm {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 20px;
    align-items: center;
}

/* Textfelder und Select im Artikel-Formular über volle Breite */
#addArticleForm input[type="text"],
#addArticleForm select {
    flex: 1 1 100%;
}

/* Button-Zeile im Artikel-Formular */
#addArticleForm .add-actions {
    display: flex;
    flex: 1 1 100%;
    gap: 10px;
}

/* Buttons in der Button-Zeile jeweils 50 % */
#addArticleForm .add-actions button {
    flex: 1 1 50%;
}

/* Voice-Button optisch leicht absetzen (aber gleiche Grundoptik) */
#voiceAddBtn {
    background-color: #0f5bd7;
}

/* Hinweis-Text neben/unter dem Voice-Button */
#voiceAddStatus {
    display: block;
    margin-top: 4px;
    font-size: 0.85rem;
    color: #555;
}

input,
select,
button {
    padding: 12px;
    font-size: 14px;
    border: 1px solid #ddd;
    border-radius: 5px;
}

/* Globale Button-Basis (oben im Formular usw.) */
button {
    background-color: #007bff;
    color: white;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.3s ease, transform 0.2s ease;
}

button:hover {
    background-color: #0056b3;
    transform: scale(1.05);
}

/* Geschäfte-Startseite */
#storeList {
    list-style: none;
    padding: 0;
    margin: 20px 0;
}

.store-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f4f4f4;
    margin-bottom: 10px;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: box-shadow 0.2s ease-in-out;
    cursor: grab;
}

.store-item.dragging {
    opacity: 0.5;
    background-color: #e0e0e0;
    border: 2px dashed #007bff;
}

.store-item:hover {
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

/* Buttons in der Geschäfts-Liste – IMMER untereinander, gleich groß */
.store-actions {
    display: flex;
    flex-direction: column;   /* untereinander */
    gap: 6px;
    align-items: flex-end;    /* rechtsbündig, nimmt wenig Breite weg */
    min-width: 0;
}

/* Flex-Items sind: <a> und <form> */
.store-actions a,
.store-actions form {
    width: 140px;             /* fixe Breite, beide exakt gleich */
    display: flex;
}

/* Button im Form auf volle Breite ziehen */
.store-actions button {
    flex: 1 1 0;
}

/* Gemeinsamer Button-Look */
.store-actions a,
.store-actions button {
    align-items: center;
    justify-content: center;
    height: 32px;
    padding: 0.3rem 0.6rem;
    border-radius: 5px;
    font-size: 13px;
    font-weight: bold;
    text-decoration: none;
    border: none;
    cursor: pointer;
    transition: background 0.3s ease, transform 0.2s ease;
}

/* Anzeigen-Button (👀) */
.store-actions .view-store {
    background: #007bff;
    color: white;
}

.store-actions .view-store:hover {
    background: #0056b3;
    transform: scale(1.05);
}

/* PDF-Button (falls wieder aktiv) */
.store-actions .pdf-button {
    background: #6c63ff;
    color: white;
}

.store-actions .pdf-button:hover {
    background: #5548c8;
    transform: scale(1.05);
}

/* Löschen-Button (🗑️) in der Store-Liste */
.store-actions .delete-store {
    background: #dc3545;
    color: white;
}

.store-actions .delete-store:hover {
    background: #b02a37;
    transform: scale(1.05);
}

/* Tabelle */
#shoppingTable {
    width: 100%;
    max-width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
    text-align: center;
    table-layout: fixed; /* verhindert, dass einzelne Spalten die Breite sprengen */
}

#shoppingTable thead {
    background-color: #007bff;
    color: white;
}

#shoppingTable th,
#shoppingTable td {
    border: 1px solid #ddd;
    padding: 12px;
    font-size: 14px;
    word-wrap: break-word;
    overflow-wrap: anywhere; /* lange Wörter/Zahlen umbrechen */
}

/* Artikel-Spalte: lange Namen/Zahlen hart umbrechen */
#shoppingTable .cell-name {
    word-break: break-all;    /* bricht auch 1234567 um */
    overflow-wrap: anywhere;
}

#shoppingTable tbody tr {
    transition: background-color 0.2s ease-in-out;
    cursor: grab;
}

#shoppingTable tbody tr.dragging {
    opacity: 0.5;
    background-color: #f0f0f0;
    border: 2px dashed #007bff;
}

#shoppingTable tbody tr:nth-child(even) {
    background-color: #f9f9f9;
}

#shoppingTable tbody tr:hover {
    background-color: #e9ecef;
}

/* Delete-Button in der Artikel-Tabelle extra schmal halten */
#shoppingTable .delete-store {
    padding: 4px 6px;
    min-width: 0;
    width: 32px;
    box-sizing: border-box;
}

/* Vorschaubild (falls du das statt Link nutzt) */
#shoppingTable .cell-image img {
    max-width: 120px;
    height: auto;
    display: block;
    margin: 0 auto;
}

/* Drag-and-Drop Handle */
.drag-handle {
    width: 20px;
    height: 20px;
    background-color: #ccc;
    border-radius: 50%;
    margin: 0 auto;
    cursor: grab;
    transition: background-color 0.2s ease-in-out;
}

.drag-handle:active {
    background-color: #888;
    cursor: grabbing;
}

/* Animationen */
@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* Responsive Styles */
@media (max-width: 768px) {

    /* harte Begrenzung, damit nichts übersteht */
    html,
    body {
        max-width: 100%;
        overflow-x: hidden;
    }

    #app {
        width: 100%;
        max-width: 100%;
        margin: 0;
        padding: 15px;
        border-radius: 0;
        box-shadow: none;
    }

    /* nur die anderen Forms einklappbar machen */
    form:not(#addArticleForm) {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    /* Artikel-Formular bleibt flex-basiert */
    #addArticleForm {
        gap: 8px;
    }

    #addArticleForm .add-actions {
        flex-direction: row;
    }

    .store-item {
        flex-direction: column;
        align-items: flex-start;
        text-align: left;
    }

    .store-actions {
        align-items: stretch;   /* Buttons über die ganze Breite */
        width: 100%;
    }

    .store-actions a,
    .store-actions form {
        width: 100%;
    }

    .store-actions a,
    .store-actions button {
        height: 34px;
        font-size: 13px;
    }

    #shoppingTable {
        display: table;
        width: 100% !important;
        max-width: 100% !important;
        table-layout: fixed !important;
        font-size: 12px;
    }

    #shoppingTable th,
    #shoppingTable td {
        padding: 6px !important;
    }

    /* Artikel-Spalte im Mobile extra "eng" halten, Browser zum Umbrechen zwingen */
    #shoppingTable .cell-name {
        max-width: 0;              /* in Kombination mit table-layout: fixed -> hartes Brechen */
    }

    /* letzte Spalte (Aktion) hart klein halten */
    #shoppingTable th:last-child,
    #shoppingTable td:last-child {
        width: 40px;
        max-width: 40px;
    }

    #shoppingTable .delete-store {
        padding: 2px 4px;
        min-width: 0;
        width: 32px;
        box-sizing: border-box;
    }

    #shoppingTable td form {
        margin: 0;
        display: flex;
        justify-content: center;
    }
}

@media (max-width: 480px) {
    h1 {
        font-size: 1.5rem;
    }

    /* ganze Tabelle auf Handy kompakter */
    #shoppingTable {
        font-size: 12px;
        table-layout: fixed !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    #shoppingTable th,
    #shoppingTable td {
        padding: 6px !important;
        font-size: 12px !important;         /* Schrift nur auf Handy kleiner */
        word-break: break-all !important;    /* lange Wörter/Zahlen umbrechen */
        overflow-wrap: anywhere !important;
    }

    /* Artikel-Spalte besonders streng, damit 7+ Ziffern nicht sprengen */
    #shoppingTable .cell-name {
        max-width: 0 !important;
        word-break: break-all !important;
        overflow-wrap: anywhere !important;
    }

    .drag-handle {
        width: 15px;
        height: 15px;
    }

    input,
    select,
    button {
        padding: 8px;
        font-size: 13px;
    }
}

@media (max-width: 360px) {
    #shoppingTable th,
    #shoppingTable td {
        padding: 4px !important;
        font-size: 11px !important;       /* garantiert kleiner */
        word-break: break-all !important; /* verhindert Überlauf bei 7+ Ziffern */
        overflow-wrap: anywhere !important;
    }

    #shoppingTable .cell-name {
        font-size: 11px !important;       /* separat sicherstellen */
        max-width: 0 !important;          /* zwingt Browser zum Umbrechen */
        word-break: break-all !important;
    }

    .drag-handle {
        width: 12px;
        height: 12px;
    }

    .store-actions a,
    .store-actions button {
        height: 30px;
        font-size: 12px;
    }
}

/* ===================== */
/*  PROFIL-SEITE (profile.php) */
/* ===================== */

/* Body-Klasse optional: <body class="profile-page"> */
.profile-page #app {
    max-width: 700px;
}

/* Profil-Überschrift leicht größer lassen, aber Card-Style beibehalten */
.profile-page h1 {
    margin-bottom: 24px;
}

/* Formulare im Profil NICHT im globalen Grid, sondern sauber untereinander */
.profile-form {
    display: flex !important;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 24px;
    align-items: flex-start;
}

/* einzelne Reihen */
.profile-row {
    width: 100%;
}

/* Label im Profil */
.profile-label {
    display: block;
    margin-bottom: 4px;
    font-weight: 600;
}

/* Inputs im Profil */
.profile-input {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding: 0.6rem 0.8rem;
    font-size: 13px;
}

/* Submit-Button unten */
.profile-submit {
    margin-top: 4px;
}

.profile-submit button {
    min-width: 160px;
}

/* Farb-Palette für Profil (wird auch auf anderen Seiten genutzt, ist aber hier wichtig) */
.color-palette {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 4px;
    margin-bottom: 4px;
}

.color-swatch {
    width: 26px;
    height: 26px;
    border-radius: 999px;
    border: 2px solid transparent;
    cursor: pointer;
    padding: 0;
}

.color-swatch.is-selected {
    border-color: #111827;
    box-shadow: 0 0 0 2px rgba(0,0,0,0.25);
}

.color-info {
    font-size: 0.85rem;
    opacity: 0.85;
}

.profile-color-preview {
    margin-top: 4px;
}

/* Mobile-Optimierung Profil */
@media (max-width: 768px) {
    .profile-form {
        gap: 14px;
    }

    .profile-input {
        font-size: 1rem;
        padding: 0.7rem 0.9rem;
    }

    .color-palette {
        justify-content: center;
    }

    .color-swatch {
        width: 30px;
        height: 30px;
    }

    .profile-color-preview,
    .profile-submit {
        text-align: center;
        width: 100%;
    }

    .profile-submit button {
        width: 100%;
        max-width: 260px;
        font-size: 1rem;
        padding: 0.8rem 0.9rem;
    }
}
