/* ============================================================================
   Gestionale Fibra — design system base styles
   Recurring patterns not (cleanly) covered by Tailwind utilities.
   Theme: dark by default (:root). Light theme: add class `light` to <html>.
   ============================================================================ */

/* ---- Fonts ------------------------------------------------------------- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

/* ---- Theme tokens ------------------------------------------------------ */
:root {
  --bg:            #0B0F19;
  --surface:       #121826;
  --surface-2:     #1A2030;
  --border:        #232B3B;
  --field:         #0E1422;
  --text:          #E6EAF2;
  --text-muted:    #94A0B8;
  --text-faint:    #5E6B85;
  --ring:          #3B82F6;
  color-scheme: dark;
}
html.light {
  --bg:            #F6F8FB;
  --surface:       #FFFFFF;
  --surface-2:     #F1F4F9;
  --border:        #E3E8F0;
  --field:         #FFFFFF;
  --text:          #0F172A;
  --text-muted:    #5A6B85;
  --text-faint:    #94A3B8;
  --ring:          #3B82F6;
  color-scheme: light;
}

html { scroll-behavior: smooth; }
body { background: var(--bg); color: var(--text); }

/* Scoped themes — force a subtree to a specific theme (used in components.html) */
.theme-dark {
  --bg:#0B0F19; --surface:#121826; --surface-2:#1A2030; --border:#232B3B; --field:#0E1422;
  --text:#E6EAF2; --text-muted:#94A0B8; --text-faint:#5E6B85; --ring:#3B82F6;
  color-scheme: dark; background: var(--bg); color: var(--text);
}
.theme-light {
  --bg:#F6F8FB; --surface:#FFFFFF; --surface-2:#F1F4F9; --border:#E3E8F0; --field:#FFFFFF;
  --text:#0F172A; --text-muted:#5A6B85; --text-faint:#94A3B8; --ring:#3B82F6;
  color-scheme: light; background: var(--bg); color: var(--text);
}
.theme-light .badge-blue   { color: #2563EB; }
.theme-light .badge-green  { color: #059669; }
.theme-light .badge-red    { color: #DC2626; }
.theme-light .badge-orange { color: #B45309; }
.theme-light .badge-purple { color: #9333EA; }
.theme-light .link         { color: #2563EB; }

/* Alpine cloak */
[x-cloak] { display: none !important; }

/* ---- Scrollbars -------------------------------------------------------- */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--text-faint); background-clip: content-box; }
.no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }

/* ============================================================================
   Buttons
   ============================================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  height: 2.25rem; padding: 0 .9rem; border-radius: 8px;
  font-size: .875rem; font-weight: 600; line-height: 1; white-space: nowrap;
  border: 1px solid transparent; cursor: pointer; user-select: none;
  transition: background-color .15s, border-color .15s, color .15s, opacity .15s;
}
.btn:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.btn .lucide { width: 16px; height: 16px; }
.btn-sm { height: 2rem; padding: 0 .7rem; font-size: .8125rem; }
.btn-lg { height: 2.75rem; padding: 0 1.25rem; font-size: .95rem; }
.btn-block { width: 100%; }

.btn-primary { background: #3B82F6; color: #fff; }
.btn-primary:hover { background: #2563EB; }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: #EF4444; color: #fff; }
.btn-danger:hover { background: #DC2626; }

/* Square icon button */
.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.25rem; height: 2.25rem; border-radius: 8px;
  color: var(--text-muted); cursor: pointer; border: 1px solid transparent;
  transition: background-color .15s, color .15s;
}
.btn-icon:hover { background: var(--surface-2); color: var(--text); }
.btn-icon .lucide { width: 18px; height: 18px; }
.btn-icon-sm { width: 1.9rem; height: 1.9rem; }
.btn-icon-sm .lucide { width: 16px; height: 16px; }

/* ============================================================================
   Form fields
   ============================================================================ */
.field {
  width: 100%; height: 2.25rem; padding: 0 .75rem; border-radius: 8px;
  background: var(--field); border: 1px solid var(--border);
  color: var(--text); font-size: .875rem;
  transition: border-color .15s, box-shadow .15s;
}
textarea.field { height: auto; padding: .6rem .75rem; line-height: 1.5; resize: vertical; }
.field::placeholder { color: var(--text-faint); }
.field:focus { outline: none; border-color: var(--ring); box-shadow: 0 0 0 3px rgba(59,130,246,.18); }
select.field { -webkit-appearance: none; appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2394A0B8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .65rem center; padding-right: 2rem; }
.label { display: block; font-size: .8125rem; font-weight: 500; color: var(--text-muted); margin-bottom: .35rem; }

/* Input with leading icon */
.field-wrap { position: relative; }
.field-wrap .lucide { position: absolute; left: .7rem; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-faint); pointer-events: none; }
.field-wrap .field { padding-left: 2.1rem; }

/* ============================================================================
   Cards
   ============================================================================ */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.card-pad { padding: 1.25rem; }

/* ============================================================================
   Badges
   ============================================================================ */
.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .15rem .55rem;
  border-radius: 6px; font-size: .75rem; font-weight: 600; line-height: 1.4; white-space: nowrap; }
