/* ============================================================
   DESIGN SYSTEM — L&V Assicurazioni Admin
   Inspired by Linear, Raycast, Attio, Vercel
   ============================================================ */

:root {
  /* Colors — refined neutral palette with cool tint */
  --c-bg:          #fafbfc;
  --c-surface:     #ffffff;
  --c-surface-2:   #f6f7f9;
  --c-surface-3:   #eceef2;
  --c-border:      #e6e8ed;
  --c-border-strong: #d4d7de;

  /* Text — slate-based for richer blacks */
  --c-text:        #0f172a;
  --c-text-muted:  #475569;
  --c-text-subtle: #64748b;
  --c-text-faint:  #94a3b8;

  /* Accent — Navy blue matching L&V Assicurazioni brand */
  --c-accent:        #1e3a8a;  /* blue-900 navy */
  --c-accent-hover:  #172554;  /* blue-950 darker */
  --c-accent-strong: #1e40af;
  --c-accent-light:  #dbeafe;
  --c-accent-bg:     #eff6ff;
  --c-accent-2:      #2563eb;  /* blue-600 — lighter variant */

  /* L&V red accent (for alerts and brand highlights) */
  --c-brand-red:     #c92b2b;
  --c-brand-red-bg:  #fef2f2;

  /* Brand gradient — navy to blue for depth */
  --gradient-brand:       linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%);
  --gradient-brand-soft:  linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);

  /* Semantic */
  --c-success:     #16a34a;
  --c-success-bg:  #f0fdf4;
  --c-warning:     #d97706;
  --c-warning-bg:  #fffbeb;
  --c-danger:      #dc2626;
  --c-danger-bg:   #fef2f2;
  --c-info:        #0284c7;

  /* WhatsApp bubble */
  --c-wa-outbound: #dcf8c6;
  --c-wa-inbound:  #ffffff;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.08), 0 8px 10px -6px rgba(0, 0, 0, 0.04);

  /* Radii */
  --r-xs: 4px;
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-xl: 16px;
  --r-full: 9999px;

  /* Spacing (8px grid) */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-8: 32px;
  --s-10: 40px;
  --s-12: 48px;
  --s-16: 64px;

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', Monaco, Consolas, monospace;

  /* Transitions */
  --transition-fast: 120ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition: 180ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Layout */
  --sidebar-w: 240px;
  --sidebar-w-collapsed: 64px;
  --topbar-h: 56px;
}

/* Sidebar collapsed state */
body[data-sidebar="collapsed"] {
  --sidebar-w: 64px;
}

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

html, body {
  height: 100%;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--c-text);
  background: var(--c-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
}

#app { min-height: 100vh; }

/* Safety: SVGs never grow beyond their attributes */
svg { flex-shrink: 0; max-width: 100%; max-height: 100%; }

/* Typography */
h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  color: var(--c-text);
  line-height: 1.25;
  letter-spacing: -0.01em;
}
h1 { font-size: 24px; letter-spacing: -0.02em; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }
h4 { font-size: 14px; }

p { color: var(--c-text-muted); }

a {
  color: var(--c-accent);
  text-decoration: none;
  transition: color var(--transition-fast);
}
a:hover { color: var(--c-accent-hover); }

code, pre {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--c-surface-2);
  padding: 2px 6px;
  border-radius: var(--r-xs);
}

hr { border: none; border-top: 1px solid var(--c-border); margin: var(--s-6) 0; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  padding: 8px 14px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  user-select: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--c-accent);
  color: white;
  box-shadow: var(--shadow-xs);
}
.btn-primary:hover:not(:disabled) {
  background: var(--c-accent-hover);
  box-shadow: var(--shadow-sm);
}

.btn-secondary {
  background: var(--c-surface);
  color: var(--c-text);
  border-color: var(--c-border);
  box-shadow: var(--shadow-xs);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--c-surface-2);
  border-color: var(--c-border-strong);
}

.btn-ghost {
  background: transparent;
  color: var(--c-text-muted);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--c-surface-2);
  color: var(--c-text);
}

.btn-danger {
  background: var(--c-surface);
  color: var(--c-danger);
  border-color: var(--c-border);
}
.btn-danger:hover:not(:disabled) {
  background: var(--c-danger-bg);
  border-color: var(--c-danger);
}

.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-lg { padding: 10px 18px; font-size: 15px; }
.btn-icon { padding: 6px; }
.btn-icon svg { width: 16px; height: 16px; }
.btn-block { width: 100%; }

/* Forms */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  margin-bottom: var(--s-4);
}
.form-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--c-text);
}
.form-hint {
  font-size: 12px;
  color: var(--c-text-subtle);
}

