/**
 * Phase 6.4 — Enterprise Design System (public + admin)
 * Modern government enterprise · soft green/blue · Thai-first · accessible
 */
:root {
    --eds-green-900: #0d4f3c;
    --eds-green-700: #0d6b4f;
    --eds-green-500: #2d9a78;
    --eds-green-100: #e8f5f0;
    --eds-blue-800: #1a5f8a;
    --eds-blue-600: #3b82c4;
    --eds-blue-100: #e8f2fa;
    --eds-ink: #1e2a28;
    --eds-muted: #5c6b68;
    --eds-line: #d8e4e0;
    --eds-surface: #ffffff;
    --eds-soft: #f4f8f7;
    --eds-radius-sm: 8px;
    --eds-radius: 14px;
    --eds-radius-lg: 20px;
    --eds-shadow-sm: 0 2px 8px rgba(13, 79, 60, 0.06);
    --eds-shadow: 0 8px 28px rgba(13, 79, 60, 0.1);
    --eds-font: "Sarabun", "Noto Sans Thai", "Prompt", system-ui, sans-serif;
    --eds-font-size: 1.0625rem;
    --eds-line-height: 1.65;
    --eds-touch: 48px;
    --eds-focus: 0 0 0 3px rgba(45, 154, 120, 0.45);
}

/* —— Base typography & accessibility —— */
body.hf-public-body,
body.admin-body {
    font-family: var(--eds-font);
    font-size: var(--eds-font-size);
    line-height: var(--eds-line-height);
    color: var(--eds-ink);
}

.hf-skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 9999;
    padding: 0.75rem 1.25rem;
    background: var(--eds-green-700);
    color: #fff;
    font-weight: 600;
    border-radius: 0 0 var(--eds-radius-sm) var(--eds-radius-sm);
    text-decoration: none;
}

.hf-skip-link:focus {
    left: 0.5rem;
    top: 0.5rem;
    outline: none;
    box-shadow: var(--eds-focus);
}

:focus-visible {
    outline: 2px solid var(--eds-green-500);
    outline-offset: 2px;
}

/* —— Buttons —— */
.btn,
.hf-btn {
    min-height: 2.75rem;
    font-weight: 600;
    border-radius: var(--eds-radius-sm);
}

.btn-lg,
.btn-hf-primary,
.btn-hf-light {
    min-height: var(--eds-touch);
    padding: 0.65rem 1.35rem;
}

.btn-hf-primary,
.btn-primary {
    background: var(--eds-green-700);
    border-color: var(--eds-green-700);
}

.btn-hf-primary:hover,
.btn-primary:hover {
    background: var(--eds-green-900);
    border-color: var(--eds-green-900);
}

.btn-outline-primary {
    color: var(--eds-green-700);
    border-color: var(--eds-green-500);
}

.btn-outline-primary:hover {
    background: var(--eds-green-100);
    color: var(--eds-green-900);
}

/* —— Forms (elder-friendly) —— */
.form-control,
.form-select {
    min-height: var(--eds-touch);
    font-size: 1.05rem;
    border-radius: var(--eds-radius-sm);
    border-color: var(--eds-line);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--eds-green-500);
    box-shadow: var(--eds-focus);
}

.form-label {
    font-weight: 600;
    margin-bottom: 0.35rem;
}

/* —— Cards —— */
.hf-eds-card,
.hf-stat-card,
.hf-kpi-card,
.hf-detail-card,
.hf-project-card,
.hf-report-card,
.hf-exercise-card {
    border-radius: var(--eds-radius);
    border: 1px solid var(--eds-line);
    background: var(--eds-surface);
    box-shadow: var(--eds-shadow-sm);
}

.hf-stat-card,
.hf-kpi-card {
    padding: 1.25rem 1.35rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.hf-stat-card:hover,
.hf-kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--eds-shadow);
}

