/* Fatture — shadcn-inspired design system */

:root {
    --ft-background: #ffffff;
    --ft-foreground: #09090b;
    --ft-muted: #f4f4f5;
    --ft-muted-foreground: #71717a;
    --ft-card: #ffffff;
    --ft-card-foreground: #09090b;
    --ft-border: #e4e4e7;
    --ft-input: #e4e4e7;
    --ft-primary: #18181b;
    --ft-primary-foreground: #fafafa;
    --ft-secondary: #f4f4f5;
    --ft-secondary-foreground: #18181b;
    --ft-accent: #f4f4f5;
    --ft-accent-foreground: #18181b;
    --ft-destructive: #ef4444;
    --ft-destructive-foreground: #fafafa;
    --ft-ring: #a1a1aa;
    --ft-radius: 0.625rem;
    --ft-font-sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --ft-font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;

    --sidebar-width: 16rem;
    --header-height: 3.5rem;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    font-family: var(--ft-font-sans);
    background-color: var(--ft-background);
    color: var(--ft-foreground);
    font-size: 0.875rem;
    line-height: 1.25rem;
}

button,
input,
select,
textarea {
    font: inherit;
}

a {
    color: inherit;
    text-decoration: none;
}

/* Input group with toggle button */
.ft-input-group {
    display: flex;
    align-items: center;
    border: 1px solid var(--ft-input);
    border-radius: var(--ft-radius);
    background-color: var(--ft-background);
    overflow: hidden;
}

.ft-input-group:focus-within {
    border-color: var(--ft-ring);
    box-shadow: 0 0 0 1px var(--ft-ring);
}

.ft-input-group .ft-form-input {
    flex: 1;
    min-width: 0;
    border: none;
    background: transparent;
    border-radius: 0;
}

.ft-input-group .ft-form-input:focus {
    border-color: transparent;
    box-shadow: none;
}

.ft-input-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    border: none;
    background: transparent;
    color: var(--ft-muted-foreground);
    cursor: pointer;
    flex-shrink: 0;
}

.ft-input-toggle:hover {
    background-color: var(--ft-muted);
    color: var(--ft-foreground);
}

/* Buttons */
.ft-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 2.25rem;
    padding: 0 0.75rem;
    border: 1px solid transparent;
    border-radius: var(--ft-radius);
    background-color: var(--ft-background);
    color: var(--ft-foreground);
    font-size: 0.8125rem;
    font-weight: 500;
    line-height: 1;
    cursor: pointer;
    transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}

.ft-btn:hover {
    background-color: var(--ft-muted);
}

.ft-btn-primary {
    background-color: var(--ft-primary);
    color: var(--ft-primary-foreground);
}

.ft-btn-primary:hover {
    background-color: var(--ft-foreground);
    color: var(--ft-primary-foreground);
}

.ft-btn-secondary {
    background-color: var(--ft-secondary);
    color: var(--ft-secondary-foreground);
    border-color: var(--ft-border);
}

.ft-btn-secondary:hover {
    background-color: var(--ft-muted);
    border-color: var(--ft-border);
}

.ft-btn-ghost {
    background-color: transparent;
    border-color: var(--ft-border);
    color: var(--ft-foreground);
}

.ft-btn-ghost:hover {
    background-color: var(--ft-muted);
}

.ft-btn-sm {
    height: 1.75rem;
    padding: 0 0.5rem;
    font-size: 0.75rem;
}

/* Utility spacing helpers */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Header pagina con azioni e contatore selezione per stampe.
   Sticky: resta sempre visibile mentre la tabella scrolla. */
.ft-page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 15;
    background: var(--ft-background, #fff);
    padding: 0.75rem 0;
    box-shadow: 0 1px 0 var(--ft-border, #e4e4e7);
}

.ft-page-header .ft-page-title {
    margin: 0;
}

.ft-page-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.ft-selected-count {
    font-size: 0.8125rem;
    color: var(--ft-muted-foreground);
    min-width: 4.5rem;
    text-align: right;
}

/* Form base condivisi (dialog e pagine) */
.ft-form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.ft-form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}

