/* === FONT ROBOTO DALLA CARTELLA /fonts === */
@font-face {
    font-family: "Roboto";
    src: url("../fonts/roboto-thin.ttf");
    font-weight: 100;
    font-style: normal;
}

@font-face {
    font-family: "Roboto";
    src: url("../fonts/roboto-thin-italic.ttf");
    font-weight: 100;
    font-style: italic;
}

@font-face {
    font-family: "Roboto";
    src: url("../fonts/roboto-light.ttf");
    font-weight: 300;
    font-style: normal;
}

@font-face {
    font-family: "Roboto";
    src: url("../fonts/roboto-light-italic.ttf");
    font-weight: 300;
    font-style: italic;
}

@font-face {
    font-family: "Roboto";
    src: url("../fonts/roboto-regular.ttf");
    font-weight: 400;
    font-style: normal;
}

@font-face {
    font-family: "Roboto";
    src: url("../fonts/roboto-regular-italic.ttf");
    font-weight: 400;
    font-style: italic;
}

@font-face {
    font-family: "Roboto";
    src: url("../fonts/roboto-bold.ttf");
    font-weight: 700;
    font-style: normal;
}

@font-face {
    font-family: "Roboto";
    src: url("../fonts/roboto-bold-italic.ttf");
    font-weight: 700;
    font-style: italic;
}

:root {
    --topbar-height: 52px;
    --bottombar-height: 86px;
    --sidebar-width: 260px;
    /* Fluent 2 primary (blue) */
    --color-main: #0078d4;
    --color-main-hover: #106ebe;
    --color-mainShadow: #0078d4c0;
    --color-secondary: #005a9e;
    --color-danger: #d13438;
    --color-danger-hover: #b10e1c;
    --color-black: #343a40;
    --color-white: #ffffff;
    --color-shadowLight: #00000030;
    --color-shadow: #00000045;
    --color-shadowDark: #00000060;
    --color-gray0: #f0f4f8;
    --color-gray1: #e9ecef;
    --color-gray2: #dee2e6;
    --color-gray3: #ced4da;
    --color-gray4: #adb5bd;
    --color-gray5: #868e96;
    --color-gray6: #495057;
    --color-gray7: #242424;
    --radius-pill: 20px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-sm: 6px;
    --shadow-soft: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-card: 0 4px 16px rgba(0, 0, 0, 0.12);
    --maxw: 960px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
}

body {
    font-family: "Roboto", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 16px;
    color: var(--color-gray7);
    background: linear-gradient(135deg, #f0f4f8 0%, #e4e9f0 100%);
    background-attachment: fixed;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    overflow-x: hidden;
}

a {
    text-decoration: none;
    color: inherit;
}

.chat-page {
    min-height: 100vh;
}

/* === TOPBAR FISSA === */
.app-topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-height);
    background: var(--color-white);
    border-bottom: 1px solid var(--color-gray2);
    box-shadow: none;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
}

.app-topbar-inner {
    width: 100%;
    max-width: var(--maxw);
    padding: 0 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.brand-left {
    display: flex;
    align-items: center;
    gap: .75rem;
}

.brand-logo-img {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    box-shadow: none;
    border: 0px solid var(--color-gray3);
    object-fit: contain;
    background: var(--color-white);
    padding: 0px;
}

/* === SELECT CHE FUNGE DA "TITOLO" === */
.context-select-wrap {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
}

.context-select-shell {
    position: relative;
    display: inline-flex;
    align-items: center;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-gray3);
    background: var(--color-white);
    box-shadow: none;
    padding: 0 .9rem;
    height: 2.3rem;
}

    .context-select-shell select {
        appearance: none;
        -webkit-appearance: none;
        -moz-appearance: none;
        border: none;
        background: transparent;
        font-family: inherit;
        font-size: .85rem;
        font-weight: 600;
        color: var(--color-main);
        padding-right: 1.4rem;
        outline: none;
        cursor: pointer;
    }

        .context-select-shell select option {
            color: var(--color-gray7);
            font-weight: 500;
        }

.context-chevron {
    position: absolute;
    right: .6rem;
    pointer-events: none;
    font-size: 1.7rem;
    color: var(--color-gray5);
}

.context-select-shell:hover {
    border-color: var(--color-main);
    background: var(--color-gray1);
    box-shadow: none;
}

.brand-right {
    display: flex;
    align-items: center;
    gap: .5rem;
}

.btn-top {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: 0 .9rem;
    height: 2.3rem;
    border-radius: var(--radius-md);
    font-size: .85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s ease, color .15s ease, border-color .15s ease;
    border: 1px solid var(--color-gray3);
    box-shadow: none;
}

    .btn-top img {
        width: 18px;
        height: 18px;
        display: block;
    }

.btn-top-neutral {
    border-color: var(--color-gray3);
    background: var(--color-white);
    color: var(--color-gray7);
}

.btn-top-primary {
    border-color: var(--color-main);
    background: var(--color-main);
    color: var(--color-white);
}

.btn-top-neutral:hover {
    background: var(--color-gray1);
}

.btn-top-neutral:active {
    background: var(--color-gray2);
}

.btn-top-primary:hover {
    background: var(--color-secondary);
    border-color: var(--color-secondary);
}

.btn-top-primary:active {
    background: var(--color-main);
}

/* User icon button (always visible) */
.user-icon-btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    height: 2.3rem;
    padding: 0 .6rem 0 .4rem;
    border: 1px solid var(--color-gray3);
    background: var(--color-white);
    cursor: pointer;
    transition: background .15s, border-color .15s;
}

.user-icon-btn:hover {
    background: var(--color-gray1);
    border-color: var(--color-gray4);
}

.user-icon-btn svg {
    width: 18px;
    height: 18px;
    stroke: var(--color-gray6);
    flex-shrink: 0;
}

.user-short-name {
    font-size: .8rem;
    font-weight: 600;
    color: var(--color-gray7);
    white-space: nowrap;
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* User profile overlay */
.user-profile-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.3);
    z-index: 300;
    justify-content: center;
    align-items: flex-start;
    padding-top: calc(var(--topbar-height) + .5rem);
}

.user-profile-overlay.open {
    display: flex;
}

.user-profile-card {
    background: var(--color-white);
    border: 1px solid var(--color-gray3);
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 32px rgba(0,0,0,0.14);
    padding: 1.25rem;
    min-width: 260px;
    max-width: 320px;
    width: 90vw;
}

.user-profile-card .profile-header {
    display: flex;
    align-items: center;
    gap: .75rem;
    margin-bottom: 1rem;
    padding-bottom: .75rem;
    border-bottom: 1px solid var(--color-gray2);
}