.hf-stat-card i,
.hf-kpi-card i {
    font-size: 1.5rem;
    color: var(--eds-green-700);
    margin-bottom: 0.5rem;
    display: block;
}

.hf-stat-card strong,
.hf-kpi-card strong {
    font-size: 1.35rem;
    color: var(--eds-ink);
    display: block;
}

.hf-stat-card span,
.hf-kpi-card span {
    font-size: 0.9rem;
    color: var(--eds-muted);
}

/* —— Badges & alerts —— */
.hf-badge,
.badge {
    font-weight: 600;
    border-radius: 999px;
}

.hf-alert,
.alert {
    border-radius: var(--eds-radius-sm);
    border: none;
}

/* —— Tables responsive —— */
.hf-table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--eds-radius-sm);
    border: 1px solid var(--eds-line);
}

.hf-table-responsive table {
    margin-bottom: 0;
}

@media (max-width: 767.98px) {
    .hf-table-stack thead {
        display: none;
    }

    .hf-table-stack tr {
        display: block;
        border-bottom: 1px solid var(--eds-line);
        padding: 0.75rem 0;
    }

    .hf-table-stack td {
        display: flex;
        justify-content: space-between;
        gap: 1rem;
        padding: 0.35rem 1rem;
        border: none;
    }

    .hf-table-stack td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--eds-muted);
        flex-shrink: 0;
    }
}

/* —— Search & filters —— */
.hf-search-panel {
    background: var(--eds-soft);
    border: 1px solid var(--eds-line);
    border-radius: var(--eds-radius);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}

.hf-filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.hf-filter-chip {
    display: inline-flex;
    align-items: center;
    padding: 0.35rem 0.85rem;
    border-radius: 999px;
    font-size: 0.9rem;
    font-weight: 600;
    background: var(--eds-surface);
    border: 1px solid var(--eds-line);
    color: var(--eds-muted);
}

.hf-filter-chip.is-active {
    background: var(--eds-green-100);
    border-color: var(--eds-green-500);
    color: var(--eds-green-900);
}

.hf-result-count {
    font-size: 0.95rem;
    color: var(--eds-muted);
    margin-bottom: 1rem;
}

/* —— Empty & loading —— */
.hf-empty-enterprise {
    text-align: center;
    padding: 2.5rem 1.5rem;
    border-radius: var(--eds-radius);
    border: 2px dashed var(--eds-line);
    background: var(--eds-soft);
}

.hf-empty-enterprise i {
    font-size: 2.5rem;
    color: var(--eds-muted);
    opacity: 0.7;
}

.hf-skeleton {
    background: linear-gradient(90deg, #eef2f1 25%, #f8faf9 50%, #eef2f1 75%);
    background-size: 200% 100%;
    animation: hf-skeleton 1.2s ease-in-out infinite;
    border-radius: var(--eds-radius-sm);
    min-height: 1rem;
}

@keyframes hf-skeleton {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.hf-loading-spinner {
    width: 2.5rem;
    height: 2.5rem;
    border: 3px solid var(--eds-line);
    border-top-color: var(--eds-green-700);
    border-radius: 50%;
    animation: hf-spin 0.7s linear infinite;
}

@keyframes hf-spin {
    to { transform: rotate(360deg); }
}

/* —— Hero polish —— */
.hf-hero--enterprise {
    position: relative;
    overflow: hidden;
}

.hf-hero--enterprise.hf-hero--has-bg:not(.hf-hero--has-carousel)::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(13, 79, 60, 0.88), rgba(26, 95, 138, 0.82));
    z-index: 0;
}

.hf-hero--enterprise .container {
    position: relative;
    z-index: 1;
}

.hf-hero--enterprise h1 {
    font-size: clamp(1.75rem, 4vw, 2.5rem);
    line-height: 1.25;
    font-weight: 700;
}

.hf-hero--enterprise .lead {
    font-size: clamp(1.05rem, 2.5vw, 1.2rem);
    max-width: 42rem;
}

