:root {
    /* Palette allineata al logo DF Parafarmaceutici: blu principale, verde come accento */
    --df-primary: #1f4e96;
    --df-primary-dark: #14335f;
    --df-primary-light: #e8eef9;
    --df-accent: #2f6fcb;
    --df-danger: #d1453b;
    --df-warning: #d98c0f;
    --df-success: #4caf50;
    --df-green: #4caf50;
    --df-green-light: #eaf6ea;
    --df-bg: #f4f6f8;
    --df-surface: #ffffff;
    --df-border: #e1e5eb;
    --df-text: #1b2430;
    --df-text-muted: #647082;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(15, 25, 45, 0.08), 0 1px 2px rgba(15, 25, 45, 0.06);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--df-bg);
    color: var(--df-text);
    -webkit-tap-highlight-color: transparent;
}

a { color: var(--df-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0 0 0.5em; }

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5em;
    padding: 0.65em 1.2em;
    border-radius: var(--radius);
    border: 1px solid transparent;
    background: var(--df-primary);
    color: #fff;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s ease;
}
.btn:hover { background: var(--df-primary-dark); text-decoration: none; }
.btn-outline { background: transparent; border-color: var(--df-border); color: var(--df-text); }
.btn-outline:hover { background: var(--df-primary-light); }
.btn-danger { background: var(--df-danger); }
.btn-danger:hover { background: #a8332b; }
.btn-sm { padding: 0.4em 0.8em; font-size: 0.85rem; }
.btn-block { width: 100%; justify-content: center; }

.card {
    background: var(--df-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
}

.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 600; margin-bottom: 0.35em; font-size: 0.9rem; }
.form-control {
    width: 100%;
    padding: 0.6em 0.75em;
    border: 1px solid var(--df-border);
    border-radius: 8px;
    font-size: 1rem;
    background: #fff;
    color: var(--df-text);
}
.form-control:focus { outline: none; border-color: var(--df-primary); box-shadow: 0 0 0 3px var(--df-primary-light); }
textarea.form-control { resize: vertical; min-height: 80px; }

.badge {
    display: inline-block;
    padding: 0.25em 0.7em;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}
.badge-pending { background: #fdf1dd; color: var(--df-warning); }
.badge-approved, .badge-success { background: #e4f7ea; color: var(--df-success); }
.badge-rejected, .badge-danger { background: #fbe9e8; color: var(--df-danger); }
.badge-info { background: #e5f2fb; color: var(--df-accent); }
.badge-muted { background: #eef0f0; color: var(--df-text-muted); }

.badge-select {
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    cursor: pointer;
    border: none;
}

.alert { padding: 0.85em 1em; border-radius: var(--radius); margin-bottom: 1rem; font-size: 0.9rem; }
.alert-error { background: #fbe9e8; color: #8a251d; }
.alert-success { background: #e4f7ea; color: #15532f; }

/* ---- Guest (login) layout ---- */
.guest-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: linear-gradient(160deg, var(--df-primary) 0%, var(--df-primary-dark) 100%);
}
.guest-card {
    width: 100%;
    max-width: 380px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    padding: 2rem;
    text-align: center;
}
.guest-card .logo { font-size: 1.4rem; font-weight: 800; color: var(--df-primary-dark); margin-bottom: 0.2em; }
.login-logo { max-width: 220px; width: 100%; height: auto; margin-bottom: 0.5rem; }
.guest-card .subtitle { color: var(--df-text-muted); margin-bottom: 1.5rem; font-size: 0.9rem; }
.guest-card form { text-align: left; }

/* ---- App shell ---- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
    width: 230px;
    background: var(--df-primary-dark);
    color: #fff;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
}
.sidebar .brand { padding: 1.25rem 1.25rem 0.5rem; font-weight: 800; font-size: 1.1rem; }
.sidebar .brand small { display: block; font-weight: 400; font-size: 0.7rem; opacity: 0.75; margin-top: 0.5rem; }
.brand-logo { background: #fff; border-radius: 8px; padding: 0.4rem 0.6rem; display: inline-block; max-width: 100%; }
.brand-logo img { display: block; max-width: 100%; height: 34px; width: auto; }

.sidebar-collapse-toggle {
    position: absolute;
    top: 1.1rem;
    right: 10px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--df-surface);
    color: var(--df-primary);
    border: 1px solid var(--df-border);
    box-shadow: var(--shadow);
    cursor: pointer;
    font-size: 0.7rem;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
}
.sidebar { position: relative; }
.sidebar.collapsed { width: 72px; }
.sidebar.collapsed .brand small,
.sidebar.collapsed .nav-label { display: none; }
.sidebar.collapsed .brand-logo { padding: 0.35rem; }
.sidebar.collapsed .brand-logo img { height: 24px; }
.sidebar.collapsed nav a { justify-content: center; padding: 0.8em 0.5rem; }
.sidebar.collapsed .logout-form { padding: 1rem 0.5rem; }
.sidebar.collapsed .logout-form .btn { padding: 0.5em; }
.sidebar.collapsed .sidebar-collapse-toggle i { transform: rotate(180deg); }
.sidebar nav { flex: 1; padding: 0.5rem 0; overflow-y: auto; }
.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 0.7em;
    padding: 0.7em 1.25rem;
    color: rgba(255,255,255,0.85);
    font-size: 0.92rem;
}
.sidebar nav a:hover, .sidebar nav a.active { background: rgba(255,255,255,0.12); text-decoration: none; color: #fff; }
.sidebar .logout-form { padding: 1rem 1.25rem; }

.main-area { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
    background: var(--df-surface);
    border-bottom: 1px solid var(--df-border);
    padding: 0.85rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}
.topbar .page-title { font-weight: 700; font-size: 1.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .user-chip { display: flex; align-items: center; gap: 0.6em; font-size: 0.9rem; color: var(--df-text-muted); }
.menu-toggle { display: none; background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--df-text); }
.back-btn {
    background: var(--df-primary-light);
    border: none;
    color: var(--df-primary-dark);
    width: 34px;
    height: 34px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.back-btn:hover { background: var(--df-primary); color: #fff; }

.content { padding: 1.5rem; flex: 1; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.kpi-tile { background: var(--df-surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem; display: flex; justify-content: space-between; align-items: flex-start; gap: 0.75rem; }
.kpi-tile .kpi-label { font-size: 0.8rem; color: var(--df-text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.kpi-tile .kpi-value { font-size: 1.6rem; font-weight: 800; margin: 0.2em 0; }
.kpi-icon {
    flex-shrink: 0;
    width: 42px;
    height: 42px;
    border-radius: 10px;
    background: var(--df-primary-light);
    color: var(--df-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
}
.kpi-tile .kpi-trend { font-size: 0.8rem; }
.kpi-trend.up { color: var(--df-success); }
.kpi-trend.down { color: var(--df-danger); }

.data-table { width: 100%; border-collapse: collapse; background: var(--df-surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.data-table th, .data-table td { padding: 0.75em 1em; text-align: left; border-bottom: 1px solid var(--df-border); font-size: 0.9rem; }
.data-table th { background: #f8faf9; font-weight: 700; color: var(--df-text-muted); font-size: 0.78rem; text-transform: uppercase; }
.data-table tr:last-child td { border-bottom: none; }

.toolbar { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; justify-content: space-between; margin-bottom: 1.25rem; }
.toolbar .search-box { display: flex; gap: 0.5rem; flex: 1; max-width: 420px; }

/* ---- Card grid for mobile-first customer/product views ---- */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.entity-card { background: var(--df-surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; display: flex; flex-direction: column; gap: 0.5rem; }
.entity-card .entity-title { font-weight: 700; font-size: 1rem; }
.entity-card .entity-meta { font-size: 0.85rem; color: var(--df-text-muted); }
.entity-card .entity-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; flex-wrap: wrap; }

.two-col-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.two-col-cards.uneven { grid-template-columns: 1.4fr 1fr; }
.two-col-cards.uneven-reverse { grid-template-columns: 2fr 1fr; }
@media (max-width: 900px) {
    .two-col-cards, .two-col-cards.uneven, .two-col-cards.uneven-reverse { grid-template-columns: 1fr; }
}

.pricelist-form-grid { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr auto; gap: 0.75rem; align-items: end; }
@media (max-width: 900px) {
    .pricelist-form-grid { grid-template-columns: 1fr 1fr; }
    .pricelist-form-grid .btn { grid-column: 1 / -1; }
}
@media (max-width: 480px) {
    .pricelist-form-grid { grid-template-columns: 1fr; }
}

/* ---- Listino prodotti (rep) - vista a lista con barcode scansionabile ---- */
.listino-list { display: flex; flex-direction: column; gap: 0.6rem; }
.listino-row {
    background: var(--df-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}
.listino-icon {
    flex-shrink: 0;
    width: 64px;
    height: 64px;
    border-radius: 12px;
    background: var(--df-primary-light);
    color: var(--df-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}
.listino-icon-img { padding: 0; overflow: hidden; background: #fff; border: 1px solid var(--df-border); cursor: zoom-in; }
.listino-icon-img img { width: 100%; height: 100%; object-fit: cover; }
.listino-range-hint { font-size: 0.72rem; color: var(--df-accent); font-weight: 600; margin-top: 0.2rem; }

.view-toggle { display: inline-flex; border: 1px solid var(--df-border); border-radius: var(--radius); overflow: hidden; }
.view-toggle-btn { background: var(--df-surface); border: none; padding: 0.5em 0.8em; cursor: pointer; color: var(--df-text-muted); }
.view-toggle-btn.active { background: var(--df-primary); color: #fff; }
.view-toggle-btn:not(:last-child) { border-right: 1px solid var(--df-border); }
.pdf-preview-card { width: 100%; max-width: 800px; height: 90vh; display: flex; flex-direction: column; }
.pdf-preview-frame { flex: 1; width: 100%; border: 1px solid var(--df-border); border-radius: 8px; }
.listino-qty-form { display: flex; align-items: center; gap: 0.4rem; }
.listino-qty-input { width: 56px; text-align: center; padding: 0.45em 0.3em; }
.listino-info { flex: 1; min-width: 0; }
.listino-name { font-weight: 700; }
.listino-meta { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; font-size: 0.8rem; color: var(--df-text-muted); margin-top: 0.2rem; }
.listino-barcode { flex-shrink: 0; width: 150px; text-align: center; cursor: zoom-in; }
.listino-barcode .df-barcode { max-width: 100%; height: 34px; }
.listino-ean-text { font-size: 0.7rem; color: var(--df-text-muted); letter-spacing: 0.03em; margin-top: 0.1rem; }
.listino-price { flex-shrink: 0; width: 110px; text-align: right; }
.listino-price-old { display: block; font-size: 0.78rem; color: var(--df-text-muted); text-decoration: line-through; }
.listino-price-final { display: block; font-size: 1.05rem; font-weight: 800; color: var(--df-green); }
.listino-actions { flex-shrink: 0; }

@media (max-width: 900px) {
    .listino-row { flex-wrap: wrap; }
    .listino-barcode, .listino-price, .listino-actions {
        width: calc(100% - 80px);
        margin-left: 80px;
        text-align: left;
        box-sizing: border-box;
    }
    .listino-actions .btn { width: 100%; justify-content: center; }
    .listino-qty-form { width: 100%; }
    .listino-qty-form .btn { flex: 1; width: auto; }
}

/* ---- Rep "app" quick actions (mobile) ---- */
.quick-actions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.9rem; }
.quick-action {
    background: var(--df-surface);
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 1.4rem 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    text-align: center;
    color: var(--df-text);
    font-weight: 700;
    font-size: 0.95rem;
}
.quick-action i { font-size: 1.6rem; color: var(--df-primary); }
.quick-action:hover { text-decoration: none; background: var(--df-primary-light); }

/* ---- Cassa (carrello a comparsa) ---- */
.cart-items { flex: 1; overflow-y: auto; margin: 0.75rem 0; }
.cart-item { display: flex; justify-content: space-between; gap: 0.5rem; padding: 0.5em 0; border-bottom: 1px solid var(--df-border); font-size: 0.88rem; }
.cart-item .qty-input { width: 55px; padding: 0.2em; text-align: center; border: 1px solid var(--df-border); border-radius: 6px; }
.cart-total { display: flex; justify-content: space-between; font-weight: 800; font-size: 1.1rem; padding-top: 0.5rem; }

.product-search { display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.product-search input, .product-search select { flex: 1; min-width: 150px; }

.cassa-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 55;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--df-primary);
    color: #fff;
    border: none;
    font-size: 1.4rem;
    box-shadow: 0 6px 18px rgba(20, 51, 95, 0.35);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.cassa-fab:hover { background: var(--df-primary-dark); }
.cassa-fab.bump { animation: df-cassa-bump 0.35s ease; }
@keyframes df-cassa-bump {
    0% { transform: scale(1); }
    35% { transform: scale(1.18); }
    100% { transform: scale(1); }
}
.cassa-fab-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--df-danger);
    color: #fff;
    border-radius: 999px;
    min-width: 22px;
    height: 22px;
    padding: 0 5px;
    font-size: 0.72rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
}
.cassa-drawer-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 25, 45, 0.4);
    z-index: 65;
}
.cassa-drawer-overlay.show { display: block; }
.cassa-drawer {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: 380px;
    max-width: 100%;
    background: var(--df-surface);
    box-shadow: -6px 0 24px rgba(0,0,0,0.18);
    z-index: 70;
    transform: translateX(100%);
    transition: transform 0.25s ease;
    display: flex;
    flex-direction: column;
    padding: 1.25rem;
}
.cassa-drawer.open { transform: translateX(0); }

@media (max-width: 768px) {
    .cassa-fab { bottom: 16px; right: 16px; }
    .cassa-drawer {
        top: auto;
        left: 0;
        height: 85vh;
        width: 100%;
        border-radius: 16px 16px 0 0;
        transform: translateY(100%);
    }
    .cassa-drawer.open { transform: translateY(0); }
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0; top: 0; bottom: 0;
        transform: translateX(-100%);
        z-index: 40;
        transition: transform 0.2s ease;
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar.collapsed { width: 230px; }
    .sidebar.collapsed .brand small { display: block; }
    .sidebar.collapsed .nav-label { display: inline; }
    .sidebar.collapsed nav a { justify-content: flex-start; }
    .sidebar-collapse-toggle { display: none; }
    .menu-toggle { display: inline-block; }
    .back-btn { width: 38px; height: 38px; font-size: 1.05rem; }
    .topbar { padding: 0.65rem 0.85rem; gap: 0.5rem; }
    .topbar .page-title { font-size: 1rem; }
    .user-chip span { display: none; }
    .content { padding: 1rem; }
    .data-table thead { display: none; }
    .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
    .data-table tr { margin-bottom: 0.75rem; border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
    .data-table td {
        display: flex;
        justify-content: space-between;
        gap: 1rem;
        border-bottom: 1px solid var(--df-border);
        text-align: right;
    }
    .data-table td::before {
        content: attr(data-label);
        font-weight: 700;
        color: var(--df-text-muted);
        text-align: left;
        font-size: 0.78rem;
        text-transform: uppercase;
    }
}

.overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: 30;
}
.overlay.show { display: block; }

.empty-state { text-align: center; padding: 3rem 1rem; color: var(--df-text-muted); }

.progress-bar { background: var(--df-border); border-radius: 999px; height: 10px; overflow: hidden; margin: 0.4rem 0; }
.progress-fill { height: 100%; border-radius: 999px; transition: width 0.3s ease; }
.progress-fill-success { background: var(--df-success); }
.progress-fill-warning { background: var(--df-warning); }
.progress-fill-danger { background: var(--df-danger); }
.empty-state i { font-size: 2.5rem; margin-bottom: 0.5rem; opacity: 0.5; }

.signature-pad-wrap { position: relative; border: 1px dashed var(--df-border); border-radius: 8px; background: #fff; touch-action: none; }
.signature-pad { width: 100%; height: 140px; display: block; cursor: crosshair; touch-action: none; }
.signature-pad-placeholder { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); color: var(--df-text-muted); font-size: 0.85rem; pointer-events: none; }
.signature-pad-placeholder.hidden { display: none; }

.chat-wrap { display: flex; flex-direction: column; height: calc(100vh - 180px); min-height: 360px; background: var(--df-surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.chat-thread { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: 0.5rem; }
.chat-bubble { max-width: 75%; padding: 0.5em 0.8em; border-radius: 14px; background: var(--df-primary-light); align-self: flex-start; font-size: 0.9rem; }
.chat-bubble.me { background: var(--df-primary); color: #fff; align-self: flex-end; }
.chat-bubble .chat-meta { display: block; font-size: 0.7rem; margin-top: 0.2em; opacity: 0.7; }
.chat-tick { font-size: 0.75rem; margin-left: 2px; }
.chat-tick-read { color: #4fc3f7; opacity: 1; }
.chat-input-bar { display: flex; gap: 0.5rem; padding: 0.75rem; border-top: 1px solid var(--df-border); }
.chat-input-bar textarea { flex: 1; resize: none; }
.chat-conv-list a { display: flex; justify-content: space-between; align-items: center; padding: 0.85rem 1rem; border-bottom: 1px solid var(--df-border); }
.chat-conv-list a:hover { background: var(--df-bg); }
.chat-conv-name { font-weight: 600; }
.chat-conv-preview { color: var(--df-text-muted); font-size: 0.82rem; max-width: 380px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-unread-dot { background: var(--df-danger); color: #fff; border-radius: 999px; font-size: 0.7rem; padding: 1px 7px; font-weight: 700; }
.nav-chat-badge { background: var(--df-danger); color: #fff; border-radius: 999px; font-size: 0.65rem; padding: 1px 6px; font-weight: 700; margin-left: auto; }

.sync-banner { display: none; align-items: center; justify-content: space-between; gap: 0.75rem; background: var(--df-warning); color: #fff; padding: 0.6rem 1rem; font-size: 0.85rem; font-weight: 600; }
.sync-banner.show { display: flex; }
.sync-banner button { flex-shrink: 0; }
