.gf-page {
    display: grid;
    gap: 20px;
    width: 100%;
}

/* ---------- Hero ---------- */
.gf-hero {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 20px;
    padding: 28px 32px;
    color: #fff;
    border-radius: 18px;
    background: linear-gradient(125deg, #17223b, #2859b8 62%, #168f89 130%);
    box-shadow: 0 14px 32px rgba(31, 72, 148, .2);
}

.gf-hero h1 {
    margin: 0 0 6px;
    font-family: Prompt, sans-serif;
    font-size: 28px;
}

.gf-hero p {
    margin: 0;
    color: rgba(255, 255, 255, .82);
}

.gf-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    background: rgba(255, 255, 255, .12);
    border: 1px solid rgba(255, 255, 255, .22);
    border-radius: 999px;
}

.gf-eyebrow i {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #94a3b8;
    transition: background .3s;
}

/* ไฟสถานะการดึงข้อมูลแบบเรียลไทม์ */
.gf-page[data-live="ok"] .gf-eyebrow i {
    background: #5eead4;
    animation: gf-led 2s ease-in-out infinite;
}

.gf-page[data-live="error"] .gf-eyebrow i {
    background: #f87171;
}

.gf-live-text {
    font-variant-numeric: tabular-nums;
    letter-spacing: 0;
    text-transform: none;
    font-weight: 500;
}

.gf-hero-stats {
    display: flex;
    gap: 12px;
}

.gf-hero-stats div {
    display: grid;
    min-width: 96px;
    padding: 12px 16px;
    text-align: center;
    background: rgba(255, 255, 255, .12);
    border: 1px solid rgba(255, 255, 255, .2);
    border-radius: 14px;
}

.gf-hero-stats strong {
    font-size: 26px;
    font-family: Prompt, sans-serif;
}

.gf-hero-stats span {
    font-size: 12px;
    color: rgba(255, 255, 255, .8);
}

/* ---------- Panels ---------- */
.gf-panel {
    padding: 20px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 16px;
}

.gf-empty {
    text-align: center;
    color: var(--text-muted);
}

.gf-muted {
    margin: 0;
    color: var(--text-muted);
    font-size: 14px;
}

.gf-alert {
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
}

.gf-alert-success {
    color: #116149;
    background: var(--teal-soft);
    border: 1px solid #a7eadf;
}

.gf-alert-error {
    color: #9b1c2e;
    background: var(--rose-soft);
    border: 1px solid #f7b9c9;
}

/* ---------- Create / edit form ---------- */
.gf-create > summary {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    cursor: pointer;
    list-style: none;
}

.gf-create > summary::-webkit-details-marker,
.gf-edit > summary::-webkit-details-marker {
    display: none;
}

.gf-plus {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    color: var(--blue);
    background: var(--blue-soft);
    border-radius: 8px;
    font-size: 18px;
}

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

.gf-field {
    display: grid;
    gap: 6px;
    margin: 0;
    font-size: 14px;
}

.gf-field > span,
.gf-field legend {
    font-weight: 600;
    color: var(--text);
}

.gf-field input[type="text"] {
    padding: 10px 12px;
    font: inherit;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
}

.gf-field input[type="text"]:focus {
    outline: 2px solid var(--blue-soft);
    border-color: var(--blue);
}

.gf-fan-picker {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 8px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
}

.gf-fan-picker legend {
    padding: 0 6px;
}

.gf-check {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
}

.gf-check:hover {
    background: var(--bg);
}

.gf-tag {
    padding: 1px 8px;
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg);
    border-radius: 999px;
    white-space: nowrap;
}

.gf-form-actions {
    display: flex;
    justify-content: flex-end;
}

.gf-btn {
    display: inline-flex;
    align-items: center;
    padding: 8px 16px;
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 999px;
    cursor: pointer;
    list-style: none;
}

.gf-btn:hover {
    border-color: var(--blue);
    color: var(--blue);
}

.gf-btn-primary {
    color: #fff;
    background: var(--blue);
    border-color: var(--blue);
}

.gf-btn-primary:hover {
    color: #fff;
    filter: brightness(1.08);
}

.gf-btn-danger {
    color: var(--red);
}

.gf-btn-danger:hover {
    color: #fff;
    background: var(--red);
    border-color: var(--red);
}

/* ---------- Group cards ---------- */
.gf-grid {
    display: grid;
    gap: 16px;
}

/* หนึ่งแถวต่อกลุ่ม: การ์ดรายการซ้าย แผงพัดลมใหญ่ขวา */
.gf-group {
    display: grid;
    grid-template-columns: minmax(340px, 450px) minmax(0, 1fr);
    align-items: start;
    gap: 16px;
}

/* แผงภาพ: พัดลมเป็นตาราง 2 คอลัมน์ทางซ้าย บอร์ดควบคุมอยู่ขวา กึ่งกลางแนวตั้ง */
.gf-stage {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-evenly;
    gap: 32px;
    padding: 28px 24px;
}

.gf-stage-fans {
    display: grid;
    grid-template-columns: repeat(2, auto);
    gap: 24px 32px;
}

.gf-stage-boards {
    display: grid;
    justify-items: center;
    gap: 24px;
}

