/* =========================================================
   Dashboard 2569 — Responsive UI/UX (Desktop + Mobile)
   ========================================================= */

:root {
  --dash-primary: #0F4C81;
  --dash-secondary: #176B9C;
  --dash-accent: #F59E0B;
  --dash-success: #10B981;
  --dash-bg: #F4F7FB;
  --dash-text: #17324D;
  --dash-muted: #5A6F85;
  --dash-card: #ffffff;
  --dash-border: #E2E8F0;
  --dash-shadow: 0 8px 24px rgba(15, 76, 129, 0.08);
  --dash-radius: 14px;
  --dash-hero-from: #0F4C81;
  --dash-hero-to: #176B9C;
  --dash-pad-x: clamp(12px, 2.5vw, 28px);
  --dash-max: 1280px;
  --dash-touch: 44px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  overflow-x: hidden;
  background: var(--dash-bg);
}

/* ----- Layout: nav / hero / content / footer ----- */
.container-main.dashboard-layout {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto auto 1fr auto;
  grid-template-areas:
    "nav"
    "main"
    "content"
    "footer";
  min-height: 100vh;
  width: 100%;
  max-width: 100%;
  background: var(--dash-bg);
  gap: 0;
}

.dashboard-layout > nav { grid-area: nav; }
.dashboard-layout > main { grid-area: main; }
.dashboard-layout > footer { grid-area: footer; }

#dashboard-content {
  grid-area: content;
  width: 100%;
  max-width: var(--dash-max);
  margin: 0 auto;
  padding: 8px var(--dash-pad-x) 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

#dashboard-content[hidden] {
  display: none !important;
}

#dashboard-content[aria-busy="true"] {
  opacity: 0.4;
  pointer-events: none;
}

/* ----- Nav mobile polish (override) ----- */
.dashboard-layout nav {
  position: sticky;
  top: 0;
  z-index: 1000;
  width: 100%;
  overflow: visible;
}

.dashboard-layout nav ul {
  z-index: 1001;
}

.dashboard-layout .checkbtn {
  min-width: var(--dash-touch);
  min-height: var(--dash-touch);
  display: none;
  align-items: center;
  justify-content: center;
  margin-right: 12px;
  line-height: 1;
}

/* ----- Hero ----- */
.dashboard-layout main {
  background: linear-gradient(135deg, var(--dash-hero-from) 0%, var(--dash-hero-to) 55%, #2a5298 100%);
  padding: clamp(18px, 3vw, 32px) var(--dash-pad-x);
  min-height: auto;
}

.dashboard-layout .main-content {
  max-width: var(--dash-max);
  margin: 0 auto;
  flex-direction: column;
  align-items: stretch;
}

.dashboard-layout .text-header {
  font-size: clamp(0.95rem, 1.6vw, 1.2rem);
  max-width: 900px;
  margin: 0 auto;
  line-height: 1.65;
  word-break: break-word;
}

.dashboard-layout .text-header--course {
  margin-top: 10px !important;
  font-size: clamp(0.85rem, 1.4vw, 1.05rem) !important;
  font-weight: 500 !important;
  opacity: 0.97;
}

.dash-hero-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 14px;
}

.dash-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: clamp(0.78rem, 1.2vw, 0.9rem);
  font-weight: 500;
  max-width: 100%;
}

.dash-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 16px;
}

.dash-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 10px;
  min-height: var(--dash-touch);
  padding: 10px 18px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.dash-btn:focus-visible {
  outline: 3px solid var(--dash-accent);
  outline-offset: 2px;
}

@media (hover: hover) {
  .dash-btn:hover {
    transform: translateY(-2px);
  }
}

.dash-btn-primary {
  background: var(--dash-accent);
  color: #1a1a1a;
  box-shadow: 0 6px 16px rgba(245, 158, 11, 0.35);
}

.dash-btn-ghost {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.4);
}

/* ----- Section cards ----- */
.dash-section {
  background: var(--dash-card);
  border-radius: var(--dash-radius);
  margin: 0;
  padding: clamp(16px, 2.2vw, 28px);
  box-shadow: var(--dash-shadow);
  border: 1px solid var(--dash-border);
  width: 100%;
}

.dash-section .titleChat {
  border-left-color: var(--dash-primary);
  background: linear-gradient(90deg, rgba(15, 76, 129, 0.1) 0%, transparent 100%);
  color: var(--dash-text);
  text-align: left;
  font-size: clamp(1.05rem, 1.8vw, 1.3rem) !important;
  margin: 0 0 8px 0;
  word-break: break-word;
}

