/* =============================================
   OPERATION — Design System CSS
   ============================================= */

:root {
  /* Sidebar */
  --sidebar-bg-from: #0f0c29;
  --sidebar-bg-to: #302b63;
  --sidebar-text: #e2e8f0;
  --sidebar-active-bg: rgba(255, 255, 255, 0.15);
  --sidebar-hover-bg: rgba(255, 255, 255, 0.08);

  /* Content */
  --content-bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;

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

  /* Semantici */
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #06b6d4;

  /* Task validity */
  --strategic: #8b5cf6;
  --operational: #10b981;
  --future-idea: #f59e0b;
  --low-priority: #94a3b8;
  --discarded: #ef4444;

  /* Testo — font più grandi rispetto al CRM */
  --text-xs: 0.8125rem;    /* 13px */
  --text-sm: 0.9375rem;    /* 15px */
  --text-base: 1.0625rem;  /* 17px */
  --text-lg: 1.25rem;      /* 20px */
  --text-xl: 1.5rem;       /* 24px */
  --text-2xl: 1.875rem;    /* 30px */
}

/* =============================================
   RESET / BASE
   ============================================= */

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: var(--text-base);
  color: #1e293b;
  -webkit-font-smoothing: antialiased;
  background: var(--content-bg);
}

#app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

h1 { font-size: var(--text-2xl); font-weight: 700; margin: 0 0 0.5rem; }
h2 { font-size: var(--text-xl); font-weight: 600; margin: 0 0 0.5rem; }
h3 { font-size: var(--text-lg); font-weight: 600; margin: 0 0 0.5rem; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

label {
  font-size: var(--text-sm);
  font-weight: 500;
  color: #374151;
  display: block;
  margin-bottom: 0.375rem;
}

/* =============================================
   FORM CONTROLS
   ============================================= */

.form-control, .form-select {
  font-size: var(--text-sm);
  padding: 0.5rem 0.875rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

textarea.form-control {
  resize: vertical;
  min-height: 5rem;
}

/* =============================================
   BUTTONS
   ============================================= */

.btn {
  font-size: var(--text-sm);
  font-weight: 600;
  padding: 0.5rem 1.25rem;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
  line-height: 1.5;
}

.btn:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.2);
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn-secondary {
  background: #f1f5f9;
  border-color: var(--border);
  color: #374151;
}

.btn-secondary:hover:not(:disabled) {
  background: #e2e8f0;
}

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

.btn-danger:hover:not(:disabled) {
  background: #dc2626;
  border-color: #dc2626;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: #64748b;
}

.btn-ghost:hover:not(:disabled) {
  background: #f1f5f9;
}

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

.btn-sm {
  font-size: var(--text-xs);
  padding: 0.3rem 0.75rem;
}

.btn-lg {
  font-size: var(--text-base);
  padding: 0.75rem 1.75rem;
}

/* =============================================
   CARD
   ============================================= */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.card-title {
  font-size: var(--text-base);
  font-weight: 600;
  color: #1e293b;
  margin-bottom: 0.25rem;
}

.card-subtitle {
  font-size: var(--text-sm);
  color: #64748b;
}

/* =============================================
   BADGE — task validity
   ============================================= */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: var(--text-xs);
  font-weight: 600;
}

