/* ============================================================
   Cortex — il tuo secondo cervello
   Dark, chat-first, color-coded task manager. Custom aesthetic.
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=Manrope:wght@400;500;600;700;800&display=swap');

/* Font locale bundlato (fallback offline, quando Google Fonts non e' raggiungibile) */
@font-face {
  font-family: 'CortexLocal';
  src: url('fonts/NotoSans-VariableFont_wdth_wght.ttf') format('truetype');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'CortexLocal';
  src: url('fonts/NotoSans-Italic-VariableFont_wdth_wght.ttf') format('truetype');
  font-weight: 100 900;
  font-style: italic;
  font-display: swap;
}

:root {
  /* surfaces — near-black, slight cool */
  --bg:        #0A0A0F;
  --bg-2:      #0E0E15;
  --surface:   #14141C;
  --surface-2: #1C1C26;
  --surface-3: #25252F;
  --line:      rgba(255,255,255,0.07);
  --line-2:    rgba(255,255,255,0.13);
  --line-3:    rgba(255,255,255,0.28);

  --text:   #ECECF2;
  --dim:    #9A9AAB;
  --faint:  #5C5C6B;

  /* brand / AI accent — electric iris */
  --iris:    #7C6BFF;
  --iris-2:  #9D8BFF;
  --iris-dk: #5B49E0;
  --iris-grad: linear-gradient(135deg, #9D8BFF 0%, #6C5CE7 55%, #5BC8FF 120%);

  --ok:   #2FD98A;
  --warn: #FFB23F;
  --bad:  #FB5E6F;

  --font-display: 'Space Grotesk', 'CortexLocal', system-ui, sans-serif;
  --font: 'Manrope', 'CortexLocal', system-ui, -apple-system, sans-serif;

  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --shadow-pop: 0 20px 50px -12px rgba(0,0,0,0.7), 0 0 0 1px rgba(255,255,255,0.05);

  /* density (tweakable) */
  --row-pad: 13px;
  --row-gap: 8px;
  --fs-task: 15px;
  --radius: 14px;
}
[data-density="compatto"] { --row-pad: 8px;  --row-gap: 4px;  --fs-task: 14px; --radius: 11px; }
[data-density="comodo"]   { --row-pad: 13px; --row-gap: 8px;  --fs-task: 15px; --radius: 14px; }
[data-density="spazioso"] { --row-pad: 18px; --row-gap: 12px; --fs-task: 16px; --radius: 16px; }

/* task color palette — value is the hue, tint computed via color-mix */
[data-tc="coral"]   { --tc: #FB5E5E; }
[data-tc="amber"]   { --tc: #FB923C; }
[data-tc="gold"]    { --tc: #F5C842; }
[data-tc="lime"]    { --tc: #84CC4E; }
[data-tc="emerald"] { --tc: #2FD98A; }
[data-tc="teal"]    { --tc: #2DD4BF; }
[data-tc="sky"]     { --tc: #46A6FF; }
[data-tc="indigo"]  { --tc: #7C8BFF; }
[data-tc="violet"]  { --tc: #B57BFF; }
[data-tc="pink"]    { --tc: #FB6FB0; }

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, textarea { font-family: inherit; }
button { cursor: pointer; }
::selection { background: rgba(124,107,255,0.4); }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 99px; border: 2px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); background-clip: padding-box; }

h1,h2,h3 { font-family: var(--font-display); }

/* ============================================================ shell */
.app {
  display: grid;
  grid-template-columns: 76px 1fr;
  height: 100vh;
  position: relative;
}
.app.split { grid-template-columns: 76px 1fr; }

/* atmosphere */
.atmo { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.atmo .glow { position: absolute; border-radius: 50%; filter: blur(90px); opacity: 0.5; }
.atmo .g1 { top: -200px; left: 30px; width: 520px; height: 520px; background: radial-gradient(circle, rgba(124,107,255,0.35), transparent 70%); }
.atmo .g2 { bottom: -260px; right: -120px; width: 620px; height: 620px; background: radial-gradient(circle, rgba(45,212,191,0.16), transparent 70%); }

/* ============================================================ rail */
.rail {
  background: var(--bg-2);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center;
  padding: 16px 0 14px; gap: 6px;
}
.rail .logo {
  width: 42px; height: 42px; border-radius: 13px; margin-bottom: 14px;
  background: var(--iris-grad); display: grid; place-items: center; position: relative;
  box-shadow: 0 6px 20px -4px rgba(124,107,255,0.6);
}
.rail .logo svg { width: 23px; height: 23px; color: #fff; }
.rail-btn {
  width: 50px; height: 50px; border-radius: 14px; border: none; background: none;
  color: var(--faint); display: grid; place-items: center; position: relative;
  transition: all var(--ease) .18s;
}
.rail-btn svg { width: 23px; height: 23px; stroke-width: 1.8; transition: transform var(--ease) .18s; }
.rail-btn:hover { color: var(--dim); background: var(--surface); }
.rail-btn.on { color: var(--text); }
.rail-btn.on::before { content: ''; position: absolute; left: -1px; top: 50%; transform: translateY(-50%); width: 3px; height: 24px; border-radius: 0 4px 4px 0; background: var(--iris); }
.rail-btn.on { background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line-2); }
.rail-btn .pip { position: absolute; top: 9px; right: 10px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--iris); color: #fff; font-size: 10px; font-weight: 700; display: grid; place-items: center; font-family: var(--font); }
.rail-btn .lbl { position: absolute; left: 64px; white-space: nowrap; background: var(--surface-3); color: var(--text); font-size: 12.5px; font-weight: 600; padding: 6px 10px; border-radius: 8px; opacity: 0; pointer-events: none; transform: translateX(-4px); transition: all var(--ease) .15s; z-index: 60; box-shadow: var(--shadow-pop); }
.rail-btn:hover .lbl { opacity: 1; transform: none; }
.rail .spacer { flex: 1; }

/* ============================================================ main + panes */
.main { display: flex; flex-direction: column; overflow: hidden; min-width: 0; position: relative; }

/* header */
.view-head { padding: 26px 34px 18px; display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; flex: none; }
.view-head .vh-l { min-width: 0; }
.view-head .eyebrow { font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--iris-2); font-weight: 700; margin-bottom: 8px; }
.view-head h1 { font-size: 30px; font-weight: 700; margin: 0; letter-spacing: -0.02em; line-height: 1; }
.view-head .vh-sub { color: var(--dim); font-size: 14px; margin-top: 9px; }
.view-head .vh-actions { display: flex; gap: 9px; align-items: center; flex: none; }

.seg {
  display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 11px; padding: 3px; gap: 2px;
}
.seg button { border: none; background: none; color: var(--dim); font-size: 13px; font-weight: 600; padding: 7px 13px; border-radius: 8px; transition: all var(--ease) .18s; white-space: nowrap; }
.seg button.on { color: #fff; background: var(--surface-3); box-shadow: 0 1px 3px rgba(0,0,0,0.3); }
.seg button:hover:not(.on) { color: var(--text); }

.icon-btn { width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line-2); background: var(--surface); color: var(--dim); display: grid; place-items: center; transition: all var(--ease) .18s; flex: none; }
.icon-btn svg { width: 20px; height: 20px; stroke-width: 1.8; }
.icon-btn:hover { color: var(--text); border-color: var(--line-3); background: var(--surface-2); }
.icon-btn.on { color: #fff; background: var(--iris); border-color: transparent; }

.scroller { flex: 1; overflow-y: auto; padding: 4px 34px 120px; }

/* ============================================================ task row */
.task {
  --tint: color-mix(in srgb, var(--tc, #6b6b78) 13%, var(--surface));
  --tint-line: color-mix(in srgb, var(--tc, #6b6b78) 34%, var(--line-2));
  display: flex; align-items: flex-start; gap: 11px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid transparent;
  border-radius: var(--radius);
  padding: var(--row-pad) 14px var(--row-pad) 13px;
  transition: background var(--ease) .15s, border-color var(--ease) .15s, transform .08s var(--ease), opacity .15s, box-shadow var(--ease) .15s;
  position: relative;
}
.task[data-tc] { background: var(--tint); border-color: var(--tint-line); border-left-color: var(--tc); }
.task:hover { box-shadow: 0 6px 18px -8px rgba(0,0,0,0.6); }
.task:hover:not([data-tc]) { border-color: var(--line-2); }
.task.done { opacity: 0.48; }
.task.dragging { opacity: 0.3; }
.task.lift { box-shadow: var(--shadow-pop); transform: scale(1.005); }

.task .grip { cursor: grab; color: var(--faint); opacity: 0; margin: 3px -2px 0 -3px; transition: opacity var(--ease) .15s; flex: none; touch-action: none; }
.task:hover .grip { opacity: .55; }
.task .grip:active { cursor: grabbing; }
.task .grip svg { width: 15px; height: 17px; }

.cbx { width: 21px; height: 21px; border-radius: 7px; flex: none; margin-top: 1px; border: 2px solid var(--line-3); background: none; display: grid; place-items: center; transition: all var(--ease) .15s; }
.task[data-tc] .cbx { border-color: color-mix(in srgb, var(--tc) 60%, transparent); }
.cbx:hover { border-color: var(--tc, var(--iris)); }
.cbx.on { background: var(--tc, var(--iris)); border-color: transparent; }
.cbx svg { width: 12px; height: 12px; stroke: #0A0A0F; stroke-width: 3.5; opacity: 0; transform: scale(.4); transition: all var(--ease) .18s; }
.cbx.on svg { opacity: 1; transform: scale(1); }

.task-main { flex: 1; min-width: 0; cursor: default; }
.task-title { font-size: var(--fs-task); font-weight: 600; line-height: 1.34; color: var(--text); outline: none; border-radius: 5px; word-break: break-word; letter-spacing: -0.005em; }
.task.done .task-title { text-decoration: line-through; color: var(--dim); }
.task-title[contenteditable]:focus { box-shadow: 0 0 0 1px var(--line-2); padding: 1px 5px; margin: -1px -5px; background: var(--bg); }

.task-meta { display: flex; align-items: center; gap: 7px; margin-top: 8px; flex-wrap: wrap; }
.task-meta:empty { display: none; }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: 8px; background: rgba(255,255,255,0.05); border: 1px solid var(--line); color: var(--dim); }
.chip svg { width: 13px; height: 13px; }
.chip.due.overdue { color: #ffb3ba; border-color: rgba(251,94,111,0.4); background: rgba(251,94,111,0.1); }
.chip.due.today-due { color: #8ff0c4; border-color: rgba(47,217,138,0.4); background: rgba(47,217,138,0.1); }
.chip.grp .gd { width: 7px; height: 7px; border-radius: 50%; }
.chip.att svg { width: 13px; height: 13px; }
.prio { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 8px; }
.prio .pd { width: 6px; height: 6px; border-radius: 50%; }
.prio.alta { color: #ff9aa3; background: rgba(251,94,111,0.13); } .prio.alta .pd { background: var(--bad); }
.prio.media { color: #ffd089; background: rgba(255,178,63,0.12); } .prio.media .pd { background: var(--warn); }
.prio.bassa { color: #9fc3ff; background: rgba(70,166,255,0.12); } .prio.bassa .pd { background: var(--sky, #46A6FF); }

/* attachment preview inside row */
.att-strip { display: flex; gap: 8px; margin-top: 9px; flex-wrap: wrap; }
.att-thumb { width: 54px; height: 54px; border-radius: 9px; overflow: hidden; border: 1px solid var(--line-2); flex: none; cursor: pointer; background: var(--bg); }
.att-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.att-audio { display: inline-flex; align-items: center; gap: 8px; background: rgba(255,255,255,0.05); border: 1px solid var(--line-2); border-radius: 9px; padding: 5px 11px 5px 6px; }
.att-audio button { width: 28px; height: 28px; border-radius: 8px; border: none; background: var(--iris); color: #fff; display: grid; place-items: center; flex: none; }
.att-audio button svg { width: 14px; height: 14px; }
.att-audio .wave { display: flex; gap: 2px; align-items: center; height: 16px; }
.att-audio .wave i { width: 2.5px; border-radius: 2px; background: var(--iris-2); display: block; }
.att-audio .dur { font-size: 11.5px; color: var(--dim); font-variant-numeric: tabular-nums; }

/* row actions */
.task-actions { display: flex; gap: 2px; align-items: center; opacity: 0; transition: opacity var(--ease) .15s; flex: none; }
.task:hover .task-actions, .task.menu-open .task-actions { opacity: 1; }
.ta-btn { width: 30px; height: 30px; border-radius: 9px; border: none; background: none; color: var(--faint); display: grid; place-items: center; transition: all var(--ease) .15s; position: relative; }
.ta-btn:hover { background: rgba(255,255,255,0.07); color: var(--text); }
.ta-btn.star.on { color: var(--warn); }
.ta-btn svg { width: 17px; height: 17px; stroke-width: 1.8; }
.ta-btn .swatch-dot { width: 15px; height: 15px; border-radius: 50%; border: 2px solid var(--line-3); }
.ta-btn .swatch-dot.set { border-color: transparent; }

/* color popover */
.color-pop {
  position: absolute; z-index: 80; top: calc(100% + 6px); right: 0;
  background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 14px; padding: 10px;
  box-shadow: var(--shadow-pop); display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; width: 188px;
  animation: pop .16s var(--ease);
}
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(.97); } }
.color-pop .sw { width: 26px; height: 26px; border-radius: 8px; border: 2px solid transparent; cursor: pointer; transition: transform var(--ease) .12s; position: relative; }
.color-pop .sw:hover { transform: scale(1.12); }
.color-pop .sw.on { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px #fff; }
.color-pop .sw.none { background: var(--surface-3); display: grid; place-items: center; }
.color-pop .sw.none svg { width: 14px; height: 14px; color: var(--faint); }

/* drop indicator */
.drop-line { height: 0; position: relative; }
.drop-line.show::after { content: ''; position: absolute; left: 4px; right: 4px; top: calc(var(--row-gap, 8px) / -2 - 1px); height: 2.5px; border-radius: 3px; background: var(--iris); box-shadow: 0 0 10px rgba(124,107,255,0.7); }

/* expanded detail */
.task-detail { margin-top: 11px; padding-top: 12px; border-top: 1px solid var(--line); display: grid; gap: 11px; animation: din .2s var(--ease); }
@keyframes din { from { opacity: 0; } }
.task-detail textarea { width: 100%; background: var(--bg); border: 1px solid var(--line-2); border-radius: 10px; color: var(--text); font-family: var(--font); font-size: 13.5px; line-height: 1.55; padding: 10px 12px; resize: vertical; min-height: 54px; outline: none; }
.task-detail textarea:focus { border-color: var(--iris); }
.drow { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; }
.drow .dlabel { font-size: 10.5px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--faint); margin-right: 3px; font-weight: 700; }
.cbtn { font-size: 12.5px; font-weight: 600; padding: 6px 12px; border-radius: 9px; border: 1px solid var(--line-2); background: var(--surface); color: var(--dim); transition: all var(--ease) .15s; }
.cbtn:hover { color: var(--text); border-color: var(--line-3); }
.cbtn.on { color: #fff; background: var(--iris); border-color: transparent; }
.cbtn.danger:hover { color: #ff9aa3; border-color: rgba(251,94,111,0.5); }

/* ============================================================ group block */
.group { margin-bottom: 30px; }
.group-head { display: flex; align-items: center; gap: 10px; padding: 6px 4px; border-radius: 9px; transition: background var(--ease) .15s; }
.group-head:hover { background: rgba(255,255,255,0.03); }
.group-head.drop-target { background: rgba(124,107,255,0.1); box-shadow: inset 0 0 0 1px var(--iris); }
.group-head .caret { width: 17px; height: 17px; color: var(--faint); transition: transform var(--ease) .18s; flex: none; cursor: pointer; }
.group-head.collapsed .caret { transform: rotate(-90deg); }
.group-head .gd { width: 11px; height: 11px; border-radius: 50%; flex: none; }
.group-head .gn { font-family: var(--font-display); font-size: 16px; font-weight: 600; letter-spacing: -0.01em; white-space: nowrap; outline: none; }
.group-head .gn[contenteditable]:focus { background: var(--surface); border-radius: 5px; padding: 1px 5px; margin: -1px -5px; box-shadow: 0 0 0 1px var(--line-2); }
.group-head .gc { font-size: 12.5px; color: var(--faint); font-variant-numeric: tabular-nums; font-weight: 600; }
.group-head .ga { margin-left: auto; display: flex; gap: 3px; opacity: 0; transition: opacity var(--ease) .15s; }
.group-head:hover .ga { opacity: 1; }
.group-head .ga button { width: 28px; height: 28px; border-radius: 8px; border: none; background: none; color: var(--faint); display: grid; place-items: center; }
.group-head .ga button:hover { background: rgba(255,255,255,0.07); color: var(--text); }
.group-head .ga button svg { width: 15px; height: 15px; stroke-width: 1.8; }

.group-body { padding-top: 11px; display: flex; flex-direction: column; gap: var(--row-gap); }
.group.collapsed .group-body { display: none; }
.subhead { display: flex; align-items: center; gap: 9px; padding: 10px 4px 3px; }
.subhead .sn { font-size: 11px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--faint); white-space: nowrap; }
.subhead .sl { flex: 1; height: 1px; background: var(--line); }

/* ============================================================ agenda */
.agenda-day { margin-bottom: 26px; }
.agenda-day .day-head { display: flex; align-items: baseline; gap: 12px; padding: 4px 4px 12px; position: sticky; top: 0; background: linear-gradient(var(--bg) 70%, transparent); z-index: 5; }
.agenda-day .dh-num { font-family: var(--font-display); font-size: 26px; font-weight: 700; letter-spacing: -0.02em; line-height: 1; }
.agenda-day .dh-meta { display: flex; flex-direction: column; gap: 2px; flex: none; }
.agenda-day .dh-day { font-size: 14px; font-weight: 700; white-space: nowrap; }
.agenda-day .dh-rel { font-size: 11.5px; color: var(--dim); }
.agenda-day.is-today .dh-num, .agenda-day.is-today .dh-day { color: var(--iris-2); }
.agenda-day.is-overdue .dh-num, .agenda-day.is-overdue .dh-day { color: #ff9aa3; }
.agenda-day .dh-line { flex: 1; height: 1px; background: var(--line); align-self: center; }
.agenda-day .dh-count { font-size: 12px; color: var(--faint); font-weight: 600; }
.agenda-list { display: flex; flex-direction: column; gap: var(--row-gap); padding-left: 2px; }

/* ============================================================ empty */
.empty { text-align: center; padding: 80px 20px; color: var(--faint); }
.empty .ering { width: 88px; height: 88px; margin: 0 auto 22px; border-radius: 26px; background: var(--surface); border: 1px solid var(--line-2); display: grid; place-items: center; position: relative; }
.empty .ering::after { content: ''; position: absolute; inset: -2px; border-radius: 28px; background: var(--iris-grad); opacity: .18; z-index: -1; filter: blur(8px); }
.empty .ering svg { width: 34px; height: 34px; color: var(--dim); stroke-width: 1.4; }
.empty h3 { color: var(--dim); font-size: 17px; font-weight: 700; margin: 0 0 7px; }
.empty p { font-size: 13.5px; margin: 0 auto; max-width: 340px; line-height: 1.5; }

/* ============================================================ composer (capture bar) */
.composer-wrap { position: absolute; left: 0; right: 0; bottom: 0; padding: 0 34px 22px; background: linear-gradient(transparent, var(--bg) 38%); pointer-events: none; }
.composer-wrap > * { pointer-events: auto; }
.composer {
  background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 18px;
  box-shadow: 0 18px 40px -16px rgba(0,0,0,0.8); overflow: hidden;
  transition: border-color var(--ease) .2s;
}
.composer.focus { border-color: var(--iris); box-shadow: 0 18px 40px -16px rgba(0,0,0,0.8), 0 0 0 3px rgba(124,107,255,0.18); }
.composer.rec { border-color: var(--bad); }

/* attachment tray */
.tray { display: flex; gap: 9px; padding: 12px 14px 0; flex-wrap: wrap; }
.tray:empty { display: none; }
.tray-item { position: relative; }
.tray-item .ti-img { width: 56px; height: 56px; border-radius: 11px; object-fit: cover; border: 1px solid var(--line-2); display: block; }
.tray-item .ti-audio { height: 56px; display: flex; align-items: center; gap: 9px; padding: 0 14px; background: var(--surface-3); border: 1px solid var(--line-2); border-radius: 11px; }
.tray-item .ti-audio svg { width: 18px; height: 18px; color: var(--iris-2); }
.tray-item .ti-audio .d { font-size: 12px; color: var(--dim); font-variant-numeric: tabular-nums; }
.tray-item .rm { position: absolute; top: -7px; right: -7px; width: 20px; height: 20px; border-radius: 50%; background: var(--surface-3); border: 1px solid var(--line-2); color: var(--text); display: grid; place-items: center; }
.tray-item .rm svg { width: 11px; height: 11px; }

.composer-row { display: flex; align-items: flex-end; gap: 8px; padding: 11px 11px 11px 14px; }
.composer textarea {
  flex: 1; background: none; border: none; outline: none; resize: none; color: var(--text);
  font-family: var(--font); font-size: 15.5px; line-height: 1.45; padding: 9px 0; max-height: 140px;
}
.composer textarea::placeholder { color: var(--faint); }
.comp-tool { width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--dim); display: grid; place-items: center; flex: none; transition: all var(--ease) .15s; }
.comp-tool:hover { color: var(--text); border-color: var(--line-3); background: var(--surface-3); }
.comp-tool svg { width: 19px; height: 19px; stroke-width: 1.8; }
.comp-tool.mic.armed { background: var(--bad); border-color: transparent; color: #fff; animation: micPulse 1.4s infinite; }
@keyframes micPulse { 0%,100% { box-shadow: 0 0 0 0 rgba(251,94,111,0.5); } 50% { box-shadow: 0 0 0 8px rgba(251,94,111,0); } }
.comp-send { width: 42px; height: 42px; border-radius: 12px; border: none; background: var(--iris-grad); color: #fff; display: grid; place-items: center; flex: none; transition: all var(--ease) .15s; box-shadow: 0 4px 14px -4px rgba(124,107,255,0.7); }
.comp-send:disabled { opacity: 0.35; box-shadow: none; }
.comp-send svg { width: 19px; height: 19px; stroke-width: 2.2; }

/* parse preview */
.parse-row { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 14px 12px; }
.parse-row:empty { display: none; }
.pchip { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 8px; border: 1px solid var(--line-2); color: var(--text); animation: pop .18s var(--ease); }
.pchip svg { width: 12px; height: 12px; }
.pchip .pd2 { width: 8px; height: 8px; border-radius: 50%; }

/* recording state */
.rec-bar { display: flex; align-items: center; gap: 13px; padding: 16px 16px; }
.rec-bar .rdot { width: 11px; height: 11px; border-radius: 50%; background: var(--bad); animation: blink 1s infinite; flex: none; }
@keyframes blink { 50% { opacity: .25; } }
.rec-bar .rtime { font-family: var(--font-display); font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }
.rec-bar .rwave { flex: 1; display: flex; gap: 3px; align-items: center; height: 28px; overflow: hidden; }
.rec-bar .rwave i { flex: 1; background: var(--iris-2); border-radius: 2px; min-height: 3px; transition: height .1s; }
.rec-bar .rtext { font-size: 13px; color: var(--dim); font-style: italic; max-width: 40%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec-bar .rstop { width: 40px; height: 40px; border-radius: 12px; border: none; background: var(--iris); color: #fff; display: grid; place-items: center; flex: none; }
.rec-bar .rstop.cancel { background: var(--surface-3); color: var(--dim); border: 1px solid var(--line-2); }
.rec-bar .rstop.cancel:hover { color: var(--text); }
.rec-bar .rstop svg { width: 16px; height: 16px; }

.comp-hint { display: flex; align-items: center; gap: 7px; padding: 0 16px 12px; font-size: 11px; color: var(--faint); }
.comp-hint kbd { font-family: var(--font); background: var(--surface); border: 1px solid var(--line-2); border-radius: 5px; padding: 1px 6px; font-size: 10.5px; color: var(--dim); }

/* ============================================================ CHAT (Cervello) view */
.brain { display: grid; grid-template-rows: auto 1fr auto; height: 100%; overflow: hidden; }
.brain-scroll { overflow-y: auto; padding: 8px 0 18px; }
.brain-inner { max-width: 760px; margin: 0 auto; padding: 0 30px; display: flex; flex-direction: column; gap: 18px; }

.brain-hero { text-align: center; padding: 26px 0 8px; }
.brain-hero .orb { width: 72px; height: 72px; border-radius: 50%; margin: 0 auto 18px; background: var(--iris-grad); display: grid; place-items: center; position: relative; box-shadow: 0 10px 40px -8px rgba(124,107,255,0.7); }
.brain-hero .orb::after { content: ''; position: absolute; inset: -6px; border-radius: 50%; border: 1px solid var(--line-2); }
.brain-hero .orb svg { width: 34px; height: 34px; color: #fff; }
.brain-hero h2 { font-size: 25px; font-weight: 700; margin: 0 0 8px; letter-spacing: -0.02em; }
.brain-hero p { color: var(--dim); font-size: 14.5px; margin: 0 auto; max-width: 420px; line-height: 1.55; }

.suggest-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }
.sg-card { text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 15px; color: var(--text); font-size: 13.5px; font-weight: 600; line-height: 1.4; transition: all var(--ease) .15s; display: flex; gap: 11px; align-items: center; }
.sg-card:hover { border-color: var(--line-3); background: var(--surface-2); transform: translateY(-1px); }
.sg-card .si { width: 34px; height: 34px; border-radius: 10px; background: rgba(124,107,255,0.13); display: grid; place-items: center; flex: none; }
.sg-card .si svg { width: 18px; height: 18px; color: var(--iris-2); }

.msg { display: flex; gap: 12px; max-width: 100%; animation: msgin .25s var(--ease); }
@keyframes msgin { from { transform: translateY(8px); } }
.msg .av { width: 30px; height: 30px; border-radius: 50%; flex: none; display: grid; place-items: center; }
.msg.bot .av { background: var(--iris-grad); } .msg.bot .av svg { width: 16px; height: 16px; color: #fff; }
.msg.user { flex-direction: row-reverse; }
.msg.user .av { background: var(--surface-3); border: 1px solid var(--line-2); color: var(--dim); } .msg.user .av svg { width: 15px; height: 15px; }
.bubble { font-size: 14.5px; line-height: 1.6; padding: 12px 15px; border-radius: 16px; word-break: break-word; max-width: 86%; }
.msg.bot .bubble { background: var(--surface); border: 1px solid var(--line); border-top-left-radius: 5px; }
.msg.user .bubble { background: rgba(124,107,255,0.15); border: 1px solid rgba(124,107,255,0.3); border-top-right-radius: 5px; }
.bubble p { margin: 0 0 9px; } .bubble p:last-child { margin: 0; }
.bubble p.md-h { font-family: var(--font-display); font-weight: 600; font-size: 14.5px; margin: 13px 0 6px; } .bubble p.md-h:first-child { margin-top: 0; }
.bubble strong { font-weight: 700; color: #fff; }
.bubble em { font-style: italic; color: var(--dim); }
.bubble ul, .bubble ol { margin: 7px 0; padding-left: 20px; } .bubble li { margin: 4px 0; }
.bubble .att-strip { margin: 4px 0 0; }
.bubble .um-img { max-width: 220px; border-radius: 11px; margin-bottom: 8px; display: block; border: 1px solid var(--line-2); }

.typing { display: flex; gap: 4px; padding: 5px 2px; }
.typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); animation: tb 1.2s infinite; }
.typing span:nth-child(2){animation-delay:.2s;} .typing span:nth-child(3){animation-delay:.4s;}
@keyframes tb { 0%,60%,100%{opacity:.25;} 30%{opacity:1;} }

.brain-foot { padding: 0 30px 20px; max-width: 760px; margin: 0 auto; width: 100%; }
.mode-seg { display: flex; gap: 6px; margin-bottom: 11px; justify-content: center; }
.mode-seg button { font-size: 12.5px; font-weight: 700; padding: 7px 16px; border-radius: 99px; border: 1px solid var(--line-2); background: var(--surface); color: var(--dim); transition: all var(--ease) .15s; display: inline-flex; align-items: center; gap: 6px; }
.mode-seg button svg { width: 14px; height: 14px; }
.mode-seg button.on { color: #fff; background: var(--iris); border-color: transparent; }

.saved-flash { font-size: 12.5px; color: var(--ok); font-weight: 700; text-align: center; margin-bottom: 9px; animation: pop .2s var(--ease); }

/* memory list (cattura mode) */
.mem-head { font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--faint); font-weight: 700; margin: 4px 0 2px; }
.mem-card { background: var(--surface); border: 1px solid var(--line); border-radius: 13px; padding: 13px 15px; display: flex; flex-direction: column; gap: 9px; animation: msgin .2s var(--ease); }
.mem-card .mc-top { display: flex; align-items: center; gap: 9px; }
.mem-card .mc-tag { font-size: 10.5px; font-weight: 700; letter-spacing: 0.06em; padding: 3px 9px; border-radius: 7px; background: rgba(124,107,255,0.14); color: var(--iris-2); }
.mem-card .mc-time { font-size: 11px; color: var(--faint); margin-left: auto; }
.mem-card .mc-text { font-size: 14px; line-height: 1.55; color: var(--text); }

/* image lightbox */
.lightbox { position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,0.85); display: grid; place-items: center; padding: 40px; animation: din .2s var(--ease); }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 14px; box-shadow: var(--shadow-pop); }
.lightbox .lb-close { position: absolute; top: 24px; right: 24px; }

/* toast */
.toast { position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%); z-index: 300; background: var(--surface-3); border: 1px solid var(--line-2); color: var(--text); font-size: 13.5px; font-weight: 600; padding: 12px 20px; border-radius: 12px; box-shadow: var(--shadow-pop); animation: toastin .25s var(--ease); display: flex; align-items: center; gap: 9px; }
.toast svg { width: 17px; height: 17px; color: var(--warn); }
@keyframes toastin { from { opacity: 0; transform: transl(-50%, 10px); } }

/* groups quick-bar in task views */
.grpbar { display: flex; gap: 8px; flex-wrap: wrap; padding: 2px 0 18px; }
.grp-pill { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 600; padding: 8px 14px; border-radius: 11px; border: 1px solid var(--line); background: var(--surface); color: var(--dim); transition: all var(--ease) .15s; }
.grp-pill:hover { color: var(--text); border-color: var(--line-2); }
.grp-pill.on { color: #fff; background: var(--surface-3); border-color: var(--line-3); }
.grp-pill .gd { width: 9px; height: 9px; border-radius: 50%; }
.grp-pill .gc { font-size: 11.5px; color: var(--faint); font-variant-numeric: tabular-nums; }
.grp-pill.add { color: var(--iris-2); border-style: dashed; }
.grp-pill.add svg { width: 15px; height: 15px; }

/* la bottom-nav esiste solo su mobile (nascosta su desktop) */
.botnav { display: none; }

@media (max-width: 860px) {
  .app, .app.split { grid-template-columns: 56px 1fr; }
  .rail { width: 56px; }
  .scroller, .composer-wrap { padding-left: 16px; padding-right: 16px; }
  .view-head { padding: 20px 16px 14px; }
  .suggest-grid { grid-template-columns: 1fr; }
  .brain-inner, .brain-foot { padding-left: 16px; padding-right: 16px; }
}

/* ====== MOBILE: rail nascosta, bottom-nav attiva ====== */
@media (max-width: 640px) {
  .app, .app.split { grid-template-columns: 1fr; }
  .rail { display: none; }

  .botnav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 120;
    background: color-mix(in srgb, var(--bg-2) 92%, transparent);
    backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--line-2);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
  }
  .bn-btn {
    flex: 1; min-width: 0; border: none; background: none; color: var(--faint);
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    padding: 7px 2px; border-radius: 12px; min-height: 52px; transition: color var(--ease) .15s, background var(--ease) .15s;
  }
  .bn-btn .bn-ic { position: relative; display: grid; place-items: center; }
  .bn-btn .bn-ic svg { width: 23px; height: 23px; stroke-width: 1.8; }
  .bn-btn .bn-lbl { font-size: 10.5px; font-weight: 700; letter-spacing: -0.01em; }
  .bn-btn.on { color: var(--text); }
  .bn-btn.on .bn-ic::after { content: ''; position: absolute; inset: -7px -10px; border-radius: 12px; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line-2); z-index: -1; }
  .bn-btn .bn-pip { position: absolute; top: -6px; right: -10px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--iris); color: #fff; font-size: 10px; font-weight: 700; display: grid; place-items: center; }

  /* lo scroller deve lasciare spazio a composer + bottom-nav */
  .scroller { padding-bottom: 200px; -webkit-overflow-scrolling: touch; }
  .composer-wrap { bottom: calc(64px + env(safe-area-inset-bottom, 0px)); padding-bottom: 12px; }
  .brain { padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px)); }

  /* target touch più ampi */
  .task-actions { opacity: 1; }
  .ta-btn { width: 38px; height: 38px; }
  .ta-btn svg { width: 19px; height: 19px; }
  .cbx { width: 24px; height: 24px; }
  .task .grip { opacity: .6; }   /* maniglia sempre visibile su mobile */
  .comp-send { width: 46px; height: 46px; }
  .comp-tool { width: 44px; height: 44px; }
  .view-head h1 { font-size: 25px; }
  .grp-pill { padding: 9px 14px; }
}

/* ============================================================ sotto-task */
.subtasks { display: flex; flex-direction: column; gap: var(--row-gap); margin-top: var(--row-gap); padding-left: 26px; position: relative; }
.subtasks::before { content: ''; position: absolute; left: 12px; top: -2px; bottom: 10px; width: 2px; border-radius: 2px; background: var(--line); }
.task.subtask { padding-top: 9px; padding-bottom: 9px; background: var(--surface); border-style: solid; }
.task.subtask .task-title { font-size: 14px; font-weight: 500; }
.task .sub-elbow { width: 6px; flex: none; }
.chip.sub-count { color: var(--iris-2); border-color: rgba(124,107,255,0.3); background: rgba(124,107,255,0.1); }
.ta-btn.add-sub svg { width: 16px; height: 16px; }

/* riga "aggiungi sotto-attività" */
.subadd { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.subadd input {
  flex: 1; background: var(--bg); border: 1px solid var(--line-2); border-radius: 10px;
  color: var(--text); font-family: var(--font); font-size: 13.5px; padding: 9px 12px; outline: none;
}
.subadd input:focus { border-color: var(--iris); }

/* ============================================================ footer "completate" (vista Oggi) */
.done-footer { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; padding: 14px 2px 4px; margin-top: 4px; border-top: 1px dashed var(--line); }
.df-toggle, .df-archive {
  display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 600;
  padding: 7px 13px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--surface); color: var(--dim);
  transition: all var(--ease) .15s;
}
.df-toggle:hover, .df-archive:hover { color: var(--text); border-color: var(--line-3); }
.df-toggle svg, .df-archive svg { width: 15px; height: 15px; }
.df-archive { color: var(--iris-2); }

/* archivio */
.task.archived { opacity: 0.62; }
.task.archived .task-title { text-decoration: line-through; }

/* ============================================================ barra di sincronizzazione (non invasiva) */
.sync-bar { position: absolute; top: 0; left: 0; right: 0; height: 2px; z-index: 40; overflow: hidden; background: transparent; }
.sync-bar::after {
  content: ''; position: absolute; top: 0; left: -40%; width: 40%; height: 100%;
  background: var(--iris-grad); animation: syncSlide 1.1s var(--ease) infinite;
}
@keyframes syncSlide { 0% { left: -40%; } 100% { left: 100%; } }

/* riduci animazioni se l'utente lo preferisce */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ============================================================
   PWA — Login + Promemoria (aggiunte rispetto al design base)
   ============================================================ */
.login-screen {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: var(--bg); padding: 24px; z-index: 200;
}
.login-card {
  position: relative; z-index: 2; width: 100%; max-width: 360px;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: 22px;
  padding: 34px 28px; display: flex; flex-direction: column; align-items: center; gap: 12px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.55);
}
.login-orb {
  width: 64px; height: 64px; border-radius: 20px; display: grid; place-items: center;
  background: var(--iris-grad); color: #fff; margin-bottom: 4px;
  box-shadow: 0 10px 30px rgba(124,107,255,0.35);
}
.login-orb svg { width: 32px; height: 32px; }
.login-card h1 { font-family: var(--font-display); font-size: 22px; margin: 2px 0 0; color: var(--text); }
.login-card p { color: var(--dim); font-size: 13.5px; margin: 0 0 8px; text-align: center; }
.login-card input {
  width: 100%; box-sizing: border-box; background: var(--bg-2); border: 1px solid var(--line-2);
  border-radius: 12px; padding: 13px 14px; color: var(--text); font-size: 15px; outline: none;
  transition: border-color var(--ease) .15s;
}
.login-card input:focus { border-color: var(--iris); }
.login-err { width: 100%; color: var(--bad); font-size: 13px; text-align: center; }
.login-btn {
  width: 100%; border: none; border-radius: 12px; padding: 13px; margin-top: 4px;
  background: var(--iris); color: #fff; font-weight: 700; font-size: 15px; cursor: pointer;
  transition: filter var(--ease) .15s, opacity var(--ease) .15s;
}
.login-btn:hover:not(:disabled) { filter: brightness(1.08); }
.login-btn:disabled { opacity: .55; cursor: default; }

/* striscia promemoria imminenti sopra lo scroller */
.reminders-strip {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin: 0 28px 8px; padding: 9px 12px; border-radius: 12px;
  background: rgba(124,107,255,0.08); border: 1px solid rgba(124,107,255,0.22);
  color: var(--dim); font-size: 12.5px;
}
.reminders-strip > svg { width: 16px; height: 16px; color: var(--iris-2); flex: none; }
.reminders-strip .rs-title { font-weight: 700; color: var(--text); }
.reminders-strip .rs-pill {
  display: inline-flex; align-items: center; max-width: 320px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; padding: 3px 9px; border-radius: 8px;
  background: rgba(255,255,255,0.05); border: 1px solid var(--line); color: var(--text);
}
@media (max-width: 720px) { .reminders-strip { margin-left: 16px; margin-right: 16px; } }

/* mem-head con icona inline */
.mem-head { display: flex; align-items: center; gap: 6px; }
.mem-head svg { width: 15px; height: 15px; }
.mc-tag svg { width: 13px; height: 13px; vertical-align: -2px; margin-right: 3px; }