.user-profile-card .profile-avatar {
    width: 40px;
    height: 40px;
    background: var(--color-gray1);
    border: 1px solid var(--color-gray3);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.user-profile-card .profile-avatar svg {
    width: 22px;
    height: 22px;
    stroke: var(--color-gray5);
}

.user-profile-card .profile-info {
    overflow: hidden;
}

.user-profile-card .profile-name {
    font-size: .9rem;
    font-weight: 600;
    color: var(--color-gray7);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-profile-card .profile-email {
    font-size: .75rem;
    color: var(--color-gray5);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-profile-card .profile-role {
    font-size: .8rem;
    color: var(--color-gray6);
    margin-bottom: 1rem;
}

.user-profile-card .profile-role strong {
    color: var(--color-main);
}

.user-profile-card .profile-actions {
    display: flex;
    gap: .5rem;
}

.user-profile-card .profile-logout-btn {
    flex: 1;
    padding: .5rem;
    border: 1px solid var(--color-danger);
    background: var(--color-danger);
    color: var(--color-white);
    font-size: .8rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, border-color .15s;
}

.user-profile-card .profile-logout-btn:hover {
    background: var(--color-danger-hover);
    border-color: var(--color-danger-hover);
}

.user-profile-card .profile-close-btn {
    flex: 1;
    padding: .5rem;
    border: 1px solid var(--color-gray3);
    background: var(--color-gray1);
    color: var(--color-gray6);
    font-size: .8rem;
    cursor: pointer;
    transition: background .15s;
}

.user-profile-card .profile-close-btn:hover {
    background: var(--color-gray2);
}

/* === LANGUAGE SELECTOR === */
.lang-selector {
    position: relative;
    display: inline-flex;
    margin-right: .25rem;
}

.lang-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.3rem;
    height: 2.3rem;
    padding: 0;
    border: 1px solid var(--color-gray3);
    border-radius: var(--radius-sm);
    background: var(--color-white);
    cursor: pointer;
    transition: background .15s, border-color .15s;
}

.lang-btn:hover {
    background: var(--color-gray1);
    border-color: var(--color-gray4);
}

.lang-flag {
    font-size: .75rem;
    font-weight: 700;
    color: var(--color-gray7);
    letter-spacing: .02em;
}

.lang-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    background: var(--color-white);
    border: 1px solid var(--color-gray3);
    border-radius: var(--radius-md);
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
    z-index: 200;
    display: none;
    min-width: 120px;
}

.lang-selector.open .lang-dropdown {
    display: block;
}

.lang-option {
    display: flex;
    align-items: center;
    gap: .5rem;
    width: 100%;
    padding: .5rem .75rem;
    border: none;
    background: var(--color-white);
    font-size: .85rem;
    color: var(--color-gray7);
    cursor: pointer;
    text-align: left;
    transition: background .15s;
}

.lang-option:hover {
    background: var(--color-gray1);
}

.lang-option.active {
    background: var(--color-gray1);
    color: var(--color-main);
    font-weight: 600;
}

.lang-flag-opt {
    font-size: .7rem;
    font-weight: 700;
    color: var(--color-gray6);
    width: 22px;
    text-align: center;
    padding: 2px 4px;
    background: var(--color-gray1);
    border: 1px solid var(--color-gray2);
}

/* === AREA CHAT SCROLL === */
.chat-scroll {
    width: 100%;
    max-width: var(--maxw);
    margin: 0 auto;
    padding: calc(var(--topbar-height) + 1.5rem) 1rem calc(var(--bottombar-height) + 1.5rem);
    display: flex;
    flex-direction: column;
    gap: .4rem;
}

    .chat-scroll.empty {
        justify-content: center;
        min-height: 100vh;
    }

/* Intro centrale */
.intro {
    width: 100%;
    max-width: 720px;
    margin: 0 auto;
    padding: 1.5rem 1.4rem 1.8rem;
    background: var(--color-white);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-soft);
    border: 1px solid var(--color-gray2);
}

.intro-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: .9rem;
    align-items: center;
}

    .intro-grid > h2 {
        margin: 0;
        text-align: center;
        font-weight: 300;
        font-size: 1.4rem;
        color: var(--color-gray7);
    }

#center-form {
    margin-top: .4rem;
}

.intro-subtitle {
    text-align: center;
    font-size: .9rem;
    color: var(--color-gray6);
    margin-bottom: .4rem;
}

.tips {
    margin-top: 1.2rem;
    background: var(--color-gray0);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-gray2);
    padding: .9rem 1rem .85rem;
}

    .tips .label {
        font-size: .8rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: .08em;
        color: var(--color-gray6);
        margin-bottom: .35rem;
    }

.tip-list {
    list-style: none;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .25rem .75rem;
    font-size: .88rem;
    color: var(--color-gray7);
}

    .tip-list li::before {
        content: "•";
        margin-right: .35rem;
        color: var(--color-secondary);
    }

@media (max-width: 640px) {
    .tip-list {
        grid-template-columns: 1fr;
    }
}

/* === MESSAGGI CHAT === */
.msg {
    max-width: 680px;
    padding: .75rem 1rem;
    margin: .25rem 0;
    border-radius: var(--radius-md);
    font-size: .95rem;
    line-height: 1.5;
    box-shadow: none;
    border: 1px solid var(--color-gray3);
    white-space: pre-wrap;
}

    .msg.user {
        margin-left: auto;
        background: var(--color-main);
        color: var(--color-white);
        border-color: var(--color-main);
    }

    .msg.ai {
        margin-right: auto;
        background: var(--color-white);
        border-color: var(--color-gray3);
    }

    .msg.info {
        margin: 0 auto;
        background: #e8f4fd;
        border-color: #2196f3;
        color: #1565c0;
        font-style: italic;
        text-align: center;
        max-width: 80%;
    }

/* === BOTTOM INPUT BAR FISSA === */
.chat-form {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    padding: .55rem .75rem .9rem;
    background: var(--color-gray0);
}

    .chat-form .inner {
        max-width: var(--maxw);
        margin: 0 auto;
        padding: .45rem .6rem;
        border-radius: var(--radius-md);
        background: var(--color-white);
        box-shadow: none;
        border: 1px solid var(--color-gray2);
    }

.row {
    display: flex;
    align-items: flex-end;
    gap: .55rem;
}

input[type="text"],
textarea#q,
textarea#q-center {
    flex: 1;
    min-height: 2.8rem;
    max-height: 10rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-gray3);
    padding: .6rem 1rem;
    font-size: .95rem;
    font-family: inherit;
    color: var(--color-gray7);
    background: var(--color-white);
    outline: none;
    resize: none;
    overflow-y: auto;
    line-height: 1.5;
    box-sizing: border-box;
}

    input[type="text"]::placeholder,
    textarea#q::placeholder,
    textarea#q-center::placeholder {
        color: var(--color-gray5);
    }

button {
    height: 2.6rem;
    padding: 0 1.35rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-main);
    background: var(--color-main);
    color: var(--color-white);
    font-weight: 700;
    font-size: .9rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: .55rem;
    box-shadow: none;
    transition: background .15s ease, color .15s ease;
}

    button:hover {
        background: var(--color-secondary);
    }

    button:active {
        background: var(--color-main);
        color: var(--color-white);
    }

.btn-ask img {
    width: 18px;
    height: 18px;
    display: block;
}

@media (max-width: 640px) {
    .app-topbar-inner {
        padding-inline: .85rem;
    }

    .intro {
        padding-inline: 1.1rem;
    }

    .chat-form .inner {
        border-radius: var(--radius-md);
    }

    .btn-top span,
    .btn-ask span {
        display: none; /* solo icona su schermi molto piccoli */
    }

    .btn-top,
    .btn-ask {
        width: 2.6rem;
        padding: 0;
        justify-content: center;
    }

    .context-selector select {
        min-width: 140px;
        max-width: 180px;
        font-size: .8rem;
        padding: .4rem .6rem;
    }

    .brand-left {
        gap: .5rem;
        min-width: 0;
    }

    .brand-right {
        gap: .3rem;
        flex-shrink: 0;
    }

    .context-select-wrap {
        gap: .35rem;
    }

    .btn-action {
        padding: .4rem .6rem;
        font-size: .8rem;
    }

    .btn-action span {
        display: none;
    }

    /* On mobile: icon only, hide abbreviated name */
    .user-short-name {
        display: none;
    }

    .user-icon-btn {
        width: 2.3rem;
        padding: 0;
        justify-content: center;
    }
}