.gf-big-fan {
    display: grid;
    justify-items: center;
    gap: 10px;
    width: 180px;
    margin: 0;
    --fan-color: #b8bfcc;
}

.gf-big-fan[data-state="on"] {
    --fan-color: var(--green);
}

.gf-big-fan[data-state="off"] {
    --fan-color: var(--amber);
}

.gf-big-fan svg {
    width: 100%;
    height: auto;
    overflow: visible;
}

.gf-big-housing {
    fill: var(--panel);
    stroke: var(--fan-color);
    stroke-width: 4;
    transition: stroke .3s;
}

.gf-big-fan[data-state="on"] .gf-big-housing {
    filter: drop-shadow(0 0 8px rgba(34, 181, 115, .35));
}

.gf-big-grille {
    fill: var(--bg);
    stroke: var(--border);
    stroke-width: 1.5;
}

.gf-rotor {
    transform-origin: 60px 60px;
    animation: gf-spin var(--spin, 1s) linear infinite;
    animation-play-state: paused;
}

.gf-big-fan[data-state="on"] .gf-rotor {
    animation-play-state: running;
}

.gf-big-blade {
    fill: var(--fan-color);
    opacity: .9;
    transition: fill .3s;
}

.gf-big-hub {
    fill: var(--panel);
    stroke: var(--fan-color);
    stroke-width: 3;
}

.gf-big-cap {
    fill: var(--fan-color);
}

/* บอร์ดควบคุมใหญ่ (Shelly): กรอบ/ไฟตามสถานะ แถบบนจอยาวตาม % ความเร็ว (--level 0–1) */
.gf-board-body {
    fill: var(--panel);
    stroke: var(--fan-color);
    stroke-width: 4;
    stroke-linejoin: round;
    transition: stroke .3s;
}

.gf-big-fan[data-state="on"] .gf-board-body {
    filter: drop-shadow(0 0 8px rgba(34, 181, 115, .35));
}

.gf-board-term {
    fill: var(--bg);
    stroke: var(--border);
    stroke-width: 1.5;
}

.gf-board-screw {
    fill: #b8bfcc;
}

.gf-board-screen {
    fill: #1d2433;
}

.gf-board-level {
    fill: var(--fan-color);
    transform: scaleX(var(--level, 0));
    transform-box: fill-box;
    transform-origin: left center;
    transition: transform .4s, fill .3s;
}

.gf-big-fan .gf-board-led {
    fill: var(--fan-color);
}

.gf-big-fan figcaption {
    display: grid;
    justify-items: center;
    gap: 2px;
    max-width: 100%;
    font-size: 13px;
    text-align: center;
}

.gf-big-fan figcaption strong {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.gf-big-fan figcaption span {
    color: var(--text-muted);
    font-size: 12px;
}

.gf-big-fan[data-state="on"] [data-field="state"] {
    color: var(--green);
    font-weight: 600;
}

@media (max-width: 900px) {
    .gf-group {
        grid-template-columns: minmax(0, 1fr);
    }
}

.gf-card {
    display: grid;
    align-content: start;
    gap: 14px;
}

.gf-card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
}

.gf-card-head h2 {
    margin: 0;
    font-family: Prompt, sans-serif;
    font-size: 18px;
}

.gf-card-head p {
    margin: 4px 0 0;
    font-size: 13px;
    color: var(--text-muted);
}

.gf-card-stats {
    display: flex;
    gap: 6px;
}

.gf-chip {
    padding: 4px 10px;
    font-size: 12px;
    color: var(--text-muted);
    background: var(--bg);
    border-radius: 999px;
    white-space: nowrap;
}

.gf-chip b {
    color: var(--text);
}

.gf-chip-on {
    color: #116149;
    background: var(--teal-soft);
}

.gf-chip-on b {
    color: #116149;
}

