/* Reset e stili base per FullHD TV */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-primary: #0a0e17;
  --bg-card: #111827;
  --bg-header: #1f2937;
  --border-color: #374151;
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --accent-blue: #3b82f6;
  --accent-cyan: #06b6d4;
  --accent-green: #10b981;
  --topbar-height: 48px;
}

html, body {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-main);
  user-select: none;
}

/* Header Top Bar */
.top-bar {
  height: var(--topbar-height);
  background: rgba(17, 24, 39, 0.95);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  position: relative;
  z-index: 100;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

/* Auto-hide top bar in kiosk/fullscreen mode */
body.kiosk-mode .top-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  opacity: 0;
  transform: translateY(-100%);
}

body.kiosk-mode .top-bar:hover,
body.kiosk-mode .top-bar.force-visible {
  opacity: 1;
  transform: translateY(0);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.status-dot {
  width: 10px;
  height: 10px;
  background-color: var(--accent-green);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--accent-green);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.8; }
}

.brand-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: #fff;
}

.current-time {
  font-family: "Courier New", monospace;
  font-size: 14px;
  color: var(--accent-cyan);
  font-weight: bold;
  background: rgba(6, 182, 212, 0.1);
  padding: 2px 8px;
  border-radius: 4px;
}

.controls {
  display: flex;
  align-items: center;
  gap: 14px;
}

.layout-selector, .refresh-controls, .zoom-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.btn-layout {
  background: #1e293b;
  color: var(--text-main);
  border: 1px solid var(--border-color);
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-layout:hover {
  background: #334155;
  border-color: var(--accent-blue);
}

.btn-layout.active {
  background: var(--accent-blue);
  color: #fff;
  border-color: var(--accent-blue);
  box-shadow: 0 0 10px rgba(59, 130, 246, 0.4);
}

.select-interval, .select-zoom {
  background: #1e293b;
  color: var(--text-main);
  border: 1px solid var(--border-color);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  outline: none;
}

.btn-icon {
  background: #1e293b;
  color: var(--text-main);
  border: 1px solid var(--border-color);
  width: 32px;
  height: 32px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
}

.btn-icon:hover {
  background: #334155;
  border-color: var(--accent-blue);
}

/* Griglia Wallboard */
.wallboard-container {
  width: 100vw;
  height: calc(100vh - var(--topbar-height));
  display: grid;
  gap: 6px;
  padding: 6px;
  transition: all 0.3s ease;
}

body.kiosk-mode .wallboard-container {
  height: 100vh;
}

/* LAYOUT 1: 2x2 (4 Riquadri uguali) */
body.layout-grid-4 .wallboard-container {
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
}
body.layout-grid-4 #card-5,
body.layout-grid-4 #card-6 {
  display: none;
}

/* LAYOUT 2: 4+1 (2x2 sulla sinistra + 1 colonna verticale a destra) */
body.layout-grid-4-plus-1 .wallboard-container {
  grid-template-columns: 2fr 2fr 1.6fr;
  grid-template-rows: repeat(2, 1fr);
}
body.layout-grid-4-plus-1 #card-1 { grid-column: 1; grid-row: 1; }
body.layout-grid-4-plus-1 #card-2 { grid-column: 2; grid-row: 1; }
body.layout-grid-4-plus-1 #card-3 { grid-column: 1; grid-row: 2; }
body.layout-grid-4-plus-1 #card-4 { grid-column: 2; grid-row: 2; }
body.layout-grid-4-plus-1 #card-5 {
  grid-column: 3;
  grid-row: 1 / span 2; /* Somma verticale di 2 */
  display: flex !important;
}
body.layout-grid-4-plus-1 #card-6 {
  display: none;
}

/* LAYOUT 3: 3x2 (6 Riquadri) */
body.layout-grid-6 .wallboard-container {
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 1fr);
}
body.layout-grid-6 #card-5,
body.layout-grid-6 #card-6 {
  display: flex !important;
}

/* Card / Frame */
.frame-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.frame-header {
  height: 28px;
  background: #172033;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  z-index: 10;
}

.frame-title {
  color: #93c5fd;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.frame-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-mini-refresh, .btn-mini-link {
  background: transparent;
  color: var(--text-muted);
  border: none;
  font-size: 12px;
  cursor: pointer;
  text-decoration: none;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 3px;
}

.btn-mini-refresh:hover, .btn-mini-link:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

/* ==========================================================================
   VIEWPORT EMULATION & AUTO-ZOOM TRICK
   ========================================================================== */
.iframe-wrapper {
  flex: 1;
  position: relative;
  width: 100%;
  height: calc(100% - 28px);
  background: #000;
  overflow: hidden; /* Nasconde l'eccesso dell'iframe scalato */
}

/* Modalità Scalata Full HD (Default): l'iframe pensa di essere a 1920x1080 */
.iframe-wrapper.emulate-fullhd iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 1920px;
  height: 1080px;
  transform-origin: 0 0;
  border: 0;
  display: block;
}

/* Modalità Responsiva nativa (100% standard se disattivato zoom) */
.iframe-wrapper.emulate-native iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  transform: none !important;
  border: 0;
  display: block;
}

/* Loader Overlay */
.loader-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(17, 24, 39, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  transition: opacity 0.4s ease;
  pointer-events: none;
  z-index: 5;
}

.loader-overlay.hidden {
  opacity: 0;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(59, 130, 246, 0.2);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* Modal */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-backdrop.hidden {
  display: none;
}

.modal-card {
  background: #1e293b;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  width: 90%;
  max-width: 640px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
}

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

.modal-header h2 {
  font-size: 16px;
  color: #fff;
}

.btn-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
}

.modal-body {
  padding: 20px;
}

.modal-note {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.input-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.input-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.input-row label {
  font-size: 12px;
  font-weight: 600;
  color: #93c5fd;
}

.input-row input {
  background: #0f172a;
  border: 1px solid var(--border-color);
  color: #fff;
  padding: 8px 12px;
  border-radius: 4px;
  font-size: 13px;
  outline: none;
}

.input-row input:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 6px rgba(59, 130, 246, 0.4);
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.btn-primary, .btn-secondary {
  padding: 8px 16px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
}

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

.btn-primary:hover {
  background: #2563eb;
}

.btn-secondary {
  background: #334155;
  color: #e2e8f0;
}

.btn-secondary:hover {
  background: #475569;
}
