/* === Variables === */
:root {
  --primary: #1B3A6B;
  --primary-light: #2a5298;
  --accent-blue: #4A9FD9;
  --success: #2EA88F;
  --danger: #E84D2E;
  --warning: #F5952D;
  --accent-yellow: #F5C525;
  --gray-light: #f5f7fa;
  --gray-border: #ddd;
  --gray-text: #888;
  --text: #333;
  --white: #fff;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 20px rgba(0,0,0,0.1);
}

/* === Reset === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-light);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* === Header === */
.header {
  background: var(--primary);
  color: var(--white);
  padding: 8px 16px;
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 960px;
  margin: 0 auto;
}
.logo-pill {
  background: var(--white);
  border-radius: var(--radius);
  padding: 4px 12px;
  display: inline-flex;
  align-items: center;
}
.header-logo { height: 32px; display: block; }
.header-nav { display: flex; gap: 12px; align-items: center; }
.nav-link {
  color: var(--gray-border);
  text-decoration: none;
  font-size: 13px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
}
.nav-link:hover { color: var(--white); }
.nav-logout { display: inline; }

/* === Hero === */
.hero {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: var(--white);
  padding: 32px 16px;
  text-align: center;
}
.hero h1 { font-size: 22px; font-weight: 700; margin-bottom: 6px; }
.hero p { opacity: 0.8; font-size: 14px; }

/* === Form container === */
.form-container {
  padding: 0 12px;
  margin-top: -24px;
  position: relative;
  z-index: 1;
}
.form-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 24px 16px;
  box-shadow: var(--shadow-lg);
  max-width: 700px;
  margin: 0 auto;
}

/* === Steps === */
.steps {
  display: flex;
  margin-bottom: 24px;
  gap: 4px;
}
.step {
  flex: 1;
  text-align: center;
}
.step-number {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  background: var(--gray-border);
  color: var(--gray-text);
}
.step-label {
  font-size: 11px;
  margin-top: 4px;
  color: var(--gray-text);
  display: none;
}
.step.active .step-number { background: var(--primary); color: var(--white); }
.step.active .step-label { color: var(--primary); font-weight: 600; }
.step.completed .step-number { background: var(--success); color: var(--white); }
.step.completed .step-number::before { content: '\2713'; }
.step.completed .step-label { color: var(--success); font-weight: 600; }

/* === Field groups === */
.field-group { margin-bottom: 16px; }
.field-group label {
  font-size: 13px;
  color: #555;
  font-weight: 600;
  display: block;
  margin-bottom: 6px;
}

/* === Tom Select overrides === */
.field-group .ts-wrapper { width: 100%; }
.field-group .ts-control {
  border: 2px solid var(--gray-border);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 14px;
  min-height: 44px;
  background: var(--white);
}
.field-group .ts-control:focus-within,
.field-group .ts-wrapper.focus .ts-control {
  border-color: var(--primary);
  box-shadow: none;
}
.field-group .ts-wrapper.disabled .ts-control {
  background: #f9f9f9;
  opacity: 0.5;
}
.field-group .ts-dropdown {
  border: 1px solid var(--gray-border);
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.field-group .ts-dropdown .option {
  padding: 10px 14px;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}
.field-group .ts-dropdown .active {
  background: var(--gray-light);
  color: var(--text);
}
.ts-meta { color: var(--gray-text); font-size: 12px; }
.no-results { padding: 14px; text-align: center; color: var(--gray-text); font-size: 14px; }

/* === Spinner === */
.spinner { display: none; }
.htmx-request .spinner,
.htmx-request.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--gray-border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
}
@keyframes spin { to { transform: translateY(-50%) rotate(360deg); } }

/* === Buttons === */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 24px;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: opacity 0.2s;
  font-family: inherit;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--white); }
.btn-primary:hover:not(:disabled) { opacity: 0.9; }
.btn-outline {
  background: var(--white);
  color: var(--primary);
  border: 1px solid var(--primary);
}
.btn-full { width: 100%; }
.form-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 8px;
}

/* === Alerts === */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  margin-bottom: 16px;
}
.alert-error { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }
.alert-success { background: #f0faf7; color: var(--success); border: 1px solid #a7f3d0; }

/* === Login page === */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 16px;
}
.login-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 40px 24px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}
.login-logo { text-align: center; margin-bottom: 28px; }
.logo-pill-large {
  display: inline-block;
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 12px 20px;
}
.login-logo-img { height: 64px; display: block; }
.login-subtitle { color: var(--gray-text); font-size: 13px; margin-top: 12px; }
.form-group { margin-bottom: 16px; }
.form-group label {
  font-size: 13px;
  color: #555;
  display: block;
  margin-bottom: 4px;
}
.form-group input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--gray-border);
  border-radius: 6px;
  font-size: 14px;
  outline: none;
}
.form-group input:focus { border-color: var(--primary); }
.form-group small { color: var(--gray-text); font-size: 12px; margin-top: 4px; display: block; }
.input-readonly { background: #f9f9f9; cursor: not-allowed; }

/* === Profile === */
.page-container {
  max-width: 600px;
  margin: 24px auto;
  padding: 0 16px;
}
.profile-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 32px 24px;
  box-shadow: var(--shadow);
}
.profile-card h2 { margin-bottom: 24px; color: var(--primary); }
.profile-card hr { border: none; border-top: 1px solid var(--gray-border); margin: 20px 0; }

