/* ═══════════════════════════════════════════════
   PHICU Manager — custom.css
   Mobile-first, aesthetic redesign
   ═══════════════════════════════════════════════ */

/* ── Palette & Variables ── */
:root {
  /* HSL Tailored Colors */
  --primary-color:  hsl(222, 47%, 11%); /* Slate 900 */
  --primary-brand:  hsl(221, 83%, 53%); /* Blue Royal */
  --primary-light:  hsl(221, 83%, 60%);
  --primary-pale:   hsl(210, 40%, 98%); /* Lighter bg Slate */
  
  --success-color:  hsl(150, 84%, 37%); /* Emerald 600 */
  --success-light:  hsl(150, 84%, 97%);
  
  --warning-color:  hsl(38, 92%, 50%); /* Amber 500 */
  --warning-light:  hsl(38, 92%, 97%);
  
  --danger-color:   hsl(0, 84%, 60%); /* Rose 500 */
  --danger-light:   hsl(0, 84%, 97%);

  --info-color:     hsl(187, 85%, 45%); /* Cyan 600 */
  --info-light:     hsl(187, 85%, 97%);
  
  --dark-color:     hsl(222, 47%, 11%);
  --text-main:      hsl(215, 25%, 27%); /* Slate 700 */
  --text-muted:     hsl(215, 16%, 47%); /* Slate 500 */
  --text-faint:     hsl(215, 16%, 65%);
  --light-bg:       hsl(210, 40%, 96.5%);
  --surface:        #ffffff;
  --border-color:   rgba(15, 23, 42, 0.06);
  --card-shadow:    0 4px 6px -1px rgba(0, 0, 0, 0.04), 0 2px 4px -2px rgba(0, 0, 0, 0.04);
  --hover-shadow:   0 10px 20px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -4px rgba(15, 23, 42, 0.08);
  --radius-sm:      6px;
  --radius:         10px;
  --radius-lg:      14px;
  --radius-xl:      18px;
  --bottom-nav-h:   64px;
}

/* Elegant Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(15, 23, 42, 0.12);
  border-radius: 99px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(15, 23, 42, 0.24);
}

/* ── Base ── */
html { scroll-behavior: smooth; }

body {
  background-color: var(--light-bg);
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--text-main);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Spazio per bottom nav su mobile */
@media (max-width: 991.98px) {
  body {
    padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 4px));
  }
}

/* ── Navbar ── */
.bg-ti {
  background: rgba(15, 23, 42, 0.92) !important;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.04);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.navbar {
  min-height: 56px;
  padding-top: 0;
  padding-bottom: 0;
}
.navbar-brand {
  font-size: 1.25rem;
  font-weight: 750 !important;
  letter-spacing: -0.02em;
}
.navbar-phicu {
  font-size: 1.1rem;
  font-weight: 800 !important;
  letter-spacing: -0.03em;
  color: #ffffff !important;
  opacity: 1 !important;
}
.navbar-phicu-sub {
  font-weight: 300;
  letter-spacing: 0.01em;
  opacity: 0.65;
}
.nav-link {
  font-weight: 600;
  transition: color 0.15s ease;
  padding-top: 0.8rem;
  padding-bottom: 0.8rem;
}

