:root {
  --bg: #f4f5f7; --surface: #ffffff; --surface-2: #eef0f3; --text: #1b1f24; --muted: #667080;
  --border: #dde1e6; --accent: #1f5fae; --accent-ink: #ffffff; --danger: #c0352b;
  --c-nota: #c98a00; --c-diario: #7a4fbf; --c-password: #1f7a5a; --c-evento: #1f5fae; --c-documento: #a5532a;
  --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418; --surface: #1a1e24; --surface-2: #242a32; --text: #e7eaee; --muted: #9aa4b1;
    --border: #2e353e; --accent: #5b9be6; --accent-ink: #0b1220; --danger: #ef6b60;
    --c-nota: #e2b13c; --c-diario: #b294ea; --c-password: #4fc39a; --c-evento: #5b9be6; --c-documento: #e08b5e;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); overflow-x: hidden; }
body { font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.splash { display: grid; place-items: center; min-height: 100vh; color: var(--muted); }
.hidden { display: none !important; }

/* ---- login ---- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth form { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 28px 22px; box-shadow: var(--shadow); }
.auth h1 { margin: 0 0 4px; font-size: 1.5rem; display: flex; align-items: center; gap: 10px; }
.auth h1 img { width: 34px; height: 34px; }
.auth p { color: var(--muted); margin: 0 0 20px; font-size: .92rem; }
.err { color: var(--danger); font-size: .9rem; min-height: 1.3em; margin: 4px 0 8px; }

label.f { display: block; margin-bottom: 14px; }
label.f > span { display: block; font-size: .82rem; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
input[type=text], input[type=password], input[type=search], input[type=date], input[type=time], input[type=url], textarea, select {
  width: 100%; padding: 11px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); outline: none;
  min-height: 44px;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
textarea { resize: vertical; min-height: 160px; line-height: 1.5; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 500; text-decoration: none; color: var(--text); }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn.small { min-height: 34px; padding: 0 10px; font-size: .88rem; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { width: 44px; height: 44px; display: inline-grid; place-items: center; border: 0; background: transparent; border-radius: 10px; cursor: pointer; color: var(--text); flex: none; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg, .btn svg { width: 22px; height: 22px; }

/* ---- layout ---- */
.top { position: sticky; top: 0; z-index: 10; background: var(--bg); padding: calc(8px + env(safe-area-inset-top)) 12px 8px; border-bottom: 1px solid var(--border); }
.top-row { display: flex; align-items: center; gap: 6px; max-width: 900px; margin: 0 auto; }
.top h2 { margin: 0; font-size: 1.15rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search { flex: 1; position: relative; }
.search input { padding-left: 38px; border-radius: 22px; background: var(--surface); }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--muted); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0 2px; max-width: 900px; margin: 0 auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--border); background: var(--surface); border-radius: 18px; padding: 6px 13px; font-size: .88rem; cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
main { max-width: 900px; margin: 0 auto; padding: 12px 12px calc(96px + env(safe-area-inset-bottom)); }

.fab { position: fixed; right: max(18px, env(safe-area-inset-right)); bottom: calc(20px + env(safe-area-inset-bottom)); width: 58px; height: 58px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); border: 0; box-shadow: 0 4px 14px rgba(0,0,0,.25); cursor: pointer; display: grid; place-items: center; z-index: 20; }
.fab svg { width: 28px; height: 28px; }

