/*
 * Hestia - shared lists for small groups (web UI styles)
 * Copyright (C) 2026 Leproide
 * Author: https://github.com/Leproide
 * SPDX-License-Identifier: GPL-3.0-or-later
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later version.
 */

:root {
  --bg: #f5f5f2;
  --surface: #ffffff;
  --surface-2: #ecede8;
  --surface-3: #e3e4df;
  --text: #16181d;
  --muted: #555a64;
  --border: #d9dad5;
  --primary: #3b5bdb;
  --primary-hover: #2c46b0;
  --on-primary: #ffffff;
  --primary-soft: #d5deff;
  --on-primary-soft: #14247a;
  --danger: #b42318;
  --note-bg: #fff6db;
  --note-border: #f1df9e;
  --note-text: #3d2e00;
  --note-meta: #6b5300;
  --star: #f59f00;
  --shadow: 0 1px 2px rgba(22, 24, 29, 0.06);
  --radius: 16px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #121317;
  --surface: #1b1d22;
  --surface-2: #24262c;
  --surface-3: #2c2f36;
  --text: #ecedef;
  --muted: #a9adb6;
  --border: #3a3d45;
  --primary: #9db0ff;
  --primary-hover: #c3cfff;
  --on-primary: #0e1a4f;
  --primary-soft: #34479e;
  --on-primary-soft: #e3e8ff;
  --danger: #ff8a80;
  --note-bg: #2e2710;
  --note-border: #5a4a1a;
  --note-text: #f5e6b8;
  --note-meta: #d9c27a;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 28px; font-weight: 700; }
h2 { font-size: 20px; font-weight: 700; }
h3 { font-size: 14px; font-weight: 600; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- layout ---------- */
.shell { display: flex; min-height: 100%; }
.nav {
  width: 230px; flex: none; padding: 20px 12px; display: flex; flex-direction: column; gap: 4px;
  border-right: 1px solid var(--surface-3); background: var(--surface);
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; font-weight: 700; font-size: 18px; }
.brand .logo { width: 34px; height: 34px; border-radius: 11px; background: var(--primary); display: grid; place-items: center; }
.brand .logo svg { color: var(--on-primary); }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px;
  color: var(--muted); text-decoration: none; font-weight: 500; min-height: 44px;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a[aria-current="page"] { background: var(--primary-soft); color: var(--on-primary-soft); font-weight: 600; }
.nav .spacer { flex: 1; }
.main { flex: 1; min-width: 0; padding: 28px 24px 120px; }
.page { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-head .title { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.page-head .title h1 { overflow-wrap: anywhere; }
.row { display: flex; align-items: center; gap: 10px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

@media (max-width: 760px) {
  .shell { flex-direction: column; }
  .nav {
    position: fixed; bottom: 0; left: 0; right: 0; top: auto; height: auto; width: auto; z-index: 20;
    flex-direction: row; justify-content: space-around; padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    border-right: 0; border-top: 1px solid var(--surface-3);
  }
  .brand, .nav .spacer { display: none; }
  .nav a { flex-direction: column; gap: 2px; font-size: 12px; padding: 6px 10px; }
  .main { padding: 20px 16px 110px; }
  h1 { font-size: 24px; }
}

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 14px; border: 1px solid transparent;
  background: var(--primary); color: var(--on-primary); font-weight: 600; cursor: pointer;
  white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--primary-hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.secondary { background: transparent; color: var(--primary); border-color: var(--border); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--border); }
.btn.danger:hover { background: var(--surface-2); }
.btn.ghost { background: transparent; color: var(--primary); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.block { width: 100%; }
.icon-btn {
  width: 44px; height: 44px; flex: none; display: inline-grid; place-items: center; border-radius: 12px;
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.star-on { color: var(--star); }
.icon-btn.spin svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
svg.i { width: 22px; height: 22px; display: block; }

label.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; color: var(--muted); }
input[type="text"], input[type="password"], input[type="search"], input[type="url"], textarea {
  width: 100%; min-height: 48px; padding: 10px 14px; border-radius: 14px;
  border: 1.5px solid var(--border); background: var(--surface); font-weight: 500; color: var(--text);
}
textarea { resize: vertical; min-height: 90px; }
input:focus, textarea:focus { outline: none; border-color: var(--primary); }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 52px; }
.pw-wrap .icon-btn { position: absolute; right: 2px; top: 2px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chip {
  flex: none; min-height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--border);
  background: transparent; color: var(--muted); font-weight: 500; cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip[aria-pressed="true"] { background: var(--primary-soft); color: var(--on-primary-soft); border-color: transparent; font-weight: 600; }

.check { width: 22px; height: 22px; accent-color: var(--primary); flex: none; cursor: pointer; }

.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--border); transition: background 0.15s; }
.switch span::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); transition: transform 0.15s;
}
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }
.switch input:disabled + span { opacity: 0.5; }

