/* สถิติ — ธีมส้มขาว เต็มหน้าจอ */
.stats-page .stats-main {
    max-width: none;
    width: 100%;
}

.stats-panel {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    padding: clamp(1.25rem, 3vw, 2rem) clamp(1.25rem, 4vw, 2.5rem);
    margin-bottom: 1.25rem;
    width: 100%;
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-md);
}

.stats-header-inner {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.stats-header-actions {
    display: flex;
    gap: 1rem;
}

.stats-header-actions .header-link {
    color: #fff;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    padding: 0.4rem 0.85rem;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.15);
}

.stats-header-actions .header-link:hover {
    background: rgba(255, 255, 255, 0.25);
}

.stats-header-actions .header-link-muted {
    background: transparent;
    opacity: 0.9;
}

.stats-header-inner {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.header-actions {
    display: flex;
    gap: 1.25rem;
}

.header-link {
    color: #fff;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    padding: 0.4rem 0.85rem;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.15);
}

.header-link:hover {
    background: rgba(255, 255, 255, 0.25);
    text-decoration: none;
}

.header-link-muted {
    background: transparent;
    opacity: 0.9;
}

.stats-login-card {
    padding: 3rem 2rem;
    max-width: 420px;
    margin: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.stats-page-title,
.stats-page-desc,
.section-title {
    line-break: strict;
    word-break: normal;
    hyphens: none;
    text-align: start;
    text-wrap: pretty;
}

.stats-page-title {
    font-size: clamp(1.25rem, 2.5vw, 1.5rem);
    font-weight: 700;
    color: var(--color-primary-dark);
    margin-bottom: 0.5rem;
}

.stats-page-desc {
    color: var(--color-text-muted);
    font-size: 0.95rem;
    margin-bottom: 1.5rem;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.login-input {
    padding: 1rem 1.15rem;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    font-family: var(--font);
    font-size: 1rem;
}

.login-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 4px rgba(234, 88, 12, 0.12);
}

.login-error {
    color: var(--color-error);
    background: var(--color-error-bg);
    padding: 0.65rem 0.85rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    margin-bottom: 1rem;
    border-left: 3px solid var(--color-error);
}

.login-hint {
    margin-top: 1.25rem;
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.login-hint code {
    background: var(--color-primary-soft);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.85em;
    color: var(--color-primary-dark);
}

.stats-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 1.25rem;
    margin-bottom: 1.5rem;
    width: 100%;
}

.stats-toolbar-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
}

.year-filter {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--color-surface);
    padding: 0.75rem 1.15rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--color-border);
}

.year-filter label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text-muted);
}

.year-filter select {
    font-family: var(--font);
    font-size: 1rem;
    font-weight: 600;
    padding: 0.45rem 2rem 0.45rem 0.85rem;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: #fff;
    color: var(--color-primary-dark);
    cursor: pointer;
}

.year-filter select:focus {
    outline: none;
    border-color: var(--color-primary);
}

.stats-empty {
    padding: 3rem;
    text-align: center;
    color: var(--color-text-muted);
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.stats-empty .btn {
    margin-top: 1.25rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.25rem;
    margin-bottom: 1.5rem;
    width: 100%;
}

.stat-card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    padding: 1.35rem 1.5rem;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.stat-card-highlight {
    background: linear-gradient(135deg, var(--color-primary-dark) 0%, var(--color-primary) 100%);
    color: #fff;
    border: none;
}

.stat-card-highlight .stat-label,
.stat-card-highlight .stat-unit {
    color: rgba(255, 255, 255, 0.9);
}

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

.stat-value {
    font-size: clamp(1.75rem, 4vw, 2.25rem);
    font-weight: 700;
    line-height: 1.2;
    color: var(--color-primary-dark);
}

.stat-card-highlight .stat-value {
    color: #fff;
}

.stat-value-text {
    font-size: 1.5rem;
}

.stat-card-improve {
    min-height: 100%;
}

.stat-improve-none {
    font-size: 1.75rem !important;
}

.stat-improve-list {
    list-style: none;
    margin: 0.35rem 0 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.stat-improve-list li {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem;
    font-size: 0.82rem;
    line-height: 1.35;
}

.stat-improve-name {
    flex: 1;
    color: var(--color-text);
    font-weight: 500;
}

.stat-improve-score {
    font-weight: 700;
    white-space: nowrap;
    font-size: 0.88rem;
}

/* รายละเอียดด้านพัฒนา */
.improvement-section {
    margin-bottom: 1.25rem;
}

.improvement-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    margin: 0;
    padding: 0;
}

.improvement-item {
    background: #fff7ed;
    border: 1px solid #fed7aa;
    border-radius: var(--radius-md);
    padding: 1rem 1.15rem;
}

.improvement-item-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 0.75rem;
}

.improvement-num {
    width: 1.5rem;
    height: 1.5rem;
    background: var(--color-primary);
    color: #fff;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.78rem;
    font-weight: 700;
    flex-shrink: 0;
}

.improvement-name {
    flex: 1;
    min-width: 0;
    color: var(--color-primary-dark);
    font-size: 1rem;
}

.improvement-avg {
    font-size: 0.88rem;
    font-weight: 700;
    white-space: nowrap;
}

