/* ============================================================
   Cerchia — sistema di design
   Caldo, editoriale, umano. Palette terracotta su carta avorio,
   serif per i titoli, sans per l'interfaccia. Zero font esterni.
   ============================================================ */

:root {
  --paper: #faf7f2;
  --surface: #ffffff;
  --surface-2: #f4efe8;
  --ink: #2b2620;
  --ink-soft: #746a5e;
  --ink-faint: #a89e90;
  --line: #ece4d8;
  --line-strong: #ddd2c2;

  --accent: #c2673c;
  --accent-ink: #a8552f;
  --accent-soft: rgba(194, 103, 60, 0.10);
  --sage: #5f7d59;
  --clay: #b04a34;
  --warn: #a76a1c;

  --shadow: 0 1px 2px rgba(60, 45, 30, 0.04), 0 6px 20px rgba(60, 45, 30, 0.05);
  --radius: 16px;
  --radius-sm: 10px;

  --font-serif: Georgia, "Iowan Old Style", "Palatino Linotype", "Times New Roman", serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #16130e;
    --surface: #201c15;
    --surface-2: #2a251d;
    --ink: #ece5da;
    --ink-soft: #a89d8c;
    --ink-faint: #6f6555;
    --line: #322c22;
    --line-strong: #42392c;

    --accent: #e08a5f;
    --accent-ink: #e8a07c;
    --accent-soft: rgba(224, 138, 95, 0.14);
    --sage: #8bab84;
    --clay: #d9765c;
    --warn: #d29a44;

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.28);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--paper);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 1.9rem;
  letter-spacing: -0.01em;
  margin: 0.2rem 0 1.4rem;
}
h2 {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-soft);
  margin: 2rem 0 0.7rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
h3 {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-soft);
  margin: 1.6rem 0 0.6rem;
}

.muted { color: var(--ink-soft); }
.empty { padding: 1.5rem 0; color: var(--ink-soft); }
.error { color: var(--clay); font-weight: 600; }
.warn { color: var(--warn); font-weight: 600; }

.count {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--ink-soft);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
  letter-spacing: 0;
}

/* ---------- Layout: topbar, tabbar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.25rem;
  padding-top: max(0.85rem, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--paper) 85%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 1.35rem;
  color: var(--ink);
  letter-spacing: -0.01em;
}
.brand:hover { text-decoration: none; }
.brand-mark { color: var(--accent); }

.topnav { display: flex; align-items: center; gap: 1.5rem; }
.topnav a { color: var(--ink-soft); font-weight: 600; font-size: 0.92rem; }
.topnav a:hover { color: var(--ink); text-decoration: none; }
.btn-add {
  background: var(--accent);
  color: #fff !important;
  padding: 0.45rem 0.95rem;
  border-radius: 999px;
}
.btn-add:hover { background: var(--accent-ink); text-decoration: none; }

.tabbar {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  padding: 0.55rem 0 0.5rem;
  color: var(--ink-soft);
  font-size: 0.66rem;
  font-weight: 600;
}
.tabbar a:hover { text-decoration: none; }
.tabbar .ic { font-size: 1.25rem; line-height: 1; }
.tabbar .tab-add .ic { color: var(--accent); }

main { max-width: 680px; margin: 0 auto; padding: 1.25rem 1.15rem 3rem; }
footer { text-align: center; padding: 1.5rem 0 3rem; }
footer a { color: var(--ink-faint); font-size: 0.82rem; }

/* ---------- Card & liste persone ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.95rem 1.1rem;
  box-shadow: var(--shadow);
}
ul.cards { list-style: none; padding: 0; margin: 0.5rem 0; display: grid; gap: 0.6rem; }

.person-row { display: flex; align-items: center; gap: 0.85rem; }
.person-main { min-width: 0; flex: 1; display: flex; align-items: center; gap: 0.85rem; }
.person-text { min-width: 0; }
.person-name {
  font-weight: 600;
  font-size: 1.02rem;
  color: var(--ink);
  display: block;
}
.person-name:hover { color: var(--accent-ink); text-decoration: none; }
.sub { color: var(--ink-soft); font-size: 0.83rem; margin-top: 0.05rem; }

/* ---------- Avatar monogramma ---------- */