/* ---- lista ---- */
.group-title { font-size: .78rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin: 18px 4px 8px; }
.list { display: grid; gap: 8px; }
.card { display: flex; gap: 12px; align-items: flex-start; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; cursor: pointer; box-shadow: var(--shadow); text-align: left; width: 100%; }
.card:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.tico { flex: none; width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; color: #fff; }
.tico svg { width: 20px; height: 20px; }
.t-nota { background: var(--c-nota); } .t-diario { background: var(--c-diario); } .t-password { background: var(--c-password); }
.t-evento { background: var(--c-evento); } .t-documento { background: var(--c-documento); }
.card .main { flex: 1; min-width: 0; }
.card .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .sub { color: var(--muted); font-size: .88rem; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.card .meta { display: flex; gap: 10px; align-items: center; color: var(--muted); font-size: .78rem; margin-top: 4px; flex-wrap: wrap; }
.card .meta svg { width: 14px; height: 14px; vertical-align: -2px; }
.pin { color: var(--c-nota); }
.tag { background: var(--surface-2); border-radius: 6px; padding: 1px 7px; font-size: .78rem; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.empty svg { width: 48px; height: 48px; opacity: .5; }

/* ---- agenda ---- */
.cal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; box-shadow: var(--shadow); }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.cal-head strong { text-transform: capitalize; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.cal-grid .dow { font-size: .72rem; color: var(--muted); padding: 4px 0; font-weight: 600; }
.day { aspect-ratio: 1 / 1; max-height: 56px; border: 0; background: transparent; border-radius: 10px; cursor: pointer; position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: .95rem; padding: 0; }
.day:hover { background: var(--surface-2); }
.day.out { color: var(--muted); opacity: .45; }
.day.today { font-weight: 700; color: var(--accent); }
.day.sel { background: var(--accent); color: var(--accent-ink); }
.dots { display: flex; gap: 3px; height: 6px; margin-top: 2px; }
.dots i { width: 5px; height: 5px; border-radius: 50%; background: currentColor; display: block; }
.dots i.evento { background: var(--c-evento); } .dots i.diario { background: var(--c-diario); } .dots i.other { background: var(--c-documento); }
.day.sel .dots i { background: var(--accent-ink); }

/* ---- dettaglio / editor ---- */
.sheet { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.d-title { font-size: 1.35rem; font-weight: 700; margin: 0 0 6px; word-break: break-word; }
.d-meta { color: var(--muted); font-size: .86rem; display: flex; flex-wrap: wrap; gap: 6px 14px; margin-bottom: 14px; align-items: center; }
.d-meta > span:not(.tico) > svg { width: 16px; height: 16px; vertical-align: -3px; }
.d-body { white-space: pre-wrap; word-break: break-word; margin: 14px 0; }
.kv { display: grid; gap: 8px; margin: 10px 0; }
.kv .row { display: flex; align-items: center; gap: 8px; background: var(--surface-2); border-radius: 10px; padding: 6px 6px 6px 12px; min-height: 48px; }
.kv .row .k { font-size: .76rem; color: var(--muted); }
.kv .row .v { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; }
.kv .row .grow { flex: 1; min-width: 0; }
.type-pick { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; margin-bottom: 16px; }
.type-pick button { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 8px 2px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: .74rem; }
.type-pick button.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.type-pick .tico { width: 30px; height: 30px; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
input, textarea, select { min-width: 0; max-width: 100%; }
input[type=date], input[type=time] { -webkit-appearance: none; appearance: none; text-align: left; }
.pw-wrap { display: flex; gap: 6px; }
.pw-wrap input { flex: 1; min-width: 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.check { display: flex; align-items: center; gap: 8px; margin: 4px 0 14px; cursor: pointer; }
.check input { width: 20px; height: 20px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.actions .spacer { flex: 1; }

.att-head { display: flex; align-items: center; justify-content: space-between; margin: 18px 0 8px; gap: 8px; flex-wrap: wrap; }
.att-head .actions { margin-top: 0; }
.att-head h3 { margin: 0; font-size: 1rem; }
.atts { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.att { position: relative; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface-2); aspect-ratio: 1 / 1; display: flex; flex-direction: column; cursor: pointer; }
.att img { width: 100%; height: 100%; object-fit: cover; display: block; }
.att .fi { flex: 1; display: grid; place-items: center; color: var(--muted); }
.att .fi svg { width: 34px; height: 34px; }
.att .nm { font-size: .72rem; padding: 4px 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; background: var(--surface); border-top: 1px solid var(--border); }
.att .x { position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; display: grid; place-items: center; }
.att .x svg { width: 16px; height: 16px; }
.att.up { cursor: default; }
.att .prog { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--accent); }
.drop { outline: 2px dashed var(--accent); outline-offset: 4px; }

/* ---- viewer ---- */
.viewer { position: fixed; inset: 0; background: #000; z-index: 50; display: flex; flex-direction: column; }
.viewer .vbar { display: flex; align-items: center; gap: 6px; padding: calc(6px + env(safe-area-inset-top)) 8px 6px; color: #fff; }
.viewer .vbar .icon-btn { color: #fff; }
.viewer .vbar span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer .vbody { flex: 1; display: grid; place-items: center; overflow: auto; padding: 8px; }
.viewer img, .viewer video { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer iframe { width: 100%; height: 100%; border: 0; background: #fff; border-radius: 6px; }

/* ---- impostazioni ---- */
.sec { margin-bottom: 18px; }
.sec h3 { margin: 0 0 10px; font-size: 1.02rem; }
.dev { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--border); font-size: .9rem; }
.dev:first-of-type { border-top: 0; }
.dev .grow { flex: 1; min-width: 0; }
.dev .muted { color: var(--muted); font-size: .8rem; }
.muted { color: var(--muted); }

#toast { position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; font-size: .92rem; opacity: 0; pointer-events: none; transition: .2s; z-index: 60; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (min-width: 700px) {
  main { padding-top: 18px; }
  .sheet { padding: 22px 26px; }
}
@media (max-width: 400px) {
  .type-pick { gap: 4px; }
  .type-pick button { font-size: .68rem; padding: 8px 0; }
}
