/* ==========================================================================
   CRM Studio - Versione Statica Standalone (CSS Professionale)
   ========================================================================== */

:root {
  --font-sans: 'Plus Jakarta Sans', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, Menlo, Monaco, Consolas, monospace;

  /* Colori Light Mode */
  --bg-app: #f8fafc;
  --bg-card: #ffffff;
  --bg-subtle: #f1f5f9;
  --bg-hover: #f8fafc;
  --border: #e2e8f0;
  --border-subtle: #edf2f7;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;

  /* Brand Accents */
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;
  --primary-border: #c7d2fe;

  --success: #16a34a;
  --success-light: #f0fdf4;
  --success-border: #bbf7d0;

  --warning: #d97706;
  --warning-light: #fffbeb;
  --warning-border: #fde68a;

  --danger: #e11d48;
  --danger-light: #fff1f2;
  --danger-border: #fecdd3;

  --info: #0284c7;
  --info-light: #f0f9ff;
  --info-border: #bae6fd;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;
}

/* Dark Mode */
.dark {
  --bg-app: #030712;
  --bg-card: #0f172a;
  --bg-subtle: #1e293b;
  --bg-hover: #1e293b;
  --border: #1e293b;
  --border-subtle: #1e293b;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-subtle: #64748b;

  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: rgba(99, 102, 241, 0.12);
  --primary-border: rgba(99, 102, 241, 0.25);

  --success: #22c55e;
  --success-light: rgba(34, 197, 94, 0.12);
  --success-border: rgba(34, 197, 94, 0.25);

  --warning: #f59e0b;
  --warning-light: rgba(245, 158, 11, 0.12);
  --warning-border: rgba(245, 158, 11, 0.25);

  --danger: #f43f5e;
  --danger-light: rgba(244, 63, 94, 0.12);
  --danger-border: rgba(244, 63, 94, 0.25);

  --info: #38bdf8;
  --info-light: rgba(56, 189, 248, 0.12);
  --info-border: rgba(56, 189, 248, 0.25);

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  overflow: hidden;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

a {
  color: inherit;
  text-decoration: none;
}

.tabular-nums {
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
}

/* App Layout */
.app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 256px;
  background-color: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  flex-shrink: 0;
  z-index: 40;
  transition: transform 0.2s ease-in-out;
}

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

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 32px;
  height: 32px;
  background-color: var(--primary);
  color: #fff;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  box-shadow: 0 2px 6px rgba(79, 70, 229, 0.3);
}

.brand-title {
  font-weight: 700;
  font-size: 15px;
  line-height: 1.1;
  color: var(--text-main);
}

.brand-subtitle {
  font-size: 11px;
  color: var(--text-subtle);
  font-weight: 500;
}

.sidebar-cta {
  padding: 12px 14px;
}

.btn-sidebar-create {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  background-color: var(--primary);
  color: #fff;
  border-radius: var(--radius-md);
  font-size: 12px;
  font-weight: 600;
  transition: background-color 0.15s ease;
  box-shadow: var(--shadow-sm);
}

.btn-sidebar-create:hover {
  background-color: var(--primary-hover);
}

.nav-list {
  list-style: none;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item button {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  transition: all 0.15s ease;
}

.nav-item button:hover {
  background-color: var(--bg-subtle);
  color: var(--text-main);
}

.nav-item.active button {
  background-color: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

.nav-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.nav-badge {
  font-size: 11px;
  font-family: var(--font-mono);
  padding: 2px 7px;
  border-radius: var(--radius-full);
  background-color: var(--bg-subtle);
  color: var(--text-muted);
}

.nav-item.active .nav-badge {
  background-color: var(--primary);
  color: #fff;
}

.sidebar-footer {
  padding: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.theme-switch-tabs {
  display: flex;
  background-color: var(--bg-subtle);
  padding: 3px;
  border-radius: var(--radius-md);
}

.theme-switch-tabs button {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: all 0.15s ease;
}

.theme-switch-tabs button.active {
  background-color: var(--bg-card);
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
}

.sidebar-storage-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-subtle);
  padding: 0 4px;
}

/* Main Content & Header */
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100%;
}

.top-header {
  height: 64px;
  padding: 0 24px;
  background-color: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 30;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.btn-mobile-menu {
  display: none;
  padding: 8px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
}

.header-breadcrumbs {
  font-size: 11px;
  color: var(--text-subtle);
  display: flex;
  gap: 6px;
}

.header-page-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-search-btn {
  flex: 1;
  max-width: 400px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background-color: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 12px;
  color: var(--text-subtle);
  transition: border-color 0.15s ease;
}

.header-search-btn:hover {
  border-color: var(--primary);
}

.header-search-kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  background-color: var(--bg-card);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-theme-quick {
  padding: 8px;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  transition: all 0.15s ease;
}

.btn-theme-quick:hover {
  background-color: var(--bg-subtle);
  color: var(--text-main);
}

.btn-new-record {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background-color: var(--primary);
  color: #fff;
  border-radius: var(--radius-md);
  font-size: 12px;
  font-weight: 600;
  transition: background-color 0.15s ease;
}

.btn-new-record:hover {
  background-color: var(--primary-hover);
}

/* Dropdown Menu */
.dropdown-container {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 6px;
  width: 190px;
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 50;
  display: none;
}

.dropdown-menu.show {
  display: block;
}

.dropdown-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-main);
  border-radius: var(--radius-sm);
  text-align: left;
  transition: background-color 0.15s ease;
}