.dash-section-sub {
  color: var(--dash-muted);
  font-size: clamp(0.82rem, 1.3vw, 0.95rem);
  margin: 0 0 16px 0;
  text-align: left;
  padding-left: 12px;
  line-height: 1.5;
}

/* ----- KPI Cards ----- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.kpi-card {
  position: relative;
  overflow: hidden;
  border-radius: 12px;
  padding: 18px 16px;
  color: #fff;
  min-height: 132px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
  transition: transform 0.25s ease;
}

@media (hover: hover) {
  .kpi-card:hover {
    transform: translateY(-4px);
  }
}

.kpi-card::after {
  content: "";
  position: absolute;
  right: -20px;
  bottom: -20px;
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  pointer-events: none;
}

.kpi-card--participants { background: linear-gradient(135deg, #0F4C81, #176B9C); }
.kpi-card--satisfaction { background: linear-gradient(135deg, #0d9488, #10B981); }
.kpi-card--outcome { background: linear-gradient(135deg, #b45309, #F59E0B); }
.kpi-card--labor { background: linear-gradient(135deg, #1e3a8a, #3b82f6); }

.kpi-label {
  display: block;
  font-size: 0.88rem;
  font-weight: 500;
  opacity: 0.95;
  margin-bottom: 8px;
  padding-right: 28px;
  line-height: 1.35;
}

.kpi-value {
  display: block;
  font-size: clamp(1.45rem, 2.4vw, 2rem);
  font-weight: 700;
  line-height: 1.2;
}

.kpi-sub {
  display: block;
  margin-top: 8px;
  font-size: 0.8rem;
  opacity: 0.92;
  line-height: 1.4;
}

.kpi-icon {
  position: absolute;
  top: 14px;
  right: 14px;
  font-size: 1.45rem;
  opacity: 0.85;
}

/* ----- Chart panels ----- */
.chart-grid {
  display: grid;
  grid-template-columns: 1.15fr 0.9fr 1fr;
  gap: 14px;
  align-items: stretch;
}

.chart-panel {
  background: #f8fafc;
  border: 1px solid var(--dash-border);
  border-radius: 12px;
  padding: 14px;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.chart-panel h4 {
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--dash-text);
  margin: 0 0 10px 0;
  text-align: left;
}

.chart-wrap {
  position: relative;
  width: 100%;
  min-height: 220px;
  flex: 1;
}

.chart-wrap--donut {
  min-height: 200px;
  max-width: 280px;
  margin: 0 auto;
  width: 100%;
}

.chart-wrap canvas {
  max-width: 100% !important;
  height: auto !important;
}

.legend-list {
  list-style: none;
  padding: 0;
  margin: 10px 0 0;
  text-align: left;
}

.legend-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  color: var(--dash-text);
  margin-bottom: 6px;
  font-weight: 500;
  line-height: 1.35;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ----- Satisfaction ranking ----- */
.rank-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 10px;
}

.rank-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
  text-align: left;
  min-width: 520px;
}

.rank-table th,
.rank-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--dash-border);
  color: var(--dash-text);
  vertical-align: middle;
}

.rank-table th {
  background: rgba(15, 76, 129, 0.06);
  font-weight: 600;
  white-space: nowrap;
  position: sticky;
  top: 0;
}

.rank-table tbody tr:hover {
  background: rgba(15, 76, 129, 0.04);
}

.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--dash-primary);
  color: #fff;
  font-weight: 700;
  font-size: 0.9rem;
}

.rank-badge--top {
  background: var(--dash-accent);
  color: #1a1a1a;
}

.level-badge {
  display: inline-block;
  background: rgba(16, 185, 129, 0.15);
  color: #047857;
  border: 1px solid rgba(16, 185, 129, 0.35);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
}

.score-cell {
  font-weight: 700;
  color: var(--dash-primary);
  white-space: nowrap;
}

.avg-row {
  background: rgba(15, 76, 129, 0.06);
  font-weight: 700;
}

/* Mobile rank cards (shown < 640px) */
.rank-cards {
  display: none;
  flex-direction: column;
  gap: 10px;
}

.rank-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px 12px;
  align-items: start;
  background: #f8fafc;
  border: 1px solid var(--dash-border);
  border-radius: 12px;
  padding: 14px;
  text-align: left;
}

