/* ================================================================
   Contabilità – Dark Admin Panel CSS
   ================================================================ */

/* ----------------------------------------------------------------
   CSS Variables
   ---------------------------------------------------------------- */
:root {
  --bg:          #0f1117;
  --bg-secondary:#12151f;
  --card-bg:     #1a1d2e;
  --card-hover:  #1e2235;
  --border:      #2a2d3e;
  --border-light:#353849;

  --accent:      #6366f1;
  --accent-dark: #4f52cc;
  --accent-light:#818cf8;

  --success:     #22c55e;
  --success-bg:  rgba(34,197,94,0.12);
  --warning:     #f59e0b;
  --warning-bg:  rgba(245,158,11,0.12);
  --danger:      #ef4444;
  --danger-bg:   rgba(239,68,68,0.12);
  --info:        #38bdf8;
  --info-bg:     rgba(56,189,248,0.12);

  --text-primary:  #e2e8f0;
  --text-secondary:#94a3b8;
  --text-muted:    #64748b;

  --sidebar-width: 260px;
  --topbar-height: 64px;

  --radius-sm:  6px;
  --radius:     10px;
  --radius-lg:  16px;

  --shadow:     0 4px 24px rgba(0,0,0,0.35);
  --shadow-sm:  0 2px 8px rgba(0,0,0,0.2);
}

/* ----------------------------------------------------------------
   Reset & Base
   ---------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
  background:  var(--bg);
  color:       var(--text-primary);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size:   0.9375rem;
  line-height: 1.6;
  min-height:  100vh;
}

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

img { max-width: 100%; display: block; }

/* ----------------------------------------------------------------
   Sidebar
   ---------------------------------------------------------------- */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-width);
  background: var(--card-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform 0.3s ease;
  overflow-y: auto;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text-primary);
}

.sidebar-logo-icon {
  font-size: 1.4rem;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  padding: 6px;
  border-radius: var(--radius-sm);
}

.sidebar-close {
  display: none;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.2rem;
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: color 0.2s;
}
.sidebar-close:hover { color: var(--text-primary); }

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.15s ease;
  text-decoration: none;
}

.nav-item:hover {
  background: var(--card-hover);
  color: var(--text-primary);
}

.nav-item.active {
  background: rgba(99,102,241,0.15);
  color: var(--accent-light);
  font-weight: 600;
}

.nav-icon { font-size: 1rem; flex-shrink: 0; }

.nav-divider {
  height: 1px;
  background: var(--border);
  margin: 10px 0;
}

.nav-section-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  padding: 4px 12px;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.sidebar-user {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.user-avatar {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.875rem;
  color: #fff;
  flex-shrink: 0;
}

.user-info {
  display: flex; flex-direction: column; min-width: 0;
}

.user-name {
  font-size: 0.875rem; font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.user-role {
  font-size: 0.75rem; color: var(--text-muted);
  text-transform: capitalize;
}

.btn-logout {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.2);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  display: flex; align-items: center;
}
.btn-logout:hover { background: rgba(239,68,68,0.2); color: var(--danger); }

/* Overlay mobile */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 99;
  backdrop-filter: blur(2px);
}
.sidebar-overlay.active { display: block; }

/* ----------------------------------------------------------------
   Main Content
   ---------------------------------------------------------------- */
.main-content {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ----------------------------------------------------------------
   Topbar
   ---------------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(15,17,23,0.95);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  height: var(--topbar-height);
  display: flex; align-items: center;
  padding: 0 24px;
  gap: 16px;
  flex-shrink: 0;
}

.topbar-menu-btn {
  display: none;
  background: none; border: none;
  color: var(--text-secondary);
  font-size: 1.4rem; cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: color 0.2s;
}
.topbar-menu-btn:hover { color: var(--text-primary); }

.topbar-title {
  font-size: 1.1rem; font-weight: 700;
  color: var(--text-primary); flex: 1;
}

.topbar-actions {
  display: flex; align-items: center; gap: 12px;
}

