/* 
====================================
RUBIK ERP - Custom Styles
Responsive & Mobile-First Design
====================================
*/

:root {
    /* Colori principali (da screenshot) */
    --primary-blue: #3498db;
    --primary-dark: #2c3e50;
    --primary-light: #ecf0f1;
    
    /* Colori card statistiche */
    --card-blue: #3498db;
    --card-green: #2ecc71;
    --card-orange: #e67e22;
    --card-teal: #1abc9c;
    
    /* Grigi */
    --bg-dark: #3d4f5d;
    --sidebar-dark: #2c3e50;
    --text-light: #ecf0f1;
    --text-dark: #2c3e50;
    
    /* Alert */
    --alert-warning: #f39c12;
    
    /* Dimensioni */
    --sidebar-width: 258px;
    --topbar-height: 60px;
    --transition-speed: 0.3s;
}

/* ====================================
   RESET & BASE
   ==================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--primary-light);
    color: var(--text-dark);
    overflow-x: hidden;
}

/* ====================================
   LOGIN PAGE
   ==================================== */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--bg-dark) 0%, var(--sidebar-dark) 100%);
    padding: 20px;
}

.login-card {
    background: white;
    border-radius: 15px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    overflow: hidden;
    max-width: 450px;
    width: 100%;
    animation: slideIn 0.5s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.login-header {
    background: linear-gradient(135deg, var(--primary-blue) 0%, #5dade2 100%);
    padding: 40px 20px;
    text-align: center;
    color: white;
}

.login-header .logo-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto 20px;
    background: white;
    border-radius: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    color: var(--primary-blue);
}

.login-header h1 {
    font-size: 2rem;
    font-weight: bold;
    margin: 0;
}

.login-header p {
    font-size: 0.95rem;
    opacity: 0.9;
    margin: 10px 0 0;
}

.login-body {
    padding: 30px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-control {
    height: 50px;
    border-radius: 8px;
    border: 2px solid #dfe6e9;
    padding: 0 12px;
    font-size: 1rem;
    transition: all var(--transition-speed);
}

.form-control:focus {
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 0.2rem rgba(52, 152, 219, 0.25);
}

/* form-control-sm non deve avere height:50px */
.form-control.form-control-sm,
.form-select.form-select-sm {
    height: auto;
    padding: 0.25rem 0.5rem;
    font-size: 0.82rem;
}

/* Solo la pagina di login usa icone a sinistra */
.login-page .input-icon .form-control {
    padding-left: 45px;
}

.input-icon {
    position: relative;
}

.input-icon i {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: #95a5a6;
    font-size: 1.2rem;
}

.btn-login {
    width: 100%;
    height: 50px;
    background: var(--primary-blue);
    border: none;
    border-radius: 8px;
    color: white;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-speed);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.btn-login:hover {
    background: #2980b9;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(52, 152, 219, 0.4);
}

.login-footer {
    text-align: center;
    padding: 20px;
    border-top: 1px solid #ecf0f1;
    color: #7f8c8d;
    font-size: 0.9rem;
}

/* ====================================
   SIDEBAR
   ==================================== */
/* ═══ SIDEBAR COLLASSABILE — sostituisce le variabili e le classi esistenti ═══ */

:root {
  --sidebar-width: 220px;
  --sidebar-collapsed: 56px;
  --transition-speed: 0.25s;
}

/* Sidebar di base — collassata con solo icone */
.sidebar {
  position: fixed;
  left: 0; top: 0;
  width: var(--sidebar-collapsed);
  height: 100vh;
  background: var(--sidebar-dark);
  color: var(--text-light);
  transition: width var(--transition-speed) ease;
  z-index: 1000;
  overflow: hidden;
  box-shadow: 2px 0 10px rgba(0,0,0,0.15);
}

/* Espandi al hover */
.sidebar:hover {
  width: var(--sidebar-width);
  overflow-y: auto;
}

/* Main content si adatta */
.main-content {
  margin-left: var(--sidebar-collapsed);
  min-height: 100vh;
  transition: margin-left var(--transition-speed) ease;
}

/* Header sidebar — solo logo (icona) quando collassato */
.sidebar-header {
  padding: 10px 8px;
  text-align: center;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  color: white;
  text-decoration: none;
}

.sidebar-logo img {
  min-width: 36px;
  max-height: 36px;
  max-width: 36px;
  object-fit: contain;
  background: white;
  padding: 4px;
  border-radius: 6px;
  flex-shrink: 0;
}

.sidebar-logo i {
  font-size: 1.5rem;
  min-width: 36px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-logo .logo-text {
  opacity: 0;
  transition: opacity var(--transition-speed) ease;
  white-space: nowrap;
  overflow: hidden;
}
.sidebar:hover .logo-text { opacity: 1; }

.sidebar-logo .logo-text h2 { font-size: 1rem; margin: 0; font-weight: bold; }
.sidebar-logo .logo-text p  { font-size: 0.7rem; opacity: 0.7; margin: 0; }

/* Menu */
.sidebar-menu { padding: 8px 0; }
.menu-item     { margin: 2px 0; }

.menu-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  color: var(--text-light);
  text-decoration: none;
  transition: background var(--transition-speed);
  position: relative;
  white-space: nowrap;
  overflow: hidden;
}

.menu-link:hover { background: rgba(255,255,255,0.12); }
.menu-link.active { background: var(--primary-blue); border-left: 3px solid #2980b9; }

/* Icona — sempre visibile e di larghezza fissa */
.menu-link > i:first-child {
  min-width: 24px;
  text-align: center;
  font-size: 1rem;
  flex-shrink: 0;
}

/* Testo e freccia — nascosti quando collassato */
.menu-link > span,
.menu-link > i.fa-chevron-down {
  opacity: 0;
  transition: opacity var(--transition-speed) ease;
  white-space: nowrap;
}
.sidebar:hover .menu-link > span,
.sidebar:hover .menu-link > i.fa-chevron-down { opacity: 1; }

/* Tooltip icona quando collassato */
.sidebar:not(:hover) .menu-link::after {
  content: attr(data-tooltip);
  position: absolute;
  left: calc(var(--sidebar-collapsed) + 4px);
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0,0,0,0.85);
  color: #fff;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: .75rem;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  z-index: 2000;
}
.sidebar:not(:hover) .menu-link:hover::after { opacity: 1; }

/* Submenu */
.submenu { display: none; background: rgba(0,0,0,0.2); overflow: hidden; }
.submenu.show { display: block; }

.submenu .menu-link {
  padding-left: 52px;
  font-size: 0.85rem;
}

/* Separatori submenu — titoli di suddivisione ben visibili */
.submenu-separator {
  margin: 8px 12px 4px;
  padding: 5px 10px 6px 20px;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.09em;
  color: #7dd3fc;                     /* sky-300: distinto, non usato altrove */
  text-transform: uppercase;
  border-bottom: 1px solid rgba(125,211,252,0.45);
  background: rgba(125,211,252,0.08);
  border-radius: 4px 4px 0 0;
}

/* Mobile — sidebar normale */
@media (max-width: 991px) {
  .sidebar {
    transform: translateX(-100%);
    width: var(--sidebar-width);
  }
  .sidebar.active {
    transform: translateX(0);
    overflow-y: auto;
  }
  .sidebar .logo-text,
  .sidebar .menu-link > span,
  .sidebar .menu-link > i.fa-chevron-down { opacity: 1; }
  .main-content { margin-left: 0; }
}


.topbar {
    height: var(--topbar-height);
    background: white;
    border-bottom: 1px solid #dfe6e9;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.hamburger {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-dark);
}

@media (max-width: 991px) {
    .hamburger {
        display: block;
    }
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary-blue);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

/* Content Area */
.content-area {
    padding: 30px;
}

@media (max-width: 768px) {
    .content-area {
        padding: 15px;
    }
}

/* ====================================
   DASHBOARD CARDS
   ==================================== */
.stats-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

@media (max-width: 576px) {
    .stats-cards {
        grid-template-columns: 1fr;
    }
}

.stat-card {
    background: white;
    border-radius: 15px;
    padding: 25px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.08);
    transition: all var(--transition-speed);
    position: relative;
    overflow: hidden;
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 5px;
}

.stat-card.blue::before { background: var(--card-blue); }
.stat-card.green::before { background: var(--card-green); }
.stat-card.orange::before { background: var(--card-orange); }
.stat-card.teal::before { background: var(--card-teal); }

.stat-card-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.stat-info h3 {
    font-size: 0.9rem;
    color: #7f8c8d;
    margin-bottom: 10px;
    text-transform: uppercase;
}

.stat-info .stat-number {
    font-size: 2.5rem;
    font-weight: bold;
    color: var(--text-dark);
}

.stat-icon {
    font-size: 3rem;
    opacity: 0.2;
}

.stat-card.blue .stat-icon { color: var(--card-blue); }
.stat-card.green .stat-icon { color: var(--card-green); }
.stat-card.orange .stat-icon { color: var(--card-orange); }
.stat-card.teal .stat-icon { color: var(--card-teal); }

/* ====================================
   TABLES
   ==================================== */
.table-card {
    background: white;
    border-radius: 15px;
    padding: 25px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.08);
}