.rank-card__label {
  grid-column: 2 / 3;
  font-weight: 600;
  color: var(--dash-text);
  font-size: 0.92rem;
  line-height: 1.4;
}

.rank-card__meta {
  grid-column: 3 / 4;
  grid-row: 1 / 3;
  text-align: right;
  align-self: center;
}

.rank-card__score {
  display: block;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--dash-primary);
}

.rank-card__percent {
  display: block;
  font-size: 0.82rem;
  color: var(--dash-muted);
  margin-top: 2px;
}

.rank-card--avg {
  background: rgba(15, 76, 129, 0.06);
  border-color: rgba(15, 76, 129, 0.2);
  grid-template-columns: 1fr auto;
}

.rank-card--avg .rank-card__label {
  grid-column: 1;
}

/* ----- Progress bars ----- */
.progress-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.progress-item {
  text-align: left;
}

.progress-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.progress-label {
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--dash-text);
  flex: 1 1 180px;
  line-height: 1.4;
}

.progress-meta {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--dash-primary);
  white-space: nowrap;
  flex: 0 0 auto;
}

.progress-track {
  width: 100%;
  height: 12px;
  background: #e8eef5;
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--dash-primary), var(--dash-secondary));
  transition: width 0.9s ease;
}

.progress-fill--outcome {
  background: linear-gradient(90deg, #b45309, var(--dash-accent));
}

.progress-fill--labor {
  background: linear-gradient(90deg, #1e3a8a, #3b82f6);
}

.progress-summary {
  margin-top: 18px;
  padding: 14px 16px;
  border-radius: 10px;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.25);
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: center;
  justify-content: space-between;
  text-align: left;
}

.progress-summary strong {
  color: var(--dash-text);
  font-size: clamp(0.95rem, 1.5vw, 1.05rem);
  line-height: 1.4;
}

/* ----- States ----- */
.dash-state {
  display: none;
  grid-area: content;
  text-align: center;
  padding: 48px 20px;
  margin: 16px var(--dash-pad-x);
  border-radius: var(--dash-radius);
  background: var(--dash-card);
  box-shadow: var(--dash-shadow);
  color: var(--dash-text);
  max-width: var(--dash-max);
  width: calc(100% - (var(--dash-pad-x) * 2));
  justify-self: center;
}

.dash-state.is-visible {
  display: block;
}

.dash-state i {
  font-size: 2.5rem;
  color: var(--dash-secondary);
  display: block;
  margin-bottom: 12px;
}

.dash-state--error i { color: #dc2626; }

.dash-spinner {
  width: 42px;
  height: 42px;
  border: 4px solid #dbe7f3;
  border-top-color: var(--dash-primary);
  border-radius: 50%;
  margin: 0 auto 14px;
  animation: dash-spin 0.8s linear infinite;
}

@keyframes dash-spin {
  to { transform: rotate(360deg); }
}

.dashboard-layout footer {
  width: 100%;
}

.dashboard-layout footer p {
  word-break: break-word;
  padding: 0 8px;
  font-size: clamp(0.85rem, 1.4vw, 1rem);
}

/* =========================================================
   Breakpoints: 1366 / 1024 / 768 / 540 / 375
   ========================================================= */

/* Large desktop comfort */
@media (min-width: 1400px) {
  :root { --dash-max: 1360px; }
}

/* Laptop / small desktop */
@media (max-width: 1200px) {
  .chart-grid {
    grid-template-columns: 1fr 1fr;
  }

  .chart-grid .chart-panel:last-child {
    grid-column: 1 / -1;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Tablet */
@media (max-width: 992px) {
  .dashboard-layout .checkbtn {
    display: inline-flex !important;
  }

  .dashboard-layout nav {
    height: 56px !important;
    overflow: visible !important;
  }

  .dashboard-layout label.logo {
    line-height: 56px !important;
    padding: 0 10px !important;
  }

  .dashboard-layout label.logo .imglogo {
    width: 42px !important;
    height: 42px !important;
  }

  .dashboard-layout nav ul {
    position: fixed;
    width: min(100%, 360px);
    max-width: 100%;
    height: calc(100vh - 56px);
    height: calc(100dvh - 56px);
    background: #1e3c72;
    top: 56px;
    right: 0;
    left: auto !important;
    transform: translateX(105%);
    text-align: left;
    transition: transform 0.3s ease;
    z-index: 1001;
    margin: 0 !important;
    padding: 16px 0 32px;
    float: none !important;
    box-shadow: -8px 0 24px rgba(0, 0, 0, 0.25);
    overflow-y: auto;
  }

  .dashboard-layout nav ul li {
    display: block !important;
    margin: 0 !important;
    line-height: 1.3 !important;
  }

  .dashboard-layout nav ul li a {
    display: block;
    padding: 14px 22px !important;
    font-size: 1rem !important;
    border-radius: 0 !important;
    min-height: var(--dash-touch);
  }

  .dashboard-layout #check:checked ~ ul {
    transform: translateX(0);
    left: auto !important;
  }

  /* Backdrop when menu open */
  .dashboard-layout #check:checked ~ .checkbtn::after {
    content: "";
    position: fixed;
    inset: 56px 0 0 0;
    background: rgba(15, 30, 50, 0.45);
    z-index: 1000;
  }

  .chart-grid {
    grid-template-columns: 1fr;
  }

  .chart-grid .chart-panel:last-child {
    grid-column: auto;
  }

  .chart-wrap {
    min-height: 240px;
  }

  .chart-wrap--donut {
    max-width: 240px;
    min-height: 220px;
  }
}

/* Mobile landscape / large phone */
@media (max-width: 768px) {
  #dashboard-content {
    padding: 6px 10px 20px;
    gap: 12px;
  }

  .dash-section {
    border-radius: 12px;
    padding: 14px 12px;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .kpi-card {
    min-height: 118px;
    padding: 14px 12px;
  }

  .kpi-label {
    font-size: 0.78rem;
    padding-right: 22px;
  }

  .kpi-sub {
    font-size: 0.72rem;
  }

  .kpi-icon {
    font-size: 1.2rem;
    top: 10px;
    right: 10px;
  }

  .dash-toolbar {
    width: 100%;
  }

  .dash-btn {
    flex: 1 1 auto;
    min-width: min(100%, 160px);
  }

  .dash-section-sub {
    padding-left: 8px;
  }
}

/* Mobile portrait */
@media (max-width: 640px) {
  .rank-table-wrap {
    display: none;
  }

  .rank-cards {
    display: flex;
  }

  .progress-head {
    flex-direction: column;
    gap: 4px;
  }

  .progress-meta {
    white-space: normal;
  }

  .progress-track {
    height: 10px;
  }

  .progress-summary {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 540px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .kpi-card {
    min-height: auto;
  }

  .dashboard-layout .text-header {
    padding: 12px !important;
  }

  .dash-chip {
    font-size: 0.75rem;
    padding: 5px 10px;
  }

  .chart-wrap {
    min-height: 200px;
  }

  .dash-btn {
    width: 100%;
  }

  .dashboard-layout footer {
    padding: 16px 8px !important;
  }
}

/* Very small phones */
@media (max-width: 375px) {
  :root { --dash-pad-x: 8px; }

  #dashboard-content {
    padding: 4px 8px 16px;
  }

  .dash-section .titleChat {
    font-size: 0.98rem !important;
    padding: 8px 10px;
  }

  .kpi-value {
    font-size: 1.4rem;
  }
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }

  .progress-fill {
    transition: none;
  }
}

/* ----- Print ----- */
@media print {
  @page {
    size: A4 portrait;
    margin: 12mm;
  }

  body {
    background: #fff !important;
    color: #000 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .checkbtn,
  .dash-toolbar,
  nav ul,
  #check {
    display: none !important;
  }

  nav {
    box-shadow: none !important;
    height: auto !important;
    position: static !important;
    background: #0F4C81 !important;
  }

  .container-main.dashboard-layout {
    display: block !important;
  }

  #dashboard-content {
    max-width: none;
    padding: 0;
    display: block !important;
  }

  .dash-section {
    break-inside: avoid;
    box-shadow: none !important;
    border: 1px solid #ccc !important;
    margin: 10px 0 !important;
    page-break-inside: avoid;
  }

  .kpi-card {
    box-shadow: none !important;
    break-inside: avoid;
  }

  .kpi-grid {
    grid-template-columns: 1fr 1fr !important;
  }

  .chart-grid {
    grid-template-columns: 1fr !important;
  }

  .rank-table-wrap {
    display: block !important;
    overflow: visible !important;
  }

  .rank-table {
    min-width: 0 !important;
  }

  .rank-cards {
    display: none !important;
  }

  .dash-state {
    display: none !important;
  }

  a[href]::after {
    content: none !important;
  }
}
