/* ============================================================
   GESTIONALE FEDE — Design System
   Palette: ink navy + deep teal + amber (semaforo scadenze)
   Type: Space Grotesk (display) / Inter (body) / IBM Plex Mono (dati)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Inter:wght@400;500;600;700&family=IBM+Plex+Mono:wght@500;600&display=swap');

:root {
    /* Colore */
    --bg:            #F5F7F9;
    --surface:       #FFFFFF;
    --surface-alt:   #EEF2F5;
    --ink:           #131C24;
    --ink-soft:      #3A4552;
    --muted:         #6B7684;
    --border:        #E1E6EB;
    --border-strong: #CBD3DA;

    --primary:       #422774;
    --primary-dark:  #2A1A4E;
    --primary-soft:  #EDE8F5;
    --primary-contrast: #FFFFFF;

    --accent:        #E0983B;
    --accent-soft:   #FBEEDC;

    --danger:        #C4453C;
    --danger-soft:   #FBEAE8;
    --success:       #2E8B57;
    --success-soft:  #E7F4EC;

    /* Semaforo scadenze */
    --urgency-expired: #C4453C;
    --urgency-urgent:  #E0983B;
    --urgency-soon:    #D9B23C;
    --urgency-ok:      #2E8B57;

    /* Tipografia */
    --font-display: 'Space Grotesk', sans-serif;
    --font-body:    'Inter', sans-serif;
    --font-mono:    'IBM Plex Mono', monospace;

    /* Layout */
    --sidebar-w: 248px;
    --topbar-h: 64px;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px rgba(19, 28, 36, 0.06);
    --shadow-md: 0 4px 16px rgba(19, 28, 36, 0.08);
    --shadow-lg: 0 12px 32px rgba(19, 28, 36, 0.12);
}

/* --- Reset -------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-body);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 {
    font-family: var(--font-display);
    color: var(--ink);
    margin: 0 0 8px;
    letter-spacing: -0.01em;
}
h1 { font-size: 26px; font-weight: 700; }
h2 { font-size: 20px; font-weight: 600; }
h3 { font-size: 16px; font-weight: 600; }
p { margin: 0 0 12px; color: var(--ink-soft); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
ul { margin: 0; padding: 0; list-style: none; }
img { max-width: 100%; display: block; }
code, .mono { font-family: var(--font-mono); }

:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        transition-duration: 0.001ms !important;
    }
}

/* ============================================================
   AUTH LAYOUT (login)
   ============================================================ */
