* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: #f3f4f6;
    color: #1f2937;
}
main { max-width: 1100px; margin: 0 auto; padding: 16px; }
.topp {
    display: flex; justify-content: space-between; align-items: center;
    background: #1f2937; color: #fff; padding: 12px 16px;
}
.topp h1 { font-size: 1.25rem; margin: 0; }
.topp a { color: #d1d5db; }
.kort {
    background: #fff; border-radius: 10px; padding: 16px 20px; margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
h2 { margin-top: 0; font-size: 1.1rem; }
label { display: block; margin-bottom: 12px; font-size: .9rem; font-weight: 600; }
input[type=text], input[type=password], input[type=date], input[type=file], textarea {
    display: block; width: 100%; margin-top: 4px; padding: 8px 10px;
    border: 1px solid #d1d5db; border-radius: 6px; font: inherit; font-weight: normal;
}
.rad { display: grid; grid-template-columns: 1fr 2fr; gap: 12px; }
button {
    background: #374151; color: #fff; border: 0; border-radius: 6px;
    padding: 9px 16px; font: inherit; cursor: pointer;
}
button:hover { background: #111827; }
button.primar { background: #2563eb; font-weight: 600; }
button.primar:hover { background: #1d4ed8; }
button.radera { background: none; color: #b91c1c; padding: 4px 0; font-size: .85rem; }
button.radera:hover { text-decoration: underline; }
.hint, .liten { font-size: .8rem; color: #6b7280; }
.info { background: #ecfdf5; border: 1px solid #a7f3d0; padding: 10px 14px; border-radius: 6px; }
.meddelande { padding: 12px 16px; border-radius: 6px; margin-bottom: 16px; line-height: 1.5; overflow-wrap: anywhere; }
.meddelande.info    { background: #ecfdf5; border: 1px solid #a7f3d0; }
.meddelande.varning { background: #fffbeb; border: 1px solid #fcd34d; }
.meddelande.fel     { background: #fef2f2; border: 1px solid #fca5a5; border-left: 5px solid #dc2626; }
.meddelande .liten  { margin-top: 6px; }
.topp nav a { color: #d1d5db; }
.fel { background: #fef2f2; border: 1px solid #fecaca; padding: 10px 14px; border-radius: 6px; }

.filter { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 16px; }
.filter label { margin: 0; }
.filter input { width: auto; }

.skapa {
    display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end;
    background: #eff6ff; padding: 12px; border-radius: 8px; margin-bottom: 16px;
}
.skapa label { margin: 0; flex: 1 1 260px; }
.skapa label.check { flex: 0 0 auto; display: flex; gap: 6px; align-items: center; font-weight: normal; }

.bilder {
    list-style: none; padding: 0; margin: 0;
    display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px;
}
.bilder li { border: 1px solid #e5e7eb; border-radius: 8px; overflow: hidden; background: #fafafa; }
.val { position: relative; margin: 0; background: #111827; }
.val input[type=checkbox] { position: absolute; top: 8px; left: 8px; width: 22px; height: 22px; z-index: 2; cursor: pointer; }
.val button.visa { display: block; width: 100%; padding: 0; background: none; border-radius: 0; cursor: zoom-in; }
.val img { display: block; width: 100%; height: 220px; object-fit: contain; }
.val .form {
    position: absolute; top: 8px; right: 8px; background: rgba(0,0,0,.6); color: #fff;
    font-size: .72rem; padding: 2px 7px; border-radius: 10px; pointer-events: none;
}
.meta { padding: 8px 10px; font-size: .88rem; font-weight: normal; }
.atgarder { display: flex; gap: 6px; align-items: center; margin-top: 6px; }
button.ikon { background: #e5e7eb; color: #111827; padding: 3px 10px; font-size: 1.05rem; line-height: 1.2; }
button.ikon:hover { background: #d1d5db; }
.atgarder .radera { margin-left: auto; }

#visare {
    border: 0; padding: 0; background: #000; max-width: 96vw; max-height: 96vh; border-radius: 8px;
}
#visare::backdrop { background: rgba(0,0,0,.85); }
#visare img { display: block; max-width: 96vw; max-height: calc(96vh - 48px); margin: 0 auto; object-fit: contain; cursor: zoom-out; }
.visare-rad { display: flex; gap: 14px; align-items: center; padding: 8px 12px; color: #fff; font-size: .9rem; }
.visare-rad a { color: #93c5fd; }
.visare-rad .visare-stang { margin-left: auto; }

.login { max-width: 360px; margin: 12vh auto; background: #fff; padding: 24px; border-radius: 10px; }

@media (max-width: 600px) {
    .rad { grid-template-columns: 1fr; }
}

button.ikon.info {
    font-family: Georgia, serif; font-style: italic; font-weight: 700;
    width: 30px; height: 30px; padding: 0; border-radius: 50%;
    background: #dbeafe; color: #1d4ed8;
}
button.ikon.info:hover { background: #bfdbfe; }

#exifruta {
    width: min(720px, 94vw); max-height: 88vh; padding: 0; border: 0; border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0,0,0,.3);
}
#exifruta::backdrop { background: rgba(0,0,0,.5); }
.exif-topp {
    position: sticky; top: 0; display: flex; justify-content: space-between; align-items: center;
    background: #1f2937; color: #fff; padding: 10px 16px;
}
.exif-topp h2 { margin: 0; font-size: 1rem; }
.exif-topp button { background: none; font-size: 1.1rem; padding: 2px 6px; }
.exif-innehall { padding: 4px 16px 16px; overflow-wrap: anywhere; }
.exif-innehall h3 { font-size: .95rem; margin: 16px 0 6px; }
.exif-tabell { width: 100%; border-collapse: collapse; font-size: .86rem; }
.exif-tabell th, .exif-tabell td { text-align: left; vertical-align: top; padding: 5px 8px; border-bottom: 1px solid #e5e7eb; }
.exif-tabell th { width: 38%; font-weight: 600; color: #374151; }
.exif-tabell td { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .82rem; }
.exif-innehall details { margin-top: 16px; }
.exif-innehall summary { cursor: pointer; font-weight: 600; font-size: .95rem; }

/* Systemkontroll */
.diagnos { width: 100%; border-collapse: collapse; font-size: .9rem; }
.diagnos th, .diagnos td { text-align: left; vertical-align: top; padding: 8px; border-bottom: 1px solid #e5e7eb; }
.diagnos th { width: 30%; font-weight: 600; }
.diagnos td.status { width: 28px; text-align: center; font-weight: 700; }
.diagnos tr.ok td.status { color: #059669; }
.diagnos tr.varning td.status { color: #b45309; }
.diagnos tr.fel td.status { color: #dc2626; }
.diagnos tr.fel { background: #fef2f2; }
.diagnos tr.varning { background: #fffbeb; }
.diagnos .atgard {
    margin-top: 6px; padding: 6px 8px; background: #111827; color: #f9fafb; border-radius: 4px;
    font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .8rem; overflow-wrap: anywhere;
}
@media (max-width: 600px) {
    .diagnos th { width: auto; }
    .diagnos tr { display: grid; grid-template-columns: 28px 1fr; }
    .diagnos tr > td:last-child { grid-column: 2; }
}

/* Mallval och mallar */
select { display: block; margin-top: 4px; padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 6px; font: inherit; font-weight: normal; background: #fff; max-width: 100%; }
.skapa label.mallval { flex: 0 1 240px; }
.skapa label.mallval a { display: inline-block; margin-top: 3px; font-weight: normal; }
code { background: #f3f4f6; padding: 1px 4px; border-radius: 3px; font-size: .85em; }
.knapp { display: inline-block; background: #2563eb; color: #fff; padding: 9px 16px; border-radius: 6px; text-decoration: none; font-weight: 600; }
.malltabell { width: 100%; border-collapse: collapse; margin-bottom: 14px; }
.malltabell th, .malltabell td { text-align: left; padding: 9px 8px; border-bottom: 1px solid #e5e7eb; vertical-align: middle; }
.malltabell .knappar { text-align: right; white-space: nowrap; }
.malltabell .knappar form { display: inline-flex; gap: 12px; align-items: center; }
button.lank { background: none; color: #1d4ed8; padding: 0; text-decoration: underline; font-size: inherit; }
button.lank.radera { color: #b91c1c; }
.malleditor { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.malleditor .kort { margin-bottom: 0; }
#malltext { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .9rem; line-height: 1.5; min-height: 420px; resize: vertical; }
.rad-knappar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.makron { position: sticky; top: 12px; max-height: calc(100vh - 24px); overflow: auto; }
.makron h3 { font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; color: #6b7280; margin: 14px 0 6px; }
.makron ul { list-style: none; margin: 0; padding: 0; }
.makron li { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; font-size: .82rem; color: #4b5563; }
button.makro {
    align-self: flex-start; background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe;
    font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .8rem; padding: 3px 7px;
}
button.makro:hover { background: #dbeafe; }
@media (max-width: 860px) {
    .malleditor { grid-template-columns: 1fr; }
    .makron { position: static; max-height: none; }
    .malltabell .knappar { white-space: normal; }
}

/* Sidhuvud på smal skärm */
.topp { flex-wrap: wrap; gap: 4px 16px; }
.topp nav { font-size: .9rem; }
@media (max-width: 600px) {
    .topp h1 { font-size: 1.1rem; }
    .topp nav { width: 100%; }
}
@media (max-width: 600px) {
    .malltabell thead { display: none; }
    .malltabell tr { display: flex; flex-direction: column; padding: 8px 0; border-bottom: 1px solid #e5e7eb; }
    .malltabell td { border: 0; padding: 2px 0; }
    .malltabell td.liten { display: none; }
    .malltabell .knappar { text-align: left; }
    .malltabell .knappar form { flex-wrap: wrap; }
}