/* === CONTEXT SELECTOR === */
.context-selector select {
    padding: .45rem .75rem;
    border: 1px solid var(--color-gray3);
    border-radius: var(--radius-md);
    background: var(--color-white);
    font-size: .85rem;
    font-family: inherit;
    color: var(--color-gray7);
    cursor: pointer;
    min-width: 200px;
    max-width: 320px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.context-selector select:focus {
    outline: 2px solid var(--color-main);
    outline-offset: 2px;
}

.context-selector select option {
    padding: .3rem;
}

.context-selector select optgroup {
    font-weight: 600;
    color: var(--color-gray6);
    padding: .3rem 0;
}

.context-selector select option[data-type="plant"] {
    font-weight: 500;
    color: var(--color-main);
}

.context-error {
    font-size: .75rem;
    color: var(--color-danger);
    margin-left: .5rem;
}

/* === CHAT ACTIONS BUTTONS === */
.chat-actions {
    display: flex;
    gap: .5rem;
    margin-bottom: .5rem;
}

.btn-action {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .5rem .75rem;
    font-size: .85rem;
    border: 1px solid var(--color-gray3);
    border-radius: var(--radius-md);
    background: var(--color-white);
    color: var(--color-gray7);
    cursor: pointer;
    font-family: inherit;
    transition: background .2s, border-color .2s;
}

.btn-action img {
    width: 16px;
    height: 16px;
    display: block;
}

.btn-action:hover {
    background: var(--color-gray1);
    border-color: var(--color-gray4);
}

.btn-action:disabled {
    opacity: .5;
    cursor: not-allowed;
}

.btn-action svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.btn-role {
    border-color: var(--color-main);
    color: var(--color-main);
}

.btn-role:hover {
    background: var(--color-main);
    color: var(--color-white);
    border-color: var(--color-main);
}

.btn-role:hover svg {
    stroke: var(--color-white);
}

/* === LOADING INDICATOR (thinking typewriter) === */
.msg.loading {
    font-style: italic;
    color: var(--color-gray5);
    min-height: 1.5em;
}

.thinking-timer {
    color: var(--color-gray4);
    margin-left: .5rem;
    font-size: .8em;
}

/* === ERROR MESSAGE === */
.msg.error {
    margin-right: auto;
    background: #fff8e1;
    border-color: #f9a825;
    color: #5d4037;
    padding-left: .75rem;
}

.msg.error .error-icon {
    font-size: 1.1rem;
    margin-right: .25rem;
    vertical-align: middle;
}

/* === MODAL OVERLAY === */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal-content {
    background: var(--color-white);
    width: 90%;
    max-width: 450px;
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.14);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--color-gray2);
}

.modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--color-gray5);
    line-height: 1;
}

.modal-close:hover {
    color: var(--color-gray7);
}

.modal-body {
    padding: 1.25rem;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: .4rem;
    font-size: .9rem;
    font-weight: 500;
    color: var(--color-gray6);
}

.form-group input,
.form-group select {
    width: 100%;
    padding: .6rem .75rem;
    border: 1px solid var(--color-gray3);
    border-radius: var(--radius-md);
    font-size: .95rem;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--color-main);
}

.form-error {
    color: var(--color-danger);
    font-size: .85rem;
    margin-top: .5rem;
}

.form-value {
    display: block;
    padding: .5rem 0;
    font-size: .95rem;
    color: var(--color-gray6);
}

.warning-text {
    font-size: .85rem;
    color: var(--color-gray5);
    margin: .5rem 0 0;
    font-style: italic;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: .5rem;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--color-gray2);
}

.btn-modal {
    padding: .5rem 1rem;
    border: 1px solid var(--color-gray3);
    border-radius: var(--radius-md);
    font-size: .9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background .2s, border-color .2s;
}

.btn-modal-secondary {
    background: var(--color-white);
    color: var(--color-gray6);
}

.btn-modal-secondary:hover {
    background: var(--color-gray1);
}

.btn-modal-primary {
    background: var(--color-main);
    color: var(--color-white);
    border-color: var(--color-main);
}

.btn-modal-primary:hover {
    background: var(--color-main-hover);
}

.btn-modal-danger {
    background: #dc2626;
    color: var(--color-white);
    border-color: #dc2626;
}

.btn-modal-danger:hover {
    background: #b91c1c;
}

.btn-modal:disabled {
    opacity: .6;
    cursor: not-allowed;
}

/* === IMPORT MATRICOLE MODAL === */
.modal-content-wide {
    max-width: 550px;
}

.modal-description {
    font-size: .9rem;
    color: var(--color-gray6);
    margin-bottom: 1rem;
    line-height: 1.5;
}

.import-select-all {
    margin-bottom: .75rem;
    padding-bottom: .75rem;
    border-bottom: 1px solid var(--color-gray2);
}

.import-select-all label {
    display: flex;
    align-items: center;
    gap: .5rem;
    cursor: pointer;
    font-size: .9rem;
    font-weight: 500;
    color: var(--color-gray6);
}

.import-list {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--color-gray2);
}

.import-item {
    border-bottom: 1px solid var(--color-gray1);
}

.import-item:last-child {
    border-bottom: none;
}

.import-label {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .75rem 1rem;
    cursor: pointer;
    transition: background .15s;
}

.import-label:hover {
    background: var(--color-gray0);
}

.import-checkbox {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.import-serial {
    font-weight: 600;
    font-size: .95rem;
    color: var(--color-gray7);
}

.import-meta-badge {
    font-size: .75rem;
    padding: .15rem .5rem;
    border-radius: var(--radius-md);
}

.import-meta-badge.has-meta {
    background: #d1fae5;
    color: #065f46;
}

.import-meta-badge.no-meta {
    background: var(--color-gray1);
    color: var(--color-gray5);
}

.import-description {
    font-size: .8rem;
    color: var(--color-gray5);
    margin-left: auto;
}

/* === DOCUMENTS PAGE (FILE EXPLORER) === */
.documents-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.page-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--color-gray7);
    margin: 0;
}

/* === DOCUMENT CONTAINER (File Explorer Layout) === */
.doc-container {
    display: flex;
    flex: 1;
    margin-top: var(--topbar-height);
    height: calc(100vh - var(--topbar-height));
}

/* === SIDEBAR === */
.doc-sidebar {
    width: 280px;
    min-width: 280px;
    background: var(--color-white);
    border-right: 1px solid var(--color-gray2);
    overflow-y: auto;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid var(--color-gray2);
    background: var(--color-gray0);
}

.sidebar-header h2 {
    font-size: .9rem;
    font-weight: 600;
    color: var(--color-gray6);
    margin: 0;
    text-transform: uppercase;
    letter-spacing: .05em;
}

/* === FOLDER TREE === */
.folder-tree {
    padding: .5rem 0;
}

.tree-root {
    list-style: none;
    margin: 0;
    padding: 0;
}

.tree-item {
    margin: 0;
    padding: 0;
}

.tree-folder {
    cursor: pointer;
}

.tree-folder-header {
    display: flex;
    align-items: center;
    padding: .5rem 1rem;
    width: 100%;
    transition: background .15s;
    gap: .5rem;
}