.ft-form-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

/* [hidden] deve vincere sui display author-level */
[hidden] {
    display: none !important;
}

.ft-form-label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--ft-foreground);
}

.ft-form-input {
    height: 2.25rem;
    padding: 0 0.75rem;
    border: 1px solid var(--ft-input);
    border-radius: var(--ft-radius);
    background-color: var(--ft-background);
    color: var(--ft-foreground);
    font-size: 0.8125rem;
    outline: none;
    transition: border-color 150ms ease, box-shadow 150ms ease;
}

.ft-form-input:focus {
    border-color: var(--ft-ring);
    box-shadow: 0 0 0 1px var(--ft-ring);
}

textarea.ft-form-input {
    height: auto;
    padding: 0.5rem 0.75rem;
    resize: vertical;
}

select.ft-form-input {
    padding-right: 1.75rem;
}

.ft-form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

/* Select ricercabile (componente SearchableSelect, funziona dentro <dialog>) */
.ft-searchable-select {
    position: relative;
    width: 100%;
}

.ft-searchable-select-input {
    width: 100%;
    height: 2.25rem;
    padding: 0 0.75rem;
    border: 1px solid var(--ft-input);
    border-radius: var(--ft-radius);
    font-size: 0.8125rem;
    background: var(--ft-background);
    color: var(--ft-foreground);
    outline: none;
    transition: border-color 150ms ease, box-shadow 150ms ease;
}

.ft-searchable-select-input:focus {
    border-color: var(--ft-ring);
    box-shadow: 0 0 0 1px var(--ft-ring);
}

/* fixed = esce dal contenitore: sfugge all'overflow del <dialog> nativo.
   left/top/bottom/width sono impostati da JS su coordinate viewport. */
.ft-searchable-select-dropdown {
    display: none;
    position: fixed;
    max-height: 240px;
    overflow-y: auto;
    background: var(--ft-background);
    border: 1px solid var(--ft-border);
    border-radius: var(--ft-radius);
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.1);
    z-index: 10;
    margin: 0;
    padding: 0.25rem;
    list-style: none;
}

.ft-searchable-select-dropdown.open {
    display: block;
}

.ft-searchable-select-item {
    padding: 0.5rem 0.75rem;
    font-size: 0.8125rem;
    border-radius: 0.25rem;
    cursor: pointer;
    color: var(--ft-foreground);
}

.ft-searchable-select-item:hover,
.ft-searchable-select-item.active {
    background: var(--ft-muted);
}

.ft-searchable-select-item.selected {
    background: var(--ft-muted);
    font-weight: 600;
}

.ft-searchable-select-empty {
    color: var(--ft-muted-foreground);
    font-style: italic;
}

.ft-searchable-select-no-results {
    padding: 0.75rem;
    font-size: 0.8125rem;
    color: var(--ft-muted-foreground);
    text-align: center;
}

/* ---------- TableSelect: autocomplete con dropdown a tabella ---------- */

.ft-tableselect {
    position: relative;
    width: 100%;
}

.ft-tableselect-dropdown {
    position: fixed;
    z-index: 1070;
    display: none;
    overflow-y: auto;
    max-height: 24rem;
    background: #fff;
    border: 1px solid var(--ft-border, #e2e8f0);
    border-radius: 0.5rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
}

.ft-tableselect-dropdown.open {
    display: block;
}

.ft-tableselect-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}

.ft-tableselect-table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #f8fafc;
    padding: 0.5rem 0.625rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--ft-muted-foreground, #64748b);
    border-bottom: 1px solid var(--ft-border, #e2e8f0);
    white-space: nowrap;
}

.ft-tableselect-table td {
    padding: 0.375rem 0.625rem;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
    color: var(--ft-foreground);
}

.ft-tableselect-row {
    cursor: pointer;
}

.ft-tableselect-row:hover,
.ft-tableselect-row.active {
    background: #eff6ff;
}

.ft-tableselect-row.selected {
    background: #dbeafe;
}

