/* QuickTiles – gemensam stil för startsida, inloggning och admin */
:root {
  color-scheme: light;
  --bg: #eef1f5;
  --bg2: #e3e8ef;
  --surface: #ffffff;
  --surface2: #f4f6f9;
  --text: #1a1e24;
  --muted: #69727d;
  --border: rgba(20, 30, 45, .12);
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --danger: #d23f3f;
  --ok: #1f9d55;
  --shadow: 0 1px 2px rgba(15, 25, 40, .08), 0 6px 18px rgba(15, 25, 40, .10);
  --shadow-lift: 0 10px 30px rgba(15, 25, 40, .28);
  --radius: 14px;
  --tile: 140px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #13161b;
    --bg2: #181c22;
    --surface: #222831;
    --surface2: #2a313b;
    --text: #e7eaee;
    --muted: #9aa4af;
    --border: rgba(255, 255, 255, .10);
    --accent: #5b8cff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 18px rgba(0, 0, 0, .35);
    --shadow-lift: 0 12px 32px rgba(0, 0, 0, .6);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #13161b;
  --bg2: #181c22;
  --surface: #222831;
  --surface2: #2a313b;
  --text: #e7eaee;
  --muted: #9aa4af;
  --border: rgba(255, 255, 255, .10);
  --accent: #5b8cff;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 18px rgba(0, 0, 0, .35);
  --shadow-lift: 0 12px 32px rgba(0, 0, 0, .6);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: linear-gradient(160deg, var(--bg) 0%, var(--bg2) 100%) fixed;
  color: var(--text);
  font-size: 15px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }

/* ---------- knappar och fält ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 16px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface2); cursor: pointer;
  text-decoration: none; color: var(--text); white-space: nowrap;
}
.btn:hover { filter: brightness(.97); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 13px; color: var(--muted); }
.input, select.input {
  width: 100%; min-height: 42px; padding: 8px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface2); outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.error-text { color: var(--danger); font-size: 14px; min-height: 1.2em; margin: 4px 0 10px; }

/* segmenterade val */
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: inline-block; padding: 7px 12px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface2); font-size: 14px;
}
.seg input:checked + span { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* färgrutor */
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 30px; height: 30px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0;
  box-shadow: inset 0 0 0 1px var(--border);
}
.swatch.auto {
  background: conic-gradient(#e85d5d, #f0b429, #3ebd77, #3b8cf0, #a061e8, #e85d5d);
}
.swatch[aria-pressed="true"] { border-color: var(--text); }

/* ---------- dialoger ---------- */
dialog {
  border: none; padding: 0; border-radius: 18px; background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-lift); width: min(440px, calc(100vw - 32px)); max-height: calc(100dvh - 32px);
}
dialog::backdrop { background: rgba(10, 14, 20, .45); }
.dlg { padding: 20px; overflow: auto; max-height: calc(100dvh - 32px); }
.dlg h2 { margin: 0 0 16px; font-size: 19px; }
.dlg .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.dlg .actions .left { margin-right: auto; }