.tree-folder:hover > .tree-folder-header {
    background: var(--color-gray1);
}

.tree-folder.active > .tree-folder-header {
    background: var(--color-gray1);
    border-left: 3px solid var(--color-main);
    padding-left: calc(1rem - 3px);
}

.tree-folder.system-folder > .tree-folder-header {
    font-weight: 600;
}

.folder-icon {
    font-size: 1rem;
    flex-shrink: 0;
}

.folder-name {
    font-size: .9rem;
    color: var(--color-gray7);
}

.tree-toggle {
    margin-left: auto;
    font-size: .75rem;
    color: var(--color-gray5);
    transition: transform .2s;
}

.tree-folder.expanded > .tree-folder-header .tree-toggle {
    transform: rotate(90deg);
}

.tree-children {
    list-style: none;
    margin: 0;
    padding-left: 1.5rem;
    display: none;
}

.tree-folder.expanded > .tree-children {
    display: block;
}

/* === MAIN CONTENT AREA === */
.doc-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--color-gray0);
    overflow: hidden;
}

/* === BREADCRUMB === */
.doc-breadcrumb {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: 1rem;
    background: var(--color-white);
    border-bottom: 1px solid var(--color-gray2);
    font-size: .9rem;
    flex-wrap: wrap;
}

.breadcrumb-item {
    color: var(--color-gray6);
    cursor: pointer;
}

.breadcrumb-item:hover {
    color: var(--color-main);
    text-decoration: underline;
}

.breadcrumb-item:last-child {
    color: var(--color-gray7);
    font-weight: 600;
    cursor: default;
}

.breadcrumb-item:last-child:hover {
    text-decoration: none;
    color: var(--color-gray7);
}

.breadcrumb-separator {
    color: var(--color-gray4);
}

/* === ACTION BAR === */
.doc-actions {
    display: flex;
    gap: .5rem;
    padding: 1rem;
    background: var(--color-white);
    border-bottom: 1px solid var(--color-gray2);
    flex-wrap: wrap;
}

/* === FILE GRID === */
.doc-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.file-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
}

.file-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem;
    background: var(--color-white);
    border: 1px solid var(--color-gray2);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-soft);
    cursor: pointer;
    transition: border-color .15s, background .15s, box-shadow .15s;
}

.file-item:hover {
    border-color: var(--color-gray4);
    background: var(--color-gray1);
}

.file-item.selected {
    border-color: var(--color-main);
    background: #e5f3ff;
}

.file-icon {
    font-size: 2.5rem;
    margin-bottom: .5rem;
}

.file-name {
    font-size: .85rem;
    color: var(--color-gray7);
    text-align: center;
    word-break: break-word;
    max-width: 100%;
}

.file-meta {
    font-size: .75rem;
    color: var(--color-gray5);
    margin-top: .25rem;
}

.file-actions {
    display: flex;
    gap: .25rem;
    margin-top: .5rem;
    opacity: 0;
    transition: opacity .15s;
}

.file-item:hover .file-actions {
    opacity: 1;
}

.file-action-btn {
    padding: .25rem .5rem;
    font-size: .75rem;
    border: 1px solid var(--color-gray3);
    background: var(--color-white);
    cursor: pointer;
    border-radius: var(--radius-md);
    height: auto;
}

.file-action-btn:hover {
    background: var(--color-gray1);
}

.file-action-btn.delete:hover {
    background: #fee;
    border-color: var(--color-danger);
    color: var(--color-danger);
}

/* === FILE SYNC INDICATOR === */
.sync-indicator {
    font-size: .7rem;
    margin-top: .35rem;
    padding: .1rem .45rem;
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    letter-spacing: .01em;
}
.sync-indicator::before {
    content: '';
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
}
.sync-indicator.sync-ok {
    color: #2e7d32;
}
.sync-indicator.sync-ok::before {
    background: #2e7d32;
}
.sync-indicator.sync-pending {
    color: #e65100;
    font-weight: 600;
}
.sync-indicator.sync-pending::before {
    background: #e65100;
}
.sync-indicator.sync-unknown {
    color: var(--color-gray4);
}
.sync-indicator.sync-unknown::before {
    background: var(--color-gray4);
}

/* === STATES === */
.loading-state,
.empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 200px;
    color: var(--color-gray5);
    font-size: .95rem;
}

/* === UPLOAD PROGRESS === */
.upload-progress {
    margin-top: 1rem;
}

.progress-bar {
    height: 8px;
    background: var(--color-gray2);
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: var(--color-main);
    transition: width .2s;
}

.progress-text {
    font-size: .85rem;
    color: var(--color-gray6);
    margin-top: .25rem;
    display: block;
}

/* === HELP TEXT === */
.help-text {
    font-size: .8rem;
    color: var(--color-gray5);
    margin-top: .25rem;
}

/* === FILE INPUT === */
.form-group input[type="file"] {
    padding: .5rem;
    border: 1px dashed var(--color-gray3);
    background: var(--color-gray0);
    cursor: pointer;
}

.form-group input[type="file"]:hover {
    border-color: var(--color-main);
}

/* === UPLOAD DESTINATION === */
.upload-destination {
    font-weight: 500;
    color: var(--color-gray7);
    font-family: monospace;
    background: var(--color-gray1);
    padding: .25rem .5rem;
}

/* === SIDEBAR TABS === */
.sidebar-tabs {
    display: flex;
    padding: 0;
    gap: 0;
}

.sidebar-tab {
    flex: 1;
    padding: .75rem 1rem;
    font-size: .85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--color-gray5);
    background: var(--color-gray0);
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: color .15s, border-color .15s, background .15s;
}

.sidebar-tab:hover {
    color: var(--color-gray7);
    background: var(--color-gray1);
}

.sidebar-tab.active {
    color: var(--color-main);
    border-bottom-color: var(--color-main);
    background: var(--color-white);
}

/* === SIDEBAR PANELS === */
.sidebar-panel {
    overflow-y: auto;
    flex: 1;
}

/* === PLANT LIST (sidebar) === */
.plant-list {
    padding: .5rem 0;
}

.plant-list-item {
    display: flex;
    align-items: center;
    padding: .6rem 1rem;
    cursor: pointer;
    transition: background .15s;
    gap: .5rem;
    font-size: .9rem;
    color: var(--color-gray7);
}

.plant-list-item:hover {
    background: var(--color-gray1);
}

.plant-list-item.active {
    background: var(--color-gray1);
    border-left: 3px solid var(--color-main);
    padding-left: calc(1rem - 3px);
}

.plant-list-item .plant-icon {
    font-size: 1rem;
    flex-shrink: 0;
}

.plant-list-item .plant-info {
    flex: 1;
    min-width: 0;
}

.plant-list-item .plant-item-name {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.plant-list-item .plant-item-meta {
    font-size: .75rem;
    color: var(--color-gray5);
}

/* === PLANT DETAIL VIEW === */
.plant-detail {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}

.plant-detail-header {
    padding: 1.25rem;
    background: var(--color-white);
    border-bottom: 1px solid var(--color-gray2);
}

.plant-detail-header h3 {
    margin: 0 0 .5rem;
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--color-gray7);
}

.plant-meta-row {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
    font-size: .85rem;
    color: var(--color-gray6);
}

.plant-meta-label {
    font-weight: 600;
    color: var(--color-gray5);
    margin-right: .25rem;
}