.dropdown-item:hover {
  background-color: var(--bg-subtle);
}

/* Scrollable Viewport */
.content-viewport {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.container-narrow {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Cards & Surfaces */
.card {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

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

.card-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
}

.card-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.kpi-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  cursor: pointer;
  transition: all 0.15s ease;
  box-shadow: var(--shadow-sm);
}

.kpi-card:hover {
  border-color: var(--primary);
  transform: translateY(-1px);
}

.kpi-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.kpi-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

.kpi-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.kpi-value {
  font-size: 24px;
  font-weight: 800;
  color: var(--text-main);
  margin-top: 10px;
  font-family: var(--font-mono);
}

.kpi-footer {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  display: flex;
  gap: 8px;
}

/* Two Column Split */
.two-col-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 20px;
}

/* Data Tables */
.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  text-align: left;
}

.data-table th {
  padding: 12px 16px;
  background-color: var(--bg-subtle);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-main);
  vertical-align: middle;
}

.data-table tr:hover td {
  background-color: var(--bg-hover);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-success {
  background-color: var(--success-light);
  color: var(--success);
  border: 1px solid var(--success-border);
}

.badge-warning {
  background-color: var(--warning-light);
  color: var(--warning);
  border: 1px solid var(--warning-border);
}

.badge-danger {
  background-color: var(--danger-light);
  color: var(--danger);
  border: 1px solid var(--danger-border);
}

.badge-neutral {
  background-color: var(--bg-subtle);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.badge-info {
  background-color: var(--info-light);
  color: var(--info);
  border: 1px solid var(--info-border);
}

/* Filters & Search Toolbar */
.toolbar-card {
  padding: 14px 18px;
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--shadow-sm);
}

.search-input-wrapper {
  position: relative;
  flex: 1;
  min-width: 240px;
}

.search-input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background-color: var(--bg-subtle);
  color: var(--text-main);
  font-size: 12px;
  outline: none;
}

.search-input:focus {
  border-color: var(--primary);
  background-color: var(--bg-card);
}

.search-icon-left {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-subtle);
  pointer-events: none;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.select-filter {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background-color: var(--bg-subtle);
  color: var(--text-main);
  font-size: 12px;
  outline: none;
}

.segmented-control {
  display: flex;
  background-color: var(--bg-subtle);
  padding: 3px;
  border-radius: var(--radius-md);
}

.segmented-control button {
  padding: 5px 12px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
}

.segmented-control button.active {
  background-color: var(--bg-card);
  color: var(--text-main);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

/* Kanban Board */
.kanban-board {
  display: grid;
  grid-template-columns: repeat(6, minmax(260px, 1fr));
  gap: 14px;
  overflow-x: auto;
  padding-bottom: 16px;
  align-items: start;
}

.kanban-col {
  background-color: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 480px;
}

.kanban-col.drag-over {
  border-color: var(--primary);
  background-color: var(--primary-light);
}

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

.kanban-col-title {
  font-size: 12px;
  font-weight: 700;
}

.kanban-col-total {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  font-weight: 600;
}

.kanban-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  cursor: grab;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: all 0.15s ease;
}

.kanban-card:hover {
  border-color: var(--primary-border);
  box-shadow: var(--shadow-md);
}

.kanban-card:active {
  cursor: grabbing;
}

.kanban-card-title {
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
}

.kanban-card-val {
  font-size: 13px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-main);
}

.kanban-card-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 6px;
  border-top: 1px solid var(--border-subtle);
  font-size: 11px;
  color: var(--text-subtle);
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(3, 7, 18, 0.5);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-box {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  transform: scale(0.96);
  transition: transform 0.2s ease;
}

.modal-overlay.open .modal-box {
  transform: scale(1);
}

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

.modal-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
}

.modal-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

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

.form-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}

.form-label span.req {
  color: var(--danger);
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background-color: var(--bg-subtle);
  color: var(--text-main);
  font-size: 13px;
  outline: none;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--primary);
  background-color: var(--bg-card);
}

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

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* Slide-over Drawer */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(3, 7, 18, 0.4);
  backdrop-filter: blur(2px);
  z-index: 90;
  display: flex;
  justify-content: flex-end;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.drawer-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.drawer-panel {
  width: 100%;
  max-width: 580px;
  height: 100%;
  background-color: var(--bg-card);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.drawer-overlay.open .drawer-panel {
  transform: translateX(0);
}

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

.drawer-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Command Palette */
.palette-modal {
  max-width: 580px;
}

.palette-input-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.palette-input {
  width: 100%;
  border: none;
  background: transparent;
  outline: none;
  font-size: 14px;
  color: var(--text-main);
}

.palette-list {
  max-height: 380px;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.palette-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  text-align: left;
  transition: background-color 0.15s ease;
}

.palette-item:hover {
  background-color: var(--bg-subtle);
}

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

.toast {
  pointer-events: auto;
  min-width: 280px;
  max-width: 380px;
  padding: 12px 16px;
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 12px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideUp 0.2s ease;
}

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

/* Responsive */
@media (max-width: 1024px) {
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .btn-mobile-menu {
    display: block;
  }
}

@media (max-width: 640px) {
  .content-viewport {
    padding: 16px;
  }

  .form-row {
    grid-template-columns: 1fr;
  }
}