.ft-tableselect-empty td {
    color: var(--ft-muted-foreground);
    font-style: italic;
}

.ft-tableselect-noresults {
    padding: 0.75rem;
    font-size: 0.8125rem;
    color: var(--ft-muted-foreground);
    text-align: center;
}

/* Celle di uso comune: codice prodotto + alias e giacenza colorata */
.ft-ts-code {
    font-weight: 600;
    white-space: nowrap;
}

.ft-ts-code-alias {
    font-weight: 700;
    color: #1d4ed8;
    white-space: nowrap;
}

.ft-ts-code-root {
    font-size: 0.75rem;
    color: var(--ft-muted-foreground, #64748b);
    white-space: nowrap;
}

.ft-ts-qty {
    display: inline-block;
    min-width: 2.75rem;
    padding: 0.125rem 0.5rem;
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.75rem;
    text-align: center;
}

.ft-ts-qty-pos {
    background: #dcfce7;
    color: #15803d;
}

.ft-ts-qty-zero {
    background: #fef9c3;
    color: #a16207;
}

.ft-ts-qty-neg {
    background: #fee2e2;
    color: #b91c1c;
}

/* Avvisi in dialog */
.ft-alert {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
    padding: 0.75rem 1rem;
    border-radius: var(--ft-radius);
    border: 1px solid var(--ft-border);
    font-size: 0.8125rem;
    line-height: 1.4;
    color: var(--ft-foreground);
}

.ft-alert svg {
    flex-shrink: 0;
    margin-top: 0.125rem;
}

.ft-alert-warning {
    background: #fffbeb;
    border-color: #fcd34d;
    color: #92400e;
}

.ft-alert-info {
    background: #eff6ff;
    border-color: #93c5fd;
    color: #1e40af;
}

.ft-alert-warning svg {
    color: #d97706;
}

.ft-alert-error {
    background: #fef2f2;
    border-color: #fca5a5;
    color: #991b1b;
}

.ft-alert-error svg {
    color: #dc2626;
}

.ft-error-list {
    margin: 0;
    padding-left: 1rem;
}

.ft-error-list li+li {
    margin-top: 0.25rem;
}

.ft-alert-compare {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 0.5rem;
    align-items: center;
    margin: 0.75rem 0;
    text-align: center;
}

.ft-alert-compare .ft-compare-item {
    border: 1px solid var(--ft-border);
    border-radius: var(--ft-radius);
    padding: 0.625rem 0.75rem;
    background: var(--ft-background);
}

.ft-alert-compare .ft-compare-item dt {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--ft-muted-foreground);
    margin-bottom: 0.25rem;
}

.ft-alert-compare .ft-compare-item dd {
    margin: 0;
    font-size: 0.9375rem;
    font-weight: 600;
}

.ft-alert-compare .ft-compare-item.old dd {
    color: #d97706;
}

.ft-alert-compare .ft-compare-item.new dd {
    color: #16a34a;
}

.ft-alert-compare .ft-compare-arrow {
    color: var(--ft-muted-foreground);
}

/* Tabs nei form dialog */
.ft-form-tabs {
    display: flex;
    gap: 0.25rem;
    border-bottom: 1px solid var(--ft-border);
    margin-bottom: 1rem;
}

.ft-form-tabs .ft-tab {
    padding: 0.5rem 0.75rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--ft-muted-foreground);
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
}

.ft-form-tabs .ft-tab.active {
    color: var(--ft-foreground);
    border-bottom-color: var(--ft-foreground);
}

.ft-tab-panel {
    display: none;
}

.ft-tab-panel.active {
    display: block;
}

