/* ============================================================
   style.css — Assistente Finanziario AI
   ============================================================ */
/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:           #090e17;
    --surface:      rgba(30, 41, 59, 0.65);
    --surface2:     rgba(30, 41, 59, 0.90);
    --border:       rgba(255, 255, 255, 0.09);
    --border-focus: rgba(139, 92, 246, 0.6);
    --text:         #f0f4fc;
    --text-dim:     #e2e8f0;
    --muted:        #94a3b8;
    --primary:      #8b5cf6;
    --primary-glow: rgba(139, 92, 246, 0.28);
    --green:        #10b981;
    --red:          #f43f5e;
    --yellow:       #f59e0b;
    --radius-card:  20px;
    --radius-input: 10px;
}
body.light {
    --bg:       #eef2fa;
    --surface:  rgba(255, 255, 255, 0.72);
    --surface2: rgba(255, 255, 255, 0.95);
    --border:   rgba(0, 0, 0, 0.08);
    --border-focus: rgba(139, 92, 246, 0.5);
    --text:     #0f172a;
    --text-dim: #1e293b;
    --muted:    #64748b;
}

html { font-size: 16px; }
body {
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
    transition: background 0.3s, color 0.3s;
    -webkit-font-smoothing: antialiased;
}

/* Ambient top glow */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    background: radial-gradient(circle at 50% 0%, #1e1b4b 0%, transparent 55%);
    z-index: -1;
    pointer-events: none;
}
body.light::before {
    background: radial-gradient(circle at 50% 0%, #ddd6fe 0%, transparent 55%);
}

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-thumb { background: rgba(150,150,150,0.25); border-radius: 10px; }

/* ============================================================
   TOP MENU
   ============================================================ */
.top-menu {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    padding: 14px 20px;
    flex-wrap: wrap;
    position: relative;
    z-index: 100;
}

/* shared control style */
.ctrl {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 9px 16px;
    border-radius: 12px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    backdrop-filter: blur(12px);
    transition: background 0.18s, transform 0.18s, border-color 0.18s;
    white-space: nowrap;
}
.ctrl:hover {
    background: var(--surface2);
    transform: translateY(-1px);
}
.ctrl:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}
.ctrl--primary {
    background: var(--primary);
    color: #fff;
    border-color: transparent;
}
.ctrl--primary:hover {
    background: #7c3aed;
}

/* ============================================================
   MAIN 3-COLUMN LAYOUT
   ============================================================ */
.main-layout {
    display: grid;
    grid-template-columns: 290px 1fr 290px;
    gap: 18px;
    width: 100%;
    max-width: 1380px;
    margin: 0 auto;
    padding: 6px 18px 48px;
    align-items: start;
}

@media (max-width: 1150px) {
    .main-layout {
        grid-template-columns: 1fr;
        max-width: 580px;
    }
    .center-stage { order: -1; }
}

/* ============================================================
   GLASS CARD (base block)
   ============================================================ */
.glass-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: 20px;
    backdrop-filter: blur(14px);
    box-shadow: 0 6px 28px rgba(0,0,0,0.18);
}

/* ============================================================
   SIDE PANELS
   ============================================================ */
.side-panel {
    display: flex;
    flex-direction: column;
    gap: 16px;
    /* prevent overflow beyond grid cell */
    min-width: 0;
    width: 100%;
}

/* Right panel specific: constrain height so form stays in view */
#right-panel .glass-card {
    display: flex;
    flex-direction: column;
}

/* ============================================================
   METRICS (left panel)
   ============================================================ */
.metric-title {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--muted);
    margin-bottom: 6px;
}
.metric-value {
    font-size: 2.1rem;
    font-weight: 700;
    letter-spacing: -1px;
    line-height: 1;
}
.metric-row {
    display: flex;
    justify-content: space-between;
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
    gap: 10px;
}
.metric-row > div { flex: 1; }

.text-green  { color: var(--green); }
.text-yellow { color: var(--yellow); }
.text-red    { color: var(--red); }

/* 50/30/20 bars */
.bar-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.82rem;
    margin-bottom: 5px;
}
.progress-bg {
    height: 7px;
    background: rgba(0,0,0,0.25);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 10px;
}
body.light .progress-bg { background: rgba(0,0,0,0.08); }
.progress-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.7s cubic-bezier(.4,0,.2,1);
}

/* Fido input */
.fido-input {
    width: 100%;
    text-align: center;
    font-size: 1.5rem;
    font-weight: 700;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--muted);
    color: var(--text);
    padding: 6px 4px;
    font-family: inherit;
    transition: border-color 0.2s;
}
.fido-input:focus {
    outline: none;
    border-bottom-color: var(--primary);
}

