/* =============================================
   Mars Group License Dashboard — Main CSS
   Design: Refined minimal, dark sidebar
   ============================================= */

:root {
  --sidebar-w: 250px;
  --brand-dark: #0f1117;
  --brand-accent: #3b7ef8;
  --brand-accent-light: #e8f0fe;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --surface-3: #f0f2f5;
  --border: #e5e7eb;
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.08), 0 2px 4px -1px rgba(0,0,0,.06);
  --font: 'DM Sans', system-ui, sans-serif;
  --font-mono: 'DM Mono', monospace;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; }

body {
  font-family: var(--font);
  background: var(--surface-2);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── App Layout ─────────────────────────── */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--brand-dark);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 1.5rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,.07);
}

.brand-icon {
  width: 36px; height: 36px;
  background: var(--brand-accent);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-size: 1rem;
  flex-shrink: 0;
}

.brand-name {
  display: block;
  color: #fff;
  font-weight: 600;
  font-size: .95rem;
  letter-spacing: -.01em;
}

.brand-sub {
  display: block;
  color: rgba(255,255,255,.4);
  font-size: .7rem;
  font-weight: 400;
  letter-spacing: .02em;
  text-transform: uppercase;
}

.sidebar-nav {
  flex: 1;
  padding: 1.25rem .75rem;
}

.nav-section-label {
  color: rgba(255,255,255,.3);
  font-size: .65rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 0 .5rem;
  margin-bottom: .4rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .6rem .75rem;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,.6);
  text-decoration: none;
  font-size: .875rem;
  font-weight: 400;
  transition: all .15s ease;
  margin-bottom: .15rem;
}

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

.nav-item:hover {
  background: rgba(255,255,255,.06);
  color: rgba(255,255,255,.9);
}

.nav-item.active {
  background: var(--brand-accent);
  color: #fff;
  font-weight: 500;
}

.sidebar-footer {
  padding: 1rem .75rem;
  border-top: 1px solid rgba(255,255,255,.07);
  display: flex;
  align-items: center;
  gap: .5rem;
}

.user-info {
  display: flex;
  align-items: center;
  gap: .6rem;
  flex: 1;
  min-width: 0;
}

.user-avatar {
  width: 30px; height: 30px;
  background: var(--brand-accent);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-size: .75rem;
  font-weight: 600;
  flex-shrink: 0;
}

.user-name {
  display: block;
  color: rgba(255,255,255,.85);
  font-size: .8rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  display: block;
  color: rgba(255,255,255,.35);
  font-size: .68rem;
}

.logout-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,.4);
  cursor: pointer;
  padding: .35rem;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  transition: color .15s;
  flex-shrink: 0;
}
.logout-btn:hover { color: var(--danger); }

/* ── Main Content ────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
  padding: 2rem;
}

/* ── Page Header ────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1.75rem;
  gap: 1rem;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -.02em;
  color: var(--text-primary);
  line-height: 1.3;
}

.page-subtitle {
  font-size: .875rem;
  color: var(--text-secondary);
  margin-top: .2rem;
}

/* ── Cards ──────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-header {
  padding: 1.1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.card-body { padding: 1.25rem; }

/* ── Stat Cards ────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 1rem;
}

.stat-icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
}

.stat-icon.blue  { background: #eff6ff; color: #3b82f6; }
.stat-icon.green { background: #f0fdf4; color: #10b981; }
.stat-icon.amber { background: #fffbeb; color: #f59e0b; }
.stat-icon.red   { background: #fef2f2; color: #ef4444; }

.stat-value {
  font-size: 1.6rem;
  font-weight: 600;
  letter-spacing: -.03em;
  line-height: 1;
  color: var(--text-primary);
}

.stat-label {
  font-size: .78rem;
  color: var(--text-secondary);
  margin-top: .2rem;
}

/* ── Tables ─────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
}

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

thead th {
  background: var(--surface-2);
  padding: .6rem 1rem;
  text-align: left;
  font-size: .72rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .05em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: .8rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }

/* ── Badges ─────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .2rem .6rem;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 500;
  white-space: nowrap;
}

.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger  { background: #fee2e2; color: #991b1b; }
.badge-info    { background: #dbeafe; color: #1e40af; }
.badge-gray    { background: #f3f4f6; color: #374151; }

/* ── Buttons ─────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem 1rem;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: all .15s ease;
  white-space: nowrap;
}

.btn-primary {
  background: var(--brand-accent);
  color: #fff;
  border-color: var(--brand-accent);
}
.btn-primary:hover { background: #2563eb; }

.btn-secondary {
  background: var(--surface);
  color: var(--text-primary);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--surface-2); }

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover { background: #dc2626; }

.btn-sm {
  padding: .3rem .65rem;
  font-size: .8rem;
}

.btn-icon {
  padding: .35rem;
  width: 30px; height: 30px;
  justify-content: center;
}

/* ── Forms ───────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

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

.form-full { grid-column: 1 / -1; }

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

.form-label {
  font-size: .8rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-label.required::after {
  content: ' *';
  color: var(--danger);
}

.form-control {
  padding: .55rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: .875rem;
  color: var(--text-primary);
  background: var(--surface);
  transition: border-color .15s;
  width: 100%;
}

.form-control:focus {
  outline: none;
  border-color: var(--brand-accent);
  box-shadow: 0 0 0 3px rgba(59,126,248,.1);
}

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

.form-section-title {
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-primary);
  padding-bottom: .6rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: .5rem;
}

.form-section-title i { color: var(--brand-accent); }

/* ── Alert Log section ──────────────────── */
.log-section {
  background: #f8faff;
  border: 1px solid #dbeafe;
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-top: 1.5rem;
}