/* ── Bottom Navigation (mobile only, hidden on ≥lg) ── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1030;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  border-top: 1px solid rgba(15, 23, 42, 0.06);
  box-shadow: 0 -8px 24px rgba(15, 23, 42, 0.04);
  display: flex;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 3px 6px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.2;
  min-height: var(--bottom-nav-h);
  transition: color 0.2s cubic-bezier(0.4, 0, 0.2, 1), transform 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.bottom-nav-item i {
  font-size: 1.35rem;
  margin-bottom: 2px;
  display: block;
}
.bottom-nav-item.active,
.bottom-nav-item:focus-visible {
  color: var(--primary-brand);
  transform: translateY(-1px);
  outline: none;
}
.bottom-nav-plus {
  color: var(--primary-brand) !important;
  transform: translateY(-4px);
}
.bottom-nav-plus i {
  font-size: 1.85rem;
  filter: drop-shadow(0 4px 8px rgba(37, 99, 235, 0.24));
}
.bottom-nav-plus:active {
  transform: translateY(-2px) scale(0.95);
}

/* Tabs moderne ed eleganti */
.nav-tabs {
  border-bottom: 1.5px solid rgba(15, 23, 42, 0.06) !important;
}
.nav-tabs .nav-link {
  border: none !important;
  background: transparent !important;
  color: var(--text-muted) !important;
  font-weight: 600 !important;
  padding: 0.6rem 1.1rem !important;
  position: relative;
  transition: color 0.15s ease !important;
  border-bottom: 2.5px solid transparent !important;
}
.nav-tabs .nav-link:hover {
  color: var(--primary-brand) !important;
}
.nav-tabs .nav-link.active {
  color: var(--primary-brand) !important;
  border-bottom: 2.5px solid var(--primary-brand) !important;
}

/* ── Login page ── */
.login-page {
  background: radial-gradient(circle at top right, #1e3a8a 0%, var(--dark-color) 100%);
}
.login-card {
  width: 100%;
  max-width: 390px;
  border-radius: var(--radius-lg);
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(10px);
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.28);
}

/* ── PHICU title (login) ── */
.phicu-title {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1;
  background: linear-gradient(130deg, #1e3a8a 0%, #3b82f6 60%, #60a5fa 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.phicu-divider {
  width: 36px;
  height: 3px;
  border-radius: 99px;
  background: linear-gradient(90deg, #3b82f6, #60a5fa);
  margin: 8px auto 6px;
}
.phicu-subtitle {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: #64748b;
}
.phicu-caption {
  font-size: 0.78rem;
  color: #94a3b8;
}

/* ── Page headers ── */
h2.page-title {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--dark-color);
}
@media (max-width: 575.98px) {
  h2, h2.page-title { font-size: 1.15rem; }
}

/* ── Sezione turni nel dashboard ── */
.shift-panel {
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.75rem;
  height: 100%;
}
.shift-panel-header {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.4rem;
}
.shift-giorno {
  background: #fffbeb;
  border: 1px solid #fde68a;
}
.shift-giorno .shift-panel-header { color: #92400e; }
.shift-notte {
  background: #eef0fa;
  border: 1px solid #c7d2fe;
}
.shift-notte .shift-panel-header { color: #312e81; }
.shift-name {
  font-size: 0.87rem;
  font-weight: 600;
  color: var(--dark-color);
  line-height: 1.35;
}

/* ── KPI cards ── */
.kpi-card {
  border-radius: var(--radius);
  border: 1px solid rgba(15, 23, 42, 0.05);
  background: var(--surface);
  box-shadow: var(--card-shadow);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--hover-shadow);
}
.kpi-number {
  font-size: 2.2rem;
  font-weight: 800;
  line-height: 1.1;
  color: var(--primary-brand);
}
.kpi-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 4px;
}
.kpi-sub {
  font-size: 0.72rem;
  color: var(--text-faint);
}

/* ── Box occupancy ── */
.box-clickable {
  cursor: pointer;
  border-radius: var(--radius) !important;
  background: var(--surface) !important;
  border: 1px solid rgba(15, 23, 42, 0.06) !important;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1),
              box-shadow 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: var(--card-shadow) !important;
  min-height: 86px;
  position: relative;
  overflow: hidden;
}

/* Accent Borders */
.box-occupied {
  border-left: 4px solid var(--primary-brand) !important;
}
.box-occupied .small.text-muted {
  color: var(--primary-brand) !important;
  opacity: 0.85;
}
.box-free {
  border-left: 4px solid var(--success-color) !important;
}
.box-free .small.text-muted {
  color: var(--success-color) !important;
  opacity: 0.85;
}
.box-urgenza {
  border-left: 4px solid var(--danger-color) !important;
}
.box-urgenza .small.text-muted {
  color: var(--danger-color) !important;
  opacity: 0.85;
}
.box-postop {
  border-left: 4px solid #8b5cf6 !important; /* Elegant Violet */
}
.box-postop .small.text-muted {
  color: #8b5cf6 !important;
  opacity: 0.85;
}
.box-appoggio {
  border-left: 4px solid #14b8a6 !important; /* Teal */
}
.box-appoggio .small.text-muted {
  color: #14b8a6 !important;
  opacity: 0.85;
}