/* ============================================================
   CATEGORY LIST (right panel - dashboard view)
   ============================================================ */
.cat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    border-radius: 14px;
    border: 1px solid transparent;
    background: rgba(255,255,255,0.03);
    cursor: pointer;
    transition: background 0.18s, border-color 0.18s, transform 0.18s;
    user-select: none;
}
body.light .cat-item { background: rgba(0,0,0,0.03); border-color: var(--border); }
.cat-item:hover {
    background: rgba(255,255,255,0.07);
    border-color: var(--primary-glow);
    transform: translateX(3px);
}
.cat-item__name { font-weight: 600; font-size: 0.92rem; }
.cat-item__amount { font-size: 1.1rem; font-weight: 700; }

/* ============================================================
   CATEGORY DETAIL (right panel - detail view)
   ============================================================ */
.detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.detail-header h3 {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--primary);
    margin: 0;
}

/* Entry list */
.entry-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 280px;
    overflow-y: auto;
    padding-right: 4px;
    /* reserve space for scrollbar */
    margin-right: -4px;
}

.entry-row {
    display: grid;
    grid-template-columns: 32px 1fr auto 28px;
    gap: 8px;
    align-items: center;
    padding: 10px 12px;
    background: rgba(0,0,0,0.18);
    border-radius: 11px;
    font-size: 0.88rem;
}
body.light .entry-row { background: rgba(0,0,0,0.05); }

.entry-icon { font-size: 1.3rem; text-align: center; line-height: 1; }
.entry-name { font-weight: 600; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry-meta { font-size: 0.72rem; color: var(--muted); margin-top: 1px; }
.entry-amount { font-weight: 700; font-size: 0.95rem; text-align: right; white-space: nowrap; }
.btn-remove {
    background: transparent;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 1rem;
    padding: 2px;
    line-height: 1;
    transition: color 0.15s;
    border-radius: 4px;
}
.btn-remove:hover { color: var(--red); }

.empty-state {
    text-align: center;
    color: var(--muted);
    padding: 28px 0 14px;
    font-size: 0.9rem;
    font-style: italic;
}

/* ============================================================
   ADD FORM  ← fixed layout
   ============================================================ */
.add-form-section {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
}
.add-form-section .section-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 10px;
}

/* Stacked layout — no 2-column grid that overflows 290px */
.add-form-stack {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.add-form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

/* All form controls share this base */
.form-ctrl {
    background: rgba(0,0,0,0.22);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-input);
    padding: 9px 12px;
    font-family: inherit;
    font-size: 0.88rem;
    width: 100%;
    transition: border-color 0.18s, background 0.18s;
}
body.light .form-ctrl {
    background: rgba(255,255,255,0.7);
    color: var(--text);
}
.form-ctrl:focus {
    outline: none;
    border-color: var(--border-focus);
    background: rgba(139, 92, 246, 0.06);
}
.form-ctrl::placeholder { color: var(--muted); }

/* Date picker icon */
.form-ctrl[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(0.7);
    cursor: pointer;
    opacity: 0.6;
}
body.light .form-ctrl[type="date"]::-webkit-calendar-picker-indicator { filter: none; opacity: 0.5; }