.topbar-user {
  font-size: 0.875rem; color: var(--text-muted);
}

/* ----------------------------------------------------------------
   Page Content
   ---------------------------------------------------------------- */
.page-content {
  padding: 28px 24px;
  flex: 1;
  max-width: 1400px;
  width: 100%;
}

/* ----------------------------------------------------------------
   Cards
   ---------------------------------------------------------------- */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.card-title {
  font-size: 1rem; font-weight: 600;
  color: var(--text-primary); margin: 0;
}

.card-body { padding: 20px; }

/* ----------------------------------------------------------------
   Stats Grid
   ---------------------------------------------------------------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex; align-items: flex-start; gap: 16px;
  transition: border-color 0.2s;
}
.stat-card:hover { border-color: var(--accent); }

.stat-icon {
  width: 48px; height: 48px;
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}

.stat-body { flex: 1; min-width: 0; }

.stat-value {
  font-size: 1.6rem; font-weight: 700;
  color: var(--text-primary); line-height: 1.2;
}

.stat-label {
  font-size: 0.8rem; color: var(--text-muted);
  margin-top: 2px;
}

/* ----------------------------------------------------------------
   Section Header
   ---------------------------------------------------------------- */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
}

.section-title {
  font-size: 1.05rem; font-weight: 600;
  color: var(--text-primary); margin: 0;
}

/* ----------------------------------------------------------------
   Fornitori Grid (Dashboard)
   ---------------------------------------------------------------- */
.fornitori-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}

.fornitore-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  transition: all 0.2s ease;
}
.fornitore-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.fornitore-card.completed { border-color: rgba(34,197,94,0.3); background: rgba(34,197,94,0.03); }

.fornitore-card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px; gap: 8px;
}

.fornitore-nome { font-weight: 600; font-size: 0.9rem; }

.fornitore-card-meta { margin-bottom: 12px; }

.fornitore-card-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ----------------------------------------------------------------
   Buttons
   ---------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius);
  font-size: 0.875rem; font-weight: 600;
  cursor: pointer; border: none;
  transition: all 0.15s ease;
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.4;
}

.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-dark); color: #fff; }

.btn-secondary {
  background: rgba(255,255,255,0.06);
  color: var(--text-secondary);
  border: 1px solid var(--border-light);
}
.btn-secondary:hover:not(:disabled) {
  background: rgba(255,255,255,0.1);
  color: var(--text-primary);
  border-color: var(--border-light);
}

.btn-danger {
  background: rgba(239,68,68,0.12);
  color: var(--danger);
  border: 1px solid rgba(239,68,68,0.25);
}
.btn-danger:hover:not(:disabled) { background: rgba(239,68,68,0.22); }

.btn-success {
  background: rgba(34,197,94,0.12);
  color: var(--success);
  border: 1px solid rgba(34,197,94,0.25);
}
.btn-success:hover:not(:disabled) { background: rgba(34,197,94,0.22); }

.btn-sm { padding: 5px 12px; font-size: 0.8rem; }
.btn-lg { padding: 12px 24px; font-size: 1rem; }

/* ----------------------------------------------------------------
   Badges
   ---------------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.72rem; font-weight: 600;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.badge-success  { background: var(--success-bg);  color: var(--success); }
.badge-warning  { background: var(--warning-bg);  color: var(--warning); }
.badge-danger   { background: var(--danger-bg);   color: var(--danger); }
.badge-info     { background: var(--info-bg);     color: var(--info); }
.badge-secondary{ background: rgba(255,255,255,0.07); color: var(--text-secondary); border: 1px solid var(--border-light); }
.badge-accent   { background: rgba(99,102,241,0.15); color: var(--accent-light); }

/* Categorie fornitori */
.badge-fatture     { background: rgba(99,102,241,0.15); color: var(--accent-light); }
.badge-transazioni { background: rgba(34,197,94,0.15);  color: var(--success); }
.badge-annuale     { background: rgba(245,158,11,0.15); color: var(--warning); }