/* ---------- cards / lists ---------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel { background: var(--surface); border-radius: 18px; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.list-card {
  display: flex; align-items: center; gap: 14px; padding: 14px 6px 14px 16px; cursor: pointer;
  background: var(--surface); border-radius: 18px; box-shadow: var(--shadow); border: 0; text-align: left; width: 100%;
}
.list-card:hover { background: var(--surface-2); }
.list-card .body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.list-card .name { font-weight: 600; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress { height: 5px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.progress > div { height: 100%; background: var(--primary); border-radius: 3px; }
.badge {
  width: 46px; height: 46px; flex: none; border-radius: 14px; display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 18px;
}
.avatar {
  flex: none; border-radius: 50%; display: inline-grid; place-items: center; color: #fff; font-weight: 600;
  overflow: hidden; background: #3b5bdb; user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatars { display: flex; }
.avatars .avatar { border: 2px solid var(--surface); margin-left: -6px; }
.avatars .avatar:first-child { margin-left: 0; }
.handle {
  width: 36px; height: 44px; flex: none; display: grid; place-items: center; color: var(--muted);
  cursor: grab; touch-action: none; border-radius: 10px; border: 0; background: transparent; padding: 0;
}
@media (max-width: 760px) { .handle { width: 30px; } .list-card { gap: 10px; padding-left: 12px; } }
.handle:hover { background: var(--surface-3); }
.dragging { position: relative; z-index: 5; box-shadow: 0 10px 28px rgba(0, 0, 0, 0.25) !important; transform: scale(1.01); cursor: grabbing; }

.item {
  display: flex; align-items: center; gap: 10px; min-height: 56px; padding: 4px 4px 4px 12px;
  background: var(--surface); border-radius: 16px;
}
.item.done { background: var(--surface-2); }
.item .text { flex: 1; min-width: 0; overflow-wrap: anywhere; cursor: pointer; padding: 8px 0; }
.item.done .text { color: var(--muted); text-decoration: line-through; }
.item .by { font-size: 12px; color: var(--muted); white-space: nowrap; }
.note {
  display: flex; gap: 12px; padding: 12px 4px 12px 16px; background: var(--note-bg); color: var(--note-text);
  border: 1px solid var(--note-border); border-radius: 16px;
}
.note .text { flex: 1; min-width: 0; white-space: pre-wrap; overflow-wrap: anywhere; cursor: pointer; }
.note .meta { font-size: 12px; color: var(--note-meta); }
.note svg.i { color: var(--note-meta); }
.section-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 10px 4px 0; }

.addbar {
  position: sticky; bottom: 0; z-index: 10; background: var(--surface); border-radius: 18px;
  padding: 12px; display: flex; flex-direction: column; gap: 10px; box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.08);
}
@media (max-width: 760px) { .addbar { bottom: 76px; } }

.person { display: flex; align-items: center; gap: 12px; min-height: 60px; padding: 6px 12px 6px 16px; }
.person + .person { border-top: 1px solid var(--surface-3); }
.person .who { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.person .who b { font-weight: 600; }

.swatches { display: grid; grid-template-columns: repeat(var(--n, 8), minmax(0, 1fr)); gap: 8px; max-width: 460px; }
.swatch {
  aspect-ratio: 1; border-radius: 12px; border: 3px solid transparent; padding: 3px; cursor: pointer;
  background-clip: content-box; display: grid; place-items: center; color: #fff;
}
.swatch.round { border-radius: 50%; }
.swatch[aria-checked="true"] { border-color: var(--text); }
.swatch svg.i { width: 18px; height: 18px; }

.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.stat { background: var(--surface); border-radius: 14px; padding: 12px; }
.stat b { display: block; font-size: 22px; }
.role {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600;
  background: var(--primary-soft); color: var(--on-primary-soft);
}
.role.admin { background: var(--text); color: var(--bg); }
.role.off { background: var(--surface-3); color: var(--muted); }
.perm { display: flex; align-items: center; gap: 12px; min-height: 64px; padding: 8px 16px; }
.perm + .perm { border-top: 1px solid var(--surface-3); }
.perm .who { flex: 1; }

/* ---------- login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login form { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 18px; }
.login .logo { width: 64px; height: 64px; border-radius: 20px; background: var(--primary); display: grid; place-items: center; }
.login .logo svg { width: 32px; height: 32px; color: var(--on-primary); }

/* ---------- dialogs ---------- */
dialog {
  border: 0; border-radius: 20px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 24px);
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
dialog .dlg { padding: 20px; display: flex; flex-direction: column; gap: 16px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 20px; user-select: all; overflow-wrap: anywhere; }

.crop { position: relative; width: 100%; max-width: 360px; aspect-ratio: 1; margin: 0 auto; background: #000; border-radius: 12px; overflow: hidden; touch-action: none; cursor: grab; }
.crop canvas { width: 100%; height: 100%; display: block; }
input[type="range"] { width: 100%; accent-color: var(--primary); }

.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); z-index: 50;
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 12px; max-width: calc(100vw - 32px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3); font-weight: 500;
}
.empty { padding: 24px 4px; color: var(--muted); }
.spinner { width: 28px; height: 28px; border: 3px solid var(--surface-3); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 40px auto; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---- security, devices, system ---- */
.qr { width: 220px; height: 220px; max-width: 100%; background: #fff; padding: 8px; border-radius: 12px; align-self: center; image-rendering: pixelated; }
dialog .qr { width: 240px; height: 240px; display: block; margin: 0 auto; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; align-items: baseline; }
.kv .mono { word-break: break-all; }
.warn { margin: 0; padding: 10px 12px; border-radius: 10px; background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); font-size: .9rem; }
.codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px 16px; }
pre.log, pre.notes { margin: 0; max-height: 320px; overflow: auto; padding: 12px; border-radius: 10px; background: var(--surface-2, rgba(127,127,127,.12)); font-size: .8rem; white-space: pre-wrap; word-break: break-word; }
details summary { cursor: pointer; color: var(--muted); padding: 4px 0; }
hr { border: 0; border-top: 1px solid var(--border, rgba(127,127,127,.25)); margin: 8px 0; width: 100%; }
