/**
 * E-Kodu põhistiilid
 */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #333;
}

.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Login vorm */
.login-container {
    background: white;
    padding: 40px;
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    width: 100%;
    max-width: 400px;
}

.login-container h1 {
    text-align: center;
    margin-bottom: 30px;
    color: #667eea;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: #555;
}

.form-group input {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 16px;
    transition: border-color 0.3s;
}

.form-group input:focus {
    outline: none;
    border-color: #667eea;
}

.btn {
    width: 100%;
    padding: 12px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.error {
    background: #fee;
    color: #c33;
    padding: 10px;
    border-radius: 5px;
    margin-bottom: 20px;
    border: 1px solid #fcc;
}

.success {
    background: #efe;
    color: #3c3;
    padding: 10px;
    border-radius: 5px;
    margin-bottom: 20px;
    border: 1px solid #cfc;
}

/* Pealeht */
.main-container {
    background: white;
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    min-height: 80vh;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid #eee;
}

.header h1 {
    color: #667eea;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 15px;
}

.user-info span {
    font-weight: 500;
}

.btn-small {
    padding: 8px 16px;
    background: #667eea;
    color: white;
    text-decoration: none;
    border-radius: 5px;
    font-size: 14px;
    transition: background 0.3s;
}

.btn-small:hover {
    background: #5568d3;
}

/* Inbox vorm */
.inbox-form {
    background: #f9f9f9;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 30px;
}

.inbox-form textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 16px;
    min-height: 100px;
    font-family: inherit;
}

.inbox-form textarea:focus {
    outline: none;
    border-color: #667eea;
}

/* Items list */
.items-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 15px;
}

.item-card {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 15px;
    transition: box-shadow 0.3s;
}

.item-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.item-header strong {
    color: #333;
    font-size: 16px;
}

.item-date {
    color: #999;
    font-size: 12px;
}

.item-content {
    color: #666;
    line-height: 1.6;
    margin-bottom: 15px;
}

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

.item-actions .btn-small {
    padding: 6px 12px;
    font-size: 13px;
}

.item-actions button {
    border: none;
    cursor: pointer;
}

/* Images grid */
.images-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 15px;
    margin-top: 15px;
}

.image-card {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    overflow: hidden;
    transition: box-shadow 0.3s;
}

.image-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.image-card img {
    width: 100%;
    height: 200px;
    object-fit: cover;
    display: block;
}

.image-info {
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.image-name {
    font-size: 14px;
    color: #333;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.image-card .item-actions {
    padding: 0 10px 10px 10px;
}

/* Lightbox modal */
.lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox-content {
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.lightbox-content img {
    max-width: 100%;
    max-height: 80vh;
    object-fit: contain;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.8);
}

.lightbox-caption {
    color: white;
    text-align: center;
    margin-top: 15px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.lightbox-close {
    position: absolute;
    top: 20px;
    right: 35px;
    color: white;
    font-size: 50px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.3s;
    z-index: 10000;
}

.lightbox-close:hover {
    color: #ccc;
}

.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: none;
    font-size: 40px;
    padding: 10px 20px;
    cursor: pointer;
    transition: background 0.3s;
    z-index: 10000;
}

.lightbox-nav:hover {
    background: rgba(255, 255, 255, 0.3);
}

.lightbox-prev {
    left: 20px;
}

.lightbox-next {
    right: 20px;
}

/* ========== USER DROPDOWN MENÜÜ ========== */
.user-dropdown {
    position: relative;
}

.user-dropdown-toggle {
    background: #667eea;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: background 0.2s;
}

.user-dropdown-toggle:hover {
    background: #5568d3;
}

.user-dropdown-menu {
    position: absolute;
    top: calc(100% + 5px);
    right: 0;
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    min-width: 200px;
    display: none;
    z-index: 1000;
    overflow: hidden;
}

.user-dropdown-menu.active {
    display: block;
}

.user-dropdown-menu a {
    display: block;
    padding: 12px 16px;
    color: #333;
    text-decoration: none;
    transition: background 0.2s;
    font-size: 14px;
}

.user-dropdown-menu a:hover {
    background: #f5f5f5;
}

.dropdown-divider {
    height: 1px;
    background: #e0e0e0;
    margin: 5px 0;
}

/* ========== MOBIILI VAADE ========== */
@media (max-width: 768px) {
    /* Header mobiilis - 2 rida kui vaja */
    .header {
        padding: 12px 15px;
        gap: 8px;
        flex-wrap: wrap;
    }

    .header h1 {
        font-size: 16px;
        margin: 0;
        flex: 1 1 auto;
        min-width: 120px;
    }

    .header h1 a {
        font-size: 15px;
    }

    /* Juhend nupp - väiksem mobiilis */
    .header button[onclick="openHelpModal()"] {
        padding: 6px 12px !important;
        font-size: 12px !important;
        gap: 4px !important;
        white-space: nowrap;
    }

    /* User dropdown mobiilis */
    .user-dropdown-toggle {
        padding: 6px 10px;
        font-size: 12px;
        white-space: nowrap;
    }

    /* Nool jääb nähtavaks - näitab et dropdown */

    .user-dropdown-menu {
        min-width: 180px;
        right: -10px;
    }

    .user-info {
        flex-direction: column;
        gap: 8px;
        width: 100%;
    }

    .user-info .btn-small {
        font-size: 13px;
        padding: 8px 12px;
        width: 100%;
        text-align: center;
    }

    .user-info span {
        font-size: 13px;
    }

    /* Item-card'id mobiilis */
    .item-card {
        padding: 12px;
    }

    .item-actions {
        flex-direction: column;
        gap: 8px;
    }

    .item-actions .btn-small,
    .item-actions button {
        width: 100%;
    }

    /* Lightbox noolekesed väiksemaks */
    .lightbox-prev,
    .lightbox-next {
        width: 40px;
        height: 40px;
        font-size: 24px;
    }

    .lightbox-prev {
        left: 10px;
    }

    .lightbox-next {
        right: 10px;
    }
}

/* ========================================
   MOBIILISÕBRALIK TEKSTI MURDMINE
   Pikad lingid, failinimed, galerii nimed
   ======================================== */

/* Kõik pealkirjad ja tugevdatud tekstid */
.item-header strong,
.item-card h3,
.item-card h4,
.playlist-title,
.audio-collection-preview h4 {
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
    max-width: 100%;
}

/* Lingid ja URL'id - PEAB murduma! */
.item-content a,
.bookmark-url,
a[href^="http"],
a[href^="https"] {
    word-wrap: break-word;
    word-break: break-all;
    overflow-wrap: break-word;
    max-width: 100%;
    display: inline-block;
}

/* Failinimed (audio, galeriid, failid) */
.playlist-item,
.file-item,
.gallery-item,
.audio-item {
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
}

/* Timeline item'id */
.timeline-item,
.item-card {
    overflow: hidden;
    max-width: 100%;
}

.timeline-item *,
.item-card * {
    max-width: 100%;
}

/* Üldine reegel kõigile tekstielementidele */
p, span, div, a, h1, h2, h3, h4, h5, h6 {
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Mobiiliekraanidel veelgi agressiivsem murdmine */
@media (max-width: 768px) {
    * {
        word-wrap: break-word;
        word-break: break-word;
        overflow-wrap: break-word;
    }

    /* Pealkirjad ja kuupäevad - UUENDATUD LAYOUT */
    .item-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .item-header strong {
        width: 100%;
        /* Lubame pealkirjal võtta mitu rida */
    }

    .item-date {
        align-self: flex-end;
        text-align: right;
        font-size: 11px;
    }
}
