/*
 * NICU Risk Dashboard - Visual Styles matching the Mockup
 * Colors: White backgrounds, soft gray borders, solid primary blue (#1e68d7)
 */

@import url('https://fonts.googleapis.com/css2?family=Kanit:wght@300;400;500;600;700&family=Sarabun:wght@300;400;500;600;700&display=swap');

:root {
  /* Color Tokens */
  --primary: #1e68d7;
  --bg-app: #f4f7fc;
  --border-color: #e2eaf5;
  --text-main: #2c3e50;
  --text-muted: #8a9ba8;
  --bg-card: #ffffff;
  
  /* Status Colors */
  --near-miss: #42a5f5;
  --miss: #ef5350;
  --success: #2ecc71;
  --warning: #f1c40f;
  --purple: #9b59b6;
  --cyan: #00acc1;

  /* Shadows */
  --card-shadow: 0 8px 20px rgba(164, 185, 215, 0.2), 0 2px 4px rgba(0, 0, 0, 0.02);
  --hover-shadow: 0 16px 32px rgba(164, 185, 215, 0.35), 0 4px 8px rgba(0, 0, 0, 0.04);
}

/* Reset and Core Setup */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Sarabun', 'Kanit', sans-serif;
  background-color: var(--bg-app);
  color: var(--text-main);
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Sidebar Navigation */
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  width: 260px;
  height: 100vh;
  background-color: var(--bg-card);
  border-right: 1px solid var(--border-color);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  z-index: 100;
  box-shadow: 2px 0 10px rgba(0, 0, 0, 0.01);
}

.sidebar-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding-bottom: 24px;
  border-bottom: 1.5px dashed var(--border-color);
}

.logo-incubator {
  margin-bottom: 8px;
}

.sidebar-logo-text {
  font-family: 'Kanit', sans-serif;
  font-size: 1.6rem;
  font-weight: 700;
  color: #11346c;
  line-height: 1;
}

.sidebar-logo-sub {
  font-family: 'Kanit', sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: #5d78a2;
  margin-top: 4px;
}

.sidebar-logo-year {
  font-family: 'Kanit', sans-serif;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--primary);
  margin-top: 4px;
}

/* Sidebar Menu Items */
.sidebar-menu {
  list-style: none;
  margin-top: 24px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 12px;
  color: #4a607a;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.sidebar-item svg {
  width: 20px;
  height: 20px;
  stroke-width: 2.2;
}

.sidebar-item:hover {
  background-color: #f0f4f9;
  color: var(--primary);
}

.sidebar-item.active {
  background-color: var(--primary);
  color: #ffffff;
}

/* Sidebar Footer Card matching mockup */
.sidebar-footer-card {
  margin-top: auto;
  background-color: #eef5ff;
  border-radius: 18px;
  padding: 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  border: 1px solid #d4e5ff;
}

.footer-card-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: 'Kanit', sans-serif;
  font-size: 0.88rem;
  font-weight: 700;
  color: #1a4f9b;
  margin-bottom: 8px;
}

.footer-card-header svg {
  width: 14px;
  height: 14px;
  fill: #ff8a80;
  stroke: none;
}

.footer-baby-container {
  margin-top: 6px;
}

/* Main Dashboard Area */
.main-content {
  margin-left: 260px;
  flex: 1;
  padding: 24px 30px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  max-width: 1600px;
}

/* Header Area styling */
.top-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-title-area h1 {
  font-family: 'Kanit', sans-serif;
  font-size: 1.65rem;
  font-weight: 700;
  color: #11346c;
}

.header-title-area p {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-top: 2px;
  font-weight: 500;
}

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

/* Dropdown Filters */
.filter-select {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  color: #2c3e50;
  padding: 10px 16px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 0.88rem;
  outline: none;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0,0,0,0.01);
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: inherit;
}

.filter-select:hover {
  border-color: var(--primary);
}

/* Cards System */
.card {
  background-color: var(--bg-card);
  border-radius: 16px;
  border: 1px solid var(--border-color);
  box-shadow: var(--card-shadow);
  padding: 20px;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: var(--hover-shadow);
}

/* KPI Cards Layout (5 columns) */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 16px;
}

.kpi-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
}

