/* =============================================
   CRI – Ponti Radio  |  Bootstrap 5 theme
   ============================================= */

/* ---------- Variables ---------- */
:root {
  --cri-red:       #C8102E;
  --cri-dark:      #9e0c23;
  --cri-light:     #fce8eb;
  --cri-pale:      #fdf3f4;
  --cri-sidebar:   #b30f28;

  --sidebar-width: 240px;
  --topbar-h:      60px;

  --page-bg:       #F3F4F6;
  --card-bg:       #ffffff;
  --border:        #E5E7EB;
  --text:          #111827;
  --muted:         #6B7280;
}

/* ---------- Global reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--page-bg);
  color: var(--text);
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

/* =============================================
   SIDEBAR
   ============================================= */
.app-sidebar {
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  width: var(--sidebar-width);
  background: var(--cri-sidebar);
  display: flex;
  flex-direction: column;
  z-index: 1040;
  transition: transform .25s ease;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Brand */
.sidebar-brand {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,.15);
  flex-shrink: 0;
}
.brand-logo {
  width: 42px;
  height: 42px;
  background: #fff;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}
.brand-logo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.brand-text {
  min-width: 0;
}
.brand-title {
  color: #fff;
  font-weight: 800;
  font-size: .95rem;
  display: block;
  line-height: 1.2;
}
.brand-org {
  color: rgba(255,255,255,.65);
  font-size: .68rem;
  display: flex;
  flex-direction: column;
  line-height: 1.3;
  margin-top: 2px;
}
.brand-org span {
  display: block;
}
.btn-sidebar-close {
  margin-left: auto;
  background: none; border: none;
  color: rgba(255,255,255,.75);
  cursor: pointer; padding: 4px 6px;
  font-size: 1rem; line-height: 1;
  border-radius: 6px;
  display: none;
}

/* Navigation */
.sidebar-nav {
  flex: 1;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.nav-section-label {
  color: rgba(255,255,255,.5);
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .09em;
  padding: 14px 12px 5px;
}
.sidebar-nav .nav-link,
.nav-logout {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: rgba(255,255,255,.85);
  text-decoration: none;
  font-size: .88rem;
  font-weight: 500;
  transition: background .13s, color .13s;
  border: none;
  background: none;
  width: 100%;
  cursor: pointer;
  text-align: left;
}
.sidebar-nav .nav-link:hover,
.nav-logout:hover {
  background: rgba(255,255,255,.15);
  color: #fff;
}
.sidebar-nav .nav-link.active {
  background: rgba(255,255,255,.22);
  color: #fff;
  font-weight: 700;
}
.sidebar-nav .nav-link i,
.nav-logout i {
  font-size: 1rem;
  width: 18px;
  text-align: center;
  flex-shrink: 0;
}

/* Footer */
.sidebar-footer {
  padding: 8px;
  border-top: 1px solid rgba(255,255,255,.15);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

/* =============================================
   MAIN AREA
   ============================================= */
.app-main {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Topbar */
.app-topbar {
  height: var(--topbar-h);
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
}
.topbar-toggle {
  background: none; border: none;
  color: var(--text); cursor: pointer;
  padding: 6px; font-size: 1.25rem;
  border-radius: 6px;
  display: none;
  align-items: center;
}
.topbar-breadcrumb { flex: 1; min-width: 0; }
.topbar-breadcrumb .breadcrumb {
  margin: 0;
  font-size: .84rem;
  flex-wrap: nowrap;
  overflow: hidden;
}
.topbar-breadcrumb .breadcrumb-item a {
  color: var(--muted);
  text-decoration: none;
}
.topbar-breadcrumb .breadcrumb-item a:hover { color: var(--cri-red); }
.topbar-breadcrumb .breadcrumb-item.active {
  color: var(--text);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-end {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.user-name {
  font-size: .84rem;
  color: var(--muted);
  white-space: nowrap;
}
.role-badge {
  font-size: .7rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  text-transform: capitalize;
  white-space: nowrap;
}
.role-amministratore { background: var(--cri-light); color: var(--cri-dark); }
.role-tecnico        { background: #dbeafe; color: #1e40af; }
.role-rtl_tlc        { background: #fef9c3; color: #713f12; }
.role-visualizzatore { background: #dcfce7; color: #166534; }

/* Content */
.app-content {
  padding: 28px;
  flex: 1;
}

/* Mobile overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1039;
}

/* =============================================
   RESPONSIVE
   ============================================= */
@media (max-width: 991.98px) {
  .app-sidebar { transform: translateX(-100%); }
  .app-sidebar.open { transform: translateX(0); }
  .app-main { margin-left: 0; }
  .topbar-toggle { display: flex; }
  .btn-sidebar-close { display: flex; }
  .sidebar-overlay.show { display: block; }
  .app-content { padding: 20px 16px; }
}

/* =============================================
   PAGE HEADER
   ============================================= */
.page-header-bar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.page-title {
  margin: 0 0 4px;
  font-size: 1.45rem;
  font-weight: 800;
  line-height: 1.2;
}
.page-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: .88rem;
}
.eyebrow {
  margin: 0 0 4px;
  color: var(--cri-red);
  font-size: .7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .08em;
}

/* =============================================
   BOOTSTRAP OVERRIDES
   ============================================= */

/* Card */
.card {
  border-color: var(--border);
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.07);
}
.card-header {
  background: var(--card-bg);
  border-bottom-color: var(--border);
  font-weight: 700;
  border-radius: 12px 12px 0 0 !important;
  padding: 14px 20px;
}
.card-body { padding: 20px; }

/* Form */
.form-label {
  font-weight: 600;
  font-size: .86rem;
  color: var(--muted);
  margin-bottom: 5px;
}
.form-control, .form-select {
  border-color: var(--border);
  border-radius: 8px;
  font-size: .92rem;
}
.form-control:focus, .form-select:focus {
  border-color: var(--cri-red);
  box-shadow: 0 0 0 .2rem rgba(200,16,46,.15);
}
textarea.form-control { resize: vertical; min-height: 80px; }

/* Buttons */
.btn-primary {
  background-color: var(--cri-red) !important;
  border-color: var(--cri-red) !important;
  font-weight: 700;
}
.btn-primary:hover, .btn-primary:active {
  background-color: var(--cri-dark) !important;
  border-color: var(--cri-dark) !important;
}
.btn-primary:focus {
  box-shadow: 0 0 0 .2rem rgba(200,16,46,.3) !important;
}
.btn-outline-primary {
  color: var(--cri-red) !important;
  border-color: var(--cri-red) !important;
}
.btn-outline-primary:hover {
  background-color: var(--cri-red) !important;
  color: #fff !important;
}
.btn-outline-danger {
  color: #991b1b !important;
  border-color: #991b1b !important;
}
.btn-outline-danger:hover {
  background-color: #991b1b !important;
  color: #fff !important;
}
.btn { border-radius: 8px; font-weight: 600; font-size: .88rem; }
.btn-sm { font-size: .8rem; }

/* Tables */
.table th {
  color: var(--muted);
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  border-top: none;
  padding: 10px 14px;
  white-space: nowrap;
}
.table td { padding: 12px 14px; vertical-align: middle; }
.table-hover > tbody > tr:hover > * { background-color: var(--cri-pale); }
.table-sort-link {
  color: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}
.table-sort-link:hover {
  color: var(--cri-red);
}
.table a { color: var(--cri-red); font-weight: 600; text-decoration: none; }
.table a:hover { text-decoration: underline; }

/* Badges */
.badge { font-size: .72rem; font-weight: 700; padding: 4px 10px; border-radius: 999px; }
.badge-operativo     { background: #dcfce7; color: #166534; }
.badge-malfunzionante { background: #fef3c7; color: #92400e; }
.badge-non_operativo  { background: #fee2e2; color: #991b1b; }
.badge-aperto        { background: #fef3c7; color: #92400e; }
.badge-in_lavorazione { background: #dbeafe; color: #1e40af; }
.badge-chiuso        { background: #dcfce7; color: #166534; }
.badge-ordinario     { background: #f3f4f6; color: #374151; }
.badge-straordinario { background: #fef3c7; color: #92400e; }
.badge-emergenza     { background: #fee2e2; color: #991b1b; }
.badge-tecnico       { background: #dbeafe; color: #1e40af; }
.badge-amministratore { background: var(--cri-light); color: var(--cri-dark); }
.badge-visualizzatore { background: #dcfce7; color: #166534; }
.badge-attivo        { background: #dcfce7; color: #166534; }
.badge-disattivato   { background: #fee2e2; color: #991b1b; }

/* Alerts */
.alert { border-radius: 10px; font-size: .9rem; }

/* Accordion */
.accordion-item { border-color: var(--border); }
.accordion-item:first-of-type .accordion-button { border-radius: 12px 12px 0 0; }
.accordion-button {
  font-weight: 700;
  font-size: .92rem;
  color: var(--text);
  background: var(--card-bg);
}
.accordion-button:not(.collapsed) {
  color: var(--cri-dark);
  background: var(--cri-pale);
  box-shadow: none;
}
.accordion-button:focus {
  box-shadow: 0 0 0 .2rem rgba(200,16,46,.15);
}
.accordion-body { padding: 20px; }

/* Detail grid (scheda ponte, read-only) */
.detail-dl {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px 24px;
  margin: 0;
}
.detail-dl > div { display: grid; gap: 3px; }
.detail-dl-3 { grid-template-columns: repeat(3, 1fr); }
.detail-dl dt {
  font-size: .75rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}
.detail-dl dd {
  margin: 0;
  font-size: .92rem;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Form grid inside accordion */
.form-grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px 20px;
}
.form-grid-2 .col-full { grid-column: 1 / -1; }

.form-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px 20px;
}

@media (max-width: 991.98px) {
  .form-grid-3 {
    grid-template-columns: 1fr;
  }
}

/* Stat cards (dashboard) */
.stat-card { text-align: center; padding: 22px 16px; }
.stat-value {
  font-size: 2.2rem;
  font-weight: 800;
  line-height: 1;
  margin-bottom: 4px;
  display: block;
}
.stat-label {
  font-size: .82rem;
  color: var(--muted);
  font-weight: 600;
}
.stat-dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}

/* Dashboard map */
.map-container {
  width: 100%;
  height: 460px;
  border-radius: 0 0 12px 12px;
  overflow: hidden;
}
@media (max-width: 767.98px) {
  .map-container { height: 300px; }
}

/* User card (admin) */
.user-row-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

/* Document grid */
.doc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}
.doc-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: .85rem;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.doc-item a {
  color: var(--cri-red);
  font-weight: 600;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.doc-item a:hover { text-decoration: underline; }

.photo-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
}

.photo-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px;
  background: #fff;
}

.photo-card-button {
  width: 100%;
  text-align: left;
  appearance: none;
  cursor: pointer;
}

.photo-card:hover {
  border-color: rgba(200, 29, 37, .28);
  box-shadow: 0 8px 20px rgba(15, 23, 42, .06);
}

.photo-thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 6px;
  background: #f3f4f6;
}

.photo-name {
  font-size: .76rem;
  line-height: 1.25;
  color: var(--cri-red);
  font-weight: 600;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 1.25em;
}

.photo-viewer-dialog {
  max-width: min(1100px, calc(100vw - 24px));
}

.photo-viewer-content {
  background: #111827;
  color: #f9fafb;
  border: none;
}

.photo-viewer-content .btn-close {
  filter: invert(1);
}

.photo-viewer-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: min(72vh, 780px);
}

.photo-viewer-image {
  max-width: 100%;
  max-height: min(72vh, 780px);
  object-fit: contain;
  border-radius: 10px;
}

.photo-viewer-content .carousel-control-prev,
.photo-viewer-content .carousel-control-next {
  width: 8%;
}

.bridge-album-list {
  display: grid;
  gap: 16px;
}

.bridge-album-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  background: #fff;
}

.bridge-album-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.bridge-album-note {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: .88rem;
}

.bridge-album-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
}

.bridge-album-thumb,
.bridge-album-more {
  appearance: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  min-height: 96px;
}

.bridge-album-thumb img {
  width: 100%;
  height: 96px;
  object-fit: cover;
  display: block;
}

.bridge-album-more {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--cri-red);
  font-weight: 700;
  font-size: 1rem;
}

/* Meta pill (dashboard) */
.meta-pill {
  min-width: 110px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--cri-pale);
  text-align: center;
}
.meta-pill strong { font-size: 1.5rem; display: block; line-height: 1.1; }
.meta-pill span   { font-size: .8rem; color: var(--muted); font-weight: 600; }

/* Filter bar */
.filter-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 20px;
}
.filter-bar .form-control,
.filter-bar .form-select { min-width: 130px; flex: 1; }
.filter-bar .form-control:first-child { flex: 2; }

/* Permission list */
.perm-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.perm-item:last-child { border-bottom: none; }

/* Code */
code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  background: rgba(200,16,46,.08);
  color: var(--cri-dark);
  padding: 2px 6px;
  border-radius: 5px;
  font-size: .88em;
}

/* =============================================
   AUTH PAGES (login)
   ============================================= */
.auth-page {
  min-height: 100vh;
  background: linear-gradient(145deg, var(--cri-red) 0%, #7a0818 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card {
  width: min(420px, 100%);
  background: #fff;
  border-radius: 16px;
  padding: 36px;
  box-shadow: 0 24px 64px rgba(0,0,0,.25);
}
.auth-logo {
  width: 56px; height: 56px;
  background: #fff;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}
.auth-logo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.auth-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}
.auth-brand-text {
  min-width: 0;
}
.auth-brand-title {
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.15;
  color: var(--text);
}
.auth-brand-org {
  font-size: .78rem;
  line-height: 1.25;
  color: var(--muted);
}

.upload-form-grid {
  display: grid;
  grid-template-columns: minmax(180px, 220px) minmax(280px, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.upload-form-field {
  min-width: 0;
}

.upload-form-file .form-control {
  width: 100%;
}

.upload-form-action {
  align-self: end;
}

.upload-form-action .btn {
  min-width: 110px;
}

/* Responsive utilities */
@media (max-width: 991.98px) {
  .upload-form-grid {
    grid-template-columns: 1fr;
  }

  .upload-form-action .btn {
    width: 100%;
  }
}

@media (max-width: 575.98px) {
  .page-header-bar { gap: 12px; }
  .page-header-bar .d-flex { flex-wrap: wrap; }
  .filter-bar { flex-direction: column; }
  .filter-bar .form-control,
  .filter-bar .form-select { min-width: 100%; }
}