/* ----------------------------------------------------------------
   Table
   ---------------------------------------------------------------- */
.table-responsive { overflow-x: auto; }

.table {
  width: 100%; border-collapse: collapse;
  font-size: 0.875rem;
}

.table th {
  background: rgba(255,255,255,0.03);
  color: var(--text-muted);
  font-size: 0.75rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  text-align: left; white-space: nowrap;
}

.table td {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  color: var(--text-primary);
  vertical-align: middle;
}

.table tbody tr:hover td { background: rgba(255,255,255,0.02); }
.table tbody tr:last-child td { border-bottom: none; }

.table tfoot td {
  padding: 12px 16px;
  border-top: 2px solid var(--border);
  font-weight: 600;
}

.table-footer-row td { background: rgba(99,102,241,0.05); }

.row-completed td { opacity: 0.7; }
.row-completed .fornitore-nome-table { text-decoration: line-through; }

/* ----------------------------------------------------------------
   Forms
   ---------------------------------------------------------------- */
.form-group {
  display: flex; flex-direction: column;
  gap: 6px;
  flex: 1;
}

.form-label {
  font-size: 0.8rem; font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.03em;
}

.form-control {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 9px 12px;
  color: var(--text-primary);
  font-size: 0.9rem;
  width: 100%;
  transition: all 0.15s ease;
  appearance: none;
  -webkit-appearance: none;
}

.form-control:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
  background: rgba(255,255,255,0.06);
}

.form-control::placeholder { color: var(--text-muted); }

.form-control-sm { padding: 6px 10px; font-size: 0.82rem; }

select.form-control {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
  cursor: pointer;
}

select.form-control option {
  background: var(--card-bg);
  color: var(--text-primary);
}

textarea.form-control { resize: vertical; min-height: 80px; }

.form-row {
  display: flex; gap: 16px; flex-wrap: wrap;
}
.form-row .form-group { min-width: 140px; }

/* Checkbox */
input[type="checkbox"] {
  width: 17px; height: 17px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ----------------------------------------------------------------
   Alerts
   ---------------------------------------------------------------- */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  border: 1px solid transparent;
}
.alert-success { background: var(--success-bg); color: var(--success); border-color: rgba(34,197,94,0.25); }
.alert-danger  { background: var(--danger-bg);  color: var(--danger);  border-color: rgba(239,68,68,0.25); }
.alert-warning { background: var(--warning-bg); color: var(--warning); border-color: rgba(245,158,11,0.25); }
.alert-info    { background: var(--info-bg);    color: var(--info);    border-color: rgba(56,189,248,0.25); }

/* ----------------------------------------------------------------
   Progress Bar
   ---------------------------------------------------------------- */
.progress-bar-wrap {
  width: 100%; height: 8px;
  background: rgba(255,255,255,0.07);
  border-radius: 99px; overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-light));
  border-radius: 99px;
  transition: width 0.6s ease;
}