.gf-fans {
    display: grid;
    gap: 6px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.gf-fan {
    display: grid;
    grid-template-columns: 26px minmax(0, 1fr) auto auto auto auto;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    font-size: 13px;
    background: var(--bg);
    border-radius: 10px;
}

/* ไอคอนพัดลม (มิเตอร์): หมุนตลอด แต่หยุด (ค้างมุมเดิม) เมื่อไม่ได้ ON */
.gf-fan-icon {
    width: 26px;
    height: 26px;
    color: #b8bfcc;
    animation: gf-spin var(--spin, 1s) linear infinite;
    animation-play-state: paused;
}

.gf-fan-guard {
    fill: none;
    stroke: currentColor;
    stroke-width: 1.2;
    opacity: .45;
}

.gf-fan-blade,
.gf-fan-hub {
    fill: currentColor;
}

.gf-fan[data-state="on"] .gf-fan-icon {
    color: var(--green);
    animation-play-state: running;
}

.gf-fan[data-state="off"] .gf-fan-icon {
    color: var(--amber);
}

/* ไอคอนบอร์ดควบคุม (Shelly): สีตามสถานะ ไฟ LED กะพริบเมื่อ ON */
.gf-board-icon {
    width: 26px;
    height: 26px;
    color: #b8bfcc;
}

.gf-board-icon-body {
    fill: none;
    stroke: currentColor;
    stroke-width: 1.4;
    stroke-linejoin: round;
}

.gf-board-icon-term {
    fill: currentColor;
    opacity: .35;
}

.gf-board-icon .gf-board-led {
    fill: currentColor;
}

.gf-fan[data-state="on"] .gf-board-icon {
    color: var(--green);
}

.gf-fan[data-state="off"] .gf-board-icon {
    color: var(--amber);
}

.gf-board-led {
    animation: gf-led 1.2s ease-in-out infinite;
    animation-play-state: paused;
}

.gf-fan[data-state="on"] .gf-board-led,
.gf-big-fan[data-state="on"] .gf-board-led {
    animation-play-state: running;
}

@keyframes gf-spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes gf-led {
    50% {
        opacity: .3;
    }
}

@media (prefers-reduced-motion: reduce) {
    .gf-fan-icon,
    .gf-rotor,
    .gf-board-led,
    .gf-eyebrow i {
        animation: none !important;
    }
}

.gf-fan-name {
    overflow: hidden;
    color: var(--text);
    font-weight: 600;
    text-decoration: none;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.gf-fan-name:hover {
    color: var(--blue);
}

.gf-state {
    font-size: 12px;
    color: var(--text-muted);
}

.gf-fan[data-state="on"] .gf-state {
    color: var(--green);
    font-weight: 600;
}

.gf-metric {
    min-width: 56px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.gf-fan[data-state="offline"] .gf-metric {
    color: var(--text-muted);
}

/* อุณหภูมิขาเข้า/โดยรอบ: บรรทัดแยกใต้แถว และใต้ชื่อในการ์ดใหญ่ */
.gf-temps {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 14px;
    font-size: 12px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.gf-temps b {
    color: var(--text);
    font-weight: 600;
}

/* การ์ดอุณหภูมิแยกใต้การ์ดกลุ่ม */
.gf-side {
    display: grid;
    gap: 16px;
    min-width: 0;
}

.gf-temp-card {
    display: grid;
    gap: 14px;
}

.gf-temp-head {
    display: flex;
    align-items: center;
    gap: 8px;
}

.gf-temp-head svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: var(--rose);
    stroke-width: 2;
}

.gf-temp-head h3 {
    margin: 0;
    font-family: Prompt, sans-serif;
    font-size: 16px;
}

.gf-temp-device {
    display: grid;
    gap: 8px;
}

.gf-temp-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
}

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

.gf-temp-tile {
    --tone: var(--blue);
    --tone-soft: var(--blue-soft);
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas: "icon label" "icon value";
    align-items: center;
    column-gap: 12px;
    padding: 14px 16px;
    background: var(--tone-soft);
    border-radius: 14px;
    position: relative;
    overflow: hidden;
}

.gf-temp-ambient {
    --tone: var(--amber);
    --tone-soft: var(--amber-soft);
}

/* แถบสีด้านซ้ายของแต่ละช่อง */
.gf-temp-tile::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 4px;
    background: var(--tone);
}

.gf-temp-icon {
    grid-area: icon;
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    background: var(--panel);
    border-radius: 50%;
    box-shadow: 0 2px 6px rgb(0 0 0 / .06);
}

.gf-temp-icon svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: var(--tone);
    stroke-width: 2;
}

.gf-temp-icon circle {
    fill: var(--tone);
    stroke: none;
}

.gf-temp-label {
    grid-area: label;
    font-size: 12px;
    color: var(--text-muted);
}

.gf-temp-tile strong {
    grid-area: value;
    font-size: 22px;
    font-weight: 700;
    line-height: 1.2;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.gf-temp-device[data-state="offline"] .gf-temp-tile {
    --tone: #b8bfcc;
    --tone-soft: var(--bg);
}

.gf-temp-device[data-state="offline"] .gf-temp-tile strong {
    color: var(--text-muted);
}

.gf-big-fan figcaption .gf-temps {
    justify-content: center;
}

.gf-card-foot {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 8px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.gf-card-foot form {
    margin: 0;
}

.gf-edit {
    flex: 1 1 100%;
    order: 2;
}

.gf-edit[open] > summary {
    margin-bottom: 4px;
}

@media (max-width: 640px) {
    .gf-hero {
        padding: 22px 20px;
    }

    .gf-stage {
        gap: 16px;
        padding: 20px 12px;
    }

    .gf-stage-fans {
        gap: 16px;
    }

    .gf-big-fan {
        width: 130px;
    }

    .gf-fan {
        display: flex;
        flex-wrap: wrap;
        row-gap: 4px;
    }

    .gf-fan-name {
        flex: 1 1 0;
    }

    .gf-fan .gf-metric {
        min-width: 0;
        text-align: left;
    }

    .gf-fan .gf-metric:first-of-type {
        margin-left: 20px;
    }

    .gf-temp-tiles {
        gap: 8px;
    }

    .gf-temp-tile {
        padding: 12px;
        column-gap: 8px;
    }

    .gf-temp-icon {
        width: 32px;
        height: 32px;
    }

    .gf-temp-tile strong {
        font-size: 18px;
    }
}
