/*
 * CALYPSO GESTIONALE - Responsive & Polish
 * Aggiunge: breakpoint completi, table responsive, form grid, utilities
 * Caricato DOPO calypso-app.css
 */

/* ===== RESPONSIVE TABLES - Global fix ===== */
.table-auto-responsive {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    -ms-overflow-style: -ms-autohiding-scrollbar;
}

.table-auto-responsive > .table {
    margin-bottom: 0;
    white-space: nowrap;
}

/* Card tables: auto-responsive */
.card > .table,
.card > .table-responsive > .table,
.card-body > .table {
    margin-bottom: 0;
}

.card > .table-auto-responsive {
    border-radius: 0 0 0.75rem 0.75rem;
}

/* Scroll indicator shadow */
.table-auto-responsive {
    background:
        linear-gradient(to right, #fff 30%, transparent),
        linear-gradient(to left, #fff 30%, transparent),
        linear-gradient(to right, rgba(0,0,0,.08), transparent 70%),
        linear-gradient(to left, rgba(0,0,0,.08), transparent 70%);
    background-position: left center, right center, left center, right center;
    background-repeat: no-repeat;
    background-size: 20px 100%, 20px 100%, 10px 100%, 10px 100%;
    background-attachment: local, local, scroll, scroll;
}

/* ===== RESPONSIVE GRID - Stat cards ===== */
.stats-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

/* ===== RESPONSIVE FORM ROWS ===== */
.form-row-responsive {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

.form-row-responsive.cols-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.form-row-responsive.cols-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.form-row-responsive.cols-4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

/* ===== FILTER TOOLBAR ===== */
.filter-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: flex-end;
    padding: 1rem;
}

.filter-toolbar .form-group {
    flex: 1;
    min-width: 150px;
}

.filter-toolbar .form-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: #6c757d;
    margin-bottom: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.filter-toolbar .btn-group-filter {
    display: flex;
    gap: 0.375rem;
    flex-shrink: 0;
}

/* ===== ACTION BAR (top of page) =====
   ⚠️ E' la fascia in testa alla pagina, come `.doc-banner`: stesse misure,
   stesso colore di sezione. Era un titolo nero su fondo bianco, e le cinque
   pagine che la usano - articoli, profilo, password, 2FA, ricerca - erano le
   uniche del gestionale senza fascia colorata: aprendone una sembrava di
   essere finiti in un'altra applicazione. */
.action-bar {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    background: var(--section-gradient, linear-gradient(135deg, #102F4D, #1A4B7C));
    color: var(--section-text, #fff);
    border-radius: .75rem;
    padding: .75rem 1.25rem;
    margin-bottom: .75rem;
}

.action-bar-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.05rem;
    font-weight: 600;
    color: inherit;
    min-width: 0;
}

/* ⚠️ L'icona era colorata col colore di sezione: sopra la fascia, che di quel
   colore e' fatta, sparirebbe. Prende il colore del testo. */
.action-bar-title i {
    color: inherit;
}

.action-bar-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* ===== DETAIL PAGE - Two columns ===== */
.detail-grid {
    display: grid;
    gap: 1.5rem;
    grid-template-columns: 1fr;
}

@media (min-width: 992px) {
    .detail-grid { grid-template-columns: 2fr 1fr; }
    .detail-grid.balanced { grid-template-columns: 1fr 1fr; }
    .detail-grid.wide-left { grid-template-columns: 3fr 1fr; }
}

.detail-grid .full-width {
    grid-column: 1 / -1;
}

/* ===== TABLE COLUMN WIDTHS - Fluid ===== */
.col-icon    { width: 3rem; max-width: 3rem; }
.col-id      { width: 5rem; max-width: 6rem; }
.col-code    { width: 8rem; max-width: 10rem; }
.col-date    { width: 7rem; max-width: 8rem; }
.col-money   { width: 6rem; max-width: 8rem; }
.col-status  { width: 6rem; max-width: 8rem; }
.col-qty     { width: 4rem; max-width: 5rem; }
.col-pct     { width: 3.5rem; max-width: 4.5rem; }
.col-actions { width: 5rem; max-width: 7rem; white-space: nowrap; }

/* ===== PAGINATION ===== */
.pagination-wrapper {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
}

.pagination-info {
    font-size: 0.85rem;
    color: #6c757d;
}

/* ===== BADGES - Status ===== */
.badge-status {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.35em 0.65em;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 50rem;
}

.badge-status::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}

.badge-status.paid, .badge-status.success    { background: #d1fae5; color: #065f46; }
.badge-status.paid::before, .badge-status.success::before { background: #10b981; }
.badge-status.pending, .badge-status.warning { background: #fef3c7; color: #92400e; }
.badge-status.pending::before, .badge-status.warning::before { background: #f59e0b; }
.badge-status.shipped, .badge-status.info    { background: #dbeafe; color: #1e40af; }
.badge-status.shipped::before, .badge-status.info::before { background: #3b82f6; }
.badge-status.cancelled, .badge-status.danger { background: #fee2e2; color: #991b1b; }
.badge-status.cancelled::before, .badge-status.danger::before { background: #ef4444; }
.badge-status.draft, .badge-status.secondary { background: #f3f4f6; color: #4b5563; }
.badge-status.draft::before, .badge-status.secondary::before { background: #9ca3af; }

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: #9ca3af;
}

.empty-state i {
    font-size: 3rem;
    opacity: 0.4;
    margin-bottom: 1rem;
    display: block;
}

.empty-state p {
    font-size: 0.95rem;
    margin: 0;
}

/* ===== TRUNCATE TEXT ===== */
.text-truncate-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ===== BREAKPOINTS ===== */

/* ---- Extra Small (< 576px) - Phones ---- */
@media (max-width: 575.98px) {
    .main-content { padding: 0.75rem; }
    .navbar-top { padding: 0.5rem 0.75rem; }
    
    .page-header { padding: 1rem 0.75rem; }
    .page-title { font-size: 1.15rem; }
    
    .stat-card { padding: 0.875rem; }
    .stat-icon { width: 44px; height: 44px; font-size: 1.2rem; }
    .stat-content h3 { font-size: 1.35rem; }
    .stat-content p { font-size: 0.8rem; }
    
    .card-header { padding: 0.75rem 1rem; font-size: 0.9rem; }
    .card-body { padding: 0.75rem; }
    
    .table thead th { padding: 0.625rem 0.5rem; font-size: 0.7rem; }
    .table tbody td { padding: 0.625rem 0.5rem; font-size: 0.85rem; }
    
    .btn { padding: 0.4rem 0.75rem; font-size: 0.85rem; }
    .btn-sm { padding: 0.25rem 0.5rem; font-size: 0.8rem; }
    
    .filter-toolbar { padding: 0.75rem; }
    .filter-toolbar .form-group { min-width: 100%; }
    
    .action-bar { flex-direction: column; align-items: stretch; }
    .action-bar-actions { justify-content: flex-end; }
    
    /* Hide less important columns on phones */
    .d-phone-none { display: none !important; }
    
    .detail-grid { gap: 1rem; }
    
    .login-card { padding: 1.5rem; margin: 1rem; }
    .login-logo-icon { width: 60px; height: 60px; }
    .login-title { font-size: 1.5rem; }
}

/* ---- Small (576px - 767px) - Large phones / Small tablets ---- */
@media (min-width: 576px) and (max-width: 767.98px) {
    .main-content { padding: 1rem; }
    
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    
    .filter-toolbar .form-group { min-width: 45%; }
    
    .d-phone-none { display: revert !important; }
}

/* ---- Medium (768px - 991px) - Tablets ---- */
@media (min-width: 768px) and (max-width: 991.98px) {
    .main-content { padding: 1.25rem; }
    
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    
    .detail-grid { grid-template-columns: 1fr; }
    
    .form-row-responsive { grid-template-columns: repeat(2, 1fr); }
}

/* ---- Large (992px - 1199px) - Small desktops ---- */
@media (min-width: 992px) and (max-width: 1199.98px) {
    .stats-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ---- Extra Large (1200px - 1399px) - Desktops ---- */
@media (min-width: 1200px) and (max-width: 1399.98px) {
    .stats-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ---- XXL (1400px+) - Large desktops ---- */
@media (min-width: 1400px) {
    .stats-grid { grid-template-columns: repeat(4, 1fr); }
    
    .main-content { padding: 2rem; max-width: 1600px; }
}

/* ---- Print refinements ---- */
@media print {
    .sidebar, .navbar-top, .app-footer, .no-print, .btn,
    .filter-toolbar, .action-bar-actions,
    .sidebar-backdrop, .mobile-sidebar-toggle { display: none !important; }
    
    .app-content { margin-left: 0 !important; }
    .main-content { padding: 0 !important; }
    
    .card { box-shadow: none !important; border: 1px solid #ddd !important; break-inside: avoid; }
    
    .table thead th { background: #f0f0f0 !important; }
    .table-auto-responsive { overflow: visible; }
    
    body { background: #fff !important; }
}

/* ===== CARD INSIDE TABLE FIX ===== */
.card .table-auto-responsive:last-child {
    border-radius: 0 0 0.75rem 0.75rem;
}

/* ===== TOOLTIP CUSTOM ===== */
.tooltip-custom {
    position: relative;
}
.tooltip-custom::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-4px);
    background: var(--calypso-dark);
    color: #fff;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
    z-index: 1000;
}
.tooltip-custom:hover::after { opacity: 1; }

/* ===== SCROLLBAR GLOBAL ===== */
* {
    scrollbar-width: thin;
    scrollbar-color: rgba(0,0,0,0.15) transparent;
}

*::-webkit-scrollbar { width: 6px; height: 6px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 3px; }
*::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.25); }

/* ===== MOBILE TAP TARGETS ===== */
@media (max-width: 991.98px) {
    .sidebar-link { padding: 0.75rem 1.25rem; min-height: 44px; }
    .btn { min-height: 38px; }
    .form-control, .form-select { min-height: 40px; font-size: 16px; }
    
    .table .btn-sm { min-height: 32px; min-width: 32px; padding: 0.25rem 0.4rem; }
}

/* ===== ACCESSIBILITY ===== */
:focus-visible {
    outline: 2px solid var(--calypso-primary);
    outline-offset: 2px;
}

.sidebar-link:focus-visible,
.btn:focus-visible {
    outline-offset: -2px;
}

/* Skip nav link */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    padding: 0.5rem 1rem;
    background: var(--calypso-primary);
    color: #fff;
    z-index: 9999;
    transition: top 0.2s;
}

.skip-link:focus { top: 0; }