.progress-bar-success {
  background: linear-gradient(90deg, var(--success), #4ade80);
}

/* ----------------------------------------------------------------
   Period Nav
   ---------------------------------------------------------------- */
.period-nav {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 24px; flex-wrap: wrap;
}

.period-current { flex: 1; }

.period-form {
  display: flex; gap: 10px; flex-wrap: wrap;
}

.period-form .form-control {
  width: auto; min-width: 120px;
}

/* ----------------------------------------------------------------
   Filter Form
   ---------------------------------------------------------------- */
.filter-form .filter-row {
  display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end;
}

.filter-row .form-group { flex: 1; min-width: 120px; max-width: 200px; }

/* ----------------------------------------------------------------
   Modal
   ---------------------------------------------------------------- */
.modal-overlay {
  display: none;
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  align-items: center; justify-content: center;
  padding: 20px;
}
.modal-overlay.active { display: flex; }

.modal {
  background: var(--card-bg);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  width: 100%; max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
  animation: modalIn 0.2s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(-8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-title { font-size: 1rem; font-weight: 700; margin: 0; }

.modal-close {
  background: none; border: none;
  color: var(--text-muted); cursor: pointer;
  font-size: 1.1rem; padding: 4px;
  border-radius: var(--radius-sm);
  transition: color 0.15s;
}
.modal-close:hover { color: var(--text-primary); }

.modal-body { padding: 20px; }

.modal-footer {
  display: flex; gap: 10px; justify-content: flex-end;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

/* ----------------------------------------------------------------
   Dropzone
   ---------------------------------------------------------------- */
.dropzone {
  border: 2px dashed var(--border-light);
  border-radius: var(--radius-lg);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.dropzone:hover,
.dropzone.drag-over {
  border-color: var(--accent);
  background: rgba(99,102,241,0.06);
}

.dropzone-icon { font-size: 2.5rem; margin-bottom: 12px; }

.dropzone-text {
  color: var(--text-secondary); font-size: 0.9rem;
  margin-bottom: 4px;
}

.dropzone-link { color: var(--accent); font-weight: 600; }

.dropzone-hint { color: var(--text-muted); font-size: 0.8rem; }

/* ----------------------------------------------------------------
   Spinner
   ---------------------------------------------------------------- */
.spinner {
  width: 40px; height: 40px;
  border: 3px solid rgba(99,102,241,0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ----------------------------------------------------------------
   Toast Notifications
   ---------------------------------------------------------------- */
.toast-container {
  position: fixed; bottom: 24px; right: 24px;
  z-index: 9999;
  display: flex; flex-direction: column; gap: 10px;
  pointer-events: none;
}

.toast {
  background: var(--card-bg);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 12px 18px;
  font-size: 0.875rem; font-weight: 500;
  color: var(--text-primary);
  box-shadow: var(--shadow);
  pointer-events: auto;
  display: flex; align-items: center; gap: 10px;
  min-width: 280px; max-width: 400px;
  animation: toastIn 0.3s ease;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

.toast.hiding { animation: toastOut 0.3s ease forwards; }

@keyframes toastOut {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(20px); }
}

.toast-success { border-left: 3px solid var(--success); }
.toast-error   { border-left: 3px solid var(--danger); }
.toast-warning { border-left: 3px solid var(--warning); }
.toast-info    { border-left: 3px solid var(--info); }

.toast-icon { font-size: 1.1rem; flex-shrink: 0; }
.toast-msg  { flex: 1; }

/* ----------------------------------------------------------------
   Stato Select (inline in tabella)
   ---------------------------------------------------------------- */
.stato-select {
  padding: 4px 28px 4px 8px !important;
  font-size: 0.78rem !important;
  border-radius: 20px !important;
}

/* ----------------------------------------------------------------
   Checklist checkbox column
   ---------------------------------------------------------------- */
.check-fornitore { transform: scale(1.2); cursor: pointer; }

/* ----------------------------------------------------------------
   Text utilities
   ---------------------------------------------------------------- */
.text-muted   { color: var(--text-muted); }
.text-accent  { color: var(--accent); }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-warning { color: var(--warning); }

.fornitore-nome-table { font-weight: 600; }

/* ----------------------------------------------------------------
   Responsive – Mobile
   ---------------------------------------------------------------- */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow);
  }
  .sidebar-close { display: flex; }

  .main-content { margin-left: 0; }

  .topbar-menu-btn { display: flex; }

  .page-content { padding: 16px; }

  .stats-grid { grid-template-columns: 1fr 1fr; }

  .fornitori-grid { grid-template-columns: 1fr; }

  .form-row { flex-direction: column; }

  .filter-row { flex-direction: column; }
  .filter-row .form-group { max-width: 100%; }

  .period-nav { flex-direction: column; align-items: stretch; }
  .period-nav .btn { text-align: center; }
  .period-current { width: 100%; }
  .period-form { flex-direction: row; }

  .modal { max-width: 100%; }

  .topbar-user { display: none; }

  .table th, .table td { padding: 10px 12px; font-size: 0.8rem; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .stat-value { font-size: 1.3rem; }
}