/* Hover glowing shadows matching state */
.box-clickable:hover,
.box-clickable:focus-visible {
  transform: translateY(-4px) scale(1.02);
  outline: none;
}
.box-occupied:hover {
  box-shadow: 0 10px 20px rgba(37, 99, 235, 0.1) !important;
}
.box-free:hover {
  box-shadow: 0 10px 20px rgba(16, 185, 129, 0.1) !important;
}
.box-urgenza:hover {
  box-shadow: 0 10px 20px rgba(239, 68, 68, 0.1) !important;
}
.box-postop:hover {
  box-shadow: 0 10px 20px rgba(139, 92, 246, 0.1) !important;
}
.box-appoggio:hover {
  box-shadow: 0 10px 20px rgba(20, 184, 166, 0.1) !important;
}

.box-clickable:active {
  transform: translateY(-1px) scale(0.98);
  transition-duration: 0.08s;
}
@media (max-width: 575.98px) {
  .box-clickable { min-height: 74px; }
}

/* ── Tables ── */
.table {
  border-color: #f1f5f9;
}
.table th {
  font-size: 0.71rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background-color: #f8fafc;
  padding: 9px 12px;
  white-space: nowrap;
}
.table td {
  padding: 9px 12px;
  vertical-align: middle;
}
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ── Row highlights ── */
tr.row-isolated td { background-color: #fffbeb !important; }
tr.row-long-stay td { background-color: #fef2f2 !important; }

/* ── Cards ── */
.card {
  border-radius: var(--radius);
  border: 1px solid rgba(15, 23, 42, 0.06);
  box-shadow: var(--card-shadow);
}
.card-header {
  background-color: var(--surface) !important;
  border-bottom: 1px solid rgba(15, 23, 42, 0.07) !important;
  border-radius: var(--radius) var(--radius) 0 0 !important;
  font-weight: 600;
  color: var(--dark-color);
  padding: 0.65rem 1rem;
}
.card-body {
  padding: 0.85rem 1rem;
}

/* ── Buttons (touch-friendly, ≥44px on mobile) ── */
.btn {
  border-radius: var(--radius-sm);
  font-weight: 600;
  padding: 8px 16px;
  min-height: 38px;
  transition: all 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn-sm {
  padding: 5px 12px;
  font-size: 0.82rem;
  border-radius: 7px;
  min-height: 32px;
}
.btn-xs {
  padding: 3px 8px;
  font-size: 0.72rem;
  border-radius: 5px;
  min-height: 26px;
}
@media (max-width: 575.98px) {
  .btn       { min-height: 44px; }
  .btn-sm    { min-height: 38px; }
  .btn-xs    { min-height: 30px; }
  /* Pulsanti blocco interi su mobile per le azioni principali */
  .btn-mobile-full { width: 100% !important; }
}

/* ── Form elements ── */
.form-control,
.form-select {
  border-radius: var(--radius-sm);
  border-color: rgba(15, 23, 42, 0.16);
  padding: 8px 12px;
  font-size: 0.9rem;
  line-height: 1.5;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.form-control:focus,
.form-select:focus {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.13);
}
/* Previene lo zoom automatico iOS su focus degli input */
@media (max-width: 767.98px) {
  .form-control,
  .form-select,
  .form-control-sm,
  .form-select-sm,
  input[type="text"],
  input[type="password"],
  input[type="email"],
  input[type="datetime-local"],
  input[type="date"],
  textarea {
    font-size: 16px !important;
  }
}
.form-label {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--dark-color);
  margin-bottom: 4px;
}
.form-text {
  font-size: 0.78rem;
  color: var(--text-muted);
}
.input-group-text {
  border-color: rgba(15, 23, 42, 0.16);
  background: #f8fafc;
  border-radius: var(--radius-sm);
}

/* ── Badges ── */
.badge {
  font-weight: 600;
  padding: 4px 9px;
  border-radius: 6px;
  letter-spacing: 0.01em;
}

/* ── Alerts ── */
.alert {
  border-radius: var(--radius-sm);
  border-width: 1px;
  padding: 0.75rem 1rem;
  font-size: 0.88rem;
}

/* ── Modals – bottom-sheet su schermi piccoli ── */
@media (max-width: 575.98px) {
  /* Dialog non-centrati: scorri dal basso */
  .modal-dialog:not(.modal-dialog-centered):not(.modal-fullscreen) {
    margin: 0;
    max-width: 100%;
  }
  .modal-dialog:not(.modal-dialog-centered):not(.modal-fullscreen) .modal-content {
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    border: none;
  }
  /* Dialog centrati (hub paziente, NEMS, ecc.): rimangono centrati ma più larghi */
  .modal-dialog-centered {
    margin: auto 0.5rem;
    max-width: calc(100% - 1rem);
  }
  .modal-dialog-centered .modal-content {
    border-radius: var(--radius-lg);
  }
  .modal-dialog.modal-sm {
    max-width: calc(100% - 2rem);
    margin: auto 1rem;
  }
  /* Modal scrollabile: max altezza 85% schermo */
  .modal-dialog-scrollable {
    max-height: 85vh;
  }
  /* Body del modal: aggiunge padding-bottom per safe area */
  .modal-body {
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  }
}

/* ── Sticky Columns for Shift Grid ── */
.grid-table {
  border-collapse: separate !important;
  border-spacing: 0;
}
.grid-table th, .grid-table td {
  border: 1px solid #cbd5e1;
}
.grid-table td.daycol { font-weight: 700; }
.grid-table .sticky-col-1 {
  position: sticky !important;
  left: 0 !important;
  z-index: 10 !important;
  background-color: #f1f5f9 !important;
  min-width: 32px !important;
  max-width: 32px !important;
  width: 32px !important;
  box-shadow: 2px 0 0 rgba(0,0,0,0.05);
}
.grid-table .sticky-col-2 {
  position: sticky !important;
  left: 32px !important;
  z-index: 10 !important;
  background-color: #f1f5f9 !important;
  min-width: 44px !important;
  max-width: 44px !important;
  width: 44px !important;
  box-shadow: 2px 0 0 rgba(0,0,0,0.05);
  border-right: 2px solid #64748b !important;
}
.grid-table thead .sticky-col-1,
.grid-table thead .sticky-col-2 {
  z-index: 25 !important;
}

/* ── Flags column ── */
.flags-col { white-space: nowrap; }
.flags-col .badge { font-size: 0.68rem; padding: 4px 8px; border-radius: 6px; }

/* ── Responsive spacing ── */
@media (max-width: 767.98px) {
  .container-fluid {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }
}
@media (max-width: 575.98px) {
  .container-fluid {
    padding-left: 0.6rem;
    padding-right: 0.6rem;
  }
  h2 {
    font-size: 1.1rem;
    font-weight: 700;
  }
  .kpi-number {
    font-size: 1.8rem;
  }
}

/* ── Print Styles ── */
@media print {
  body {
    background-color: #ffffff !important;
    font-size: 0.85rem !important;
    color: #000000 !important;
    padding-bottom: 0 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  .d-print-none,
  nav, .navbar, .bottom-nav, .btn,
  form, .modal, .card-header .btn, a[href*="edit"] {
    display: none !important;
  }
  .container, .container-fluid {
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }
  .card {
    border: 1px solid #cbd5e1 !important;
    box-shadow: none !important;
    margin-bottom: 1rem !important;
    page-break-inside: avoid;
  }
  .table-responsive { overflow: visible !important; }
  table { width: 100% !important; page-break-inside: auto; }
  tr { page-break-inside: avoid !important; page-break-after: auto !important; }
  canvas { max-width: 100% !important; height: auto !important; }
  .page-break-before {
    page-break-before: always !important;
  }
}

/* ── Telegram WebApp Theme Overrides ── */
html.is-webapp body {
  background-color: var(--tg-theme-bg-color, var(--light-bg)) !important;
  color: var(--tg-theme-text-color, var(--text-main)) !important;
  /* Spazio per la bottom-nav + safe area del dispositivo */
  padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px)) !important;
}

/* La navbar in alto resta nascosta (Telegram ha già la sua barra),
   ma la bottom-nav serve per muoversi fra le sezioni con un tap. */
html.is-webapp nav.navbar {
  display: none !important;
}
@media (max-width: 991.98px) {
  html.is-webapp nav.bottom-nav {
    display: flex !important;
    background: var(--tg-theme-secondary-bg-color, rgba(255, 255, 255, 0.95));
  }
}

html.is-webapp .container-fluid {
  padding-top: 12px !important;
}

/* Le barre sticky in basso (salva disponibilità, ecc.) devono stare sopra
   la safe area di Telegram e non sparire dietro la gesture bar di iPhone */
html.is-webapp .position-sticky.bottom-0 {
  padding-bottom: env(safe-area-inset-bottom, 0px) !important;
  /* Assicura che rimanga sopra eventuali elementi nativi */
  z-index: 100;
}

html.is-webapp .card {
  background-color: var(--tg-theme-secondary-bg-color, var(--surface)) !important;
  border-color: rgba(15, 23, 42, 0.08) !important;
  color: var(--tg-theme-text-color, var(--text-main)) !important;
}

html.is-webapp .card-header {
  background-color: var(--tg-theme-secondary-bg-color, var(--surface)) !important;
  color: var(--tg-theme-text-color, var(--dark-color)) !important;
  border-bottom: 1.5px solid rgba(15, 23, 42, 0.08) !important;
}

html.is-webapp .btn-primary {
  background-color: var(--tg-theme-button-color, var(--primary-brand)) !important;
  border-color: var(--tg-theme-button-color, var(--primary-brand)) !important;
  color: var(--tg-theme-button-text-color, #ffffff) !important;
}

html.is-webapp .btn-outline-primary {
  color: var(--tg-theme-button-color, var(--primary-brand)) !important;
  border-color: var(--tg-theme-button-color, var(--primary-brand)) !important;
}

html.is-webapp .btn-outline-primary:hover {
  background-color: var(--tg-theme-button-color, var(--primary-brand)) !important;
  color: var(--tg-theme-button-text-color, #ffffff) !important;
}

html.is-webapp a {
  color: var(--tg-theme-link-color, var(--primary-brand));
}

html.is-webapp .text-muted,
html.is-webapp .small {
  color: var(--tg-theme-hint-color, var(--text-muted)) !important;
}

html.is-webapp .table th {
  background-color: var(--tg-theme-secondary-bg-color, #f8fafc) !important;
  color: var(--tg-theme-hint-color, var(--text-muted)) !important;
}

html.is-webapp .table td {
  color: var(--tg-theme-text-color, var(--text-main)) !important;
}

/* ── Login Redesign & Branding ── */
/* Card Logo */
.curanda-card-logo {
  height: 54px;
  width: auto;
}
.hrnurse-card-logo {
  height: 58px;
  width: auto;
  margin-right: 12px;
  filter: drop-shadow(0 4px 12px rgba(30, 58, 138, 0.18));
}
.hrnurse-card-title {
  font-size: 2.2rem;
  font-weight: 850;
  line-height: 1;
  letter-spacing: -0.04em;
  background: linear-gradient(130deg, #1e3a8a 0%, #3b82f6 60%, #60a5fa 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.hrnurse-card-title span {
  font-weight: 300;
}