.btn-add {
    width: 100%;
    padding: 10px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius-input);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.18s, transform 0.15s;
    margin-top: 2px;
}
.btn-add:hover { background: #7c3aed; transform: translateY(-1px); }
.btn-add:active { transform: translateY(0); }

.btn-delete-cat {
    width: 100%;
    margin-top: 14px;
    padding: 9px;
    background: rgba(244,63,94,0.08);
    border: 1px solid var(--red);
    border-radius: var(--radius-input);
    color: var(--red);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.18s;
}
.btn-delete-cat:hover { background: rgba(244,63,94,0.18); }

/* ============================================================
   CENTER STAGE: AI AVATAR + CHAT
   ============================================================ */
.center-stage {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.avatar-stage {
    position: relative;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 5;
    padding: 0 0 8px;
}

.avatar-wrapper {
    width: 200px;
    height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.ai-avatar-widget { display: block; width: 100%; height: 100%; }
.ai-avatar-svg    { width: 100%; height: 100%; overflow: visible; }

/* Avatar internals */
.ai-avatar-body-group { transform-origin: 120px 112px; will-change: transform; }
.ai-avatar-body       { filter: drop-shadow(0 20px 28px rgba(0,0,0,0.55)); transition: all 1s ease-in-out; }
.ai-avatar-highlight  { fill: rgba(255,255,255,0.32); opacity: 0.55; filter: blur(1px); }
.ai-faceplate         { fill: rgba(3,3,7,0.88); stroke: rgba(198,154,255,0.22); stroke-width: 2; }
.ai-eyes              { transform-origin: 120px 110px; will-change: transform; }
.ai-eye               { fill: var(--ai-eye-color, #c69aff); filter: drop-shadow(0 0 5px var(--ai-eye-glow, rgba(198,154,255,0.8))) drop-shadow(0 0 13px var(--ai-eye-glow, rgba(198,154,255,0.8))); transition: all 0.5s ease; }
.ai-orb-group         { transform-origin: 180px 126px; will-change: transform; }
.ai-orb               { filter: drop-shadow(0 8px 18px rgba(0,0,0,0.5)); }
.ai-orb-dot           { fill: var(--ai-eye-color, #c69aff); filter: drop-shadow(0 0 5px var(--ai-eye-glow, rgba(198,154,255,0.8))); }
.ai-ground-glow       { fill: var(--ai-ground-color, rgba(168,104,255,0.4)); filter: blur(10px); transform-origin: 120px 202px; will-change: transform, opacity; }

/* States */
.is-ottimo   { --ai-eye-color:#d9d1ff; --ai-eye-glow:rgba(217,209,255,0.95); --ai-ground-color:rgba(190,150,255,0.55); }
.is-normal   { --ai-eye-color:#c69aff; --ai-eye-glow:rgba(198,154,255,0.78); --ai-ground-color:rgba(168,104,255,0.42); }
.is-warning  { --ai-eye-color:#b899ff; --ai-eye-glow:rgba(184,153,255,0.6);  --ai-ground-color:rgba(155,92,255,0.34); }
.is-critical { --ai-eye-color:#ff7f9c; --ai-eye-glow:rgba(255,91,122,0.65); --ai-ground-color:rgba(255,70,100,0.4); }

.is-ottimo  .ai-avatar-body-group { animation: ai-float-ottimo  4s ease-in-out infinite; }
.is-normal  .ai-avatar-body-group { animation: ai-float-normal  5s ease-in-out infinite; }
.is-warning .ai-avatar-body-group { animation: ai-float-warning 6s ease-in-out infinite; }
.is-critical .ai-avatar-body-group { animation: ai-float-critical 8s ease-in-out infinite; }

.is-ottimo  .ai-orb-group { animation: ai-orb-ottimo  5s ease-in-out infinite; }
.is-normal  .ai-orb-group { animation: ai-orb-normal  6s ease-in-out infinite; }
.is-warning .ai-orb-group { animation: ai-orb-warning 7s ease-in-out infinite; }
.is-critical .ai-orb-group { animation: ai-orb-critical 8s ease-in-out infinite; }

.is-ottimo  .ai-ground-glow { animation: ai-shadow-ottimo  4s ease-in-out infinite; }
.is-normal  .ai-ground-glow { animation: ai-shadow-normal  5s ease-in-out infinite; }
.is-warning .ai-ground-glow { animation: ai-shadow-warning 6s ease-in-out infinite; }
.is-critical .ai-ground-glow { animation: ai-shadow-critical 8s ease-in-out infinite; }

.is-ottimo .ai-eye  { rx: 8px; ry: 16px; }
.is-warning .ai-eye { rx: 7px; ry: 12px; }
.is-warning .ai-eye-left  { transform: rotate(-5deg); }
.is-warning .ai-eye-right { transform: rotate(5deg); }
.is-critical .ai-avatar-body { rx: 58px; ry: 50px; }
.is-critical .ai-eye { rx: 8px; ry: 8px; opacity: 0.9; }
.is-critical .ai-eye-left  { transform: rotate(-8deg) scaleY(0.75); }
.is-critical .ai-eye-right { transform: rotate(8deg) scaleY(0.75); }

@keyframes ai-float-ottimo  { 0%,100% {transform:translateY(-10px)} 50% {transform:translateY(-28px) scale(1.02)} }
@keyframes ai-float-normal  { 0%,100% {transform:translateY(0)} 50% {transform:translateY(-18px) scale(1.01)} }
@keyframes ai-float-warning { 0%,100% {transform:translateY(10px)} 50% {transform:translateY(2px)} }
@keyframes ai-float-critical { 0%,92%,100% {transform:translateY(20px) scale(1.05,0.95)} 96% {transform:translateY(20px) translateX(2px) scale(1.05,0.95)} }
@keyframes ai-orb-ottimo  { 0%,100% {transform:translate(0,0)} 33% {transform:translate(14px,-23px)} 66% {transform:translate(-9px,-13px)} }
@keyframes ai-orb-normal  { 0%,100% {transform:translate(0,0)} 50% {transform:translate(7px,-16px)} }
@keyframes ai-orb-warning { 0%,100% {transform:translate(-25px,15px)} 50% {transform:translate(-30px,20px)} }
@keyframes ai-orb-critical { 0%,100% {transform:translate(-45px,35px)} 50% {transform:translate(-45px,38px)} }
@keyframes ai-shadow-ottimo  { 0%,100% {transform:scale(0.9); opacity:0.6} 50% {transform:scale(0.6); opacity:0.2} }
@keyframes ai-shadow-normal  { 0%,100% {transform:scale(1); opacity:0.8} 50% {transform:scale(0.8); opacity:0.4} }
@keyframes ai-shadow-warning { 0%,100% {transform:scale(1.1); opacity:0.9} 50% {transform:scale(1.0); opacity:0.7} }
@keyframes ai-shadow-critical { 0%,100% {transform:scale(1.2); opacity:1} }
@keyframes ai-eye-breathe { 0%,100% {transform:scaleY(1)} 50% {transform:scaleY(1.04)} }
.ai-avatar-widget:not(.is-critical) .ai-eyes { animation: ai-eye-breathe 6s ease-in-out infinite, ai-blink-normal 7s ease-in-out infinite; }
@keyframes ai-blink-normal { 0%,93%,100% {transform:scaleY(1)} 95% {transform:scaleY(0.1)} 97% {transform:scaleY(1)} }

/* AI message */
#ai-message {
    font-size: 1rem;
    font-weight: 500;
    text-align: center;
    width: 100%;
    max-width: 420px;
    margin-top: 8px;
    line-height: 1.55;
    color: var(--muted);
    min-height: 52px;
    transition: color 0.3s;
    padding: 0 8px;
}

/* Chat input */
.chat-container {
    width: 100%;
    max-width: 440px;
    position: relative;
    margin-top: 14px;
}
#naturalStatus {
    position: absolute;
    width: 100%;
    text-align: center;
    top: -22px;
    font-size: 0.82rem;
    font-weight: 600;
    opacity: 0;
    transition: opacity 0.3s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#naturalInput {
    width: 100%;
    padding: 16px 20px;
    border-radius: 30px;
    border: 1px solid var(--border);
    background: rgba(10,15,30,0.55);
    color: var(--text);
    font-family: inherit;
    font-size: 0.96rem;
    backdrop-filter: blur(14px);
    box-shadow: 0 8px 36px rgba(0,0,0,0.28);
    text-align: center;
    transition: border-color 0.25s, box-shadow 0.25s, background 0.25s, transform 0.2s;
}
body.light #naturalInput { background: rgba(255,255,255,0.78); }
#naturalInput::placeholder { color: var(--muted); }
#naturalInput:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 8px 44px var(--primary-glow);
    transform: translateY(-2px);
}
#naturalInput:disabled { opacity: 0.5; cursor: not-allowed; }

/* ============================================================
   SHARED BACK BUTTON
   ============================================================ */
.btn-back {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
    border-radius: 8px;
    padding: 5px 12px;
    font-size: 0.82rem;
    cursor: pointer;
    font-family: inherit;
    transition: border-color 0.18s, color 0.18s;
}
.btn-back:hover { border-color: var(--muted); color: var(--text); }

/* ============================================================
   SMOOTH ORB MOTION FIX — solo animazione avatar/orb
   ============================================================ */
.ai-avatar-body-group,
.ai-orb-group,
.ai-ground-glow,
.ai-eyes,
.ai-eye,
.ai-eye-left,
.ai-eye-right {
    animation: none !important;
    transform-box: fill-box;
}

.ai-avatar-body-group,
.ai-orb-group,
.ai-orb,
.ai-orb-dot,
.ai-eyes,
.ai-eye {
    transform-origin: center center;
    transform-box: fill-box;
    will-change: transform;
}

.ai-orb-dot {
    filter:
        drop-shadow(0 0 6px var(--ai-eye-glow, rgba(198,154,255,0.85)))
        drop-shadow(0 0 16px var(--ai-eye-glow, rgba(198,154,255,0.55)));
}

.ai-orb {
    filter:
        drop-shadow(0 8px 18px rgba(0,0,0,0.5))
        drop-shadow(0 0 10px rgba(198,154,255,0.20));
}

.is-warning .ai-eye-left,
.is-warning .ai-eye-right,
.is-critical .ai-eye-left,
.is-critical .ai-eye-right {
    transform: none !important;
}