.badge-strategic   { background: #ede9fe; color: #6d28d9; }
.badge-operational { background: #d1fae5; color: #065f46; }
.badge-future-idea { background: #fef3c7; color: #92400e; }
.badge-low-priority { background: #f1f5f9; color: #475569; }
.badge-discarded   { background: #fee2e2; color: #991b1b; }
.badge-backlog     { background: #e0e7ff; color: #3730a3; }
.badge-in-progress { background: #dbeafe; color: #1e40af; }
.badge-done        { background: #d1fae5; color: #065f46; }

/* =============================================
   PRIORITY BAR
   ============================================= */

.priority-bar-container {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.priority-bar {
  flex: 1;
  height: 6px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}

.priority-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.3s ease;
}

.priority-value {
  font-size: var(--text-xs);
  font-weight: 700;
  color: #374151;
  min-width: 2.5rem;
  text-align: right;
}

/* =============================================
   TABLE
   ============================================= */

.table {
  width: 100%;
  font-size: var(--text-sm);
  border-collapse: collapse;
}

.table th {
  font-weight: 600;
  color: #374151;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 2px solid var(--border);
  background: #f8fafc;
}

.table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  color: #1e293b;
  vertical-align: middle;
}

.table tbody tr:hover {
  background: #f8fafc;
}

/* =============================================
   LOGIN PAGE
   ============================================= */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f0c29 0%, #302b63 50%, #24243e 100%);
}

.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 25px 50px rgba(0,0,0,0.25);
}

.login-logo {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 1.5rem;
  display: block;
}

.login-title {
  font-size: var(--text-xl);
  font-weight: 700;
  color: #1e293b;
  margin-bottom: 0.375rem;
}

.login-subtitle {
  font-size: var(--text-sm);
  color: #64748b;
  margin-bottom: 1.75rem;
}

.code-input {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.5rem;
  text-align: center;
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  width: 100%;
}

.code-input:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.login-divider {
  text-align: center;
  font-size: var(--text-xs);
  color: #94a3b8;
  margin: 1rem 0;
  position: relative;
}

.login-divider::before, .login-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 42%;
  height: 1px;
  background: var(--border);
}

.login-divider::before { left: 0; }
.login-divider::after { right: 0; }

.alert {
  padding: 0.75rem 1rem;
  border-radius: 6px;
  font-size: var(--text-sm);
  margin-bottom: 1rem;
}

.alert-danger {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.alert-success {
  background: #d1fae5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.alert-info {
  background: #e0f2fe;
  color: #0c4a6e;
  border: 1px solid #bae6fd;
}

/* =============================================
   DASHBOARD KPI
   ============================================= */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.75rem;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.kpi-label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
  margin-bottom: 0.5rem;
}

.kpi-value {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: #1e293b;
  line-height: 1;
}

.kpi-sub {
  font-size: var(--text-xs);
  color: #94a3b8;
  margin-top: 0.25rem;
}

/* =============================================
   PAGE HEADER
   ============================================= */

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.page-title {
  font-size: var(--text-xl);
  font-weight: 700;
  color: #1e293b;
  margin: 0;
}

.page-subtitle {
  font-size: var(--text-sm);
  color: #64748b;
  margin-top: 0.25rem;
}

/* =============================================
   FILTERS BAR
   ============================================= */

.filters-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.filter-select {
  font-size: var(--text-sm);
  padding: 0.4rem 0.875rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: #374151;
  cursor: pointer;
}

/* =============================================
   SPINNER
   ============================================= */

.spinner {
  display: inline-block;
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid rgba(79, 70, 229, 0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.spinner-sm {
  width: 1rem;
  height: 1rem;
}

.spinner-lg {
  width: 2.5rem;
  height: 2.5rem;
  border-width: 3px;
}

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

.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  gap: 1rem;
  color: #64748b;
  font-size: var(--text-sm);
}

/* =============================================
   EMPTY STATE
   ============================================= */

.empty-state {
  text-align: center;
  padding: 3rem 2rem;
  color: #94a3b8;
}

.empty-state-icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
}

.empty-state-title {
  font-size: var(--text-base);
  font-weight: 600;
  color: #475569;
  margin-bottom: 0.5rem;
}

.empty-state-sub {
  font-size: var(--text-sm);
}

/* =============================================
   TASK FORM
   ============================================= */

.task-form-container {
  max-width: 800px;
}

.task-form-container textarea.form-control {
  font-size: var(--text-base);
  min-height: 5rem;
  line-height: 1.6;
}

.analysis-card {
  background: var(--primary-light);
  border: 1px solid #c7d2fe;
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
  margin-top: 1.25rem;
}

.analysis-card-title {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sub-tasks-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sub-task-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 0.875rem;
  font-size: var(--text-sm);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sub-task-item::before {
  content: '→';
  color: var(--primary);
  flex-shrink: 0;
}

/* =============================================
   UTILITY
   ============================================= */

.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.d-flex { display: flex; }
.align-items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.w-100 { width: 100%; }
.text-muted { color: #64748b; font-size: var(--text-sm); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.fw-600 { font-weight: 600; }

/* =============================================
   BLAZOR SYSTEM
   ============================================= */

#blazor-error-ui {
  color-scheme: light only;
  background: #fef2f2;
  border-top: 1px solid #fecaca;
  color: #991b1b;
  bottom: 0;
  box-sizing: border-box;
  display: none;
  left: 0;
  padding: 0.75rem 1.5rem;
  position: fixed;
  width: 100%;
  z-index: 10000;
  font-size: var(--text-sm);
}

#blazor-error-ui .dismiss {
  cursor: pointer;
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.25rem;
}

.blazor-error-boundary {
  background: #fee2e2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 1rem 1rem 1rem 3.5rem;
  color: #991b1b;
  position: relative;
}

.blazor-error-boundary::before {
  content: '⚠';
  position: absolute;
  left: 1rem;
  top: 1rem;
  font-size: 1.5rem;
}

.blazor-error-boundary::after {
  content: "Si è verificato un errore.";
}

.loading-progress {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: block;
  width: 5rem;
  height: 5rem;
}

.loading-progress circle {
  fill: none;
  stroke: #e0e7ff;
  stroke-width: 0.5rem;
  transform-origin: 50% 50%;
  transform: rotate(-90deg);
}

.loading-progress circle:last-child {
  stroke: var(--primary);
  stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
  transition: stroke-dasharray 0.05s ease-in-out;
}

.loading-progress-text {
  position: fixed;
  top: calc(50% + 3.5rem);
  left: 0;
  right: 0;
  text-align: center;
  font-size: var(--text-sm);
  color: #64748b;
  font-weight: 500;
}

.loading-progress-text:after {
  content: var(--blazor-load-percentage-text, "Caricamento...");
}

/* Validation */
.valid.modified:not([type=checkbox]) { border-color: var(--success); }
.invalid { border-color: var(--danger); }
.validation-message { color: var(--danger); font-size: var(--text-xs); margin-top: 0.25rem; }