.badge .lucide { width: 12px; height: 12px; }
.badge-blue   { background: rgba(59,130,246,.15);  color: #60A5FA; }
.badge-green  { background: rgba(16,185,129,.15);  color: #34D399; }
.badge-red    { background: rgba(239,68,68,.15);   color: #F87171; }
.badge-orange { background: rgba(245,158,11,.16);  color: #FBBF24; }
.badge-purple { background: rgba(168,85,247,.16);  color: #C084FC; }
.badge-gray   { background: var(--surface-2);      color: var(--text-muted); border: 1px solid var(--border); }
html.light .badge-blue   { color: #2563EB; }
html.light .badge-green  { color: #059669; }
html.light .badge-red    { color: #DC2626; }
html.light .badge-orange { color: #B45309; }
html.light .badge-purple { color: #9333EA; }

/* Status dot */
.dot { width: 7px; height: 7px; border-radius: 999px; display: inline-block; }

/* ============================================================================
   Tables
   ============================================================================ */
.ds-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.ds-table thead th {
  text-align: left; font-size: .6875rem; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; color: var(--text-faint);
  padding: .75rem 1rem; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.ds-table tbody td { padding: .85rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.ds-table tbody tr:last-child td { border-bottom: none; }
.ds-table tbody tr { transition: background-color .12s; }
.ds-table tbody tr:hover { background: var(--surface-2); }
.ds-table .num { font-variant-numeric: tabular-nums; }

/* ============================================================================
   Tabs
   ============================================================================ */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab {
  position: relative; padding: .7rem .9rem; font-size: .875rem; font-weight: 500;
  color: var(--text-muted); white-space: nowrap; cursor: pointer; background: none; border: none;
  border-bottom: 2px solid transparent; margin-bottom: -1px; transition: color .15s;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"], .tab.is-active { color: var(--text); border-bottom-color: #3B82F6; }

/* Pill tabs (segmented) */
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; }
.seg-item { padding: .35rem .85rem; font-size: .8125rem; font-weight: 600; border-radius: 6px; color: var(--text-muted); cursor: pointer; border: none; background: none; transition: all .15s; }
.seg-item.is-active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.2); }

/* ============================================================================
   Toggle switch
   ============================================================================ */
.switch { position: relative; width: 40px; height: 22px; border-radius: 999px; background: var(--border); cursor: pointer; transition: background .15s; flex: none; border: none; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 999px; background: #fff; transition: transform .18s; }
.switch[aria-checked="true"] { background: #3B82F6; }
.switch[aria-checked="true"]::after { transform: translateX(18px); }

/* ============================================================================
   Misc
   ============================================================================ */
.kbd { font-family: ui-monospace, monospace; font-size: .75rem; padding: .1rem .4rem; border-radius: 5px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-muted); }
.divider { height: 1px; background: var(--border); }
.link { color: #60A5FA; font-weight: 500; }
html.light .link { color: #2563EB; }
.link:hover { text-decoration: underline; }

/* OTP inputs */
.otp { width: 3rem; height: 3.5rem; text-align: center; font-size: 1.5rem; font-weight: 700; }
@media (max-width: 400px) { .otp { width: 2.6rem; height: 3.1rem; font-size: 1.25rem; } }

/* Drag & drop zone */
.dropzone { border: 1.5px dashed var(--border); border-radius: 12px; transition: border-color .15s, background .15s; }
.dropzone:hover { border-color: #3B82F6; background: rgba(59,130,246,.04); }

/* Animations */
@keyframes fadeup { from { opacity: 0; transform: translateY(6px);} to { opacity:1; transform:none;} }
.fadeup { animation: fadeup .25s ease both; }