.avatar {
  flex: none;
  width: 44px; height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.95rem;
  color: #fbf6ef;
  letter-spacing: 0.02em;
  user-select: none;
}
.avatar.lg { width: 60px; height: 60px; font-size: 1.3rem; }
.av-0 { background: #b56a44; }
.av-1 { background: #6f8a63; }
.av-2 { background: #a97f3c; }
.av-3 { background: #5f8088; }
.av-4 { background: #97627e; }
.av-5 { background: #7c7a55; }

/* ---------- Badge (cerchia, ruolo) ---------- */

.badge {
  display: inline-block;
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.14rem 0.55rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink-soft);
  vertical-align: middle;
}
.badge-intimi { background: var(--accent-soft); color: var(--accent-ink); }
.badge-amici { background: rgba(95, 125, 89, 0.15); color: var(--sage); }
.badge-conoscenti { background: var(--surface-2); color: var(--ink-soft); }
.circle-title { text-transform: uppercase; color: var(--ink-soft); }

/* ---------- Pulsanti ---------- */

button, .btn-secondary {
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--radius-sm);
  padding: 0.6rem 1rem;
  border: 1px solid transparent;
  transition: transform 0.04s ease, background 0.15s ease;
}
button { background: var(--accent); color: #fff; }
button:hover { background: var(--accent-ink); }
button:active { transform: translateY(1px); }
.btn-secondary {
  background: transparent;
  border-color: var(--line-strong);
  color: var(--ink);
}
.btn-secondary:hover { background: var(--surface-2); text-decoration: none; }

.quick button {
  background: transparent;
  color: var(--accent-ink);
  border: 1px solid var(--line-strong);
  white-space: nowrap;
  font-size: 0.82rem;
  padding: 0.45rem 0.75rem;
}
.quick button:hover { background: var(--accent-soft); }

/* ---------- Scheda persona ---------- */

.person-header {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.5rem;
}
.person-header .avatar { margin-top: 0.15rem; }
.person-header .ph-body { flex: 1; min-width: 0; }
.person-header h1 { margin: 0 0 0.5rem; }
.person-header .badges { display: flex; flex-wrap: wrap; gap: 0.35rem; }

.facts { display: grid; gap: 0.55rem; margin: 1.1rem 0; }
.facts > div { display: flex; gap: 0.75rem; font-size: 0.95rem; align-items: baseline; }
.facts .k {
  color: var(--ink-faint);
  min-width: 92px;
  flex: none;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  padding-top: 0.12rem;
}
.notes { white-space: pre-wrap; }

/* ---------- Chip / tag ---------- */

.chips-row { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; margin: 0.7rem 0; }
.chips-row.filter { margin-bottom: 1.2rem; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--ink);
  padding: 0.22rem 0.6rem;
  border-radius: 999px;
  border: 1px solid transparent;
}
.chip.mini { font-size: 0.66rem; padding: 0.04rem 0.45rem; margin-left: 0.3rem; }
.chip.active { background: var(--accent); color: #fff; }
a.chip:hover { border-color: var(--line-strong); text-decoration: none; }
a.chip.active:hover { background: var(--accent-ink); }
.chip-del button, .chip-add { background: none; border: none; padding: 0; }
.chip-del button { color: inherit; font-size: 0.66rem; cursor: pointer; opacity: 0.55; }
.chip-del button:hover { opacity: 1; background: none; }
.chip-add input {
  width: 96px;
  padding: 0.22rem 0.6rem;
  font-size: 0.78rem;
  border-radius: 999px;
  border: 1px dashed var(--line-strong);
  background: transparent;
  color: var(--ink);
}

/* ---------- Mini liste (recapiti, date, legami) ---------- */

.mini-list { list-style: none; padding: 0; margin: 0.3rem 0 0.7rem; display: grid; gap: 0; }
.mini-list li {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
  padding: 0.5rem 0.15rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.93rem;
}
.mini-list li:last-child { border-bottom: none; }
.kind {
  background: var(--surface-2);
  border-radius: 6px;
  padding: 0.05rem 0.45rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink-soft);
}

/* ---------- Form inline ---------- */

.row-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.5rem;
  align-items: center;
}
.row-form input[type=text], .row-form input[type=date], .row-form select {
  width: auto;
  flex: 1;
  min-width: 120px;
  padding: 0.5rem 0.65rem;
}
.row-form button { padding: 0.5rem 0.9rem; }
.chk { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.86rem; color: var(--ink); font-weight: 500; }
.chk input { width: auto; }

/* ---------- Form completi ---------- */

input, select, textarea {
  font: inherit;
  width: 100%;
  padding: 0.62rem 0.7rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
}
input::placeholder, textarea::placeholder { color: var(--ink-faint); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.form { display: grid; gap: 1rem; margin-top: 0.5rem; }
.form > label { display: grid; gap: 0.3rem; font-size: 0.8rem; color: var(--ink-soft); font-weight: 600; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem; }
.row label { display: grid; gap: 0.3rem; font-size: 0.8rem; color: var(--ink-soft); font-weight: 600; }
.actions { display: flex; gap: 0.7rem; align-items: center; margin-top: 0.5rem; }

fieldset {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  display: grid;
  gap: 0.9rem;
  background: color-mix(in srgb, var(--surface-2) 45%, transparent);
}
fieldset label { display: grid; gap: 0.3rem; font-size: 0.8rem; color: var(--ink-soft); font-weight: 600; }
legend {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-faint);
  font-weight: 700;
  padding: 0 0.4rem;
}

/* ---------- Registra interazione ---------- */

.interaction-form { display: grid; gap: 0.65rem; }
.interaction-form .row { grid-template-columns: 1fr 1fr; }
details { font-size: 0.9rem; }
details summary {
  cursor: pointer;
  color: var(--accent-ink);
  padding: 0.35rem 0;
  font-weight: 600;
  list-style-position: inside;
}
.participants { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; padding: 0.45rem 0; }

/* ---------- Timeline / cronologia / promemoria ---------- */

.timeline { list-style: none; padding: 0; margin: 0.3rem 0; display: grid; gap: 0; }
.timeline li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.6rem 0.15rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.92rem;
}
.timeline li:last-child { border-bottom: none; }
.timeline li.done { opacity: 0.5; text-decoration: line-through; }
.timeline .date { color: var(--ink-faint); font-variant-numeric: tabular-nums; font-size: 0.8rem; flex: none; }
.timeline .note { flex: 1; min-width: 55%; }

.senti { border-radius: 6px; padding: 0.02rem 0.4rem; font-size: 0.7rem; font-weight: 700; text-transform: lowercase; }
.senti-positiva { background: rgba(95, 125, 89, 0.18); color: var(--sage); }
.senti-neutra { background: var(--surface-2); color: var(--ink-soft); }
.senti-tesa { background: rgba(176, 74, 52, 0.15); color: var(--clay); }
.with a { font-weight: 600; }

.inline-act { margin-left: auto; }
.inline-act button, .inline-del button {
  background: none;
  border: none;
  color: var(--ink-faint);
  padding: 0.2rem 0.4rem;
  font-size: 0.9rem;
  cursor: pointer;
}
.inline-act button:hover, .inline-del button:hover { color: var(--ink); background: none; }
.timeline li .inline-del, .mini-list li .inline-del { margin-left: auto; }

/* ---------- Ricerca ---------- */

.search { display: flex; gap: 0.5rem; margin: 0.5rem 0 1rem; }
.search input { flex: 1; }

/* ---------- Dashboard: alert ---------- */

.person-row.alert { border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); }

/* ---------- Azioni in fondo alla scheda ---------- */

.footer-actions { display: flex; gap: 0.8rem; justify-content: center; margin-top: 2.5rem; }
.footer-actions form { display: contents; }
.btn-danger {
  background: none;
  color: var(--clay);
  border: 1px solid color-mix(in srgb, var(--clay) 50%, transparent);
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.95rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-danger:hover { background: rgba(176, 74, 52, 0.08); }

/* ---------- Login ---------- */

.login-page { display: grid; place-items: center; min-height: 100vh; padding: 1.5rem; }
.login-card {
  display: grid;
  gap: 0.9rem;
  width: 100%;
  max-width: 340px;
  text-align: center;
  padding: 2rem 1.6rem;
}
.login-card h1 { font-size: 2.1rem; margin: 0; }
.login-card h1 .brand-mark { color: var(--accent); }
.login-card p { margin: 0 0 0.4rem; }

/* ---------- Responsive: tab bar su mobile ---------- */

@media (max-width: 699px) {
  .topnav { display: none; }
  .tabbar { display: flex; }
  main { padding-bottom: 5rem; }
  footer { padding-bottom: 5.5rem; }
  .row { grid-template-columns: 1fr; }
  h1 { font-size: 1.65rem; }
}

/* ---------- Fase 3: suggerimenti e obiettivi ---------- */

.hdr-action { margin-left: auto; }
.link-btn {
  background: none;
  border: none;
  color: var(--accent-ink);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
  padding: 0;
}
.link-btn:hover { background: none; text-decoration: underline; }

.person-row.done .person-name { text-decoration: line-through; opacity: 0.55; }

.objective { display: grid; gap: 0.55rem; margin-bottom: 0.7rem; }
.objective.obj-closed { opacity: 0.7; }
.obj-head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.6rem; }
.obj-desc { font-family: var(--font-serif); font-size: 1.08rem; font-weight: 600; }
.assessment {
  margin: 0;
  font-size: 0.9rem;
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.7rem;
  line-height: 1.45;
}
.timeline.steps { margin: 0.2rem 0; }
.timeline.steps li { border-bottom: none; padding: 0.3rem 0.1rem; gap: 0.45rem; }
.step-toggle { display: flex; }
.step-toggle button { background: none; border: none; color: var(--accent-ink); font-size: 1.05rem; padding: 0 0.2rem; cursor: pointer; }
.step-toggle button:hover { background: none; }

.obj-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.obj-actions form { display: contents; }
.obj-actions .btn-secondary, .obj-actions .btn-danger { font-size: 0.78rem; padding: 0.4rem 0.7rem; }
.obj-hint { font-size: 0.8rem; margin-top: 0.4rem; }
