:root {
  --bg: #0f0f12;
  --surface: #18181c;
  --border: #2a2a30;
  --text: #e4e4e7;
  --text-muted: #71717a;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #22c55e;
  --danger: #ef4444;
  --radius: 8px;
  --font: 'Segoe UI', system-ui, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.hidden { display: none !important; }

/* ——— Login ——— */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  max-width: 320px;
}

.login-box h1 {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}

.login-box p {
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.login-box input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 1rem;
}

.login-box input:focus {
  outline: none;
  border-color: var(--accent);
}

.login-box button {
  width: 100%;
  padding: 0.75rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.login-box button:hover {
  background: var(--accent-hover);
}

.error {
  color: var(--danger);
  font-size: 0.875rem;
  margin-top: 0.5rem;
}

/* ——— App ——— */
#app {
  min-height: 100vh;
  padding: 1rem;
  padding-bottom: 2rem;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.header h1 {
  font-size: 1.25rem;
  font-weight: 600;
}

.btn-outline {
  padding: 0.5rem 1rem;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.875rem;
}

.btn-outline:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

/* Filtri e preset */
.filters {
  margin-bottom: 1.5rem;
}

.preset-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.btn-preset {
  padding: 0.5rem 1rem;
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.875rem;
}

.btn-preset:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

.btn-preset.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.custom-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  padding: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.custom-filters input,
.custom-filters select {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 0.875rem;
}

.custom-filters input:focus,
.custom-filters select:focus {
  outline: none;
  border-color: var(--accent);
}

.btn-primary {
  padding: 0.5rem 1rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.8125rem;
  cursor: pointer;
}

.btn-sm:hover {
  border-color: var(--text-muted);
}

/* Stats */
.stats {
  margin-bottom: 1.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  min-width: 120px;
}

.stat-value {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
}

.stat-label {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.stat-cards-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.stat-cards-row .stat-card {
  min-width: 90px;
  padding: 0.75rem 1rem;
}

.stat-cards-row .stat-value {
  font-size: 1.125rem;
}

/* Tabella */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.table-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.visits-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.visits-table th,
.visits-table td {
  padding: 0.6rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.visits-table th {
  background: var(--bg);
  color: var(--text-muted);
  font-weight: 600;
  position: sticky;
  top: 0;
}

.visits-table td {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.visits-table tr:hover td {
  background: rgba(255,255,255,0.03);
}

.visits-table .cell-muted {
  color: var(--text-muted);
}

.visits-table .cell-link {
  color: var(--accent);
  text-decoration: none;
  max-width: 220px;
  display: inline-block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.visits-table .cell-link:hover {
  text-decoration: underline;
}

/* Mobile */
@media (max-width: 640px) {
  #app { padding: 0.75rem; }
  .custom-filters {
    flex-direction: column;
    align-items: stretch;
  }
  .custom-filters input,
  .custom-filters select {
    width: 100%;
  }
  .visits-table th:nth-child(n+5),
  .visits-table td:nth-child(n+5) {
    display: none;
  }
  .visits-table th:nth-child(1),
  .visits-table th:nth-child(2),
  .visits-table th:nth-child(3),
  .visits-table th:nth-child(4) {
    display: table-cell;
  }
}

@media (max-width: 480px) {
  .preset-buttons { flex-direction: column; }
  .btn-preset { width: 100%; }
}