/* ── Log Timeline ───────────────────────── */
.log-timeline {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.log-entry {
  display: flex;
  gap: 1rem;
  padding: .75rem 0;
  border-bottom: 1px solid var(--border);
  align-items: flex-start;
}

.log-entry:last-child { border-bottom: none; }

.log-dot {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem;
  flex-shrink: 0;
  margin-top: .1rem;
}

.log-dot.attivazione  { background: #d1fae5; color: #065f46; }
.log-dot.modifica     { background: #dbeafe; color: #1e40af; }
.log-dot.sospensione  { background: #fef3c7; color: #92400e; }
.log-dot.cancellazione{ background: #fee2e2; color: #991b1b; }
.log-dot.rinnovo      { background: #ede9fe; color: #5b21b6; }

.log-content { flex: 1; min-width: 0; }

.log-title {
  font-size: .85rem;
  font-weight: 500;
  color: var(--text-primary);
}

.log-meta {
  font-size: .75rem;
  color: var(--text-secondary);
  margin-top: .15rem;
}

.log-note {
  font-size: .78rem;
  color: var(--text-secondary);
  margin-top: .2rem;
  font-style: italic;
}

.log-time {
  font-size: .72rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Scadenza badges ────────────────────── */
.days-badge {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  font-family: var(--font-mono);
  font-size: .75rem;
  font-weight: 500;
  padding: .15rem .5rem;
  border-radius: 4px;
}

.days-urgent   { background: #fee2e2; color: #991b1b; }
.days-warning  { background: #fef3c7; color: #92400e; }
.days-ok       { background: #f0fdf4; color: #166534; }
.days-none     { background: var(--surface-3); color: var(--text-muted); }

/* ── Alerts / Toast ─────────────────────── */
.alert-toast {
  position: fixed;
  top: 1rem; right: 1rem;
  padding: .75rem 1.1rem;
  border-radius: var(--radius);
  font-size: .875rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: .5rem;
  box-shadow: var(--shadow-md);
  z-index: 9999;
  animation: slideIn .2s ease;
  max-width: 380px;
}

.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }

@keyframes slideIn {
  from { transform: translateX(110%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ── Misc ───────────────────────────────── */
.text-mono { font-family: var(--font-mono); }
.text-sm   { font-size: .8rem; }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }

.categoria-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: .35rem;
  flex-shrink: 0;
}

.flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: .5rem; }
.gap-3 { gap: .75rem; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mt-3 { margin-top: 1.5rem; }
.mt-4 { margin-top: 2rem; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1.5rem; }

/* ── Portale cliente ─────────────────────── */
.portale-header {
  background: linear-gradient(135deg, var(--brand-dark) 0%, #1a2234 100%);
  color: #fff;
  padding: 1.5rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.portale-brand {
  display: flex;
  align-items: center;
  gap: .75rem;
}

.portale-body {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem;
}

/* ── Login page ─────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,.08);
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
}

.login-logo {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: 2rem;
}

.login-logo .brand-icon {
  width: 42px; height: 42px;
  font-size: 1.1rem;
}

/* ── Responsive ─────────────────────────── */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  .main-content { margin-left: 0; padding: 1rem; }
  .sidebar { display: none; }
  .form-grid, .form-grid-3 { grid-template-columns: 1fr; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
