/* ==========================================================================
   NotarIA — foglio di stile unico dell'app.
   Design token estratti dal mockup della proposta.
   ========================================================================== */

:root {
  --cream: #F6F3EC;
  --cream-2: #FFF9EC;
  --navy: #12213A;
  --navy-2: #2B3446;
  --gold: #B08D3E;
  --gold-dark: #9C6B1A;
  --green: #2E8B57;
  --red: #B0473F;
  --beige: #E4D9BE;
  --line: #E7E1D3;
  --muted: #5B6473;
  --muted-2: #9AA4B2;
  --white: #FFFFFF;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(18, 33, 58, .06);
  --shadow: 0 4px 18px rgba(18, 33, 58, .08);
  --sidebar-w: 256px;

  --font: 'Public Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  color: var(--navy-2);
  background: var(--cream);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
.icon { width: 20px; height: 20px; flex: none; }

/* ------------------------------- App shell ------------------------------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.app.is-collapsed { grid-template-columns: 72px 1fr; }

/* ------------------------------- Sidebar --------------------------------- */
.sidebar {
  background: var(--navy);
  color: #F6F3EC;
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  gap: 8px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar__brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 16px; }
.sidebar__logo {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  background: var(--gold); color: var(--navy);
  display: grid; place-items: center; font-weight: 800; font-size: 15px;
}
.sidebar__title { font-weight: 700; font-size: 15px; letter-spacing: .2px; }
.sidebar__title b { color: var(--gold); }

.nav { display: flex; flex-direction: column; gap: 3px; margin-top: 4px; }
.nav__item {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 11px; border-radius: var(--radius-sm);
  color: rgba(246, 243, 236, .7); font-weight: 500;
  transition: background .12s, color .12s;
}
.nav__item:hover { background: rgba(255, 255, 255, .06); color: #F6F3EC; }
.nav__item.is-active { background: rgba(176, 141, 62, .18); color: #F6F3EC; }
.nav__item.is-active .icon { color: var(--gold); }

.sidebar__foot { margin-top: auto; border-top: 1px solid rgba(255, 255, 255, .08); padding-top: 12px; }
.model-chip {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  border-radius: var(--radius-sm); background: rgba(255, 255, 255, .05);
  font-size: 12px; color: rgba(246, 243, 236, .8);
}
.model-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); flex: none; }
.user { display: flex; align-items: center; gap: 10px; padding: 10px 6px 2px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex: none;
  background: var(--gold); color: var(--navy);
  display: grid; place-items: center; font-weight: 700; font-size: 12px;
}
.user__name { font-size: 13px; font-weight: 600; color: #F6F3EC; }
.user__role { font-size: 11px; color: rgba(246, 243, 236, .55); }

.app.is-collapsed .sidebar__title,
.app.is-collapsed .nav__item span,
.app.is-collapsed .model-chip span,
.app.is-collapsed .user > div { display: none; }

/* ------------------------------- Main / topbar --------------------------- */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 26px; background: var(--cream);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.topbar__title { font-size: 18px; font-weight: 700; color: var(--navy); }
.topbar__sub { font-size: 12px; color: var(--muted); }
.topbar__spacer { flex: 1; }
.iconbtn {
  width: 38px; height: 38px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--white); color: var(--navy-2); display: grid; place-items: center; cursor: pointer;
}
.iconbtn:hover { border-color: var(--gold); color: var(--gold-dark); }
.iconbtn.has-badge { position: relative; }
.iconbtn .badge {
  position: absolute; top: -5px; right: -5px; min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 9px; background: var(--red); color: #fff; font-size: 10px; font-weight: 700;
  display: grid; place-items: center;
}

.content { padding: 26px; max-width: 1200px; width: 100%; }
.page-head { margin-bottom: 20px; }
.page-head h1 { font-size: 22px; color: var(--navy); font-weight: 700; }
.page-head p { color: var(--muted); margin-top: 4px; }

/* ------------------------------- Toolbar --------------------------------- */
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.search {
  display: flex; align-items: center; gap: 9px; flex: 1; min-width: 220px;
  padding: 9px 13px; background: var(--white); border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.search input { border: 0; outline: 0; width: 100%; font: inherit; background: transparent; color: var(--navy-2); }
.search .icon { color: var(--muted-2); }

.tabs { display: flex; gap: 4px; background: var(--white); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 4px; }
.tab { padding: 7px 14px; border-radius: 6px; font-weight: 600; color: var(--muted); cursor: pointer; }
.tab.is-active { background: var(--navy); color: #F6F3EC; }

/* ------------------------------- Buttons --------------------------------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  padding: 9px 16px; border-radius: var(--radius-sm); font: inherit; font-weight: 600;
  border: 1px solid var(--line); background: var(--white); color: var(--navy-2);
}
.btn:hover { border-color: var(--gold); }
.btn--primary { background: var(--gold); border-color: var(--gold); color: var(--navy); }
.btn--primary:hover { background: var(--gold-dark); border-color: var(--gold-dark); color: #fff; }
.btn--block { width: 100%; justify-content: center; }
.btn--ghost { background: transparent; }

/* ------------------------------- Cards / grid ---------------------------- */
.grid { display: grid; gap: 16px; }
.grid--3 { grid-template-columns: repeat(3, 1fr); }
.grid--2 { grid-template-columns: repeat(2, 1fr); }
.card {
  background: var(--white); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-sm);
}
.card__label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.card__value { font-size: 26px; font-weight: 800; color: var(--navy); margin-top: 6px; }
.card h3 { font-size: 15px; color: var(--navy); margin-bottom: 4px; }

.badge-pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-pill.ok { background: rgba(46, 139, 87, .12); color: var(--green); }
.badge-pill.warn { background: rgba(156, 107, 26, .14); color: var(--gold-dark); }
.badge-pill.danger { background: rgba(176, 71, 63, .12); color: var(--red); }
.badge-pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* ------------------------------- Data list / table ---------------------- */
.list { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row {
  display: grid; grid-template-columns: 1fr auto; gap: 14px; align-items: center;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--cream-2); }
.row__main { display: flex; align-items: center; gap: 12px; min-width: 0; }
.row__title { font-weight: 600; color: var(--navy); }
.row__meta { font-size: 12px; color: var(--muted); }
.row__aside { display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: 13px; }

table.data { width: 100%; border-collapse: collapse; background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.data th, table.data td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--line); }
table.data th { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); background: var(--cream-2); }
table.data tr:last-child td { border-bottom: 0; }
table.data tr:hover td { background: var(--cream-2); }