/* inställningspanelen: glider in från höger (mobil: nerifrån) */
dialog.sheet {
  margin: 0 0 0 auto; height: 100dvh; max-height: 100dvh; width: min(380px, 100vw); border-radius: 18px 0 0 18px;
}
dialog.sheet .dlg { max-height: 100dvh; height: 100%; }
@media (max-width: 600px) {
  dialog.sheet { margin: auto 0 0 0; width: 100vw; max-width: 100vw; height: auto; max-height: 88dvh; border-radius: 18px 18px 0 0; }
  dialog.sheet .dlg { max-height: 88dvh; }
}
.section { padding: 14px 0; border-top: 1px solid var(--border); }
.section:first-of-type { border-top: none; padding-top: 0; }
.section h3 { margin: 0 0 10px; font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.section .row + .row { margin-top: 8px; }
.close-x {
  position: absolute; top: 12px; right: 12px; width: 36px; height: 36px; border-radius: 50%;
  border: none; background: transparent; cursor: pointer; font-size: 22px; color: var(--muted);
}
.sheet-head { position: relative; }
input[type="range"] { width: 100%; accent-color: var(--accent); }

/* ---------- meddelanden ---------- */
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  box-shadow: var(--shadow-lift); opacity: 0; pointer-events: none; transition: all .2s ease;
  max-width: calc(100vw - 32px); z-index: 100; font-size: 14px;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- startsidan ---------- */
#bg {
  position: fixed; inset: 0; background-size: cover; background-position: center; z-index: -1;
}
body.has-bg .tile-name, body.has-bg .profile-pill { color: #fff; text-shadow: 0 1px 3px rgba(0, 0, 0, .7); }
body.has-bg .profile-pill { background: rgba(0, 0, 0, .25); }

.topbar { display: flex; justify-content: center; padding: 14px 16px 0; }
.profile-pill {
  display: inline-flex; align-items: center; gap: 6px; border: none; cursor: pointer;
  background: transparent; color: var(--muted); padding: 6px 12px; border-radius: 999px; font-size: 14px;
}
.profile-pill:hover { background: color-mix(in srgb, var(--text) 8%, transparent); }
.menu {
  position: fixed; background: var(--surface); border-radius: 12px; box-shadow: var(--shadow-lift);
  padding: 6px; min-width: 200px; z-index: 50;
}
.menu button {
  display: flex; width: 100%; text-align: left; padding: 9px 12px; border: none; background: transparent;
  border-radius: 8px; cursor: pointer; gap: 8px; align-items: center;
}
.menu button:hover, .menu button.current { background: var(--surface2); }
.menu button.current { font-weight: 600; }
.menu hr { border: none; border-top: 1px solid var(--border); margin: 4px 0; }

.grid {
  --t: min(var(--tile), calc((100vw - 32px - 2 * var(--gap)) / 3));
  --gap: clamp(14px, calc(var(--tile) * .2), 30px);
  display: grid; grid-template-columns: repeat(auto-fill, var(--t)); gap: var(--gap) var(--gap);
  justify-content: center; max-width: 1500px; margin: 0 auto; padding: 28px 16px 90px;
}
.tile { position: relative; width: var(--t); user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: manipulation; }
.tile-link { display: block; color: inherit; text-decoration: none; outline: none; -webkit-user-drag: none; }
.tile-face {
  position: relative; aspect-ratio: 1; border-radius: calc(var(--t) * .17); overflow: hidden;
  background: var(--surface); box-shadow: var(--shadow); display: grid; place-items: center;
  transition: transform .15s ease, box-shadow .15s ease;
}
.tile-link:hover .tile-face, .tile-link:focus-visible .tile-face { transform: translateY(-2px); box-shadow: var(--shadow-lift); }
.tile-link:focus-visible .tile-face { outline: 3px solid var(--accent); outline-offset: 3px; }
.tile-face img { display: block; pointer-events: none; -webkit-user-drag: none; }
.tile-face.logo img { width: 64%; height: 64%; object-fit: contain; }
.tile-face.snap img, .tile-face.upload img { width: 100%; height: 100%; object-fit: cover; object-position: top center; }
.tile-face .letter { font-size: calc(var(--t) * .44); font-weight: 700; line-height: 1; }
.tile-name {
  margin-top: 8px; text-align: center; font-size: clamp(12px, calc(var(--t) * .1), 15px);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 2px;
}
.tile-more {
  position: absolute; top: 6px; right: 6px; width: 30px; height: 30px; border-radius: 50%;
  border: none; cursor: pointer; display: grid; place-items: center; font-size: 18px; line-height: 1;
  background: rgba(0, 0, 0, .45); color: #fff; opacity: 0; transition: opacity .15s;
}
.tile:hover .tile-more, .tile-more:focus-visible { opacity: 1; }
@media (hover: none) { .tile-more { opacity: .55; width: 26px; height: 26px; font-size: 15px; } }

.spinner {
  position: absolute; inset: 0; display: grid; place-items: center; background: color-mix(in srgb, var(--surface) 55%, transparent);
}
.spinner::after {
  content: ""; width: 26%; aspect-ratio: 1; border-radius: 50%;
  border: 3px solid color-mix(in srgb, var(--text) 20%, transparent); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.tile.add .tile-face {
  background: transparent; box-shadow: none; border: 2px dashed color-mix(in srgb, var(--text) 25%, transparent);
  color: var(--muted); font-size: calc(var(--t) * .36); cursor: pointer;
}
body.has-bg .tile.add .tile-face { border-color: rgba(255, 255, 255, .6); color: #fff; }
.tile.add button.tile-link { background: none; border: none; padding: 0; width: 100%; font: inherit; color: inherit; cursor: pointer; }

/* dra-släpp */
.tile.placeholder .tile-face { opacity: .25; box-shadow: none; }
.tile.placeholder .tile-name { opacity: .25; }
.tile.ghost {
  position: fixed; z-index: 60; pointer-events: none; margin: 0; transform: scale(1.06);
}
.tile.ghost .tile-face { box-shadow: var(--shadow-lift); }
body.dragging { cursor: grabbing; user-select: none; }

.empty-hint { text-align: center; color: var(--muted); margin-top: 8vh; }

/* kugghjulet */
.gear {
  position: fixed; right: 8px; bottom: 8px; width: 28px; height: 28px; padding: 5px; border: none;
  background: transparent; color: var(--muted); opacity: .3; cursor: pointer; border-radius: 50%;
  transition: opacity .2s; z-index: 20;
}
.gear:hover, .gear:focus-visible { opacity: .9; }
body.has-bg .gear { color: #fff; }
.gear svg { width: 100%; height: 100%; display: block; }

/* förhandsvisning i tile-dialogen */
.tile-preview { display: flex; justify-content: center; margin-bottom: 16px; --t: 96px; }
.tile-preview .tile { pointer-events: none; }

/* ---------- inloggning ---------- */
.center-page { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.card { background: var(--surface); border-radius: 20px; box-shadow: var(--shadow); padding: 28px; width: min(380px, 100%); }
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }
.brand img { width: 36px; height: 36px; }
.brand h1 { margin: 0; font-size: 22px; }

/* ---------- admin ---------- */
.admin-wrap { max-width: 1000px; margin: 0 auto; padding: 20px 16px 60px; }
.admin-wrap header { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.admin-wrap header h1 { margin: 0; font-size: 22px; }
.panel { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }
.panel h2 { margin: 0 0 12px; font-size: 17px; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
td .row { flex-wrap: nowrap; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: var(--surface2); }
.badge.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.badge.bad { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat { background: var(--surface2); border-radius: 12px; padding: 12px; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 16px; font-weight: 600; margin-top: 2px; word-break: break-word; }
.scroll-list { max-height: 320px; overflow: auto; }

/* små hjälpklasser (inga inline-stilar, sidan tillåter bara stilmallar från servern) */
.mt8 { margin-top: 8px; }
.mb8 { margin: 0 0 8px; }
.note { font-size: 13px; margin: 8px 0 0; color: var(--muted); }
.foot { font-size: 12px; margin-top: 16px; }
.btn.primary.danger { background: var(--danger); color: #fff; }
.card .btn.primary { width: 100%; margin-top: 4px; }