.hf-hero-card {
    border-radius: var(--eds-radius-lg);
    box-shadow: var(--eds-shadow);
}

/* —— Dashboard preview strip —— */
.hf-dash-preview {
    background: linear-gradient(180deg, var(--eds-blue-100), var(--eds-soft));
    border-radius: var(--eds-radius);
    padding: 1.5rem;
    border: 1px solid var(--eds-line);
}

.hf-dash-preview .hf-mini-chart {
    height: 48px;
    display: flex;
    align-items: flex-end;
    gap: 4px;
}

.hf-dash-preview .hf-mini-chart span {
    flex: 1;
    background: var(--eds-green-500);
    border-radius: 4px 4px 0 0;
    opacity: 0.85;
}

/* —— Download center —— */
.hf-doc-item {
    border-radius: var(--eds-radius-sm);
    transition: background 0.15s ease;
}

.hf-doc-item:hover {
    background: var(--eds-green-100);
}

.hf-file-icon {
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--eds-radius-sm);
    background: var(--eds-blue-100);
    color: var(--eds-blue-800);
    font-size: 1.25rem;
}

.hf-file-icon--pdf { background: #fde8e8; color: #b91c1c; }
.hf-file-icon--doc { background: #e8f0fd; color: #1d4ed8; }
.hf-file-icon--xls { background: #e8f5e9; color: #047857; }

/* —— Footer —— */
.hf-footer {
    background: linear-gradient(180deg, var(--eds-green-900), #0a3d30);
}

.hf-footer-links a {
    min-height: 2.25rem;
    display: inline-flex;
    align-items: center;
}

/* —— Admin polish —— */
.admin-body {
    background: var(--eds-soft);
}

.admin-topbar {
    background: var(--eds-surface);
    border-bottom: 1px solid var(--eds-line);
    box-shadow: var(--eds-shadow-sm);
}

.hf-admin-content {
    padding-bottom: 2rem;
}

.hf-page-header {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--eds-line);
}

.hf-sticky-actions {
    position: sticky;
    bottom: 0;
    z-index: 100;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
    border-top: 1px solid var(--eds-line);
    padding: 0.75rem 1rem;
    margin: 1.5rem -1rem -1rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: flex-end;
}

.hf-toast-host {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 1090;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: min(360px, calc(100vw - 2rem));
}

.hf-toast-item {
    padding: 0.85rem 1.1rem;
    border-radius: var(--eds-radius-sm);
    background: var(--eds-surface);
    box-shadow: var(--eds-shadow);
    border-left: 4px solid var(--eds-green-700);
    font-weight: 600;
    animation: hf-toast-in 0.3s ease;
}

.hf-toast-item--error {
    border-left-color: #b91c1c;
}

@keyframes hf-toast-in {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* DataTables */
table.dataTable {
    border-radius: var(--eds-radius-sm);
    overflow: hidden;
}

.dataTables_wrapper .dataTables_filter input {
    min-height: 2.5rem;
    border-radius: var(--eds-radius-sm);
}

/* —— Mobile overflow fixes —— */
html, body {
    overflow-x: hidden;
}

.hf-chart-wrap {
    position: relative;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
}

.hf-chart-wrap canvas {
    max-width: 100% !important;
}

.modal-dialog {
    margin: 1rem auto;
    max-width: calc(100vw - 2rem);
}

img {
    max-width: 100%;
    height: auto;
}

@media (max-width: 575.98px) {
    .hf-hero-actions .btn {
        width: 100%;
    }

    .hf-detail-actions {
        flex-direction: column;
    }

    .hf-detail-actions .btn {
        width: 100%;
    }

    .admin-content {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
}

@media print {
    .hf-no-print,
    .hf-navbar,
    .hf-topbar,
    .hf-skip-link,
    .hf-toast-host {
        display: none !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
