:root {
  --bg: #0a0a12;
  --card: #14141f;
  --border: #2a2a3a;
  --text: #f0f0f5;
  --muted: #8a8a9a;
  --red: #e10600;
  --red-dim: #a00400;
  --blue: #00a0e3;
  --green: #00c853;
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100%;
  padding-bottom: calc(80px + var(--safe-bottom));
}

/* TOPBAR */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: linear-gradient(180deg, #1a0a0a 0%, var(--bg) 100%);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo { border-radius: 8px; }
.brand strong { display: block; font-size: 15px; }
.brand small { color: var(--muted); font-size: 11px; }
.user-area { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.user-area.hidden { display: none; }

/* VIEWS */
.view { padding: 16px; }
.view.hidden { display: none; }

/* CARD */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.login-card { margin-top: 40px; }
.login-card h1 { font-size: 22px; margin-bottom: 4px; }
.muted { color: var(--muted); font-size: 13px; margin-bottom: 20px; }

label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 14px;
}
input, select, textarea {
  width: 100%;
  margin-top: 6px;
  padding: 12px 14px;
  background: #0e0e18;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 15px;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--red);
}

/* BUTTONS */
.btn-primary, .btn-secondary, .btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  width: 100%;
  margin-top: 8px;
}
.btn-primary { background: var(--red); color: #fff; }
.btn-primary:active { background: var(--red-dim); }
.btn-secondary { background: #1e1e2e; color: var(--text); border: 1px solid var(--border); }
.btn-ghost { background: transparent; color: var(--muted); width: auto; padding: 8px 12px; }
.row { display: flex; gap: 10px; }
.row .btn-primary, .row .btn-secondary { flex: 1; }

.divider {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  margin: 18px 0;
  position: relative;
}
.divider::before, .divider::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 40%;
  height: 1px;
  background: var(--border);
}
.divider::before { left: 0; }
.divider::after { right: 0; }

.error { color: #ff5252; font-size: 13px; margin-top: 10px; }
.error.hidden { display: none; }

/* CASSETTI */
.cassetti {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  overflow-x: auto;
}
.cassetto {
  flex: 1;
  padding: 10px 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.cassetto.active {
  background: linear-gradient(135deg, #2a0a0a, #1a1a2a);
  border-color: var(--red);
  color: #fff;
}

/* FILTRI */
.filters {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}
.filters input[type="search"] {
  grid-column: 1 / -1;
  margin-top: 0;
}

/* LISTA */
.lista { display: flex; flex-direction: column; gap: 10px; }
.assetto-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color .15s;
}
.assetto-card:active { border-color: var(--red); }
.assetto-card h3 { font-size: 15px; margin-bottom: 4px; }
.assetto-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}
.badge {
  background: #1e1e2e;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
}
.badge.public { background: #0a2a1a; color: #6f6; }
.badge.event { background: #2a1a0a; color: #fc6; }
.badge.private { background: #1a1a2a; color: #99f; }

.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
  font-size: 14px;
}

/* FAB */
.fab {
  position: fixed;
  right: max(16px, calc(50% - 240px));
  bottom: calc(20px + var(--safe-bottom));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--red);
  color: #fff;
  font-size: 28px;
  border: none;
  box-shadow: 0 4px 20px rgba(225, 6, 0, .4);
  cursor: pointer;
  z-index: 40;
}
.fab.hidden { display: none; }

/* DETAIL */
.detail-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.detail-header h2 { font-size: 18px; }

.form-grid {
  display: grid;
  gap: 12px;
}
.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  flex-wrap: wrap;
}
.form-actions button { flex: 1; min-width: 120px; }

/* TOAST */
.toast {
  position: fixed;
  bottom: calc(90px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: #222;
  color: #fff;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 13px;
  z-index: 100;
  box-shadow: 0 4px 20px rgba(0,0,0,.5);
}
.toast.hidden { display: none; }

/* SHARE */
#view-share .card { margin-top: 40px; }
#share-link { margin: 12px 0; font-size: 13px; }

/* Setup GT7 sections */
.setup-section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-top: 8px;
}
.setup-section h3 {
  font-size: 14px;
  color: var(--red);
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.pair3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}
.setup-section label { margin-bottom: 10px; }
.attach-box {
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 12px;
  text-align: center;
}
.attach-box input[type=file] { margin-top: 8px; font-size: 13px; }
.attach-preview {
  max-width: 100%;
  max-height: 180px;
  margin-top: 10px;
  border-radius: 8px;
}
.ro-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.ro-table th, .ro-table td {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}
.ro-table th { color: var(--muted); font-weight: 500; width: 45%; }