.table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid var(--primary-blue);
}

.table-header h2 {
    font-size: 1.3rem;
    color: var(--text-dark);
    display: flex;
    align-items: center;
    gap: 10px;
}

.table-responsive {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table thead {
    background: var(--primary-light);
}

.data-table th {
    padding: 15px;
    text-align: left;
    font-weight: 600;
    color: var(--text-dark);
    white-space: nowrap;
}

.data-table td {
    padding: 15px;
    border-bottom: 1px solid #ecf0f1;
}

.data-table tbody tr:hover {
    background: #f8f9fa;
}

/* Badge */
.badge {
    display: inline-block;
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-primary { background: var(--primary-blue); color: white; }
.badge-success { background: var(--card-green); color: white; }
.badge-warning { background: var(--card-orange); color: white; }
.badge-info { background: var(--card-teal); color: white; }

/* ====================================
   BUTTONS
   ==================================== */
.btn {
    padding: 10px 20px;
    border-radius: 8px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-speed);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 44px; /* Touch-friendly */
}

.btn-primary {
    background: var(--primary-blue);
    color: white;
}

.btn-primary:hover {
    background: #2980b9;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(52, 152, 219, 0.4);
}

.btn-success {
    background: var(--card-green);
    color: white;
}

.btn-warning {
    background: var(--card-orange);
    color: white;
}

.btn-sm {
    padding: 8px 15px;
    font-size: 0.9rem;
}

/* ====================================
   ALERTS
   ==================================== */
.alert {
    padding: 15px 20px;
    border-radius: 10px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.alert-success {
    background: #d4edda;
    color: #155724;
    border-left: 4px solid var(--card-green);
}

.alert-warning {
    background: #fff3cd;
    color: #856404;
    border-left: 4px solid var(--alert-warning);
}

.alert-danger {
    background: #f8d7da;
    color: #721c24;
    border-left: 4px solid #dc3545;
}

.alert-info {
    background: #d1ecf1;
    color: #0c5460;
    border-left: 4px solid var(--card-teal);
}

.alert-dismissible {
    position: relative;
    padding-right: 40px;
}

.alert .close {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    opacity: 0.5;
}

.alert .close:hover {
    opacity: 1;
}

/* ====================================
   UTILITIES
   ==================================== */
.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-3 { margin-top: 1rem; }
.mb-3 { margin-bottom: 1rem; }
.d-none { display: none; }
.d-block { display: block; }

/* ====================================
   MOBILE OPTIMIZATIONS
   ==================================== */
@media (max-width: 768px) {
    .data-table {
        font-size: 0.9rem;
    }
    
    .data-table th,
    .data-table td {
        padding: 10px 8px;
    }
    
    /* Nascondi colonne meno importanti su mobile */
    .data-table .hide-mobile {
        display: none;
    }
}

/* ====================================
   OVERLAY (per chiudere sidebar mobile)
   ==================================== */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 999;
}

.sidebar-overlay.active {
    display: block;
}

@media (min-width: 992px) {
    .sidebar-overlay {
        display: none !important;
    }
}

/* ====================================
   LOADING SPINNER
   ==================================== */
.spinner {
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--primary-blue);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ── Widget Data Italiano ────────────────────────────────────────────── */
.rubik-date-wrap {
    position: relative;
    display: flex;
    align-items: stretch;
    width: 100%;
}
.rubik-date-wrap input.rubik-date-text {
    flex: 1;
    padding-right: 10px !important;
    cursor: text;
    border-right: none !important;
    border-top-right-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
}
.rubik-date-wrap input.rubik-date-text.is-invalid { border-color: #dc3545; }
.rubik-date-wrap input.rubik-date-text.is-valid   { border-color: #198754; }

/* Bottone calendario attaccato a destra del campo */
.rubik-date-btn-wrap {
    position: relative;
    display: flex;
    align-items: center;
}
.rubik-date-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    width: 36px;
    background: #f1f5f9;
    border: 2px solid #dfe6e9;
    border-left: none;
    border-top-right-radius: 8px;
    border-bottom-right-radius: 8px;
    color: #475569;
    cursor: pointer;
    font-size: .95rem;
    padding: 0;
    transition: background .15s, color .15s;
    position: relative;
    z-index: 2;
}
.rubik-date-btn:hover {
    background: #1e40af;
    color: #fff;
    border-color: #1e40af;
}

/* Input nativo sovrapposto al bottone — invisibile ma cliccabile */
.rubik-date-native {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    z-index: 3;
    /* Mantiene le dimensioni reali per showPicker() su Safari */
}

/* Allineamento form-control-sm */
.rubik-date-wrap .form-control-sm.rubik-date-text {
    height: auto;
    font-size: .82rem !important;
}
/* Bottone ridotto per form-control-sm (usato nelle righe documento) */
.rubik-date-wrap .form-control-sm ~ .rubik-date-btn-wrap .rubik-date-btn,
.rubik-date-wrap.sm .rubik-date-btn {
    width: 24px;
    font-size: .7rem;
    border-radius: 0 3px 3px 0;
    border-width: 1px;
}
/* Campi data altezza fissa nelle righe (height:27px) */
.tbl-righe .rubik-date-wrap {
    height: 27px;
    overflow: hidden;  /* contiene l'input nativo */
    max-width: 150px;
}
.tbl-righe .rubik-date-btn  { height: 27px; font-size: .68rem; width: 22px; }
.tbl-righe .rubik-date-text { height: 27px !important; font-size: .75rem !important; width: 110px !important; min-width: 0 !important; }
/* Impedisce all'input nativo di allargare la cella */
.tbl-righe .rubik-date-native { max-width: 28px; left: auto; right: 0; }

/* Native date input nelle celle tabella — contenimento larghezza */
.tbl-righe td input[type="date"] {
    max-width: 100%;
    min-width: 0;
    width: 96px !important;
    font-size: .72rem !important;
    padding: 2px 3px !important;
    height: 27px !important;
}
.tbl-righe td {
    max-width: 105px;
}
.tbl-righe td.ac-cell,
.tbl-righe td.iva-ac-wrap,
.tbl-righe td.imp-cell,
.tbl-righe td.tot-cell {
    max-width: none;
}
/* Input nativo nell'input-group — override Bootstrap */
.input-group .rubik-date-wrap {
    flex: 1;
}