.plant-detail-sections {
    padding: 1rem;
}

.plant-section {
    margin-bottom: 1.5rem;
    background: var(--color-white);
    border: 1px solid var(--color-gray2);
}

.plant-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--color-gray2);
    background: var(--color-gray0);
}

.plant-section-header h4 {
    margin: 0;
    font-size: .9rem;
    font-weight: 600;
    color: var(--color-gray6);
    text-transform: uppercase;
    letter-spacing: .04em;
}

.plant-section-body {
    padding: .75rem 1rem;
}

/* === PLANT ASSOCIATION ITEMS (commesse & users within detail) === */
.plant-assoc-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .5rem 0;
    border-bottom: 1px solid var(--color-gray1);
    font-size: .9rem;
}

.plant-assoc-item:last-child {
    border-bottom: none;
}

.plant-assoc-item .assoc-name {
    color: var(--color-gray7);
}

.plant-assoc-item .assoc-meta {
    font-size: .8rem;
    color: var(--color-gray5);
    margin-left: .5rem;
}

.plant-assoc-item .btn-remove {
    padding: .2rem .5rem;
    font-size: .75rem;
    border: 1px solid var(--color-gray3);
    background: var(--color-white);
    color: var(--color-gray6);
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s;
}

.plant-assoc-item .btn-remove:hover {
    background: #fee;
    border-color: var(--color-danger);
    color: var(--color-danger);
}

.plant-section-empty {
    color: var(--color-gray5);
    font-size: .85rem;
    font-style: italic;
    padding: .5rem 0;
}

.btn-plant-action {
    font-size: .8rem;
    padding: .35rem .6rem;
}

/* === COMMESSA BADGES (tree) === */
.commessa-badge {
    margin-left: auto;
    font-size: .7rem;
    padding: .1rem .35rem;
    flex-shrink: 0;
}
.commessa-badge.linked {
    color: #2e7d32;
    background: #e8f5e9;
    border: 1px solid #c8e6c9;
}
.commessa-badge.orphan {
    color: #e65100;
    background: #fff3e0;
    border: 1px solid #ffe0b2;
}
.commessa-badge.sync-needed {
    color: #e65100;
    background: #fff3e0;
    border: 1px solid #ffe0b2;
}
.commessa-badge.synced {
    color: #2e7d32;
    background: #e8f5e9;
    border: 1px solid #c8e6c9;
}

/* === PUBLISH AI BUTTON === */
.btn-publish-ai {
    background: #1565c0;
    color: #fff;
    border: none;
}
.btn-publish-ai:hover {
    background: #0d47a1;
}
.btn-publish-ai:disabled {
    opacity: .6;
    cursor: not-allowed;
}

/* === USER LIST (Utenti Tab) === */
.user-section-header {
    padding: .5rem 1rem;
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--color-gray5);
    background: var(--color-gray1);
    border-bottom: 1px solid var(--color-gray2);
}

.user-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .6rem 1rem;
    cursor: pointer;
    transition: background .15s;
    font-size: .9rem;
    color: var(--color-gray7);
    border-bottom: 1px solid var(--color-gray1);
}

.user-list-item:hover {
    background: var(--color-gray1);
}

.user-list-item.active {
    background: var(--color-gray1);
    border-left: 3px solid var(--color-main);
    padding-left: calc(1rem - 3px);
}

.user-item-left {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex: 1;
    min-width: 0;
}

.user-role-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    display: inline-block;
}

.user-item-info {
    flex: 1;
    min-width: 0;
}

.user-item-name {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-item-email {
    font-size: .75rem;
    color: var(--color-gray5);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-item-right {
    flex-shrink: 0;
    margin-left: .5rem;
}

.user-plant-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    font-size: .7rem;
    font-weight: 600;
    color: var(--color-white);
    background: var(--color-gray5);
    border-radius: 10px;
}

/* === SYNC VIEW === */
.sync-detail {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}

.sync-detail-header {
    padding: 1.25rem;
    border-bottom: 1px solid var(--color-gray2);
}

.sync-detail-header h3 {
    margin: 0 0 .5rem;
    font-size: 1.1rem;
}

.sync-totals {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.sync-stat {
    font-size: .85rem;
    padding: .25rem .6rem;
    border: 1px solid var(--color-gray3);
}

.sync-stat.upload {
    color: #e65100;
    border-color: #e65100;
    background: #fff3e0;
}

.sync-stat.delete {
    color: #c62828;
    border-color: #c62828;
    background: #ffebee;
}

.sync-stat.synced {
    color: #2e7d32;
    border-color: #2e7d32;
    background: #e8f5e9;
}

.sync-detail-body {
    padding: 1rem;
}

.sync-group {
    margin-bottom: 1.5rem;
    border: 1px solid var(--color-gray2);
}

.sync-group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: .75rem 1rem;
    background: var(--color-gray1);
    border-bottom: 1px solid var(--color-gray2);
}

.sync-group-header h4 {
    margin: 0;
    font-size: .95rem;
}

.btn-sync-folder {
    font-size: .8rem;
    padding: .25rem .75rem;
    height: auto;
}

.sync-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .85rem;
}

.sync-table th {
    text-align: left;
    padding: .5rem .75rem;
    background: var(--color-gray1);
    border-bottom: 1px solid var(--color-gray2);
    font-weight: 600;
    font-size: .8rem;
    color: var(--color-gray5);
}

.sync-table td {
    padding: .4rem .75rem;
    border-bottom: 1px solid var(--color-gray1);
}

.sync-file-name {
    font-weight: 500;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sync-status-badge {
    display: inline-block;
    padding: .15rem .5rem;
    font-size: .75rem;
    font-weight: 600;
}

.sync-status-badge.status-upload {
    color: #e65100;
    background: #fff3e0;
    border: 1px solid #e65100;
}

.sync-status-badge.status-delete {
    color: #c62828;
    background: #ffebee;
    border: 1px solid #c62828;
}

/* Sync sidebar */
.sync-folder-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: .5rem .75rem;
    border-bottom: 1px solid var(--color-gray1);
    cursor: pointer;
    font-size: .85rem;
}

.sync-folder-item:hover {
    background: var(--color-gray1);
}

.sync-folder-name {
    font-weight: 500;
}

.sync-folder-badge {
    display: flex;
    gap: .25rem;
}

.badge-upload {
    color: #e65100;
    font-weight: 600;
    font-size: .8rem;
}

.badge-delete {
    color: #c62828;
    font-weight: 600;
    font-size: .8rem;
}

.badge-external {
    display: inline-block;
    background: #e65100;
    color: #fff;
    font-size: .7rem;
    font-weight: 600;
    padding: .1rem .4rem;
    margin-left: .35rem;
    vertical-align: middle;
    text-transform: uppercase;
    letter-spacing: .02em;
}

.btn-publish-all {
    width: 100%;
    margin-top: .75rem;
    background: var(--color-main);
    color: var(--color-white);
    border: 1px solid var(--color-main);
    padding: .5rem;
    font-weight: 600;
    cursor: pointer;
    font-size: .85rem;
}

.btn-publish-all:hover {
    opacity: .9;
}
.btn-publish-all:disabled {
    opacity: .5;
    cursor: not-allowed;
}

.sync-publish-progress {
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--color-gray2);
}
.sync-publish-progress .progress-bar {
    margin-top: .35rem;
}

/* === USER DETAIL VIEW === */
.user-detail {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}