.auth-page {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1fr 1fr;
    background: var(--primary-dark);
}
.auth-visual {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 48px;
    background:
        radial-gradient(circle at 15% 20%, rgba(224,152,59,0.16), transparent 45%),
        linear-gradient(160deg, var(--primary-dark) 0%, #1A1033 100%);
    color: #EDE7F5;
    overflow: hidden;
}
.auth-visual__brand {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 20px;
    letter-spacing: -0.01em;
}
.auth-visual__brand span { color: var(--accent); }
.auth-visual__quote {
    max-width: 420px;
}
.auth-visual__quote h1 {
    color: #FFFFFF;
    font-size: 34px;
    line-height: 1.2;
}
.auth-visual__quote p { color: #C6BADD; font-size: 15px; }

/* Semaforo decorativo: rappresenta il motore scadenze, elemento firma */
.auth-visual__pulse {
    display: flex;
    gap: 6px;
    align-items: flex-end;
    height: 46px;
}
.auth-visual__pulse span {
    width: 8px;
    border-radius: 3px;
    background: var(--accent);
    opacity: 0.85;
    animation: pulse-bar 2.4s ease-in-out infinite;
}
.auth-visual__pulse span:nth-child(1) { height: 40%; animation-delay: 0s; }
.auth-visual__pulse span:nth-child(2) { height: 70%; animation-delay: 0.15s; }
.auth-visual__pulse span:nth-child(3) { height: 100%; background:#D9B23C; animation-delay: 0.3s; }
.auth-visual__pulse span:nth-child(4) { height: 55%; background:#2E8B57; animation-delay: 0.45s; }
.auth-visual__pulse span:nth-child(5) { height: 85%; background:#2E8B57; animation-delay: 0.6s; }
@keyframes pulse-bar {
    0%, 100% { transform: scaleY(1); opacity: 0.7; }
    50% { transform: scaleY(1.12); opacity: 1; }
}

.auth-form-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    padding: 32px;
}
.auth-form {
    width: 100%;
    max-width: 360px;
}
.auth-form h2 { font-size: 24px; margin-bottom: 4px; }
.auth-form .sub { color: var(--muted); margin-bottom: 28px; font-size: 14px; }

/* ============================================================
   FORM ELEMENTS
   ============================================================ */
.field { margin-bottom: 18px; }
.field label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--ink-soft);
    margin-bottom: 6px;
}
.field input,
.field select,
.field textarea {
    width: 100%;
    padding: 11px 14px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 14px;
    color: var(--ink);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}
.field .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

.search-results {
    display: none;
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    margin-top: 4px;
    max-height: 220px;
    overflow-y: auto;
    box-shadow: var(--shadow-sm);
}
.search-result-item {
    padding: 9px 14px;
    font-size: 13.5px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--surface-alt); }

.email-preview-head {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    border-bottom: none;
    background: var(--surface-alt);
    padding: 10px 16px;
    margin-bottom: -1px;
}
.email-preview-head div {
    display: flex;
    gap: 10px;
    font-size: 13px;
    color: var(--ink-soft);
    padding: 3px 0;
}
.email-preview-head span {
    width: 24px;
    flex-shrink: 0;
    font-weight: 600;
    color: var(--muted);
    font-size: 12px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 20px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.05s ease, box-shadow 0.15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: var(--primary-contrast); width: 100%; }
.btn-primary:hover { background: var(--primary-dark); text-decoration: none; }
.btn-ghost { background: transparent; border-color: var(--border-strong); color: var(--ink-soft); }
.btn-ghost:hover { background: var(--surface-alt); text-decoration: none; }
.btn-accent { background: var(--accent); color: #2A1B05; }
.btn-accent:hover { background: #C97F26; text-decoration: none; }

.alert {
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 18px;
    border: 1px solid transparent;
}
.alert-error { background: var(--danger-soft); color: #8A2E27; border-color: #F1C6C2; }
.alert-success { background: var(--success-soft); color: #1F5F3B; border-color: #BFE3CC; }

/* ============================================================
   APP LAYOUT (dashboard e pagine interne)
   ============================================================ */
.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    min-height: 100vh;
}
.content-col {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* --- Sidebar -------------------------------------------------- */
.sidebar {
    background: var(--primary-dark);
    color: #CFE3E1;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}
.sidebar__brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 22px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar__brand img {
    height: 34px;
    width: auto;
    display: block;
    background: #FFFFFF;
    border-radius: 8px;
    padding: 5px 8px;
}
.sidebar__brand .brand-text {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 12.5px;
    line-height: 1.35;
    color: #D8CFE9;
}
.sidebar__brand .brand-text strong { display: block; color: #fff; font-size: 13.5px; }
.sidebar__nav { flex: 1; overflow-y: auto; padding: 16px 12px; }
.sidebar__section-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #6F9491;
    padding: 16px 10px 6px;
    font-weight: 600;
}
.sidebar__nav a {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: #C9DEDC;
    font-size: 13.5px;
    font-weight: 500;
    margin-bottom: 2px;
    text-decoration: none;
    transition: background 0.15s ease, color 0.15s ease;
}
.sidebar__nav a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar__nav a.active {
    background: var(--primary);
    color: #fff;
}
.sidebar__nav a .icon { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.9; }
.sidebar__footer {
    padding: 14px 18px;
    border-top: 1px solid rgba(255,255,255,0.08);
    font-size: 12px;
    color: #6F9491;
}

/* --- Topbar -------------------------------------------------- */
.topbar {
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar__search {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 14px;
    width: 100%;
    max-width: 640px;
    color: var(--muted);
    position: relative;
}
.topbar__search input {
    border: none;
    background: transparent;
    outline: none;
    font-size: 13.5px;
    width: 100%;
    color: var(--ink);
}
.topbar__right { display: flex; align-items: center; gap: 18px; }
.topbar__user {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13.5px;
    padding: 4px 8px 4px 4px;
    border-radius: 20px;
    transition: background 0.15s ease;
}
.topbar__user:hover { background: var(--surface-alt); }
.avatar {
    width: 34px; height: 34px;
    border-radius: 50%;
    background: var(--primary-soft);
    color: var(--primary-dark);
    display: flex; align-items: center; justify-content: center;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 13px;
}
.topbar__user .name { font-weight: 600; color: var(--ink); }
.topbar__user .role { color: var(--muted); font-size: 12px; }

/* --- Main content ---------------------------------------------- */
.main {
    padding: 28px 32px;
    width: 100%;
}
.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    margin-bottom: 22px;
}
.page-head .eyebrow {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--primary);
    margin-bottom: 4px;
}

/* --- Grid & Cards ---------------------------------------------- */
.grid { display: grid; gap: 18px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-split { grid-template-columns: 1.6fr 1fr; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 20px;
}
.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}
.card-head h3 { margin: 0; }
.card-head a { font-size: 12.5px; font-weight: 600; }

/* --- Stat cards -------------------------------------------------- */
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 18px 20px;
    position: relative;
    overflow: hidden;
}
.stat-card .label {
    font-size: 12.5px;
    color: var(--muted);
    font-weight: 600;
    margin-bottom: 10px;
}
.stat-card .value {
    font-family: var(--font-display);
    font-size: 30px;
    font-weight: 700;
    color: var(--ink);
    line-height: 1;
}
.stat-card .delta { font-size: 12px; margin-top: 8px; font-weight: 600; }
.stat-card .delta.up { color: var(--success); }
.stat-card .delta.down { color: var(--danger); }
.stat-card .bar {
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 4px;
}
.stat-card.c-primary .bar { background: var(--primary); }
.stat-card.c-accent .bar { background: var(--accent); }
.stat-card.c-success .bar { background: var(--success); }
.stat-card.c-danger .bar { background: var(--danger); }

/* --- Liste elementi (scadenze, attività) ----------------------------- */
.list-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 4px;
    border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: none; }
.list-item__main { flex: 1; min-width: 0; }
.list-item__title {
    font-size: 13.5px;
    font-weight: 600;
    color: var(--ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.list-item__sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* Badge urgenza — il "semaforo scadenze", elemento firma ricorrente */
.tag {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: 11.5px;
    font-weight: 700;
    white-space: nowrap;
}
.tag::before {
    content: '';
    width: 6px; height: 6px;
    border-radius: 50%;
    background: currentColor;
}
.tag-expired { background: var(--danger-soft); color: var(--urgency-expired); }
.tag-urgent  { background: var(--accent-soft); color: var(--urgency-urgent); }
.tag-soon    { background: #FBF6E3; color: #A6821F; }
.tag-ok      { background: var(--success-soft); color: var(--urgency-ok); }
.tag-neutral { background: var(--surface-alt); color: var(--muted); }

/* --- Quick actions -------------------------------------------------- */
.quick-actions {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 12px;
}
.quick-action {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 16px 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--ink-soft);
    font-size: 12.5px;
    font-weight: 600;
    text-align: center;
    transition: border-color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}
.quick-action:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-sm);
    text-decoration: none;
    transform: translateY(-2px);
}
.quick-action .icon-wrap {
    width: 38px; height: 38px;
    border-radius: 10px;
    background: var(--primary-soft);
    color: var(--primary);
    display: flex; align-items: center; justify-content: center;
}

.quote-field-row {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
    align-items: center;
}

/* --- Sidebar compatta scheda cliente ---------------------------------- */
.client-meta-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 7px 0;
    border-top: 1px solid var(--border);
    font-size: 12.5px;
}
.client-meta-row > span:first-child { color: var(--muted); white-space: nowrap; }
.client-meta-row > span:last-child { color: var(--ink); font-weight: 500; }

.contact-row-inline {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    border-top: 1px solid var(--border);
}
.contact-row-inline:first-of-type { border-top: none; padding-top: 0; }

.contact-action {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    transition: background 0.15s ease, border-color 0.15s ease;
}
.contact-action:hover { background: var(--primary-soft); border-color: var(--primary); }
.contact-action.wa:hover { background: var(--accent-soft); border-color: var(--accent); }

/* --- Colonna fissa (usata nella scheda cliente: rimane visibile scorrendo) ---- */
.sticky-col {
    position: sticky;
    top: calc(var(--topbar-h) + 20px);
    max-height: calc(100vh - var(--topbar-h) - 40px);
    overflow-y: auto;
}

/* --- Tab (usato nella scheda cliente come hub) ---------------------- */
.tabbar {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 22px;
    overflow-x: auto;
}
.tabbar button {
    padding: 11px 16px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    font-family: var(--font-body);
    font-size: 13.5px;
    font-weight: 600;
    color: var(--muted);
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.15s ease, border-color 0.15s ease;
}
.tabbar button:hover { color: var(--ink); }
.tabbar button.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: tab-fade-in 0.15s ease; }
@keyframes tab-fade-in { from { opacity: 0; } to { opacity: 1; } }

/* --- Table -------------------------------------------------------- */
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
    text-align: left;
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    font-weight: 600;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}
.table td {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    color: var(--ink-soft);
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--surface-alt); }

/* --- Responsive -------------------------------------------------------- */
@media (max-width: 1100px) {
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
    .grid-split { grid-template-columns: 1fr; }
    .quick-actions { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 780px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: fixed; left: -260px; width: 240px; z-index: 50; transition: left 0.2s ease; }
    .sidebar.open { left: 0; }
    .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
    .auth-page { grid-template-columns: 1fr; }
    .auth-visual { display: none; }
    .topbar__search { display: none; }
    [data-sidebar-toggle] { display: inline-flex !important; }
}