.input, .select, .textarea {
  display: block;
  width: 100%;
  padding: 8px 12px;
  font-family: inherit;
  font-size: 14px;
  color: var(--c-text);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  transition: border var(--transition-fast), box-shadow var(--transition-fast);
  outline: none;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--c-accent);
  box-shadow: 0 0 0 3px var(--c-accent-light);
}
.input::placeholder { color: var(--c-text-faint); }
.textarea { resize: vertical; min-height: 80px; }

/* Cards */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
}
.card-header {
  padding: var(--s-4) var(--s-5);
  border-bottom: 1px solid var(--c-border);
}
.card-body {
  padding: var(--s-5);
}
.card-footer {
  padding: var(--s-3) var(--s-5);
  border-top: 1px solid var(--c-border);
  background: var(--c-surface-2);
  border-radius: 0 0 var(--r-md) var(--r-md);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
  border-radius: var(--r-full);
  background: var(--c-surface-2);
  color: var(--c-text-muted);
}
.badge-accent  { background: var(--c-accent-bg);  color: var(--c-accent); }
.badge-success { background: var(--c-success-bg); color: var(--c-success); }
.badge-warning { background: var(--c-warning-bg); color: var(--c-warning); }
.badge-danger  { background: var(--c-danger-bg);  color: var(--c-danger); }
.badge-dot::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  display: inline-block;
}

/* Tables */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.table th {
  text-align: left;
  padding: var(--s-3) var(--s-4);
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--c-text-subtle);
  background: var(--c-surface-2);
  border-bottom: 1px solid var(--c-border);
}
.table td {
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--c-border);
  color: var(--c-text);
}
.table tbody tr { transition: background var(--transition-fast); }
.table tbody tr:hover { background: var(--c-surface-2); }
.table tbody tr:last-child td { border-bottom: none; }

/* Avatars */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--c-surface-3);
  color: var(--c-text);
  font-size: 12px;
  font-weight: 600;
  border-radius: var(--r-full);
  flex-shrink: 0;
  text-transform: uppercase;
}
.avatar-sm { width: 24px; height: 24px; font-size: 10px; }
.avatar-lg { width: 40px; height: 40px; font-size: 14px; }
.avatar-xl { width: 64px; height: 64px; font-size: 20px; }

/* Auto-generate avatar colors from initials */
.avatar[data-color="1"] { background: #dbeafe; color: #1e40af; }
.avatar[data-color="2"] { background: #fef3c7; color: #92400e; }
.avatar[data-color="3"] { background: #fce7f3; color: #9d174d; }
.avatar[data-color="4"] { background: #d1fae5; color: #065f46; }
.avatar[data-color="5"] { background: #e0e7ff; color: #3730a3; }
.avatar[data-color="6"] { background: #fef2f2; color: #991b1b; }
.avatar[data-color="7"] { background: #f3e8ff; color: #6b21a8; }
.avatar[data-color="8"] { background: #ecfccb; color: #3f6212; }

/* Utility */
.text-muted { color: var(--c-text-muted); }
.text-subtle { color: var(--c-text-subtle); }
.text-xs { font-size: 12px; }
.text-sm { font-size: 13px; }
.text-lg { font-size: 16px; }
.text-xl { font-size: 18px; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-1 { gap: var(--s-1); }
.gap-2 { gap: var(--s-2); }
.gap-3 { gap: var(--s-3); }
.gap-4 { gap: var(--s-4); }
.gap-6 { gap: var(--s-6); }
.w-full { width: 100%; }
.flex-1 { flex: 1; min-width: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }

/* Scrollbar styling */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--c-surface-3);
  border-radius: var(--r-full);
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: #c4c4c7; background-clip: padding-box; border: 2px solid transparent; }

/* Toast/notifications */
.toast {
  position: fixed;
  top: var(--s-5);
  right: var(--s-5);
  padding: var(--s-3) var(--s-4);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  z-index: 1000;
  animation: toast-in 180ms ease-out;
  min-width: 240px;
  max-width: 400px;
}
.toast-success { border-left: 3px solid var(--c-success); }
.toast-error   { border-left: 3px solid var(--c-danger); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Loading */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--c-surface-3);
  border-top-color: var(--c-accent);
  border-radius: 50%;
  animation: spin 600ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--s-12) var(--s-6);
  text-align: center;
  color: var(--c-text-subtle);
}
.empty-state svg {
  width: 48px; height: 48px;
  color: var(--c-text-faint);
  margin-bottom: var(--s-4);
}
.empty-state h3 {
  color: var(--c-text);
  margin-bottom: var(--s-2);
}