/* === Results === */
.results-container {
  max-width: 700px;
  margin: 24px auto;
  padding: 0 12px;
}
.result-address {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  margin-bottom: 16px;
  border-left: 4px solid var(--success);
  box-shadow: var(--shadow);
}
.result-address-label { font-size: 13px; color: var(--gray-text); margin-bottom: 4px; }
.result-address-value { font-size: 16px; font-weight: 600; color: var(--primary); }
.results-title { font-size: 16px; color: var(--primary); margin-bottom: 16px; }

/* === Coverage Matrix (desktop only) === */
.coverage-matrix { display: none; }
.table-wrap { overflow-x: auto; }
.matrix-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  table-layout: fixed;
}
.matrix-table thead tr { border-bottom: 2px solid #eee; }
.matrix-table th {
  text-align: center;
  padding: 4px 2px;
  padding-top: 0;
  color: #555;
  font-weight: 600;
  font-size: 11px;
  vertical-align: bottom;
  height: 100px;
  position: relative;
}
.matrix-table th:first-child {
  text-align: left;
  padding-left: 16px;
  width: 130px;
  height: auto;
}
.tech-col {
  width: 40px;
}
.tech-col .tech-label {
  display: inline-block;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  white-space: nowrap;
  font-size: 11px;
  line-height: 1;
  margin: 0 auto;
}
.matrix-table td { padding: 10px 2px; text-align: center; }
.matrix-table td:first-child { padding-left: 16px; }
.matrix-table tbody tr { border-bottom: 1px solid #f0f0f0; }
.matrix-table tbody tr:last-child { border-bottom: none; }
.carrier-name { font-weight: 600; color: var(--primary); text-align: left !important; }

/* === Status dots === */
.status-dot {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-active { background: var(--success); }
.status-inactive { background: var(--danger); }
.status-saturated { background: var(--warning); }
.status-study { background: var(--accent-yellow); }
.status-unknown { background: var(--gray-border); }

/* === Coverage Cards (mobile) === */
.coverage-cards { display: block; }
.provider-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  overflow: hidden;
}
.provider-card-header {
  padding: 12px 16px;
  font-weight: 600;
  color: var(--primary);
  background: #f8fafc;
  border-bottom: 1px solid #f0f0f0;
}
.provider-card-body { padding: 8px 16px; }
.tech-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid #f8f8f8;
  font-size: 14px;
}
.tech-row:last-child { border-bottom: none; }
.tech-name { font-weight: 500; min-width: 80px; }
.tech-status { color: var(--gray-text); font-size: 12px; flex: 1; }
.tech-speed { color: var(--primary); font-size: 12px; font-weight: 600; }

/* === Legend === */
.coverage-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin: 16px 0;
  padding: 12px 0;
  border-top: 1px solid #eee;
  font-size: 12px;
  color: var(--gray-text);
}
.legend-item { display: flex; align-items: center; gap: 4px; }
.legend-item .status-dot { width: 10px; height: 10px; }

/* === Details accordion === */
.coverage-details { margin-top: 24px; }
.detail-section {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 8px;
  overflow: hidden;
}
.detail-summary {
  padding: 14px 16px;
  font-weight: 600;
  color: var(--primary);
  cursor: pointer;
  list-style: none;
}
.detail-summary::-webkit-details-marker { display: none; }
.detail-summary::before { content: '+ '; }
details[open] .detail-summary::before { content: '- '; }
.detail-body { padding: 0 16px 16px; }
.detail-tech {
  padding: 12px 0;
  border-bottom: 1px solid #f0f0f0;
}
.detail-tech:last-child { border-bottom: none; }
.detail-tech-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.detail-status { color: var(--gray-text); font-size: 12px; margin-left: auto; }
.detail-tech-info {
  margin-top: 8px;
  padding-left: 22px;
  font-size: 13px;
  color: #555;
  line-height: 1.8;
}

/* === Admin === */
.admin-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 24px;
  max-width: 800px;
  margin: 0 auto;
}
.admin-card h2 { margin-bottom: 20px; color: var(--primary); }
.admin-section { margin-bottom: 24px; }
.admin-section h3 { font-size: 16px; margin-bottom: 12px; color: #333; }
.admin-form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
}
.admin-form-row .form-group { flex: 1; min-width: 140px; }
.admin-form-row .form-group-btn { flex: 0; }
.admin-form-row select {
  width: 100%;
  padding: 10px 12px;
  border: 2px solid var(--gray-border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
}
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.admin-table th {
  text-align: left;
  padding: 10px 12px;
  color: #555;
  font-weight: 600;
  font-size: 12px;
  border-bottom: 2px solid #eee;
}
.admin-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #f0f0f0;
}
.role-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}
.role-admin { background: var(--primary); color: var(--white); }
.role-utente { background: #e8f0fe; color: var(--primary); }
.btn-delete {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  text-decoration: underline;
}
.btn-delete:hover { opacity: 0.7; }
.inline-form { display: inline; }

/* === Desktop (>=768px) === */
@media (min-width: 768px) {
  .hero { padding: 48px 24px; }
  .hero h1 { font-size: 28px; }
  .form-card { padding: 32px; }
  .step-label { display: block; }
  .form-actions { flex-direction: row; }
  .btn-full { width: auto; flex: 1; }

  /* Show matrix, hide cards */
  .coverage-matrix { display: block; }
  .coverage-cards { display: none; }

  .coverage-matrix {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow);
  }
}