.user-detail-header {
    padding: 1.25rem;
    background: var(--color-white);
    border-bottom: 1px solid var(--color-gray2);
}

.user-detail-info h3 {
    margin: 0 0 .25rem;
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--color-gray7);
}

.user-detail-email {
    margin: 0 0 .5rem;
    font-size: .9rem;
    color: var(--color-gray5);
}

.user-detail-meta {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin-bottom: .5rem;
}

.user-role-label {
    font-size: .85rem;
    font-weight: 500;
    color: var(--color-gray6);
}

.user-status {
    font-size: .75rem;
    padding: 2px 8px;
    border-radius: 3px;
}

.user-status.status-pending {
    background: #fff3cd;
    color: #856404;
}

.user-status.status-active {
    background: #d4edda;
    color: #155724;
}

.user-detail-date {
    margin: .15rem 0;
    font-size: .8rem;
    color: var(--color-gray5);
}

.user-detail-sections {
    padding: 1rem;
}

.user-plant-item {
    padding: .5rem 0;
    border-bottom: 1px solid var(--color-gray1);
}

.user-plant-name {
    font-weight: 500;
    font-size: .9rem;
    color: var(--color-gray7);
}

.user-plant-country {
    font-weight: 400;
    color: var(--color-gray5);
}

.user-plant-commesse {
    margin-top: .25rem;
    display: flex;
    flex-wrap: wrap;
    gap: .25rem;
}

.user-commessa-tag {
    display: inline-block;
    padding: 2px 8px;
    font-size: .75rem;
    background: var(--color-gray1);
    color: var(--color-gray6);
    border: 1px solid var(--color-gray2);
}

.user-detail-actions {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--color-gray2);
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
}

.btn-user-action {
    font-size: .85rem;
}

.btn-danger-action {
    color: var(--color-danger) !important;
    border-color: var(--color-danger) !important;
}

.btn-danger-action:hover {
    background: var(--color-danger) !important;
    color: var(--color-white) !important;
}

/* === RESPONSIVE (Documents Page) === */
@media (max-width: 768px) {
    .doc-container {
        flex-direction: column;
    }

    .doc-sidebar {
        width: 100%;
        min-width: 100%;
        max-height: 200px;
        border-right: none;
        border-bottom: 1px solid var(--color-gray2);
    }

    .file-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }

    .page-title {
        display: none;
    }
}

/* ================================================================
   PROMPTS PAGE
   ================================================================ */

/* Sidebar header with new prompt button */
.prompt-sidebar-header {
    padding: .5rem .75rem;
    border-bottom: 1px solid var(--color-gray2);
    display: flex;
    justify-content: center;
}

.prompt-sidebar-header .btn-action {
    width: 100%;
    justify-content: center;
}

/* Role groups in sidebar */
.prompt-role-group {
    border-bottom: 1px solid var(--color-gray1);
}

.prompt-role-header {
    padding: .6rem .75rem;
    font-weight: 700;
    font-size: .85rem;
    color: var(--color-gray6);
    background: var(--color-gray0);
    cursor: pointer;
    user-select: none;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.prompt-role-header:hover {
    background: var(--color-gray1);
}

.prompt-role-group.collapsed .prompt-role-items {
    display: none;
}

.prompt-role-items {
    padding: 0;
}

.prompt-item {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .5rem .75rem .5rem 1.25rem;
    cursor: pointer;
    border-left: 3px solid transparent;
    transition: background .15s;
}

.prompt-item:hover {
    background: var(--color-gray1);
}

.prompt-item.active {
    background: var(--color-gray1);
    border-left-color: var(--color-main);
}

.prompt-item-label {
    flex: 1;
    font-size: .85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.prompt-default-tag {
    font-size: .7rem;
    font-weight: 700;
    color: var(--color-white);
    background: var(--color-main);
    padding: .1rem .4rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    flex-shrink: 0;
}

.prompt-item-empty {
    padding: .5rem .75rem .5rem 1.25rem;
    font-size: .8rem;
    color: var(--color-gray4);
    font-style: italic;
}

/* Prompt detail area */
.prompt-empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: var(--color-gray4);
    font-size: 1rem;
}

.prompt-detail {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 1.25rem;
}

.prompt-detail-header {
    display: flex;
    align-items: center;
    gap: .75rem;
    margin-bottom: 1rem;
}

.prompt-detail-role {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--color-gray7);
}

.prompt-default-badge {
    font-size: .75rem;
    font-weight: 700;
    color: var(--color-white);
    background: var(--color-main);
    padding: .15rem .5rem;
    text-transform: uppercase;
}

.prompt-detail-form {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.prompt-detail-form .form-group {
    margin-bottom: .75rem;
}

.prompt-detail-form textarea {
    width: 100%;
    font-family: "Roboto", sans-serif;
    font-size: .9rem;
    line-height: 1.5;
    padding: .5rem;
    border: 1px solid var(--color-gray3);
    resize: vertical;
    min-height: 200px;
}

.prompt-detail-form textarea:focus {
    outline: none;
    border-color: var(--color-main);
}

.prompt-detail-meta {
    display: flex;
    gap: 2rem;
    font-size: .8rem;
    color: var(--color-gray4);
    margin-bottom: 1rem;
}

.prompt-detail-actions {
    display: flex;
    gap: .5rem;
    margin-top: .5rem;
}

/* Chat prompt selector in bottom bar */
.prompt-select-wrap {
    display: flex;
    align-items: center;
    gap: .35rem;
}

.prompt-select-wrap label {
    font-size: .8rem;
    color: var(--color-gray5);
    white-space: nowrap;
}

.prompt-select-wrap select {
    font-size: .8rem;
    padding: .2rem .4rem;
    border: 1px solid var(--color-gray3);
    background: var(--color-white);
    max-width: 200px;
}

.prompt-fallback-warning {
    display: inline-flex;
    align-items: center;
    gap: .25rem;
    font-size: .75rem;
    color: #b8860b;
    background: #fff8e1;
    padding: .15rem .5rem;
    font-weight: 600;
}

/* ====================================================
   CHAT HISTORY PAGE
   ==================================================== */

/* Calendar container in sidebar */
.chat-history-calendar {
    padding: .75rem;
    border-bottom: 1px solid var(--color-gray2);
}

/* Conversation list below calendar */
.chat-history-list {
    overflow-y: auto;
    flex: 1;
}

.chat-history-list-header {
    padding: .5rem .75rem;
    font-size: .8rem;
    font-weight: 700;
    color: var(--color-gray5);
    text-transform: uppercase;
    letter-spacing: .03em;
    border-bottom: 1px solid var(--color-gray2);
}

.chat-history-item {
    padding: .6rem .75rem;
    border-bottom: 1px solid var(--color-gray1);
    cursor: pointer;
    transition: background .15s;
}

.chat-history-item:hover {
    background: var(--color-gray1);
}

.chat-history-item.active {
    background: var(--color-gray1);
    border-left: 3px solid var(--color-main);
}

.chat-history-item-context {
    font-size: .85rem;
    font-weight: 600;
    color: var(--color-gray7);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-history-item-meta {
    font-size: .75rem;
    color: var(--color-gray4);
    margin-top: .15rem;
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
}

/* Main area: conversation detail */
.chat-history-detail {
    padding: 1rem 1.5rem;
    overflow-y: auto;
    max-height: calc(100vh - var(--topbar-height) - 60px);
}

.chat-history-detail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: .75rem;
    border-bottom: 1px solid var(--color-gray2);
}

.chat-history-detail-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-gray7);
}