.improvement-questions {
    list-style: none;
    margin: 0.75rem 0 0 2.25rem;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.improvement-questions li {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    font-size: 0.9rem;
    color: var(--color-text-muted);
    line-height: 1.45;
}

.improvement-q-score {
    font-weight: 700;
    color: #dc2626;
    white-space: nowrap;
}

.stat-unit {
    font-size: 0.82rem;
    color: var(--color-text-muted);
}

.score-high { color: #15803d; }
.score-mid { color: #ca8a04; }
.score-low { color: #dc2626; }
.score-none { color: var(--color-text-muted); }

.stat-card-highlight .score-high,
.stat-card-highlight .score-mid,
.stat-card-highlight .score-low {
    color: #fff;
}

.stats-section {
    padding: clamp(1.25rem, 3vw, 2rem) clamp(1.25rem, 4vw, 2.5rem);
    margin-bottom: 1.25rem;
    width: 100%;
}

.section-title {
    font-size: clamp(1rem, 2vw, 1.15rem);
    font-weight: 700;
    color: var(--color-primary-dark);
    margin-bottom: 1.25rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 1rem;
}

.section-num {
    font-size: 0.8rem;
    background: var(--color-primary);
    color: #fff;
    padding: 0.25rem 0.6rem;
    border-radius: 6px;
    font-weight: 600;
}

.section-avg {
    margin-left: auto;
    font-size: 0.95rem;
    font-weight: 700;
}

.charts-row {
    display: grid;
    gap: 1.25rem;
    margin-bottom: 1.25rem;
    width: 100%;
}

.charts-row-2 {
    grid-template-columns: repeat(2, 1fr);
}

.chart-card {
    overflow: hidden;
}

.chart-hint {
    font-size: 0.82rem;
    color: var(--color-text-muted);
    margin: -0.5rem 0 1rem;
}

.chart-wrap {
    position: relative;
    width: 100%;
}

.chart-wrap-bar {
    height: min(320px, 40vh);
}

.chart-wrap-radar {
    height: min(340px, 42vh);
}

.chart-wrap-horizontal {
    height: 220px;
    margin-bottom: 1rem;
}

.chart-wrap-pie {
    height: min(280px, 35vh);
}

.dim-legend {
    list-style: none;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--color-border-light);
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.65rem;
    font-size: 0.9rem;
}

.dim-legend li {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--color-primary-soft);
    border-radius: var(--radius-sm);
}

.dim-legend .dim-num {
    width: 1.4rem;
    height: 1.4rem;
    background: var(--color-primary);
    color: #fff;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    font-weight: 700;
    flex-shrink: 0;
}

.dim-legend strong {
    margin-left: auto;
    font-size: 0.95rem;
}

.stats-table-compact {
    margin-top: 0.75rem;
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}

.stats-table th,
.stats-table td {
    padding: 0.85rem 0.65rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border-light);
}

.stats-table th {
    font-weight: 600;
    color: var(--color-text-muted);
    font-size: 0.82rem;
    background: var(--color-primary-soft);
}

.stats-table tbody tr:hover {
    background: var(--color-primary-soft);
}

.stats-table tbody tr:last-child td {
    border-bottom: none;
}

.td-score {
    font-weight: 700;
    white-space: nowrap;
    width: 5rem;
}

@media (max-width: 1100px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 900px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .charts-row-2 {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .stats-section {
        padding: 1.25rem;
    }

    .section-avg {
        margin-left: 0;
    }

    .dim-legend {
        grid-template-columns: 1fr;
    }
}

/* รายการผู้ตอบ */
.respondents-section {
    margin-top: 0.5rem;
}

.respondents-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.respondents-table th:first-child,
.respondents-table td:first-child {
    width: 2.5rem;
    text-align: center;
}

.respondents-table td:nth-child(5) {
    white-space: nowrap;
}

/* ข้อเสนอแนะ */
.comments-section {
    margin-top: 0.5rem;
}

.comments-count-badge {
    margin-left: auto;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-primary);
    background: var(--color-primary-soft);
    padding: 0.25rem 0.65rem;
    border-radius: 999px;
}

.comments-empty {
    color: var(--color-text-muted);
    font-size: 0.95rem;
    padding: 0.5rem 0;
}

.comments-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-height: 520px;
    overflow-y: auto;
    padding-right: 0.25rem;
}

.comment-item {
    background: var(--color-primary-soft);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 1rem 1.15rem;
}

.comment-item-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 0.85rem;
    margin-bottom: 0.65rem;
    font-size: 0.82rem;
    color: var(--color-text-muted);
}

.comment-num {
    font-weight: 700;
    color: var(--color-primary-dark);
}

.comment-date {
    font-weight: 500;
}

.comment-meta {
    background: #fff;
    border: 1px solid var(--color-border);
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.78rem;
}

.comment-text {
    font-size: 0.95rem;
    line-height: 1.7;
    color: var(--color-text);
    white-space: pre-wrap;
    word-break: break-word;
}

@media print {
    .site-header .header-actions,
    .year-filter,
    .login-hint {
        display: none;
    }

    .stats-section,
    .stat-card {
        break-inside: avoid;
    }
}