/* KPI cards (totali documenti/fatture) */
.ft-kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.ft-kpi {
    border-radius: 0.5rem;
    padding: 0.75rem 1rem;
    color: #fff;
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.ft-kpi-btn {
    align-self: flex-start;
    margin-top: 0.4rem;
    padding: 0.2rem 0.7rem;
    border: none;
    border-radius: 9999px;
    background: rgba(255, 255, 255, 0.22);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    cursor: pointer;
    transition: background 0.15s ease;
}

.ft-kpi-btn:hover {
    background: rgba(255, 255, 255, 0.38);
}

.ft-kpi-split-cols {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    width: 100%;
}

.ft-kpi-split-col {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    min-width: 0;
}

.ft-kpi-split-right {
    text-align: right;
    align-items: flex-end;
}

.ft-kpi-btn-center {
    align-self: center;
    width: 100%;
    margin-top: 0.55rem;
    text-align: center;
}

.ft-kpi-success {
    background: #16a34a;
}

.ft-kpi-danger {
    background: #dc2626;
}

.ft-kpi-warning {
    background: #f59e0b;
}

.ft-kpi-info {
    background: #2563eb;
}

.ft-kpi-secondary {
    background: #64748b;
}

.ft-kpi-sub {
    font-size: 0.75rem;
    opacity: 0.85;
}

.ft-kpi-value {
    font-size: 1.375rem;
    font-weight: 700;
}

.ft-kpi-label {
    font-size: 0.75rem;
    opacity: 0.9;
}

/* Gruppo bottoni azione con icone */
.ft-btn-group {
    display: inline-flex;
    gap: 0.125rem;
}

.ft-btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    padding: 0;
    border: 1px solid var(--ft-border, #e2e8f0);
    border-radius: 0.375rem;
    background: var(--ft-card, #fff);
    color: var(--ft-muted-foreground, #64748b);
    cursor: pointer;
}

.ft-btn-icon:hover {
    background: var(--ft-muted, #f4f4f5);
    color: var(--ft-foreground, #0f172a);
}

.ft-btn-icon svg {
    width: 0.875rem;
    height: 0.875rem;
}

.ft-btn-icon-info {
    color: #0ea5e9;
}

.ft-btn-icon-warning {
    color: #f59e0b;
}

.ft-btn-icon-danger {
    color: #dc2626;
}

.ft-btn-icon-success {
    color: #16a34a;
}

.ft-btn-icon-purple {
    color: #8b5cf6;
}

.ft-btn-icon-secondary {
    color: #64748b;
}

/* Icone check/times colorate (es. colonna Fattura) */
.ft-ico {
    display: inline-flex;
}

.ft-ico svg {
    width: 1rem;
    height: 1rem;
}

.ft-ico-ok {
    color: #16a34a;
}

.ft-ico-no {
    color: #f59e0b;
}

/* Lista selezionabile in dialog (es. associazione fattura) */
.ft-picker-search {
    width: 100%;
    margin-bottom: 0.5rem;
}

.ft-picker-list {
    max-height: 320px;
    overflow-y: auto;
    border: 1px solid var(--ft-border, #e2e8f0);
    border-radius: 0.5rem;
}

.ft-picker-item {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: none;
    border-bottom: 1px solid var(--ft-border, #e2e8f0);
    background: var(--ft-card, #fff);
    font-size: 0.8125rem;
    text-align: left;
    cursor: pointer;
}

.ft-picker-item:last-child {
    border-bottom: none;
}

.ft-picker-item:hover {
    background: var(--ft-muted, #f4f4f5);
    box-shadow: inset 2px 0 0 var(--ft-primary, #18181b);
}

.ft-picker-item .ft-picker-main {
    font-weight: 600;
}

.ft-picker-item .ft-picker-sub {
    color: var(--ft-muted-foreground, #64748b);
}

.ft-picker-label {
    margin: 0.5rem 0 0.25rem;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.ft-picker-list-lg {
    min-height: 140px;
    max-height: 400px;
}

.ft-picker-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.25rem;
    padding: 0 0.375rem;
    margin-left: 0.375rem;
    border-radius: 999px;
    background: var(--ft-muted, #f4f4f5);
    border: 1px solid var(--ft-border, #e2e8f0);
    font-size: 0.6875rem;
    font-weight: 600;
}

.ft-tab.active .ft-picker-count {
    background: var(--ft-primary, #18181b);
    border-color: var(--ft-primary, #18181b);
    color: #fff;
}

.ft-picker-note {
    margin: 0.5rem 0 0;
    font-size: 0.75rem;
}

.ft-picker-unlink {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.25rem;
    border-radius: 0.375rem;
    color: #dc2626;
}

.ft-picker-unlink:hover {
    background: #fee2e2;
}

.ft-picker-unlink svg {
    width: 0.875rem;
    height: 0.875rem;
}

/* Griglia di valori read-only nei dialog di visualizzazione (ViewGrid.js) */
.ft-view-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
    gap: 0.5rem;
    margin: 0 0 1rem;
    padding: 0;
}

.ft-view-item {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--ft-border, #e2e8f0);
    border-radius: 0.5rem;
    background: var(--ft-card, #fff);
    min-width: 0;
}

.ft-vi-icon {
    flex-shrink: 0;
    width: 1.875rem;
    height: 1.875rem;
    border-radius: 0.4375rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ft-vi-icon svg {
    width: 1rem;
    height: 1rem;
}

.ft-vi-body {
    min-width: 0;
}

.ft-view-item dt {
    margin: 0 0 0.125rem;
    font-size: 0.625rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--ft-muted-foreground, #64748b);
}

.ft-view-item dd {
    margin: 0;
    font-size: 0.8125rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ft-view-item-empty dd {
    color: var(--ft-muted-foreground, #94a3b8);
    font-weight: 400;
}

.ft-vi-slate {
    background: #f1f5f9;
    color: #475569;
}

.ft-vi-blue {
    background: #dbeafe;
    color: #1d4ed8;
}

.ft-vi-indigo {
    background: #e0e7ff;
    color: #4338ca;
}

.ft-vi-violet {
    background: #ede9fe;
    color: #6d28d9;
}

.ft-vi-teal {
    background: #ccfbf1;
    color: #0f766e;
}

.ft-vi-cyan {
    background: #cffafe;
    color: #0e7490;
}

.ft-vi-green {
    background: #dcfce7;
    color: #15803d;
}

.ft-vi-amber {
    background: #fef3c7;
    color: #b45309;
}

.ft-vi-orange {
    background: #ffedd5;
    color: #c2410c;
}

.ft-vi-rose {
    background: #ffe4e6;
    color: #be123c;
}

.ft-vi-stone {
    background: #e7e5e4;
    color: #57534e;
}

/* Tabella dettagli scrollabile dentro i dialog */
.ft-details-scroll {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--ft-border, #e2e8f0);
    border-radius: 0.5rem;
}

.ft-details-scroll .ft-details-table {
    margin-bottom: 0;
}

.ft-details-scroll thead th {
    position: sticky;
    top: 0;
    background: var(--ft-muted, #f4f4f5);
    z-index: 1;
}

.ft-details-total {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 0.5rem;
    font-size: 0.8125rem;
}

/* Checkbox inline nella toolbar pagina */
.ft-check-inline {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.8125rem;
    color: var(--ft-muted-foreground);
    cursor: pointer;
}

/* Switch generico */
.ft-switch {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    cursor: pointer;
    user-select: none;
}

.ft-switch input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.ft-switch-slider {
    position: relative;
    width: 42px;
    height: 23px;
    flex-shrink: 0;
    background: #e2e8f0;
    border-radius: 9999px;
    transition: background 0.2s ease;
}

.ft-switch-slider::before {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 17px;
    height: 17px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.3);
    transition: transform 0.2s ease;
}

.ft-switch input:checked+.ft-switch-slider {
    background: var(--ft-switch-color, #2563eb);
}

.ft-switch input:checked+.ft-switch-slider::before {
    transform: translateX(19px);
}

.ft-switch input:focus-visible+.ft-switch-slider {
    outline: 2px solid var(--ft-switch-color, #2563eb);
    outline-offset: 2px;
}

.ft-switch-warning {
    --ft-switch-color: #d97706;
}

.ft-switch-info {
    --ft-switch-color: #0284c7;
}

.ft-switch-text {
    font-size: 0.8125rem;
    font-weight: 500;
    color: #475569;
}