.chat-history-detail-meta {
    font-size: .8rem;
    color: var(--color-gray4);
}

/* Reuse chat message styles for history view */
.chat-history-msg {
    max-width: 85%;
    padding: .75rem 1rem;
    margin-bottom: .75rem;
    font-size: .9rem;
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.chat-history-msg.user {
    margin-left: auto;
    background: var(--color-main);
    color: var(--color-white);
}

.chat-history-msg.assistant {
    margin-right: auto;
    background: var(--color-white);
    border: 1px solid var(--color-gray2);
    color: var(--color-gray7);
}

.chat-history-msg-time {
    font-size: .7rem;
    color: var(--color-gray4);
    margin-top: .25rem;
    text-align: right;
}

.chat-history-msg.user .chat-history-msg-time {
    color: rgba(255,255,255,.7);
}

/* Empty state */
.chat-history-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 300px;
    color: var(--color-gray4);
    font-size: .95rem;
}

/* Send email button in detail header */
.btn-send-email {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    padding: .35rem .75rem;
    font-size: .8rem;
    font-weight: 500;
    color: var(--color-white);
    background: var(--color-main);
    border: none;
    cursor: pointer;
    transition: background .15s;
}

.btn-send-email:hover {
    background: var(--color-main-hover);
}

.btn-send-email:disabled {
    opacity: .6;
    cursor: not-allowed;
}

/* ====================================================
   FLATPICKR THEME OVERRIDES (flat, no rounded corners)
   ==================================================== */
.flatpickr-calendar {
    border-radius: var(--radius-md) !important;
    box-shadow: none !important;
    border: 1px solid var(--color-gray2);
    font-family: "Roboto", sans-serif;
    width: 100% !important;
}

.flatpickr-months {
    border-radius: var(--radius-md) !important;
}

.flatpickr-day {
    border-radius: var(--radius-md) !important;
}

.flatpickr-day.selected,
.flatpickr-day.selected:hover {
    background: var(--color-main) !important;
    border-color: var(--color-main) !important;
    color: var(--color-white) !important;
}

.flatpickr-day.today {
    border-color: var(--color-main) !important;
}

.flatpickr-day.today:not(.selected) {
    color: var(--color-main) !important;
}

/* Dot indicator for days with chats */
.flatpickr-day.has-chat {
    position: relative;
}

.flatpickr-day.has-chat::after {
    content: '';
    position: absolute;
    bottom: 3px;
    left: 50%;
    transform: translateX(-50%);
    width: 5px;
    height: 5px;
    background: var(--color-main);
    border-radius: 50%;
}

.flatpickr-day.has-chat.selected::after {
    background: var(--color-white);
}

/* Sidebar layout for chat history */
.chat-history-sidebar-content {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--topbar-height));
    overflow: hidden;
}

@media (max-width: 768px) {
    .chat-history-detail {
        max-height: none;
        padding: .75rem;
    }

    .chat-history-msg {
        max-width: 95%;
    }
}

/* ================================================================
   DASHBOARD PAGE
   ================================================================ */

.dashboard-sidebar-content {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--topbar-height));
    overflow-y: auto;
    padding-bottom: 1rem;
}

.dashboard-filter-group {
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--color-gray2);
}

.dashboard-filter-group label {
    display: block;
    font-size: .8rem;
    font-weight: 600;
    color: var(--color-gray6);
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-bottom: .5rem;
}

.dashboard-filter-group input[type="date"],
.dashboard-filter-group input[type="text"] {
    width: 100%;
    padding: .4rem .5rem;
    border: 1px solid var(--color-gray3);
    border-radius: var(--radius-md);
    font-size: .85rem;
    font-family: inherit;
    margin-bottom: .4rem;
    box-sizing: border-box;
}

.dashboard-filter-group input:focus {
    outline: 2px solid var(--color-main);
    outline-offset: 2px;
}

.dashboard-filter-checkbox {
    display: flex;
    align-items: center;
    gap: .4rem;
    margin-bottom: .3rem;
    font-size: .85rem;
    cursor: pointer;
}

.dashboard-filter-checkbox input[type="checkbox"] {
    margin: 0;
    accent-color: var(--color-main);
}

.dashboard-filter-actions {
    padding: .75rem 1rem;
    display: flex;
    gap: .5rem;
}

.dashboard-filter-actions button {
    flex: 1;
}

.dashboard-content {
    padding: 1.5rem;
    overflow-y: auto;
    height: calc(100vh - var(--topbar-height));
}

.dashboard-section {
    margin-bottom: 2rem;
}

.dashboard-section h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-gray7);
    margin-bottom: 1rem;
    padding-bottom: .5rem;
    border-bottom: 2px solid var(--color-main);
}

.dashboard-chart-container {
    background: var(--color-white);
    padding: 1rem;
    border: 1px solid var(--color-gray2);
    height: 300px;
    position: relative;
}

.dashboard-chart-small {
    height: 250px;
}

.dashboard-tables-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.dashboard-table-card {
    flex: 1;
    min-width: 280px;
    background: var(--color-white);
    border: 1px solid var(--color-gray2);
    padding: 1rem;
}

.dashboard-table-card h4 {
    font-size: .85rem;
    font-weight: 600;
    color: var(--color-gray6);
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-bottom: .75rem;
}

.dashboard-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .85rem;
}

.dashboard-table th {
    text-align: left;
    padding: .4rem .5rem;
    border-bottom: 2px solid var(--color-gray3);
    font-weight: 600;
    color: var(--color-gray6);
    font-size: .8rem;
    text-transform: uppercase;
}

.dashboard-table td {
    padding: .4rem .5rem;
    border-bottom: 1px solid var(--color-gray1);
    color: var(--color-gray7);
}

.dashboard-table tr:hover td {
    background: var(--color-gray0);
}

.dashboard-table .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.dashboard-table .rank {
    color: var(--color-gray5);
    width: 30px;
}

.dashboard-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    color: var(--color-gray5);
    font-size: .9rem;
}

.dashboard-no-data {
    text-align: center;
    padding: 2rem;
    color: var(--color-gray5);
    font-size: .85rem;
}

.topic-examples-cell {
    max-width: 300px;
}

.topic-example {
    font-size: .78rem;
    color: var(--color-gray5);
    padding: 2px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 280px;
}

@media (max-width: 768px) {
    .dashboard-tables-row {
        flex-direction: column;
    }

    .dashboard-table-card {
        min-width: 100%;
    }

    .dashboard-content {
        padding: .75rem;
    }

    .dashboard-chart-container {
        height: 220px;
    }
}

/* ================================================================
   APP SHELL - NEW UNIFIED LAYOUT (toolbar + sidebar + main area)
   ================================================================ */

.app-shell {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* === SIDEBAR === */
.app-sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    background: rgba(255, 255, 255, 0.72);
    backdrop-filter: blur(20px) saturate(1.5);
    border-right: 1px solid rgba(0, 0, 0, 0.06);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 100;
    overflow: hidden;
}

.app-sidebar-brand {
    padding: 0 16px;
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-main);
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid var(--color-gray2);
    min-height: var(--topbar-height);
    height: var(--topbar-height);
    flex-shrink: 0;
}

.app-sidebar-brand .brand-logo-img {
    width: 32px;
    height: 32px;
    object-fit: contain;
}

