* {
    box-sizing: border-box;
}

:root {
    --ink: #263241;
    --muted: #667085;
    --line: #e7edf3;
    --soft: #f5f7fa;
    --panel: #ffffff;
    --blue: #246bfe;
    --blue-dark: #1746a2;
    --green: #168a5b;
    --green-dark: #0f5f43;
    --orange: #c46b16;
    --red: #c0392b;
    --shadow: 0 10px 30px rgba(31, 42, 55, 0.08);
}

body {
    margin: 0;
    font-family: "Segoe UI", Tahoma, Arial, sans-serif;
    background: var(--soft);
    color: var(--ink);
}

a {
    color: inherit;
}

.portal-login {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(circle at 20% 20%, rgba(36, 107, 254, 0.14), transparent 26%),
        radial-gradient(circle at 80% 15%, rgba(22, 138, 91, 0.16), transparent 24%),
        linear-gradient(135deg, #f7fafc 0%, #edf3f8 100%);
}

.login-card {
    width: min(100%, 420px);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 32px;
}

.login-card h1 {
    margin: 0;
    font-size: 25px;
    letter-spacing: 0;
}

.login-card p {
    margin: 8px 0 24px;
    color: var(--muted);
    line-height: 1.5;
}

.portal-badge {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 5px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    color: #ffffff;
    margin-bottom: 16px;
}

.portal-badge.badante,
.portal-topbar.badante {
    background: linear-gradient(135deg, var(--blue), var(--blue-dark));
}

.portal-badge.famiglia,
.portal-topbar.famiglia {
    background: linear-gradient(135deg, var(--green), var(--green-dark));
}

.form-row {
    display: grid;
    gap: 7px;
    margin-bottom: 16px;
}

.form-row label {
    font-size: 13px;
    font-weight: 700;
    color: #3a4655;
}

.form-row input,
.chat-input textarea {
    width: 100%;
    border: 1px solid #d8e0e8;
    border-radius: 7px;
    padding: 12px 13px;
    font: inherit;
    color: var(--ink);
    background: #ffffff;
}

.form-row input:focus,
.chat-input textarea:focus {
    outline: 3px solid rgba(36, 107, 254, 0.14);
    border-color: var(--blue);
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 0;
    border-radius: 7px;
    padding: 11px 16px;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
    color: #ffffff;
    min-height: 42px;
}

.button.full {
    width: 100%;
}

.button.badante {
    background: var(--blue);
}

.button.famiglia {
    background: var(--green);
}

.button.secondary {
    color: var(--ink);
    background: #ffffff;
    border: 1px solid var(--line);
}

.alert {
    border-radius: 7px;
    padding: 11px 13px;
    margin-bottom: 16px;
    font-size: 14px;
}

.alert.error {
    background: #fff1ef;
    color: #9f2f24;
    border: 1px solid #f3b8b0;
}

.portal-topbar {
    color: #ffffff;
    min-height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 12px clamp(16px, 4vw, 34px);
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.16);
}

.brand {
    display: grid;
    gap: 2px;
}

.brand strong {
    font-size: 18px;
}

.brand span,
.topbar-user span {
    font-size: 12px;
    opacity: 0.82;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.logout-link {
    color: #ffffff;
    text-decoration: none;
    border: 1px solid rgba(255, 255, 255, 0.45);
    border-radius: 7px;
    padding: 7px 12px;
    font-weight: 700;
    font-size: 13px;
}

.portal-shell {
    width: min(1180px, 100%);
    margin: 0 auto;
    padding: 28px clamp(14px, 3vw, 28px) 44px;
}

.hero-panel,
.section,
.item-card,
.chat-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.hero-panel {
    padding: 24px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 20px;
    align-items: center;
    margin-bottom: 20px;
}

.hero-panel h1 {
    margin: 0;
    font-size: clamp(24px, 3vw, 34px);
    letter-spacing: 0;
}

.hero-panel p {
    margin: 8px 0 0;
    color: var(--muted);
    line-height: 1.5;
}

.status-pill,
.small-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    border-radius: 999px;
    padding: 8px 13px;
    font-size: 13px;
    font-weight: 800;
    color: #ffffff;
    white-space: nowrap;
}

.small-pill {
    padding: 5px 9px;
    font-size: 12px;
}

.pill-green { background: var(--green); }
.pill-blue { background: var(--blue); }
.pill-orange { background: var(--orange); }
.pill-red { background: var(--red); }
.pill-gray { background: #7a8696; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 17px;
}

.stat-card span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.stat-card strong {
    display: block;
    margin-top: 8px;
    font-size: 28px;
}

