body {
    font-family: Arial, sans-serif;
    background-color: #1b2230;
    color: #fff;
    margin: 0;
}

.navbar {
    background: #1a1f2d;
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.navbar nav {
    width: 100%;
    display: flex;
    justify-content: space-between;
}

.nav-left a,
.nav-right a {
    color: white;
    text-decoration: none;
    font-weight: bold;
    margin-left: 15px;
}

.nav-left a:hover,
.nav-right a:hover {
    text-decoration: underline;
}

.nav-left {
    display: flex;
    gap: 15px;
}

.nav-right {
    display: flex;
    gap: 15px;
}

/* ======================
   Grid layout
   ====================== */
.grid {
    display: grid;
    grid-template-areas:
        "asetukset lisa_juoma pikajuomat"
        "status graafi graafi"
        "historia historia historia";
    grid-template-columns: 1fr 1fr 1fr;
    gap: 1rem;
    padding: 1rem;
}

/* Korttien paikat */
.card.asetukset { grid-area: asetukset; }
.card.lisa-juoma { grid-area: lisa_juoma; }
.card.pikajuomat { grid-area: pikajuomat; }
.card.status { grid-area: status; }
.card.graafi { grid-area: graafi; }
.card.historia { grid-area: historia; }

/* Kortit */
.card {
    background: #242b3d;
    padding: 1rem;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    height: auto;
    box-sizing: border-box;   /* ✅ varmistaa ettei padding riko leveyttä */
    max-width: 100%;          /* ✅ ei mene yli ruudun */
    overflow-wrap: break-word; /* ✅ tekstin rivinvaihto */
}


.card h2 {
    margin-top: 0;
}

/* Yhtenäiset mitat ensimmäisen rivin korteille + statukselle */
.card.asetukset,
.card.lisa-juoma,
.card.pikajuomat,
.card.status {
    flex: 1 1 280px;
    max-width: 100%;
    min-height: 300px;
    box-sizing: border-box;
}

/* Graafi venyy statuksen vierellä */
.card.graafi {
    min-height: 300px;
    overflow-x: auto;       /* ✅ estää yli menon */
    max-width: 100%;        /* ✅ kortti ei mene yli ruudun */
}
.card.graafi img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Historia koko rivin leveydellä */
.card.historia {
    flex: 1 1 100%;
    overflow-x: auto;   /* ✅ tekee taulukosta rullaavan jos leveä */
    max-width: 100%;
}

.card.historia table {
    width: 100%;
    table-layout: auto;
    border-collapse: collapse;
    word-wrap: break-word;
}

.card.historia th,
.card.historia td {
    white-space: normal;   /* ✅ teksti rivittyy, ei pakota scrollia */
    word-break: break-word;
    overflow-wrap: break-word;
}

/* ======================
   Taulukko
   ====================== */
.table {
    width: 100%;
    border-collapse: collapse;
}

.table th, .table td {
    padding: 0.4rem;
    text-align: left;
}

.table tr:nth-child(even) {
    background: #2e364b;
}

/* ======================
   Napit
   ====================== */
.btn {
    background-color: #3d7eff;
    color: white;
    border: none;
    padding: 0.4rem 0.8rem;
    cursor: pointer;
    border-radius: 4px;
}
.btn:hover {
    background-color: #1a5fff;
}

.danger-btn {
    background-color: #cc3333;
}
.danger-btn:hover {
    background-color: #aa0000;
}

/* ======================
   Juoman lisäys
   ====================== */
.when {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.when label {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    margin: 0;
}

/* ======================
   Responsiivisuus
   ====================== */
@media (max-width: 1200px) {
    .grid {
        grid-template-areas:
            "asetukset lisa_juoma"
            "pikajuomat status"
            "graafi graafi"
            "historia historia";
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 768px) {
    .grid {
        grid-template-areas:
            "asetukset"
            "lisa_juoma"
            "pikajuomat"
            "status"
            "graafi"
            "historia";
        grid-template-columns: 1fr;
    }

    .card {
        width: 100%;
    }

    table {
        font-size: 0.9rem;
    }
    th, td {
        padding: 0.3rem;
    }
}

/* ======================
   Lomakkeet
   ====================== */
.form-container {
    max-width: 400px;
    margin: 60px auto;
    padding: 20px;
    background: #22293b;
    border-radius: 8px;
    box-shadow: 0 0 10px rgba(0,0,0,0.3);
}

.form-container h2 {
    margin-bottom: 20px;
    color: #fff;
    text-align: center;
}

.form-box {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.form-box label {
    color: #ccc;
    font-weight: bold;
}

.form-box input {
    padding: 8px;
    border: 1px solid #555;
    border-radius: 4px;
    background: #1a1f2d;
    color: #fff;
}

.settings-form label {
    display: block;
}

.btn {
    padding: 10px;
    background: #3a66ff;
    border: none;
    border-radius: 4px;
    color: white;
    font-weight: bold;
    cursor: pointer;
}
.btn:hover {
    background: #2e52cc;
}

/* ======================
   Pikajuomat
   ====================== */
#favorites-wrap {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
#favorites-wrap .quick-add,
#favorites-wrap .fav-remove {
    margin-left: 4px;
    margin-top: 6px;
    margin-right: 4px;
}
#favorites-wrap .fav-remove {
    margin-left: 4px;
}
.fav-add-form {
    margin-top: 6px;
}
.fav-add-form select,
.fav-add-form button {
    margin-top: 4px;
}

/* ======================
   Hallinta
   ====================== */
.manage-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    padding: 1rem;
    margin: 0 auto;
    min-height: calc(100vh - 100px);
    justify-content: flex-start;
}
.manage-card {
    background: #242b3d;
    padding: 1rem;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    width: 100%;
    max-width: 800px;
}
.manage-card h2 {
    text-align: center;
}
.manage-card form {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}
.manage-card form label {
    display: flex;
    flex-direction: column;
}
.manage-table {
    background: #242b3d;
    padding: 1rem;
    border-radius: 8px;
    width: 100%;
    max-width: 800px;
}

/* ======================
   Ilmoitukset
   ====================== */
.flash-ok {
    background-color: #2e7d32;
    color: white;
    padding: 10px;
    border-radius: 4px;
    margin-bottom: 1rem;
}
.flash-err {
    background-color: #c62828;
    color: white;
    padding: 10px;
    border-radius: 4px;
    margin-bottom: 1rem;
}

/* ======================
   Parannettu mobiilituki
   ====================== */
html, body {
    overflow-x: hidden;
}
@media (max-width: 768px) {
    .card.asetukset,
    .card.lisa-juoma,
    .card.pikajuomat,
    .card.status,
    .card.graafi,
    .card.historia {
        flex: 1 1 100% !important;
        min-width: auto !important;
        max-width: 100% !important;
    }
    .table {
        display: block;
        width: 100%;
        overflow-x: auto;
        white-space: nowrap;
    }
    .status-graph-container {
        flex-direction: column;
    }
    input, select, button {
        max-width: 100%;
    }
}