.app-sidebar-brand .brand-name {
    flex: 1;
    font-size: .95rem;
    font-weight: 700;
    color: var(--color-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.nav-section-label {
    display: block;
    padding: 12px 16px 4px;
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--color-gray5);
    letter-spacing: .06em;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    color: var(--color-gray7);
    text-decoration: none;
    font-size: .88rem;
    cursor: pointer;
    transition: background .15s, color .15s;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-family: inherit;
    font-weight: 400;
    height: auto;
    border-radius: var(--radius-md);
}

.nav-item:hover {
    background: var(--color-gray1);
    color: var(--color-gray7);
}

.nav-item.active {
    background: rgba(0, 120, 212, 0.08);
    color: var(--color-main);
    font-weight: 600;
}

.nav-item i {
    font-size: 1.1rem;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.nav-item-badge {
    margin-left: auto;
    font-size: .7rem;
    font-weight: 700;
    padding: 1px 6px;
    background: var(--color-gray1);
    color: var(--color-gray5);
}

.nav-divider {
    height: 1px;
    background: var(--color-gray2);
    margin: 8px 0;
}

.app-sidebar-footer {
    padding: 8px;
    border-top: 1px solid var(--color-gray2);
    flex-shrink: 0;
}

/* Sidebar custom widgets (selects, etc.) */
.sidebar-widget {
    padding: 4px 16px 12px;
}

.sidebar-widget select {
    width: 100%;
    padding: .4rem .5rem;
    border: 1px solid var(--color-gray3);
    border-radius: var(--radius-md);
    font-size: .85rem;
    font-family: inherit;
    color: var(--color-gray7);
    background: var(--color-white);
    cursor: pointer;
}

.sidebar-widget select:focus {
    outline: 2px solid var(--color-main);
    outline-offset: 1px;
}

.sidebar-widget .prompt-fallback-warning {
    display: inline-flex;
    align-items: center;
    gap: .25rem;
    font-size: .7rem;
    color: #b8860b;
    background: #fff8e1;
    padding: .1rem .4rem;
    font-weight: 600;
    margin-top: 4px;
}

/* === MAIN AREA === */
.app-main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
    background: var(--color-gray0);
}

/* === TOOLBAR === */
.app-toolbar {
    height: var(--topbar-height);
    min-height: var(--topbar-height);
    background: var(--color-white);
    border-bottom: 1px solid var(--color-gray2);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 12px;
    z-index: 50;
    flex-shrink: 0;
}

.app-toolbar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    padding: 4px 6px;
    color: var(--color-gray7);
    height: auto;
}

.app-toolbar-toggle:hover {
    background: var(--color-gray1);
    color: var(--color-main);
}

.app-toolbar-title {
    font-size: .95rem;
    font-weight: 600;
    color: var(--color-gray7);
}

.app-toolbar-spacer {
    flex: 1;
}

.app-toolbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* === APP LAUNCHER === */
.app-launcher {
    position: relative;
    margin-left: auto;
    flex-shrink: 0;
}

.app-launcher-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    color: var(--color-gray5);
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s, color .15s;
    height: auto;
    width: auto;
}

.app-launcher-btn:hover {
    background: var(--color-gray1);
    color: var(--color-main);
}

.app-launcher-menu {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    min-width: 220px;
    background: var(--color-white);
    border: 1px solid var(--color-gray2);
    border-radius: var(--radius-md);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.14);
    z-index: 200;
    padding: 6px;
}

.app-launcher-menu.open {
    display: block;
}

.app-launcher-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    color: var(--color-gray7);
    text-decoration: none;
    transition: background .15s;
    font-size: .85rem;
    font-weight: 500;
    height: auto;
    border: none;
    background: none;
    width: 100%;
}

.app-launcher-item:hover {
    background: var(--color-gray1);
    color: var(--color-main);
}

.app-launcher-icon {
    width: 28px;
    height: 28px;
    background: var(--color-gray1);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    color: var(--color-main);
    flex-shrink: 0;
    overflow: hidden;
}

.app-launcher-icon img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.app-launcher-label {
    font-size: .85rem;
    font-weight: 500;
}

/* === SIDEBAR OVERLAY (mobile) === */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 90;
}

.sidebar-overlay.open {
    display: block;
}

/* === CHAT CONTENT AREA (within app-shell) === */
.chat-content {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

/* Chat scroll inside app-shell (no fixed offset) */
.app-shell .chat-scroll {
    padding: 1.5rem 1rem 1rem;
    max-width: var(--maxw);
    margin: 0 auto;
    width: 100%;
}

.app-shell .chat-scroll.empty {
    flex: 1;
    justify-content: center;
    min-height: 0;
}

/* Chat form inside app-shell (no fixed positioning) */
.app-shell .chat-form {
    position: relative;
    left: auto;
    right: auto;
    bottom: auto;
    flex-shrink: 0;
    padding: .5rem .75rem .75rem;
    background: var(--color-gray0);
    border-top: 1px solid var(--color-gray2);
}

.app-shell .chat-form .inner {
    max-width: var(--maxw);
    margin: 0 auto;
}

/* === GROUP MAPPING PAGE STYLES (moved from inline) === */
.gm-role-detail-header {
    padding: 16px 0;
    border-bottom: 1px solid var(--color-gray2);
    margin-bottom: 16px;
}

.gm-role-detail-header h2 {
    margin: 0 0 4px 0;
    font-size: 1.2rem;
}

.gm-role-detail-header span {
    color: var(--color-gray5);
    font-size: .85rem;
}

.gm-empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--color-gray4);
    font-size: 1rem;
    padding: 40px;
    text-align: center;
}

.gm-role-detail-actions {
    margin-top: 24px;
    display: flex;
    gap: 12px;
}

.group-checkbox-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 1px solid var(--color-gray1);
    cursor: pointer;
}

.group-checkbox-item input[type="checkbox"] {
    margin: 0;
    accent-color: var(--color-main);
}

.group-checkbox-label {
    flex: 1;
    font-size: .9rem;
}

.group-checkbox-key {
    color: var(--color-gray5);
    font-size: .8rem;
    font-family: monospace;
}

.gm-sync-meta {
    padding: 12px 16px;
    background: var(--color-gray0);
    border-bottom: 1px solid var(--color-gray2);
}

.gm-sync-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    font-size: .85rem;
}

.gm-sync-label {
    color: var(--color-gray5);
}

.gm-sync-value {
    font-weight: 500;
    font-family: monospace;
}

.gm-sync-actions {
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-gray2);
    display: flex;
    align-items: center;
    gap: 12px;
}

.group-structure-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--color-gray1);
    font-size: .85rem;
}

.group-structure-name {
    font-weight: 500;
}

.group-structure-key {
    color: var(--color-gray5);
    font-size: .8rem;
    font-family: monospace;
}

.group-structure-parent {
    color: var(--color-gray5);
    font-size: .8rem;
    margin-left: auto;
}

.sync-message {
    padding: 8px 12px;
    font-size: .85rem;
}

.sync-message-success {
    color: #2e7d32;
}

.sync-message-error {
    color: var(--color-danger);
}

/* === RESPONSIVE - APP SHELL === */
@media (max-width: 768px) {
    .app-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(-100%);
        transition: transform .25s ease;
        box-shadow: none;
    }

    .app-sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 16px rgba(0, 0, 0, 0.1);
    }

    .app-toolbar-toggle {
        display: flex;
    }

    .app-toolbar {
        padding: 0 12px;
    }
}
