/* Tango Sinistri Manager - Modern responsive table */
.tsm-wrapper {
    box-sizing: border-box;
    padding: 32px 24px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
    color: #1f2937;
    max-width: 1400px;
    margin: 0 auto;
}
.tsm-wrapper *,
.tsm-wrapper *::before,
.tsm-wrapper *::after { box-sizing: border-box; }

.tsm-card {
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08), 0 2px 6px rgba(15, 23, 42, 0.04);
    padding: 28px;
    border: 1px solid #eef2f7;
}

.tsm-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}
.tsm-title {
    font-size: 24px;
    font-weight: 700;
    margin: 0;
    color: #0f172a;
    letter-spacing: -0.2px;
}
.tsm-upload { display: flex; gap: 10px; flex-wrap: wrap; }

.tsm-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all .18s ease;
    text-decoration: none;
    line-height: 1;
}
.tsm-btn:disabled { opacity: .5; cursor: not-allowed; }
.tsm-btn-primary {
    background: linear-gradient(135deg, #4f46e5, #6366f1);
    color: #fff;
}
.tsm-btn-primary:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 8px 20px rgba(79, 70, 229, .28);
}
.tsm-btn-ghost {
    background: #f1f5f9;
    color: #334155;
    border-color: #e2e8f0;
}
.tsm-btn-ghost:hover:not(:disabled) { background: #e2e8f0; }
.tsm-btn-danger {
    background: linear-gradient(135deg, #dc2626, #ef4444);
    color: #fff;
}
.tsm-btn-danger:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 8px 20px rgba(220, 38, 38, .28);
}
.tsm-icon { font-size: 16px; }

.tsm-filters {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
    gap: 14px;
    margin-bottom: 20px;
    align-items: end;
}
.tsm-filter-reset .tsm-btn {
    width: 100%;
    justify-content: center;
    padding: 10px 18px;
    min-height: 40px;
}
.tsm-filter { display: flex; flex-direction: column; gap: 6px; }
.tsm-filter label {
    font-size: 12px;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: .4px;
}
.tsm-filter select,
.tsm-filter input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #f8fafc;
    font-size: 14px;
    color: #0f172a;
    transition: border-color .15s, box-shadow .15s, background .15s;
    -webkit-appearance: none;
    appearance: none;
}
.tsm-filter select:focus,
.tsm-filter input:focus {
    outline: none;
    border-color: #6366f1;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, .15);
}

.tsm-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}
.tsm-stats {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}
.tsm-stat {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 8px 16px;
    border-radius: 12px;
    min-width: 90px;
    border: 1px solid transparent;
}
.tsm-stat-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .5px;
    opacity: .75;
}
.tsm-stat-value {
    font-size: 22px;
    font-weight: 800;
    line-height: 1.1;
    margin-top: 2px;
}
.tsm-stat-todo { background: #eef2ff; color: #4338ca; border-color: #e0e7ff; }
.tsm-stat-done { background: #ecfdf5; color: #047857; border-color: #d1fae5; }
.tsm-stat-total { background: #fef3c7; color: #92400e; border-color: #fde68a; }

.tsm-table-wrap {
    overflow-x: auto;
    border: 1px solid #eef2f7;
    border-radius: 12px;
    background: #fff;
    -webkit-overflow-scrolling: touch;
}
.tsm-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 13.5px;
    min-width: 600px;
}
.tsm-table thead th {
    background: #f8fafc;
    color: #475569;
    font-weight: 600;
    text-align: left;
    padding: 12px 14px;
    border-bottom: 1px solid #e2e8f0;
    position: sticky;
    top: 0;
    white-space: nowrap;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .3px;
}
.tsm-table tbody td {
    padding: 12px 14px;
    border-bottom: 1px solid #f1f5f9;
    color: #1f2937;
    vertical-align: middle;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tsm-table tbody td.tsm-col-attivita {
    max-width: 520px;
}
.tsm-table tbody td.tsm-col-sinistro {
    cursor: pointer;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-weight: 600;
    color: #4338ca;
}
.tsm-table tbody td.tsm-col-sinistro:hover {
    background: #eef2ff;
    text-decoration: underline;
}
.tsm-table tbody tr:hover { background: #f8fafc; }
.tsm-table tbody tr.tsm-selected { background: #eef2ff; }
.tsm-table tbody tr.tsm-selected:hover { background: #e0e7ff; }
.tsm-table tbody tr:last-child td { border-bottom: none; }

.tsm-col-select { width: 50px; text-align: center; }
.tsm-table td.tsm-col-select { text-align: center; }
.tsm-table input[type="radio"] { cursor: pointer; transform: scale(1.15); accent-color: #4f46e5; }

.tsm-sortable { cursor: pointer; user-select: none; }
.tsm-sortable:hover { color: #4f46e5; }
.tsm-sort-indicator {
    display: inline-block;
    margin-left: 6px;
    font-size: 10px;
    opacity: .4;
}
.tsm-sortable.tsm-sort-asc .tsm-sort-indicator::after { content: "▲"; opacity: 1; color: #4f46e5; }
.tsm-sortable.tsm-sort-desc .tsm-sort-indicator::after { content: "▼"; opacity: 1; color: #4f46e5; }
.tsm-sortable:not(.tsm-sort-asc):not(.tsm-sort-desc) .tsm-sort-indicator::after { content: "⇅"; }

.tsm-empty td {
    text-align: center;
    padding: 40px 20px !important;
    color: #94a3b8;
    font-style: italic;
}

/* Priority badges */
.tsm-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .3px;
}
.tsm-badge-urgente { background: #fee2e2; color: #b91c1c; }
.tsm-badge-alta { background: #ffedd5; color: #c2410c; }
.tsm-badge-media { background: #fef3c7; color: #a16207; }
.tsm-badge-bassa { background: #dcfce7; color: #15803d; }
.tsm-badge-default { background: #e2e8f0; color: #475569; }

/* Toast */
.tsm-toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: #0f172a;
    color: #fff;
    padding: 14px 20px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .2);
    opacity: 0;
    transform: translateY(10px);
    transition: all .25s ease;
    pointer-events: none;
    z-index: 9999;
    max-width: 360px;
}
.tsm-toast.tsm-show { opacity: 1; transform: translateY(0); }
.tsm-toast.tsm-error { background: #b91c1c; }
.tsm-toast.tsm-success { background: #15803d; }

/* Responsive */
@media (max-width: 900px) {
    .tsm-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .tsm-filter-reset { grid-column: 1 / -1; }
    .tsm-wrapper { padding: 20px 14px; }
    .tsm-card { padding: 20px; }
    .tsm-title { font-size: 20px; }
}
@media (max-width: 560px) {
    .tsm-filters { grid-template-columns: 1fr; }
    .tsm-filter-reset { grid-column: auto; }
    .tsm-header { flex-direction: column; align-items: stretch; }
    .tsm-upload { justify-content: stretch; }
    .tsm-upload .tsm-btn { flex: 1; justify-content: center; }
    .tsm-toolbar { flex-direction: column; align-items: stretch; }
    .tsm-toolbar .tsm-btn { width: 100%; justify-content: center; }
    .tsm-wrapper { padding: 16px 10px; }
    .tsm-card { padding: 16px; border-radius: 12px; }
}
