/*
 * Community MVP - avsiktligt enkel CSS.
 * Inga ramverk, inga externa typsnitt, inga komponentbibliotek.
 * Målet är hög läsbarhet, tydliga klickytor och en lugn, något retro känsla.
 */
:root {
    --ink: #17231f;
    --muted: #5f6b66;
    --paper: #f3efe3;
    --panel: #fffdf6;
    --green: #315f52;
    --green-dark: #23483e;
    --line: #b9c0b8;
    --soft: #e5eadf;
    --danger: #8a332f;
    --warning: #7a5b1d;
    --radius: 10px;
}
* { box-sizing: border-box; }
html { background: #d8ddd5; color: var(--ink); font-family: Arial, Helvetica, sans-serif; font-size: 17px; }
body { margin: 0; background: var(--paper); min-height: 100vh; }
a { color: var(--green-dark); text-underline-offset: 3px; }
button, input, textarea, select { font: inherit; }
button, .button { min-height: 44px; }
.app-shell { max-width: 720px; margin: 0 auto; min-height: 100vh; background: var(--paper); border-inline: 1px solid #c8cec5; }
.topbar { position: sticky; top: 0; z-index: 30; display: grid; grid-template-columns: minmax(80px,1fr) auto minmax(80px,1fr); gap: .6rem; align-items: center; padding: .9rem 1rem; background: var(--green); color: white; border-bottom: 3px solid var(--green-dark); }
.topbar a, .topbar .link-button { color: white; }
.brand { font-weight: 800; text-decoration: none; font-size: 1.15rem; letter-spacing: .02em; color: white; text-align: center; }
.top-actions { display: flex; align-items: center; gap: .8rem; }
.inline-form { display: inline; margin: 0; }
.link-button { border: 0; background: transparent; padding: 0; min-height: 0; text-decoration: underline; cursor: pointer; }
.content { padding: 1rem 1rem 6.5rem; }
h1 { font-size: 2rem; margin: .3rem 0 1rem; }
h2 { font-size: 1.25rem; margin: 0 0 .8rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
p { line-height: 1.55; }
.muted { color: var(--muted); }
.small { font-size: .9rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; box-shadow: 2px 2px 0 rgba(23,35,31,.06); }
.card-header { display: flex; justify-content: space-between; gap: .8rem; align-items: center; margin-bottom: .8rem; }
.stack { display: grid; gap: .8rem; }
.grid-two { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
@media (max-width: 520px) { .grid-two { grid-template-columns: 1fr; } }
label { display: block; font-weight: 700; margin-bottom: .35rem; }
input[type=text], input[type=email], input[type=password], input[type=url], textarea, select {
    width: 100%; padding: .72rem .75rem; border: 2px solid #8d9991; border-radius: 7px; background: #fff; color: var(--ink);
}
textarea { min-height: 130px; resize: vertical; line-height: 1.5; }
input:focus, textarea:focus, select:focus, button:focus-visible, a:focus-visible { outline: 3px solid #e0a63b; outline-offset: 2px; }
.button, button.primary, button.secondary, button.danger { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; border-radius: 7px; padding: .65rem .9rem; border: 2px solid var(--green-dark); font-weight: 700; cursor: pointer; text-decoration: none; }
.button, button.primary { background: var(--green); color: white; }
.button.secondary, button.secondary { background: var(--panel); color: var(--green-dark); }
button.danger { background: #fff5f4; color: var(--danger); border-color: var(--danger); }
.actions { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.flash { border: 2px solid var(--green); background: #edf6f0; padding: .8rem; border-radius: 7px; margin-bottom: 1rem; }
.flash-error { border-color: var(--danger); background: #fff0ef; }
.flash-info { border-color: #48637a; background: #eef5fa; !important} 
.error-list { border-left: 5px solid var(--danger); background: #fff0ef; padding: .7rem 1rem; margin-bottom: 1rem; }
.profile-head { display: grid; grid-template-columns: 110px 1fr; gap: 1rem; align-items: center; }
.profile-photo, .profile-placeholder { width: 110px; height: 110px; border-radius: 12px; object-fit: cover; border: 3px solid var(--green-dark); background: var(--soft); }
.profile-placeholder { display: grid; place-items: center; font-size: 2.3rem; font-weight: 800; color: var(--green-dark); }
.bio { white-space: pre-wrap; overflow-wrap: anywhere; }
.gallery-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .45rem; }
.gallery-cell { aspect-ratio: 1 / 1; border: 1px solid #919c94; border-radius: 6px; overflow: hidden; background: #e6e4d8; position: relative; }
.gallery-cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery-empty { width: 100%; height: 100%; display: grid; place-items: center; color: #7b837d; font-size: .85rem; text-align: center; padding: .3rem; }
.gallery-editor { display: grid; grid-template-columns: repeat(3, 1fr); gap: .75rem; }
.gallery-editor button.primary {width: 75%;}
.crop-editor {width: 50%;}
.gallery-editor .slot { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: .55rem; min-width: 0; }
.gallery-editor .slot .gallery-cell { margin-bottom: .5rem; }
@media (max-width: 520px) { .gallery-editor { grid-template-columns: 1fr; } .gallery-editor .slot { display: block; grid-template-columns: 110px 1fr; gap: .7rem; } .crop-editor {width: 75%;} }
.journal-entry { border-top: 1px dashed var(--line); padding-top: .8rem; margin-top: .8rem; }
.journal-entry:first-of-type { border-top: 0; margin-top: 0; padding-top: 0; }
.journal-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.journal-image { max-width: 100%; border: 1px solid var(--line); border-radius: 7px; }
.bottom-nav { position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; width: min(720px, 100%); display: grid; grid-template-columns: repeat(3, 1fr); background: #e8e3d5; border-top: 2px solid var(--green-dark); z-index: 20; }
.nav-item { min-height: 64px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .1rem; text-decoration: none; color: var(--green-dark); font-weight: 700; }
.nav-item.active { background: var(--green); color: white; }
.nav-item.disabled { color: #7c817d; }
.nav-icon { font-size: 1.2rem; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .94rem; }
th, td { border-bottom: 1px solid var(--line); padding: .65rem .5rem; text-align: left; vertical-align: top; }
th { background: var(--soft); }
.code-field { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.note { border-left: 4px solid var(--warning); padding: .6rem .8rem; background: #fff8e7; }

/* ---------- v1.2: toppnavigation ---------- */
.topbar-side { min-width: 0; display: flex; align-items: center; }
.topbar-right { justify-content: flex-end; }
.back-link { color: white; text-decoration: none; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account-menu { position: relative; }
.account-menu summary { list-style: none; cursor: pointer; color: white; border: 2px solid rgba(255,255,255,.75); border-radius: 7px; min-width: 44px; min-height: 44px; display: grid; place-items: center; font-size: 1.25rem; }
.account-menu summary::-webkit-details-marker { display: none; }
.account-menu-panel { position: absolute; right: 0; top: calc(100% + .55rem); width: min(280px, 82vw); padding: .45rem; background: var(--panel); border: 2px solid var(--green-dark); border-radius: 9px; box-shadow: 5px 5px 0 rgba(23,35,31,.18); display: grid; z-index: 50; }
.account-menu-panel a, .menu-logout { color: var(--ink); text-align: left; padding: .75rem .7rem; text-decoration: none; border: 0; border-bottom: 1px solid var(--line); background: transparent; width: 100%; cursor: pointer; min-height: 44px; }
.account-menu-panel form:last-child .menu-logout { border-bottom: 0; }
@media (max-width: 420px) { .back-link span { display: none; } .topbar { grid-template-columns: 48px 1fr 48px; } }

/* ---------- v1.2: standardiserade bilder ---------- */
.avatar-128, .thumb-128 { width: 128px; height: 128px; object-fit: cover; border-radius: 12px; border: 1px solid var(--line); background: var(--soft); display: block; }
.avatar-small { width: 54px; height: 54px; object-fit: cover; border-radius: 9px; border: 1px solid var(--line); background: var(--soft); flex: 0 0 auto; }
.avatar-placeholder-small { width: 54px; height: 54px; border-radius: 9px; background: var(--soft); border: 1px solid var(--line); display: grid; place-items: center; font-weight: 800; color: var(--green-dark); flex: 0 0 auto; }
.thumb-512 { width: 100%; max-width: 512px; aspect-ratio: 1; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); display: block; }
.image-link { display: block; border-radius: 10px; }
.image-page-image { display: block; width: 100%; max-height: 78vh; object-fit: contain; background: #151b18; border-radius: 10px; border: 1px solid #101713; }
.image-meta { margin-top: .75rem; }

/* ---------- v1.2: cropverktyg ---------- */
.crop-editor { margin-top: .75rem; padding: .75rem; background: #e8e4d7; border: 1px solid var(--line); border-radius: 9px; }
.crop-editor canvas { display: block; width: min(100%, 360px); height: auto; aspect-ratio: 1; margin: 0 auto .7rem; border-radius: 9px; touch-action: none; cursor: grab; background: #ddd8ca; }
.crop-editor canvas:active { cursor: grabbing; }
.crop-zoom-label { max-width: 360px; margin: 0 auto; }
.crop-zoom-label input { width: 100%; }

/* ---------- v1.2: journal ---------- */
.journal-preview { display: grid; grid-template-columns: 128px 1fr; gap: .85rem; padding: .9rem 0; border-top: 1px dashed var(--line); color: inherit; text-decoration: none; }
.journal-preview:first-child { border-top: 0; padding-top: 0; }
.journal-preview:hover h3 { text-decoration: underline; }
.journal-preview-text { min-width: 0; }
.journal-preview .thumb-placeholder { width: 128px; height: 128px; border-radius: 10px; border: 1px dashed var(--line); display: grid; place-items: center; color: var(--muted); background: #ebe7dc; }
.journal-entry-full { max-width: 680px; }
.journal-entry-full .journal-body { font-size: 1.04rem; line-height: 1.7; }
.journal-entry-image { margin: 1rem 0; }
.pagination, .entry-nav { display: flex; justify-content: space-between; gap: .8rem; align-items: center; margin: 1rem 0; }
@media (max-width: 520px) { .journal-preview { grid-template-columns: 92px 1fr; } .journal-preview .thumb-128, .journal-preview .thumb-placeholder { width: 92px; height: 92px; } }

/* ---------- v1.2: Världen ---------- */
.world-compose textarea { min-height: 105px; }
.world-post { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem; margin-bottom: .8rem; }
.world-author { display: flex; gap: .7rem; align-items: center; margin-bottom: .65rem; }
.world-author-main { min-width: 0; flex: 1; }
.world-body { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.55; }
.world-image-wrap { margin: .8rem 0; }
.world-replies { margin: .8rem 0 0 1.2rem; border-left: 3px solid var(--soft); padding-left: .75rem; }
.world-reply { padding: .6rem 0; border-top: 1px dotted var(--line); }
.world-reply:first-child { border-top: 0; }
.world-reply-head { display: flex; gap: .45rem; align-items: baseline; flex-wrap: wrap; }
.reply-form { margin-top: .7rem; }
.reply-form textarea { min-height: 72px; }
.last-seen-marker { display: flex; gap: .7rem; align-items: center; margin: 1rem 0; color: var(--muted); font-weight: 700; font-size: .92rem; }
.last-seen-marker::before, .last-seen-marker::after { content: ''; flex: 1; border-top: 2px solid var(--line); }

/* ---------- v1.2: bildkommentarer ---------- */
.image-comment { display: flex; gap: .7rem; padding: .75rem 0; border-top: 1px solid var(--line); }
.image-comment:first-child { border-top: 0; }
.comment-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.journal-main-image { display: block; width: 100%; max-width: 680px; height: auto; border-radius: 10px; border: 1px solid var(--line); }


/* ---------- v1.2.1: tillfälliga admin-raderingsverktyg ---------- */
.admin-delete-form { margin-top: .65rem; }
.world-author .admin-delete-form { margin: 0 0 0 auto; flex: 0 0 auto; }
.world-author .admin-delete-form button { min-height: 36px; padding: .35rem .55rem; font-size: .82rem; }
.image-comment .admin-delete-form button, .world-reply .admin-delete-form button { min-height: 36px; padding: .35rem .55rem; font-size: .82rem; }
.admin-warning { border: 2px solid var(--danger); }

/* Generell bildregel: bilder får aldrig spränga sin parent-container. */
img { max-width: 100%; height: auto; }

/* ---------- v1.3: generell bildregel ---------- */
img { display: block; max-width: 100%; height: auto; }

/* ---------- v1.3: återanvändbara flikar ---------- */
.tabs { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: .35rem; margin: 0 0 1rem; padding: .3rem; background: #e4e0d3; border: 1px solid var(--line); border-radius: 10px; }
.tab { position: relative; min-height: 44px; display: grid; place-items: center; padding: .55rem .65rem; border-radius: 7px; text-decoration: none; font-weight: 800; color: var(--green-dark); }
.tab--active { background: var(--green); color: white; }
.tab--new:not(.tab--active)::after { content: ''; width: 8px; height: 8px; border-radius: 2px; background: var(--green); position: absolute; top: 7px; right: 8px; }

/* ---------- v1.3: personer/vänner ---------- */
.person-list { display: grid; }
.person-row { display: flex; gap: .75rem; align-items: center; justify-content: space-between; padding: .75rem 0; border-top: 1px solid var(--line); }
.person-row:first-child { border-top: 0; }
.person-main, .guestbook-author { display: flex; gap: .7rem; align-items: center; min-width: 0; text-decoration: none; color: var(--ink); }
.person-main > span:last-child, .guestbook-author > span:last-child { display: grid; min-width: 0; }
.author-link { text-decoration: none; color: var(--ink); }
.search-row { display: grid; grid-template-columns: 1fr auto; gap: .6rem; align-items: end; }
.compact-actions { justify-content: flex-end; }
.compact-actions form, .profile-actions form, .compact-form { margin: 0; }
.status-chip { display: inline-flex; min-height: 40px; align-items: center; padding: .45rem .65rem; border: 1px solid var(--line); border-radius: 7px; background: var(--soft); font-weight: 700; }
.sr-only { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0,0,0,0) !important; white-space: nowrap !important; border: 0 !important; }

/* Ikonernas innehåll definieras i CSS så designen kan bytas utan PHP-ändringar. */
.message-button { position: relative; width: 46px; height: 46px; flex: 0 0 46px; display: grid; place-items: center; border: 2px solid var(--green-dark); border-radius: 8px; text-decoration: none; background: var(--panel); color: var(--green-dark); }
.message-icon::before { content: '✉'; font-size: 1.25rem; }
.message-button--new { background: var(--soft); border-width: 3px; }
.message-button--new .message-icon::before { content: '✉'; }
.message-button--new::after { content: ''; width: 7px; height: 7px; background: var(--green-dark); border-radius: 2px; position: absolute; transform: translate(14px,-14px); }
.friends-nav-icon::before { content: '♟♟'; }
.world-nav-icon::before { content: '◎'; }
.bottom-nav-item--new:not(.active) { box-shadow: inset 0 4px 0 var(--green); background: #dfe9e1; }

/* ---------- v1.3: profil ---------- */
.profile-card h1 { margin: 0 0 .2rem; }
.profile-actions { margin-top: .9rem; }

/* ---------- v1.3: gästbok ---------- */
.guestbook-compose { padding-bottom: 1rem; margin-bottom: .5rem; border-bottom: 2px solid var(--line); }
.guestbook-entry { padding: 1rem 0; border-top: 1px solid var(--line); }
.guestbook-entry:first-child { border-top: 0; }
.guestbook-body { margin: .65rem 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.55; }
.small-button { min-height: 36px !important; padding: .35rem .55rem !important; font-size: .85rem; }

/* ---------- v1.3: chatt ---------- */
.chat-history { display: grid; gap: .55rem; padding: .35rem 0 1rem; }
.chat-message { display: flex; }
.chat-message--mine { justify-content: flex-end; }
.chat-message--theirs { justify-content: flex-start; }
.chat-bubble { max-width: min(84%, 520px); padding: .7rem .8rem; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.chat-message--mine .chat-bubble { background: #e1eadf; border-color: #9bac9f; }
.chat-body { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.45; margin-bottom: .25rem; }
.chat-compose { position: sticky; bottom: 66px; z-index: 12; display: grid; grid-template-columns: 1fr auto; gap: .55rem; align-items: end; padding: .7rem; margin: .5rem -.25rem 1rem; background: rgba(243,239,227,.97); border: 2px solid var(--green-dark); border-radius: 10px; }
.chat-compose textarea { min-height: 52px; max-height: 150px; }

/* ---------- v1.3: Världen ---------- */
.world-feed { display: grid; gap: 1rem; }
.world-post { border: 2px solid #aeb8af; box-shadow: 3px 3px 0 rgba(23,35,31,.07); margin-bottom: 0; padding: 1rem; }
.world-post--mentioned { border-color: #7a5b1d; background: #fff8df; box-shadow: inset 5px 0 0 #c79b3b, 3px 3px 0 rgba(23,35,31,.07); }
.mention-note { display: inline-block; margin: 0 0 .6rem; padding: .3rem .45rem; background: #f0ddb0; border-radius: 5px; font-weight: 700; color: #5f4515; }
.mention { font-weight: 800; }
.world-thumb { width: auto; max-width: min(100%, 512px); max-height: 512px; object-fit: contain; border-radius: 10px; border: 1px solid var(--line); }

/* ---------- v1.3: 3×3 ---------- */
.mosaic-tool { border-width: 2px; }

@media (max-width: 520px) {
    .person-row { align-items: flex-start; }
    .compact-actions { flex-direction: column; align-items: stretch; }
    .search-row { grid-template-columns: 1fr; }
    .chat-compose { grid-template-columns: 1fr; bottom: 64px; }
    .chat-bubble { max-width: 92%; }
}