/* ------------------------------- Chat ------------------------------------ */
.chat { display: flex; flex-direction: column; height: calc(100vh - 66px); }
.chat__stream { flex: 1; overflow-y: auto; padding: 24px 26px; display: flex; flex-direction: column; gap: 16px; }
.msg { display: flex; gap: 12px; max-width: 760px; }
.msg__avatar { width: 32px; height: 32px; border-radius: 8px; flex: none; display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.msg--ai .msg__avatar { background: var(--navy); color: var(--gold); }
.msg--user { align-self: flex-end; flex-direction: row-reverse; }
.msg--user .msg__avatar { background: var(--gold); color: var(--navy); }
.msg__bubble { padding: 12px 15px; border-radius: 12px; background: var(--white); border: 1px solid var(--line); box-shadow: var(--shadow-sm); }
.msg--user .msg__bubble { background: var(--cream-2); border-color: rgba(176, 141, 62, .25); }
.msg__bubble ul { margin: 8px 0 0 18px; }
.chat__composer { border-top: 1px solid var(--line); padding: 16px 26px; background: var(--cream); }
.composer {
  display: flex; align-items: center; gap: 10px; background: var(--white);
  border: 1px solid var(--line); border-radius: 14px; padding: 8px 8px 8px 16px;
}
.composer input { flex: 1; border: 0; outline: 0; font: inherit; background: transparent; }
.chips { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.chip {
  padding: 7px 13px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--white); color: var(--navy-2); font-size: 13px; cursor: pointer;
}
.chip:hover { border-color: var(--gold); color: var(--gold-dark); }

/* ------------------------------- Forms ----------------------------------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--navy-2); margin-bottom: 6px; }
.field input, .field select {
  width: 100%; padding: 11px 13px; font: inherit; color: var(--navy-2);
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--white); outline: 0;
}
.field input:focus, .field select:focus { border-color: var(--gold); }

/* ------------------------------- Auth pages ------------------------------ */
.auth { min-height: 100vh; display: grid; place-items: center; background: var(--cream); padding: 24px; }
.auth__card { width: 100%; max-width: 400px; background: var(--white); border: 1px solid var(--line); border-radius: 16px; padding: 32px; box-shadow: var(--shadow); }
.auth__brand { display: flex; align-items: center; gap: 10px; justify-content: center; margin-bottom: 6px; }
.auth__brand .sidebar__logo { width: 40px; height: 40px; font-size: 17px; }
.auth h1 { text-align: center; font-size: 20px; color: var(--navy); margin: 10px 0 4px; }
.auth__sub { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 24px; }
.auth__foot { text-align: center; font-size: 13px; color: var(--muted); margin-top: 18px; }
.auth__foot a { color: var(--gold-dark); font-weight: 600; }
.auth__note { display: flex; gap: 8px; align-items: center; justify-content: center; font-size: 12px; color: var(--green); margin-top: 16px; }

/* ------------------------------- Responsive ------------------------------ */
@media (max-width: 900px) {
  .app, .app.is-collapsed { grid-template-columns: 72px 1fr; }
  .sidebar__title, .nav__item span, .model-chip span, .user > div { display: none; }
  .grid--3 { grid-template-columns: 1fr; }
  .grid--2 { grid-template-columns: 1fr; }
}