.layout-grid {
    display: grid;
    grid-template-columns: 1.2fr 0.8fr;
    gap: 20px;
    align-items: start;
}

.section {
    padding: 22px;
    margin-bottom: 20px;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.section h2 {
    margin: 0;
    font-size: 18px;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.detail-item {
    padding: 13px;
    background: #f8fafc;
    border: 1px solid #edf1f5;
    border-radius: 7px;
}

.detail-item span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    margin-bottom: 4px;
}

.detail-item strong {
    font-size: 14px;
    overflow-wrap: anywhere;
}

.chips {
    display: flex;
    gap: 7px;
    flex-wrap: wrap;
    margin-top: 12px;
}

.chip {
    border-radius: 999px;
    background: #eef4ff;
    border: 1px solid #d9e5ff;
    color: #1f56bf;
    padding: 5px 9px;
    font-size: 12px;
    font-weight: 700;
}

.chip.green {
    background: #ecf8f2;
    border-color: #ccebdc;
    color: #116b48;
}

.item-list {
    display: grid;
    gap: 12px;
}

.item-card {
    padding: 16px;
    box-shadow: none;
}

.item-card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.item-card h3 {
    margin: 0 0 5px;
    font-size: 17px;
}

.item-card p {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.5;
}

.score {
    display: grid;
    place-items: center;
    min-width: 58px;
    min-height: 58px;
    border-radius: 50%;
    color: #ffffff;
    font-weight: 900;
}

.score small {
    display: block;
    font-size: 10px;
    font-weight: 700;
    opacity: 0.84;
}

.timeline {
    display: grid;
    gap: 10px;
}

.timeline-step {
    display: grid;
    grid-template-columns: 28px 1fr;
    gap: 10px;
    align-items: start;
}

.step-dot {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: #dfe7ef;
    color: #637184;
    font-weight: 900;
}

.timeline-step.done .step-dot {
    background: var(--green);
    color: #ffffff;
}

.timeline-step.active .step-dot {
    background: var(--blue);
    color: #ffffff;
}

.timeline-step strong {
    display: block;
    font-size: 14px;
}

.timeline-step span {
    display: block;
    color: var(--muted);
    font-size: 13px;
    margin-top: 2px;
}

.empty-state {
    border: 1px dashed #cfd8e3;
    border-radius: 8px;
    padding: 24px;
    text-align: center;
    color: var(--muted);
    line-height: 1.5;
}

.chat-page {
    height: 100vh;
    display: grid;
    grid-template-rows: auto 1fr auto;
    background: #eef2f6;
}

.chat-header {
    color: #ffffff;
    padding: 13px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-header.badante { background: var(--blue); }
.chat-header.famiglia { background: var(--green); }

.back-link {
    color: #ffffff;
    text-decoration: none;
    border: 1px solid rgba(255, 255, 255, 0.45);
    border-radius: 7px;
    padding: 7px 10px;
    font-weight: 900;
}

.chat-messages {
    overflow-y: auto;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.bubble-wrap {
    display: flex;
    flex-direction: column;
}

.bubble-wrap.utente {
    align-items: flex-end;
}

.bubble-wrap.admin {
    align-items: flex-start;
}

.bubble {
    max-width: min(720px, 78%);
    padding: 10px 14px;
    border-radius: 16px;
    line-height: 1.5;
    word-break: break-word;
}

.bubble.utente {
    color: #ffffff;
    background: var(--blue);
    border-bottom-right-radius: 5px;
}

.chat-page.famiglia .bubble.utente {
    background: var(--green);
}

.bubble.admin {
    background: #ffffff;
    color: var(--ink);
    border-bottom-left-radius: 5px;
    border: 1px solid var(--line);
}

.bubble-time {
    color: #8b97a7;
    font-size: 11px;
    margin-top: 3px;
    padding: 0 5px;
}

.chat-input {
    background: #ffffff;
    border-top: 1px solid var(--line);
    padding: 12px 16px;
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.chat-input textarea {
    min-height: 44px;
    max-height: 130px;
    resize: none;
}

.send-button {
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 50%;
    color: #ffffff;
    background: var(--blue);
    font-size: 18px;
    cursor: pointer;
    flex: 0 0 auto;
}

.chat-page.famiglia .send-button {
    background: var(--green);
}

@media (max-width: 860px) {
    .hero-panel,
    .layout-grid {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 560px) {
    .portal-topbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .topbar-user {
        justify-content: flex-start;
    }

    .detail-grid,
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .login-card {
        padding: 24px;
    }

    .bubble {
        max-width: 88%;
    }
}