.kpi-visual-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.kpi-icon-circle {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #f0f4f9;
}

.kpi-icon-circle svg {
  width: 24px;
  height: 24px;
}

/* Customized KPI circles fill */
.kpi-card:nth-child(1) .kpi-icon-circle { background-color: #eef5ff; border: 1.5px solid #d4e5ff; }
.kpi-card:nth-child(2) .kpi-icon-circle { background-color: #e8f8f0; border: 1.5px solid #d1f2e1; }
.kpi-card:nth-child(3) .kpi-icon-circle { background-color: #f5eefb; border: 1.5px solid #eddffa; }
.kpi-card:nth-child(4) .kpi-icon-circle { background-color: #fdeeee; border: 1.5px solid #fbdad9; }
.kpi-card:nth-child(5) .kpi-icon-circle { background-color: #e0f7fa; border: 1.5px solid #b2ebf2; }

.kpi-baby-avatar {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.kpi-content-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: right;
  gap: 2px;
}

.kpi-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
}

.kpi-value {
  font-family: 'Kanit', sans-serif;
  font-size: 2.1rem;
  font-weight: 700;
  color: #11346c;
  line-height: 1.1;
}

.kpi-subtext {
  font-size: 0.72rem;
  font-weight: 600;
  color: #7f8c8d;
}

.kpi-card:nth-child(2) .kpi-value { color: #2ecc71; }
.kpi-card:nth-child(3) .kpi-value { color: #9b59b6; }
.kpi-card:nth-child(4) .kpi-value { color: #ef5350; }

/* Dashboard Sections Grid (Table & Combichart) */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1.1fr;
  gap: 20px;
}

.section-title-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.section-number-icon {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background-color: var(--primary);
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 700;
  margin-right: 8px;
}

.section-title {
  font-family: 'Kanit', sans-serif;
  font-size: 1.05rem;
  font-weight: 700;
  color: #11346c;
  display: flex;
  align-items: center;
}

.btn-section-report {
  background-color: #f0f4f9;
  border: 1px solid var(--border-color);
  color: var(--primary);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  outline: none;
}

.btn-section-report svg {
  width: 14px;
  height: 14px;
}

.btn-section-report:hover {
  background-color: var(--primary);
  color: white;
}

/* Custom Table in Mockup */
.monthly-table-wrapper {
  overflow-x: auto;
  border-radius: 12px;
  border: 1px solid var(--border-color);
}

.custom-table {
  width: 100%;
  border-collapse: collapse;
  text-align: center;
  font-size: 0.82rem;
}

.custom-table th {
  background-color: var(--primary);
  color: #ffffff;
  font-weight: 600;
  padding: 10px 8px;
  font-size: 0.8rem;
}

.custom-table td {
  padding: 10px 8px;
  border-bottom: 1.2px solid #edf2f9;
  color: #3e5066;
  font-weight: 500;
}

.table-input {
  width: 50px;
  border: 1.2px solid transparent;
  background: transparent;
  text-align: center;
  font-family: inherit;
  font-size: inherit;
  font-weight: 700;
  color: inherit;
  outline: none;
  border-radius: 4px;
  padding: 2px;
  transition: all 0.15s ease;
}

.table-input:focus {
  border-color: var(--primary);
  background-color: #ffffff;
  box-shadow: 0 0 0 2.5px rgba(30, 104, 215, 0.15);
}

.table-input::-webkit-outer-spin-button,
.table-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.custom-table tbody tr:nth-child(even) {
  background-color: #fcfdfe;
}

.custom-table tbody tr:last-child {
  font-weight: 700;
  background-color: #eef3fb;
}

.custom-table tbody tr:last-child td {
  color: #11346c;
  border-bottom: none;
}

/* Chart Card Metrics */
.chart-footer-metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  border-top: 1.5px solid var(--border-color);
  padding-top: 16px;
  margin-top: 16px;
  text-align: center;
}

.metric-box {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.metric-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.metric-value {
  font-family: 'Kanit', sans-serif;
  font-size: 1.25rem;
  font-weight: 700;
  color: #11346c;
}

.metric-box.blue .metric-value { color: var(--near-miss); }
.metric-box.red .metric-value { color: var(--miss); }

/* Bottom Row Section (Section 3 Baby List) */
.baby-grid-card {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.baby-cols-row {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 8px;
  width: 100%;
}

.baby-month-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 4px;
}

.baby-month-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: #4a607a;
}

.baby-month-count {
  font-family: 'Kanit', sans-serif;
  font-size: 0.92rem;
  font-weight: 700;
  color: #11346c;
}

.baby-month-rate {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.baby-svg-container {
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease;
}

.baby-month-col:hover .baby-svg-container {
  transform: scale(1.1) translateY(-2px);
}

/* Baby greyed out for upcoming months */
.baby-month-col.upcoming {
  opacity: 0.35;
}

/* Editable Baby Grid Inputs (Page 3) */
.baby-edit-input {
  width: 48px;
  border: 1.5px solid transparent;
  background: transparent;
  text-align: center;
  font-family: 'Kanit', sans-serif;
  font-weight: 700;
  color: #11346c;
  outline: none;
  border-radius: 6px;
  padding: 2px 0;
  transition: all 0.2s ease;
  -moz-appearance: textfield;
}

.baby-edit-input::-webkit-outer-spin-button,
.baby-edit-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.baby-edit-count {
  font-size: 0.92rem;
}

.baby-edit-rate {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
}

.baby-edit-input:hover {
  border-color: #d4e5ff;
  background: #f8faff;
}

.baby-edit-input:focus {
  border-color: var(--primary);
  background: #ffffff;
  box-shadow: 0 0 0 2.5px rgba(30, 104, 215, 0.15);
}

/* Section 3 bottom bar info */
.baby-footer-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1.5px solid var(--border-color);
  padding-top: 16px;
  margin-top: 8px;
}

.baby-info-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  color: #3e5066;
}

.baby-info-item svg {
  width: 18px;
  height: 18px;
}

.baby-info-item.note-item {
  color: #e53935;
}

.baby-info-item.note-item svg {
  fill: #ff8a80;
  stroke: none;
}

/* Interactive Actions Overlay Form */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(17, 52, 108, 0.45);
  backdrop-filter: blur(6px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.modal-card {
  background-color: var(--bg-card);
  border-radius: 20px;
  border: 1px solid var(--border-color);
  box-shadow: 0 20px 50px rgba(17, 52, 108, 0.15);
  width: 460px;
  padding: 24px;
  transform: translateY(20px);
  transition: transform 0.25s ease;
}

.modal-overlay.active .modal-card {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  border-bottom: 1.5px dashed var(--border-color);
  padding-bottom: 12px;
}

.modal-title {
  font-family: 'Kanit', sans-serif;
  font-size: 1.15rem;
  font-weight: 700;
  color: #11346c;
}

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

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.form-group label {
  font-weight: 600;
  font-size: 0.8rem;
  color: #4a607a;
}

.form-control {
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background-color: #f8fafc;
  color: var(--text-main);
  font-size: 0.85rem;
  outline: none;
  font-family: inherit;
}

.form-control:focus {
  border-color: var(--primary);
  background-color: #ffffff;
  box-shadow: 0 0 0 3px rgba(30, 104, 215, 0.15);
}

.btn-submit {
  width: 100%;
  background-color: var(--primary);
  color: white;
  border: none;
  padding: 12px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  margin-top: 10px;
  box-shadow: 0 4px 10px rgba(30, 104, 215, 0.2);
}

.btn-submit:hover {
  background-color: #1652b0;
}

/* Floating FAB */
.fab-report {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background-color: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(30, 104, 215, 0.35);
  border: none;
  z-index: 90;
  transition: all 0.2s;
}

.fab-report:hover {
  transform: scale(1.08);
}

.fab-report svg {
  width: 24px;
  height: 24px;
  stroke: white;
}

/* ========== MOBILE / TABLET RESPONSIVE ========== */

/* Hamburger button — hidden on desktop */
.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 300;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.mobile-menu-btn svg {
  width: 22px;
  height: 22px;
  stroke: var(--primary);
}

/* Sidebar backdrop overlay */
.sidebar-backdrop {
  display: none;
  position: fixed;
  top: 0; left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(17, 52, 108, 0.35);
  backdrop-filter: blur(3px);
  z-index: 149;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.sidebar-backdrop.open {
  display: block;
  opacity: 1;
}

/* ----- Tablet / iPad (portrait & landscape) ----- */
@media (max-width: 1300px) {
  .kpi-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
  .baby-cols-row {
    grid-template-columns: repeat(6, 1fr);
  }
}

@media (max-width: 1024px) {
  /* Show hamburger */
  .mobile-menu-btn {
    display: flex;
  }

  /* Sidebar becomes a slide-over drawer */
  .sidebar {
    position: fixed;
    left: -280px;
    top: 0;
    width: 270px;
    height: 100vh;
    z-index: 200;
    transition: left 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: none;
    overflow-y: auto;
  }

  .sidebar.open {
    left: 0;
    box-shadow: 8px 0 30px rgba(0,0,0,0.12);
  }

  .main-content {
    margin-left: 0;
    padding: 70px 20px 24px;
  }

  .top-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .top-controls {
    width: 100%;
    flex-wrap: wrap;
  }

  .kpi-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
  }

  .baby-cols-row {
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
  }

  .baby-footer-info {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .chart-footer-metrics {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ----- Phone ----- */
@media (max-width: 768px) {
  .main-content {
    padding: 64px 12px 20px;
    gap: 16px;
  }

  .header-title-area h1 {
    font-size: 1.25rem;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .kpi-card {
    padding: 12px 14px;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .kpi-visual-stack {
    flex-direction: row;
    gap: 6px;
  }

  .kpi-content-stack {
    align-items: flex-start;
    text-align: left;
  }

  .kpi-value {
    font-size: 1.5rem;
  }

  .baby-cols-row {
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
  }

  .baby-svg-container svg {
    width: 50px !important;
    height: auto !important;
  }

  .section-title {
    font-size: 0.88rem;
  }

  .section-title-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .modal-card {
    width: calc(100vw - 24px);
    max-height: 90vh;
    overflow-y: auto;
    border-radius: 16px;
  }

  .paste-hint {
    font-size: 0.72rem;
    padding: 8px 12px;
  }

  .custom-table {
    font-size: 0.72rem;
  }

  .custom-table th, .custom-table td {
    padding: 7px 4px;
  }

  .table-input, .baby-edit-input {
    width: 40px;
    font-size: 0.72rem;
  }

  .filter-select {
    padding: 8px 10px;
    font-size: 0.78rem;
  }

  .toast-notification {
    width: calc(100vw - 32px);
    left: 16px;
    transform: translateX(0) translateY(20px);
    font-size: 0.8rem;
    padding: 12px 16px;
  }

  .toast-notification.show {
    transform: translateX(0) translateY(0);
  }
}

/* ----- Small phone ----- */
@media (max-width: 480px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .baby-cols-row {
    grid-template-columns: repeat(3, 1fr);
  }

  .chart-footer-metrics {
    grid-template-columns: 1fr 1fr;
  }
}

/* Dashboard View Toggle Panels */
.dashboard-view {
  display: none;
  animation: fadeInView 0.35s ease;
}

.dashboard-view.active {
  display: block;
}

@keyframes fadeInView {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Toast Notification */
.toast-notification {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: 14px;
  box-shadow: 0 12px 36px rgba(17, 52, 108, 0.18), 0 2px 6px rgba(0,0,0,0.04);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.88rem;
  font-weight: 600;
  color: #11346c;
  z-index: 999;
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
}

.toast-notification.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.toast-success svg { stroke: #2ecc71; }
.toast-info svg    { stroke: var(--primary); }

/* Paste Hint Bar */
.paste-hint {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: linear-gradient(135deg, #eef5ff 0%, #f0f9ff 100%);
  border: 1px dashed #90caf9;
  border-radius: 10px;
  font-size: 0.8rem;
  font-weight: 600;
  color: #4a607a;
  margin-bottom: 12px;
}

.paste-hint svg {
  width: 18px;
  height: 18px;
  stroke: var(--primary);
  flex-shrink: 0;
}

.paste-hint kbd {
  background: #ffffff;
  border: 1px solid #d4e5ff;
  border-radius: 4px;
  padding: 1px 6px;
  font-family: 'Kanit', monospace;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--primary);
}
