@import url('theme.css');
@import url('dark-mode.css');

body {
  font-family: 'Segoe UI', Tahoma, sans-serif;
  padding: 20px;
  background: var(--wb-bg);
  color: var(--wb-text);
  margin: 0;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  border-bottom: 2px solid var(--wb-border-light);
  padding-bottom: 15px;
  margin-bottom: 20px;
}

h2 {
  margin: 0;
  color: var(--wb-text);
  font-weight: 500;
  font-size: 1.35rem;
}

h2 i {
  margin-right: 10px;
}

.subtitle {
  color: var(--wb-text-muted);
  margin: 0 0 16px;
  font-size: 0.9rem;
}

.toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
}

.btn-primary { background: #0084ff; color: #fff; }
.btn-success { background: #2ecc71; color: #fff; }
.btn-warning { background: #f39c12; color: #fff; }
.btn-secondary { background: var(--wb-surface-3); color: var(--wb-text); border: 1px solid var(--wb-border); }

.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.filters input,
.filters select {
  padding: 8px 12px;
  border: 1px solid var(--wb-input-border);
  border-radius: 6px;
  font-size: 0.85rem;
  background: var(--wb-input-bg);
  color: var(--wb-text);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 11px 14px;
  text-align: left;
  border-bottom: 1px solid var(--wb-border-light);
  font-size: 0.88rem;
  color: var(--wb-text);
}

th {
  background: var(--wb-surface-2);
  color: var(--wb-text-secondary);
  font-weight: 600;
}

tr:hover td {
  background: var(--wb-surface-hover);
}

.badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
}

.badge-green { background: #e8f8ef; color: #27ae60; }
.badge-blue { background: #e8f0fe; color: #0b7ef3; }
.badge-orange { background: #fef5e7; color: #e67e22; }
.badge-red { background: #fdecea; color: #e74c3c; }
.badge-gray { background: #f0f0f0; color: #666; }

.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.card-item {
  border: 1px solid var(--wb-border);
  border-radius: 10px;
  padding: 18px;
  background: var(--wb-surface-2);
  text-align: center;
}

.card-item i {
  font-size: 2rem;
  margin-bottom: 10px;
}

.card-item h3 {
  margin: 6px 0;
  font-size: 1rem;
}

.card-item .value {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--wb-text);
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-box {
  background: var(--wb-surface-2);
  border-radius: 8px;
  padding: 14px;
  text-align: center;
  border: 1px solid var(--wb-border-light);
}

.stat-box .num {
  font-size: 1.5rem;
  font-weight: 700;
  color: #0084ff;
}

.stat-box .lbl {
  font-size: 0.78rem;
  color: var(--wb-text-muted);
  margin-top: 4px;
}

.chart-placeholder {
  background: linear-gradient(180deg, #f8fbff, #fff);
  border: 1px dashed #cce0ff;
  border-radius: 10px;
  padding: 40px;
  text-align: center;
  color: #666;
  margin-top: 16px;
}

.chart-placeholder i {
  font-size: 2.5rem;
  color: #74b9ff;
  margin-bottom: 10px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.form-group label {
  display: block;
  font-size: 0.82rem;
  color: var(--wb-text-secondary);
  margin-bottom: 4px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--wb-input-border);
  border-radius: 6px;
  font-size: 0.88rem;
  box-sizing: border-box;
  background: var(--wb-input-bg);
  color: var(--wb-text);
}

.qr-zone {
  text-align: center;
  padding: 40px;
  border: 2px dashed #0084ff;
  border-radius: 12px;
  background: #f0f8ff;
}

.qr-zone i {
  font-size: 4rem;
  color: #0084ff;
  margin-bottom: 16px;
}

.guide-list {
  list-style: none;
  padding: 0;
  margin: 16px 0 0;
}

.guide-list li {
  padding: 12px 14px;
  border-bottom: 1px solid #f0f0f0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.guide-list li i {
  color: #0084ff;
  width: 20px;
}

.btn-danger { background: #e74c3c; color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 0.78rem; }

.db-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  padding: 8px 12px;
  background: var(--wb-surface-2);
  border-radius: 6px;
  font-size: 0.8rem;
  color: var(--wb-text-secondary);
  border: 1px solid var(--wb-border-light);
}

.db-bar .db-status {
  flex: 1;
  padding: 4px 8px;
  border-radius: 4px;
  min-width: 120px;
}

.db-bar .db-status.idle { background: #edf2f7; color: #4a5568; }
.db-bar .db-status.loading,
.db-bar .db-status.saving { background: #ebf8ff; color: #2b6cb0; }
.db-bar .db-status.ok { background: #f0fff4; color: #276749; }
.db-bar .db-status.error { background: #fff5f5; color: #c53030; }

.empty-state {
  text-align: center;
  padding: 32px;
  color: var(--wb-text-muted);
  border: 1px dashed var(--wb-border);
  border-radius: 8px;
  background: var(--wb-surface-2);
}

.actions-cell {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: var(--wb-surface);
  color: var(--wb-text);
  border-radius: 10px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px var(--wb-shadow);
  border: 1px solid var(--wb-border);
}

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

.modal-header h3 {
  margin: 0;
  font-size: 1.1rem;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: #888;
  line-height: 1;
}

.modal-body {
  padding: 20px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px 20px;
}

.profiles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.profile-card {
  border: 2px solid var(--wb-border);
  border-radius: 12px;
  padding: 18px;
  background: var(--wb-surface-2);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.profile-card.active {
  border-color: var(--wb-accent);
  background: var(--wb-accent-soft);
  box-shadow: 0 4px 12px var(--wb-shadow-sm);
}

.profile-card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.profile-card-head h3 {
  margin: 0;
  flex: 1;
  font-size: 1rem;
}

.profile-conn {
  font-size: 0.78rem;
  color: var(--wb-text-muted);
  margin: 0 0 12px;
  word-break: break-all;
}

.profile-card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.info-box {
  background: #f0f8ff;
  border: 1px solid #cce0ff;
  border-radius: 8px;
  padding: 14px 16px;
  font-size: 0.85rem;
  line-height: 1.5;
}

.info-box ul {
  margin: 8px 0 0 18px;
  padding: 0;
}

.info-box li {
  margin-bottom: 4px;
}

.info-box code {
  background: #e8f0fe;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.82em;
}

.spiaggia-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: 6px;
  margin-top: 12px;
}

.spiaggia-cell {
  aspect-ratio: 1;
  border-radius: 6px;
  display: flex;
  cursor: pointer;
  border: 2px solid transparent;
  padding: 0;
  font: inherit;
  width: 100%;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  border: 2px solid transparent;
  position: relative;
  min-height: 48px;
}

.spiaggia-cell.cell-free {
  background: #d4edda;
  color: #155724;
  border-color: #c3e6cb;
}

.spiaggia-cell.cell-occupied {
  background: #4a90c8;
  color: #fff;
  border-color: #2d6aa0;
}

.spiaggia-cell.cell-selected {
  box-shadow: 0 0 0 3px #0084ff;
  border-color: #0084ff;
}

.spiaggia-cell:hover {
  filter: brightness(1.05);
  transform: scale(1.03);
}

.detail-free {
  color: #276749;
  font-weight: 600;
}

.detail-meta {
  font-size: 0.85rem;
  color: #64748b;
  margin-top: 8px;
}

.modal-sm {
  max-width: 400px;
}

.spiaggia-cell .cell-num { font-size: 0.85rem; }
.spiaggia-cell .cell-settore { font-size: 0.55rem; opacity: 0.85; }
.spiaggia-cell .cell-client { position: absolute; top: 2px; right: 4px; font-size: 0.5rem; }

.qr-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.qr-reader-wrap {
  margin: 16px auto;
  max-width: 400px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid #e2e8f0;
}

#qr-reader video {
  border-radius: 12px;
}

.wb-toast-root {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(360px, calc(100vw - 32px));
  pointer-events: none;
}

.wb-toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid #e2e8f0;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  font-size: 0.88rem;
  pointer-events: auto;
}

.wb-toast-success { border-left: 4px solid #22c55e; }
.wb-toast-error { border-left: 4px solid #ef4444; }

.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 16px;
  border: 1px solid var(--wb-border-light);
  border-radius: 8px;
  background: var(--wb-surface);
}

.table-scroll table {
  min-width: 560px;
}

/* Sola lettura — nasconde azioni di scrittura */
body.read-only #btn-nuovo,
body.read-only .btn-nuovo,
body.read-only [data-requires-write],
body.read-only .toolbar .btn-success,
body.read-only .toolbar .btn-primary:not(.btn-secondary) {
  display: none !important;
}

body.read-only .actions-cell {
  display: none !important;
}

.read-only-banner {
  background: #fff8e6;
  color: #7a5b00;
  text-align: center;
  padding: 8px 12px;
  font-size: 12px;
  border-bottom: 1px solid #ffe08a;
  margin: -12px -12px 12px;
}

.read-only-banner a {
  color: #0084ff;
  font-weight: 600;
}

/* Touch targets mínimos */
.btn,
.modal-close {
  min-height: 44px;
}

.btn-sm {
  min-height: 36px;
  min-width: 36px;
}

/* ── Tablet ── */
@media (max-width: 1024px) {
  body {
    padding: 16px;
  }

  .stats-row {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  }

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

/* ── Móvil ── */
@media (max-width: 768px) {
  body {
    padding: 12px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }

  h2 {
    font-size: 1.15rem;
  }

  .header {
    flex-direction: column;
    align-items: stretch;
  }

  .header h2 {
    text-align: left;
  }

  .toolbar {
    width: 100%;
  }

  .toolbar .btn {
    flex: 1;
    justify-content: center;
    min-height: 44px;
  }

  .filters {
    flex-direction: column;
  }

  .filters input,
  .filters select {
    width: 100%;
    min-height: 44px;
    font-size: 16px;
  }

  .stats-row {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .stat-box {
    padding: 10px;
  }

  .stat-box .num {
    font-size: 1.25rem;
  }

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

  .form-group input,
  .form-group select,
  .form-group textarea {
    font-size: 16px;
    min-height: 44px;
  }

  .db-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .db-bar .db-status {
    min-width: 0;
  }

  .chart-placeholder {
    padding: 24px 16px;
  }

  .grid-cards {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .card-item {
    padding: 14px;
  }

  .modal-overlay {
    padding: 0;
    align-items: flex-end;
  }

  .modal {
    max-width: none;
    border-radius: 16px 16px 0 0;
    max-height: 92dvh;
  }

  .modal-footer {
    flex-direction: column-reverse;
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  }

  .modal-footer .btn {
    width: 100%;
    justify-content: center;
  }

  th, td {
    padding: 10px 12px;
    font-size: 0.82rem;
  }

  .actions-cell .btn-sm {
    min-height: 40px;
    min-width: 40px;
    padding: 8px 12px;
  }
}

/* ── Guida / language selector ── */
.guide-lang-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
  padding: 10px 12px;
  background: var(--wb-surface-2);
  border: 1px solid var(--wb-border);
  border-radius: 10px;
}

.guide-lang-btn {
  padding: 6px 14px;
  border: 1px solid var(--wb-border);
  border-radius: 6px;
  background: var(--wb-surface);
  color: var(--wb-text-secondary);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.guide-lang-btn:hover {
  border-color: #0084ff;
  color: #0084ff;
}

.guide-lang-btn.active {
  background: #0084ff;
  border-color: #0084ff;
  color: #fff;
}

/* ── Guida / documentazione ── */
.guide-doc {
  max-width: 920px;
  line-height: 1.55;
  font-size: 0.92rem;
}

.guide-toc {
  background: var(--wb-surface-2);
  border: 1px solid var(--wb-border);
  border-radius: 10px;
  padding: 16px 20px;
  margin: 16px 0 24px;
}

.guide-toc h3 {
  margin: 0 0 10px;
  font-size: 0.95rem;
  color: var(--wb-text);
}

.guide-toc ol {
  margin: 0;
  padding-left: 20px;
  columns: 2;
  column-gap: 24px;
}

.guide-toc a {
  color: #0084ff;
  text-decoration: none;
}

.guide-toc a:hover {
  text-decoration: underline;
}

.guide-section {
  margin-bottom: 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--wb-border-light);
}

.guide-section:last-child {
  border-bottom: none;
}

.guide-section h3 {
  font-size: 1.1rem;
  color: var(--wb-text);
  margin: 0 0 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.guide-section h3 i {
  color: #0084ff;
  width: 22px;
  text-align: center;
}

.guide-section h4 {
  font-size: 0.95rem;
  color: var(--wb-text-secondary);
  margin: 14px 0 8px;
}

.guide-section p {
  margin: 0 0 10px;
  color: var(--wb-text-secondary);
}

.guide-section ul,
.guide-section ol {
  margin: 8px 0 12px;
  padding-left: 22px;
  color: var(--wb-text-secondary);
}

.guide-section li {
  margin-bottom: 6px;
}

.guide-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  margin: 10px 0 14px;
}

.guide-table th,
.guide-table td {
  border: 1px solid var(--wb-border);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
  color: var(--wb-text);
}

.guide-table th {
  background: var(--wb-surface-3);
  font-weight: 600;
}

.guide-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.guide-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}

.guide-badge.read { background: #e8f4fd; color: #0066cc; }
.guide-badge.write { background: #f0fff4; color: #276749; }
.guide-badge.admin { background: #fef3c7; color: #92400e; }

.guide-tip {
  background: #fffbeb;
  border-left: 4px solid #f59e0b;
  padding: 10px 14px;
  margin: 12px 0;
  border-radius: 0 6px 6px 0;
  font-size: 0.85rem;
}

.guide-warn {
  background: #fff5f5;
  border-left: 4px solid #e53e3e;
  padding: 10px 14px;
  margin: 12px 0;
  border-radius: 0 6px 6px 0;
  font-size: 0.85rem;
}

@media (max-width: 768px) {
  .guide-toc ol {
    columns: 1;
  }
}

/* ── Móvil pequeño ── */
@media (max-width: 480px) {
  body {
    padding: 10px;
  }

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

  .grid-cards {
    grid-template-columns: 1fr;
  }

  .toolbar {
    flex-direction: column;
  }

  .toolbar .btn {
    width: 100%;
  }
}