:root {
    --bg: #f7f3ed;
    --surface: #fffdfa;
    --surface-soft: #fbf6ee;
    --text: #20201d;
    --muted: #6c665f;
    --line: #e5d9ca;
    --brand: #8b5f3e;
    --brand-dark: #553824;
    --olive: #51604a;
    --ink: #252b28;
    --success: #25704f;
    --danger: #a33d31;
    --shadow: 0 22px 55px rgba(67, 51, 38, 0.12);
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    background:
        linear-gradient(120deg, rgba(81, 96, 74, 0.08), transparent 34%),
        linear-gradient(180deg, #f8f4ee 0%, #eee5d9 100%);
    font-family: "Inter", "Noto Sans Thai", system-ui, sans-serif;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
textarea,
select {
    font: inherit;
}

.page-shell,
.admin-wrap {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
}

.page-shell {
    padding: 22px 0 34px;
}

.admin-wrap {
    padding: 24px 0 40px;
}

.site-header,
.admin-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 18px;
}

.logo-block {
    display: inline-flex;
    align-items: center;
    gap: 12px;
}

.logo-block strong {
    display: block;
    font-size: 24px;
    line-height: 1.1;
}

.logo-mark {
    display: grid;
    width: 48px;
    height: 48px;
    place-items: center;
    border-radius: 14px;
    color: #fff;
    background: linear-gradient(135deg, var(--brand), var(--brand-dark));
    font-weight: 800;
    letter-spacing: 0;
    box-shadow: 0 14px 30px rgba(85, 56, 36, 0.2);
}

.eyebrow {
    display: block;
    margin: 0 0 5px;
    color: var(--brand);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    gap: 9px;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 11px 16px;
    cursor: pointer;
    color: #fff;
    background: linear-gradient(135deg, var(--brand), var(--brand-dark));
    font-weight: 800;
    box-shadow: 0 12px 24px rgba(85, 56, 36, 0.2);
    transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.button:hover {
    transform: translateY(-1px);
    box-shadow: 0 16px 30px rgba(85, 56, 36, 0.24);
}

.button-light,
.button-outline {
    color: var(--ink);
    background: rgba(255, 253, 250, 0.9);
    border-color: var(--line);
    box-shadow: none;
}

.button-outline:hover,
.button-light:hover {
    border-color: rgba(139, 95, 62, 0.45);
}

.hero-section {
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(300px, 0.75fr);
    gap: 24px;
    align-items: stretch;
    min-height: 430px;
    padding: 34px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background:
        linear-gradient(rgba(37, 43, 40, 0.52), rgba(37, 43, 40, 0.25)),
        url("https://images.unsplash.com/photo-1555041469-a586c61ea9bc?auto=format&fit=crop&w=1600&q=80") center/cover;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.portal-hero {
    min-height: 300px;
    padding: 26px;
}

.portal-hero .hero-copy h1 {
    max-width: 700px;
    font-size: clamp(34px, 4vw, 54px);
}

.portal-hero .lead {
    max-width: 700px;
    margin-top: 12px;
    font-size: 15px;
    line-height: 1.65;
}

.portal-hero .hero-actions {
    margin-top: 18px;
}

.portal-hero .summary-card {
    padding: 16px;
}

.portal-hero .summary-card p {
    margin-bottom: 0;
}

.portal-hero .metric-grid > div {
    padding: 14px 16px;
}

.hero-copy {
    align-self: end;
    max-width: 720px;
    color: #fff;
}

.hero-copy .eyebrow {
    color: #f2d8bc;
}

.hero-copy h1,
.section-heading h2,
.admin-title,
.panel-heading h2,
.empty-state h3 {
    margin: 0;
    letter-spacing: 0;
    line-height: 1.08;
}

.hero-copy h1 {
    max-width: 780px;
    font-size: clamp(38px, 5.2vw, 68px);
    font-weight: 800;
}

.lead {
    max-width: 720px;
    margin: 16px 0 0;
    color: rgba(255, 255, 255, 0.88);
    font-size: 17px;
    line-height: 1.8;
}

.hero-actions,
.top-actions,
.form-actions,
.table-actions,
.badge-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.hero-actions {
    margin-top: 24px;
}

.hero-summary {
    display: grid;
    gap: 14px;
    align-content: end;
}

.summary-card,
.metric-grid > div,
.panel,
.empty-state,
.module-card,
.notice {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 253, 250, 0.94);
}

.summary-card {
    padding: 20px;
}

.summary-icon,
.module-icon,
.row-icon,
.empty-icon {
    display: grid;
    place-items: center;
    color: #fff;
    background: linear-gradient(135deg, var(--olive), var(--ink));
}

.summary-icon {
    width: 48px;
    height: 48px;
    margin-bottom: 14px;
    border-radius: 8px;
}

.summary-card strong {
    display: block;
    font-size: 20px;
}

.summary-card p,
.section-heading p,
.module-description,
.admin-note,
.table-cell-muted,
.empty-state p,
.metric-grid span {
    color: var(--muted);
    line-height: 1.7;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.metric-grid.single-metric {
    grid-template-columns: 1fr;
}

.metric-grid > div {
    padding: 16px;
}

.metric-grid strong {
    display: block;
    font-size: 30px;
    line-height: 1;
}

.metric-grid span {
    display: block;
    margin-top: 8px;
    font-size: 13px;
}

.section-heading {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    margin: 30px 0 16px;
}

.section-heading h2 {
    font-size: clamp(26px, 3vw, 40px);
}

.section-heading p {
    max-width: 520px;
    margin: 0;
}

.link-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}

.module-card {
    display: flex;
    gap: 15px;
    align-items: flex-start;
    min-height: 142px;
    padding: 20px;
    box-shadow: 0 14px 36px rgba(67, 51, 38, 0.08);
    transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.module-card:hover {
    transform: translateY(-3px);
    border-color: rgba(139, 95, 62, 0.42);
    box-shadow: 0 22px 45px rgba(67, 51, 38, 0.13);
}

.module-icon,
.row-icon {
    flex: 0 0 auto;
    width: 52px;
    height: 52px;
    border-radius: 8px;
    overflow: hidden;
}

.module-icon img,
.row-icon img,
.summary-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.module-body {
    min-width: 0;
}

.module-title {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    font-size: 18px;
    font-weight: 800;
    line-height: 1.35;
}

.module-title i {
    margin-top: 4px;
    color: var(--brand);
    font-size: 14px;
}

.module-description {
    display: block;
    margin-top: 8px;
    overflow-wrap: anywhere;
}

.site-footer {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-top: 22px;
    padding: 18px 0 0;
    color: var(--muted);
    font-size: 14px;
}

.admin-layout {
    display: grid;
    grid-template-columns: minmax(320px, 410px) minmax(0, 1fr);
    gap: 18px;
    align-items: start;
}

.panel {
    padding: 22px;
    box-shadow: var(--shadow);
}

.admin-title {
    font-size: clamp(30px, 4vw, 44px);
}

.admin-note {
    margin: 8px 0 0;
}

.form-grid {
    display: grid;
    gap: 14px;
    margin-top: 18px;
}

.field label {
    display: block;
    margin-bottom: 7px;
    font-size: 13px;
    font-weight: 800;
}

.field input,
.field textarea,
.field select {
    width: 100%;
    border: 1px solid #dacdbc;
    border-radius: 8px;
    padding: 12px 13px;
    background: #fff;
    color: var(--text);
    outline: none;
}

.field input[type="file"] {
    padding: 10px;
}

.field-help {
    margin: 7px 0 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.6;
}

.image-preview {
    display: grid;
    gap: 10px;
    margin-bottom: 10px;
}

.image-preview img {
    width: 76px;
    height: 76px;
    object-fit: cover;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.checkbox-line {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.checkbox-line input {
    width: auto;
}

.field textarea {
    min-height: 96px;
    resize: vertical;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 4px rgba(139, 95, 62, 0.12);
}

.two-columns {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.panel-heading {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    margin-bottom: 14px;
}

.panel-heading h2 {
    font-size: 24px;
}

.panel-heading.small {
    margin: 0 0 10px;
}

.panel-heading.small h2 {
    font-size: 19px;
}

.count-badge,
.badge {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    border-radius: 999px;
    padding: 6px 10px;
    color: var(--brand-dark);
    background: #f1e4d5;
    font-size: 12px;
    font-weight: 800;
}

.badge-success {
    color: var(--success);
    background: rgba(37, 112, 79, 0.12);
}

.badge-danger {
    color: var(--danger);
    background: rgba(163, 61, 49, 0.12);
}

.table-list {
    display: grid;
    gap: 12px;
}

.table-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-soft);
}

.row-main {
    display: flex;
    gap: 12px;
    min-width: 0;
}

.row-main strong,
.table-cell-muted {
    display: block;
    overflow-wrap: anywhere;
}

.table-cell-muted {
    margin-top: 2px;
    font-size: 13px;
}

.badge-row {
    margin-top: 9px;
}

.table-actions {
    justify-content: flex-end;
}

.table-actions form {
    margin: 0;
}

.icon-button {
    display: inline-grid;
    width: 40px;
    height: 40px;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--ink);
    background: #fff;
    cursor: pointer;
}

.icon-button.danger {
    color: var(--danger);
}

.notice {
    padding: 13px 15px;
    margin-bottom: 16px;
}

.notice-success {
    color: var(--success);
    border-color: rgba(37, 112, 79, 0.24);
    background: rgba(37, 112, 79, 0.1);
}

.notice-danger {
    color: var(--danger);
    border-color: rgba(163, 61, 49, 0.24);
    background: rgba(163, 61, 49, 0.1);
}

.empty-state {
    padding: 38px 22px;
    text-align: center;
    box-shadow: var(--shadow);
}

.empty-state.compact {
    box-shadow: none;
    padding: 28px 18px;
}

.empty-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 14px;
    border-radius: 8px;
    font-size: 24px;
}

.empty-state h3 {
    font-size: 24px;
}

.auth-page {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 24px 16px;
}

.auth-card {
    width: min(520px, 100%);
}

.auth-card .logo-block {
    margin-bottom: 24px;
}

@media (max-width: 960px) {
    .hero-section,
    .admin-layout {
        grid-template-columns: 1fr;
    }

    .link-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .section-heading {
        display: block;
    }

    .section-heading p {
        margin-top: 10px;
    }
}

@media (max-width: 640px) {
    .page-shell,
    .admin-wrap {
        width: min(100% - 20px, 100%);
        padding-top: 12px;
    }

    .site-header,
    .admin-top,
    .site-footer,
    .panel-heading,
    .table-row {
        align-items: flex-start;
        flex-direction: column;
    }

    .site-header,
    .admin-top,
    .site-footer {
        display: flex;
    }

    .hero-section,
    .panel {
        padding: 18px;
    }

    .hero-section {
        min-height: 560px;
    }

    .hero-copy h1 {
        font-size: 36px;
    }

    .link-grid,
    .metric-grid,
    .two-columns {
        grid-template-columns: 1fr;
    }

    .module-card,
    .row-main {
        align-items: flex-start;
    }

    .table-row {
        display: grid;
        grid-template-columns: 1fr;
    }

    .table-actions {
        justify-content: flex-start;
    }
}
