:root {
    --green-950: #0b2f1a;
    --green-900: #14532d;
    --green-800: #166534;
    --green-700: #15803d;
    --green-600: #16a34a;
    --green-100: #dcfce7;
    --green-50: #f0fdf4;
    --amber-500: #eab308;
    --amber-400: #facc15;
    --amber-100: #fef3c7;
    --amber-50: #fffbeb;
    --blue-600: #2563eb;
    --blue-100: #dbeafe;
    --purple-600: #7c3aed;
    --purple-100: #ede9fe;
    --red-600: #dc2626;
    --red-100: #fee2e2;
    --red-50: #fef2f2;
    --surface: #ffffff;
    --canvas: #f5f7f5;
    --line: #e3e8e4;
    --line-strong: #d2d9d4;
    --text: #17201b;
    --text-soft: #5f6d64;
    --text-faint: #849089;
    --shadow-sm: 0 1px 2px rgba(14, 38, 23, .04), 0 3px 10px rgba(14, 38, 23, .04);
    --shadow-md: 0 12px 30px rgba(14, 38, 23, .08);
    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 22px;
    --page-width: 1240px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html { scroll-behavior: smooth; }

body {
    min-width: 320px;
    min-height: 100vh;
    background: var(--canvas);
    color: var(--text);
    font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
svg { display: block; fill: currentColor; }

.app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 74px;
    padding: 0 max(24px, calc((100vw - var(--page-width)) / 2));
    background: rgba(255, 255, 255, .94);
    border-bottom: 1px solid rgba(210, 217, 212, .8);
    box-shadow: 0 2px 14px rgba(14, 38, 23, .04);
    backdrop-filter: blur(14px);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 0 0 auto;
    text-decoration: none;
}

.brand-mark { width: 46px; height: 46px; object-fit: contain; }
.brand-wordmark { width: 170px; height: 42px; object-fit: contain; object-position: left center; }

.nav-links { display: flex; align-items: center; gap: 6px; }
.nav-link {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    padding: 10px 16px;
    color: var(--text-soft);
    border-radius: 12px;
    font-weight: 700;
    text-decoration: none;
    transition: color .18s ease, background .18s ease;
    border: 0;
    background: transparent;
    cursor: pointer;
}
.nav-link svg { width: 18px; height: 18px; }
.nav-link:hover { color: var(--green-800); background: var(--green-50); }
.nav-link.active { color: var(--green-900); background: var(--green-100); }

.page-shell {
    width: min(calc(100% - 48px), var(--page-width));
    margin: 0 auto;
    padding: 38px 0 64px;
}

.page-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 32px;
    margin-bottom: 28px;
}
.eyebrow {
    margin-bottom: 5px;
    color: var(--green-700);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
}
.page-heading h1 { font-size: clamp(26px, 3vw, 36px); line-height: 1.2; letter-spacing: -.035em; }
.page-subtitle { max-width: 680px; margin-top: 8px; color: var(--text-soft); }
.live-clock {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 220px;
    padding: 12px 15px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow-sm);
}
.live-clock svg { width: 25px; height: 25px; color: var(--green-700); }
.live-clock div { display: flex; flex-direction: column; }
.live-clock strong { font-size: 20px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.live-clock span { color: var(--text-soft); font-size: 12px; }

.overview-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.status-hero {
    position: relative;
    grid-column: span 2;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 172px;
    padding: 24px;
    overflow: hidden;
    color: #fff;
    background: linear-gradient(135deg, var(--green-900), #19733e);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}
.status-hero-top { display: flex; align-items: center; gap: 9px; }
.status-kicker { color: rgba(255,255,255,.78); font-size: 13px; font-weight: 700; }
.status-dot { width: 9px; height: 9px; background: #86efac; border: 2px solid rgba(255,255,255,.5); border-radius: 50%; box-shadow: 0 0 0 5px rgba(134,239,172,.14); }
.status-hero h2 { position: relative; z-index: 1; font-size: 30px; line-height: 1.15; letter-spacing: -.025em; }
.status-hero p { position: relative; z-index: 1; margin-top: 4px; color: rgba(255,255,255,.72); font-size: 13px; }
.status-illustration { position: absolute; right: -18px; bottom: -28px; width: 145px; height: 145px; color: rgba(255,255,255,.1); transform: rotate(-8deg); }
.status-illustration svg { width: 100%; height: 100%; }
.status-hero.status-menipis { background: linear-gradient(135deg, #a16207, #d97706); }
.status-hero.status-menipis .status-dot { background: #fde68a; }
.status-hero.status-habis { background: linear-gradient(135deg, #991b1b, #dc2626); }
.status-hero.status-habis .status-dot { background: #fecaca; animation: pulse 1.3s infinite; }
.feeding-status-hero { background: linear-gradient(135deg, #334155, #475569); }
.feeding-status-hero .status-dot { background: #cbd5e1; box-shadow: 0 0 0 5px rgba(203,213,225,.14); }
.feeding-status-hero.feeding-state-active { background: linear-gradient(135deg, #1e40af, #2563eb); }
.feeding-status-hero.feeding-state-active .status-dot { background: #bfdbfe; animation: pulse 1.3s infinite; }
.feeding-status-hero.feeding-state-complete { background: linear-gradient(135deg, #166534, #16a34a); }
.feeding-status-hero.feeding-state-complete .status-dot { background: #bbf7d0; }
.feeding-status-hero.feeding-state-stopped { background: linear-gradient(135deg, #92400e, #d97706); }
.feeding-status-hero.feeding-state-stopped .status-dot { background: #fde68a; }
.feeding-status-hero.feeding-state-fault { background: linear-gradient(135deg, #7f1d1d, #b91c1c); }
.feeding-status-hero.feeding-state-fault .status-dot { background: #fecaca; }
.feeding-status-hero.feeding-state-offline { background: linear-gradient(135deg, #3f3f46, #71717a); }
.feeding-status-hero.feeding-state-offline .status-dot { background: #d4d4d8; }

.metric-card {
    display: flex;
    align-items: center;
    gap: 14px;
    min-height: 116px;
    padding: 19px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    transition: transform .18s ease, box-shadow .18s ease;
}
.metric-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.metric-icon, .section-icon {
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    color: var(--green-700);
    background: var(--green-100);
    border-radius: 13px;
}
.metric-icon svg, .section-icon svg { width: 22px; height: 22px; }
.metric-icon-blue, .section-icon-blue { color: var(--blue-600); background: var(--blue-100); }
.metric-icon-amber, .section-icon-amber { color: #a16207; background: var(--amber-100); }
.metric-icon-purple { color: var(--purple-600); background: var(--purple-100); }
.metric-copy { display: flex; min-width: 0; flex-direction: column; }
.metric-copy > span { margin-bottom: 3px; color: var(--text-soft); font-size: 12px; font-weight: 700; }
.metric-copy strong { font-size: clamp(19px, 2vw, 25px); line-height: 1.2; letter-spacing: -.025em; white-space: nowrap; }
.metric-copy small { margin-top: 5px; color: var(--text-faint); font-size: 11px; }
.text-action { width: fit-content; margin-top: 4px; padding: 0; color: var(--green-700); background: transparent; border: 0; cursor: pointer; font-size: 11px; font-weight: 800; }
.text-action:hover { text-decoration: underline; }

.panel {
    padding: 26px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.workspace { margin-bottom: 24px; }
.section-heading { display: flex; align-items: flex-start; gap: 14px; margin-bottom: 24px; }
.section-heading h2 { font-size: 22px; line-height: 1.25; letter-spacing: -.02em; }
.section-heading p:not(.eyebrow) { margin-top: 4px; color: var(--text-soft); font-size: 13px; }
.section-heading-small { margin-bottom: 20px; }
.section-heading-small h2 { font-size: 18px; }
.section-heading-small .section-icon { width: 40px; height: 40px; }

.calculator-layout { display: grid; grid-template-columns: minmax(0, 1.75fr) minmax(280px, .8fr); gap: 24px; }
.calculator-form { display: flex; flex-direction: column; gap: 20px; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.field { display: flex; min-width: 0; flex-direction: column; gap: 7px; }
.field > span { color: #344039; font-size: 13px; font-weight: 750; }
.field > small { color: var(--text-faint); font-size: 11px; }
input[type="number"], input[type="text"], input[type="date"] {
    width: 100%;
    min-width: 0;
    height: 46px;
    padding: 0 13px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}
input::placeholder { color: #a4ada7; }
input:hover { border-color: #aeb9b1; }
input:focus { border-color: var(--green-600); box-shadow: 0 0 0 3px rgba(22, 163, 74, .13); }
.input-with-unit { display: flex; align-items: center; overflow: hidden; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); }
.input-with-unit:focus-within { border-color: var(--green-600); box-shadow: 0 0 0 3px rgba(22, 163, 74, .13); }
.input-with-unit input { border: 0; border-radius: 0; box-shadow: none !important; }
.input-with-unit > span { padding: 0 12px; color: var(--text-soft); border-left: 1px solid var(--line); font-size: 12px; font-weight: 800; }
.inline-control { display: flex; gap: 10px; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 10px 17px;
    border: 1px solid transparent;
    border-radius: 11px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 800;
    text-decoration: none;
    transition: transform .15s ease, box-shadow .15s ease, background .15s ease, border-color .15s ease;
}
.btn svg { width: 18px; height: 18px; }
.btn:hover { transform: translateY(-1px); }
.btn:focus-visible, .nav-link:focus-visible, .text-action:focus-visible { outline: 3px solid rgba(37,99,235,.28); outline-offset: 2px; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-block {width: 100%;}
.btn-primary { color: #fff; background: var(--green-700); box-shadow: 0 6px 16px rgba(21,128,61,.18);}
.btn-primary:hover { background: var(--green-800); }
.btn-secondary { color: var(--green-950); background: var(--amber-400); box-shadow: 0 5px 14px rgba(234,179,8,.18); }
.btn-secondary:hover { background: #f4c908; }
.btn-outline { color: var(--green-800); background: #fff; border-color: #b9c9bf; }
.btn-outline:hover { background: var(--green-50); border-color: #82aa90; }
.btn-ghost { color: var(--text-soft); background: #f2f5f3; }
.btn-ghost:hover { color: var(--green-800); background: var(--green-50); }
.btn-danger { color: #fff; background: var(--red-600); }
.btn-danger:hover { background: #b91c1c; }
.btn-danger-soft { color: #b91c1c; background: var(--red-50); border-color: #fecaca; }
.btn-danger-soft:hover { background: var(--red-100); }
.btn-compact { min-height: 38px; padding: 8px 12px; font-size: 12px; }

.recommendation-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    text-align: center;
    background: linear-gradient(150deg, var(--green-50), #fbfefc);
    border: 1px solid #bbdfc6;
    border-radius: var(--radius-md);
}
.recommendation-label { color: var(--green-900); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; }
.recommendation-value { display: flex; align-items: baseline; gap: 7px; margin: 8px 0 2px; }
.recommendation-value strong { color: var(--green-950); font-size: 44px; line-height: 1; letter-spacing: -.045em; }
.recommendation-value span { color: var(--green-800); font-weight: 800; }
.recommendation-card p { max-width: 280px; margin: 8px 0 18px; color: var(--text-soft); font-size: 12px; }

.fuzzy-visualization { margin-top: 24px; padding-top: 22px; border-top: 1px solid var(--line); }
.fuzzy-visual-header { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 16px; }
.fuzzy-visual-header h3 { font-size: 16px; }
.fuzzy-visual-header p { margin-top: 3px; color: var(--text-soft); font-size: 12px; }
.fuzzy-visual-hidden, .is-hidden { display: none !important; }
.fuzzy-step-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.fuzzy-step { min-width: 0; padding: 17px; background: #fafcfb; border: 1px solid var(--line); border-radius: 13px; }
.fuzzy-step-title { display: flex; align-items: center; gap: 8px; margin-bottom: 13px; font-size: 13px; font-weight: 850; }
.fuzzy-step-title > span { display: grid; place-items: center; width: 22px; height: 22px; color: var(--green-800); background: var(--green-100); border-radius: 50%; font-size: 11px; }
.membership-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; }
.membership-card, .rule-card, .decision-main > div, .decision-crisp { padding: 12px; background: #fff; border: 1px solid var(--line); border-radius: 10px; }
.membership-title { margin-bottom: 8px; font-size: 12px; font-weight: 800; }
.membership-items, .rule-list, .output-bars, .decision-summary { display: flex; flex-direction: column; gap: 9px; }
.membership-row, .rule-card-head { display: flex; justify-content: space-between; gap: 8px; font-size: 11px; }
.mini-bar, .output-bar-track { height: 7px; overflow: hidden; background: #e9eeeb; border-radius: 999px; }
.mini-bar-fill, .output-bar-fill { height: 100%; background: linear-gradient(90deg, var(--green-600), #65a30d); border-radius: inherit; }
.rule-card-top { border-color: #86c79c; box-shadow: 0 0 0 2px rgba(22,163,74,.09); }
.rule-index { color: var(--text-soft); font-weight: 700; }
.rule-strength { padding: 2px 7px; color: var(--green-800); background: var(--green-100); border-radius: 99px; font-weight: 850; }
.rule-text, .decision-text { color: #344039; font-size: 11px; line-height: 1.55; }
.output-bar-row { display: grid; grid-template-columns: 100px minmax(0, 1fr) 44px; align-items: center; gap: 9px; font-size: 11px; }
.output-bar-row-top { color: var(--green-800); font-weight: 850; }
.decision-main { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.decision-label { margin-bottom: 4px; color: var(--text-soft); font-size: 10px; font-weight: 750; }
.decision-value { font-size: 19px; font-weight: 850; }
.decision-crisp { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 11px; }
.decision-crisp strong { font-size: 19px; }
.fuzzy-empty { padding: 13px; color: var(--text-faint); background: #fff; border: 1px dashed var(--line-strong); border-radius: 10px; font-size: 11px; text-align: center; }

.operations-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; margin-bottom: 24px; }
.compact-panel { display: flex; flex-direction: column; }
.compact-panel > .btn { margin-top: 15px; }
.esp32-api-indicator { display: flex; align-items: center; gap: 12px; padding: 13px; background: #f7f9f8; border: 1px solid var(--line); border-radius: 12px; }
.esp32-api-dot { flex: 0 0 auto; width: 10px; height: 10px; background: #94a3b8; border-radius: 50%; box-shadow: 0 0 0 5px rgba(148,163,184,.12); }
.esp32-api-indicator strong { display: block; font-size: 13px; }
.esp32-api-indicator p { margin-top: 2px; color: var(--text-soft); font-size: 11px; }
.esp32-api-indicator.connected { background: var(--green-50); border-color: #b7dec2; }
.esp32-api-indicator.connected .esp32-api-dot { background: var(--green-600); box-shadow: 0 0 0 5px rgba(22,163,74,.12); }
.esp32-api-indicator.disconnected { background: var(--red-50); border-color: #fecaca; }
.esp32-api-indicator.disconnected .esp32-api-dot { background: var(--red-600); box-shadow: 0 0 0 5px rgba(220,38,38,.1); }
.mini-device-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 12px; }
.mini-device-stats div { display: flex; justify-content: space-between; padding: 10px 12px; background: #f7f9f8; border-radius: 9px; font-size: 12px; }
.mini-device-stats span { color: var(--text-soft); }

.device-panel { padding: 0; overflow: hidden; }
.collapsible-header { width: 100%; padding: 22px 26px; margin: 0; color: inherit; background: transparent; border: 0; cursor: pointer; text-align: left; }
.collapsible-header > div:nth-child(2) { flex: 1; }
.collapse-arrow { flex: 0 0 auto; width: 24px; height: 24px; color: var(--text-soft); transition: transform .2s ease; }
.collapse-arrow.is-collapsed { transform: rotate(-90deg); }
.collapsible-body { padding: 0 26px 26px; }
.device-config-layout { display: grid; grid-template-columns: 1.2fr .8fr; gap: 24px; padding-top: 22px; border-top: 1px solid var(--line); }
.esp32-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.device-message { min-height: 20px; margin-top: 10px; font-size: 12px; }
.msg-success { color: var(--green-700); font-weight: 700; }
.msg-danger { color: var(--red-600); font-weight: 700; }
.esp32-stat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.esp32-stat-grid > div { display: flex; flex-direction: column; justify-content: center; min-height: 76px; padding: 13px; background: #f7f9f8; border: 1px solid var(--line); border-radius: 11px; }
.esp32-stat-grid span:first-child { margin-bottom: 5px; color: var(--text-soft); font-size: 11px; }
.esp32-stat-grid strong { font-size: 15px; overflow-wrap: anywhere; }

.history-page { max-width: var(--page-width); }
.history-toolbar { display: grid; grid-template-columns: minmax(210px, 1fr) auto auto; align-items: end; gap: 12px; margin-bottom: 18px; padding: 18px; border-radius: var(--radius-md); }
.table-card { overflow: hidden; background: #fff; border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.table-scroll { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead { background: #f2f6f3; }
th { padding: 14px 13px; color: var(--text-soft); border-bottom: 1px solid var(--line-strong); font-size: 10px; letter-spacing: .05em; text-align: left; text-transform: uppercase; white-space: nowrap; }
td { padding: 14px 13px; border-bottom: 1px solid var(--line); font-size: 12px; text-align: left; white-space: nowrap; }
tbody tr:not(.loading-row):hover { background: #fafcfb; }
tbody tr:last-child td { border-bottom: 0; }
.status-badge { display: inline-flex; align-items: center; padding: 4px 9px; border-radius: 99px; font-size: 10px; font-weight: 800; }
.status-badge.tersedia { color: var(--green-800); background: var(--green-100); }
.status-badge.menipis { color: #92400e; background: var(--amber-100); }
.status-badge.habis { color: #b91c1c; background: var(--red-100); }
.status-badge.diproses { color: #1d4ed8; background: var(--blue-100); }
.status-badge.berhasil { color: var(--green-800); background: var(--green-100); }
.status-badge.gagal, .status-badge.gagal_sebagian { color: #b91c1c; background: var(--red-100); }
.status-badge.dihentikan { color: #475569; background: #e2e8f0; }
.status-badge.perlu_verifikasi, .status-badge.menunggu_koneksi { color: #92400e; background: var(--amber-100); }
.feeding-progress-panel { margin-bottom: 24px; border: 1px solid #bfdbfe; }
.feeding-progress-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.feeding-progress-head h2 { font-size: 21px; }
.feeding-progress-head p:last-child { margin-top: 4px; color: var(--text-soft); font-size: 13px; }
.job-progress-track { height: 10px; margin: 20px 0; overflow: hidden; background: #e2e8f0; border-radius: 99px; }
.job-progress-fill { height: 100%; background: linear-gradient(90deg, var(--blue-600), var(--green-600)); border-radius: inherit; transition: width .35s ease; }
.feeding-progress-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.feeding-progress-grid > div { min-width: 0; padding: 12px; background: #f7f9f8; border-radius: 10px; }
.feeding-progress-grid span { display: block; color: var(--text-faint); font-size: 10px; font-weight: 800; text-transform: uppercase; }
.feeding-progress-grid strong { display: block; margin-top: 3px; overflow-wrap: anywhere; font-size: 13px; }
.feeding-event-list { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 14px; }
.feeding-event { padding: 5px 9px; color: var(--text-soft); background: var(--surface); border: 1px solid var(--line); border-radius: 99px; font-size: 10px; font-weight: 700; }
.alert-dialog, .history-dialog { width: min(520px, calc(100% - 32px)); padding: 26px; color: var(--text); background: var(--surface); border: 0; border-radius: 20px; box-shadow: 0 24px 70px rgba(0,0,0,.25); }
.alert-dialog { text-align: center; }
.alert-dialog::backdrop, .history-dialog::backdrop { background: rgba(7, 20, 12, .62); backdrop-filter: blur(3px); }
.alert-dialog-icon { display: grid; width: 54px; height: 54px; margin: 0 auto 14px; place-items: center; color: #991b1b; background: var(--red-100); border-radius: 50%; font-size: 28px; font-weight: 900; }
.alert-dialog h2 { font-size: 22px; }
.alert-dialog > p { margin-top: 8px; color: var(--text-soft); }
.alert-dialog-details { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 18px; text-align: left; }
.alert-dialog-details div { padding: 10px; background: var(--red-50); border-radius: 9px; }
.alert-dialog-details dt { color: var(--text-faint); font-size: 9px; font-weight: 800; text-transform: uppercase; }
.alert-dialog-details dd { margin-top: 2px; font-size: 12px; font-weight: 800; overflow-wrap: anywhere; }
.alert-dialog-actions { margin-top: 20px; }
.alert-dialog-actions .btn { width: 100%; }
.history-detail-button { border: 0; color: var(--green-800); background: transparent; font-size: 11px; font-weight: 800; cursor: pointer; text-decoration: underline; }
.history-dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.dialog-close { width: 36px; height: 36px; border: 0; color: var(--text-soft); background: #eef2ef; border-radius: 50%; font-size: 22px; cursor: pointer; }
.history-detail-content { display: grid; gap: 10px; margin-top: 20px; }
.history-detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.history-detail-grid div { padding: 11px; background: #f7f9f8; border-radius: 9px; }
.history-detail-grid span { display: block; color: var(--text-faint); font-size: 9px; font-weight: 800; text-transform: uppercase; }
.history-detail-grid strong { display: block; margin-top: 3px; font-size: 12px; overflow-wrap: anywhere; }
.history-event-row { padding: 9px 11px; border-left: 3px solid var(--green-600); background: var(--green-50); font-size: 11px; }
.table-message { display: flex; align-items: center; justify-content: center; gap: 9px; min-height: 100px; color: var(--text-soft); }
.spinner { width: 17px; height: 17px; border: 2px solid var(--line-strong); border-top-color: var(--green-600); border-radius: 50%; animation: spin .8s linear infinite; }
.spinner-light { border-color: rgba(255,255,255,.35); border-top-color: #fff; }
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 14px 18px; background: #fbfcfb; border-top: 1px solid var(--line); }
.pagination span { color: var(--text-soft); font-size: 12px; font-weight: 750; text-align: center; }
.mobile-history-list { display: none; }

.toast-region { position: fixed; right: 20px; bottom: 20px; z-index: 300; display: flex; width: min(360px, calc(100% - 40px)); flex-direction: column; gap: 10px; pointer-events: none; }
.toast { padding: 13px 15px; color: #fff; background: var(--green-950); border-radius: 12px; box-shadow: 0 12px 32px rgba(0,0,0,.18); font-size: 13px; font-weight: 700; animation: toastIn .25s ease; }
.toast.toast-danger { background: #991b1b; }

@keyframes pulse { 50% { opacity: .5; transform: scale(.86); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 1050px) {
    .overview-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .status-hero { grid-column: span 2; grid-row: auto; }
    .calculator-layout { grid-template-columns: 1fr; }
    .recommendation-card { min-height: 235px; }
    .form-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
    body { padding-bottom: 76px; }
    .app-header { position: sticky; min-height: 64px; padding: 0 16px; }
    .brand { gap: 7px; }
    .brand-mark { width: 39px; height: 39px; }
    .brand-wordmark { width: 138px; height: 34px; }
    .nav-links { position: fixed; right: 12px; bottom: 10px; left: 12px; z-index: 150; justify-content: space-around; gap: 4px; padding: 7px; background: rgba(255,255,255,.96); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 12px 34px rgba(14,38,23,.18); backdrop-filter: blur(12px); }
    .nav-link { flex: 1; flex-direction: column; gap: 2px; min-height: 51px; padding: 6px 12px; font-size: 10px; }
    .nav-link svg { width: 20px; height: 20px; }
    .page-shell { width: min(calc(100% - 28px), var(--page-width)); padding: 25px 0 40px; }
    .page-heading { align-items: flex-start; flex-direction: column; gap: 16px; margin-bottom: 22px; }
    .page-heading h1 { font-size: 27px; }
    .page-subtitle { font-size: 13px; }
    .live-clock { width: 100%; min-width: 0; }
    .overview-grid { grid-template-columns: 1fr; gap: 12px; }
    .status-hero { grid-column: auto; min-height: 160px; }
    .metric-card { min-height: 104px; }
    .panel { padding: 19px; border-radius: var(--radius-md); }
    .section-heading { margin-bottom: 20px; }
    .section-heading h2 { font-size: 19px; }
    .form-grid { grid-template-columns: 1fr; }
    .recommendation-value strong { font-size: 40px; }
    .fuzzy-visual-header { align-items: flex-start; flex-direction: column; }
    .fuzzy-step-grid { grid-template-columns: 1fr; }
    .membership-grid { grid-template-columns: 1fr; }
    .operations-grid { grid-template-columns: 1fr; gap: 14px; }
    .device-panel { padding: 0; }
    .collapsible-header { padding: 19px; }
    .collapsible-body { padding: 0 19px 19px; }
    .device-config-layout { grid-template-columns: 1fr; }
    .inline-control { align-items: stretch; flex-direction: column; }
    .esp32-actions { flex-direction: column; }
    .esp32-actions .btn { width: 100%; }
    .history-page .page-heading > .btn { width: 100%; }
    .history-toolbar { grid-template-columns: 1fr; }
    .history-toolbar .btn { width: 100%; }
    .feeding-progress-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .feeding-progress-head { flex-direction: column; gap: 10px; }
    .alert-dialog-details, .history-detail-grid { grid-template-columns: 1fr; }
    .table-scroll { display: none; }
    .mobile-history-list { display: flex; flex-direction: column; gap: 0; }
    .history-card { padding: 17px; border-bottom: 1px solid var(--line); }
    .history-card:last-child { border-bottom: 0; }
    .history-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 13px; }
    .history-card-head strong { display: block; font-size: 14px; }
    .history-card-head span:not(.status-badge) { color: var(--text-soft); font-size: 11px; }
    .history-card-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .history-card-grid div { padding: 9px; background: #f7f9f8; border-radius: 8px; }
    .history-card-grid span { display: block; color: var(--text-soft); font-size: 9px; text-transform: uppercase; }
    .history-card-grid strong { display: block; margin-top: 2px; font-size: 12px; }
    .history-card-detail { margin: 12px 0 6px; color: var(--text-soft); font-size: 11px; }
    .mobile-empty { padding: 48px 20px; color: var(--text-soft); text-align: center; }
    .mobile-empty strong { display: block; color: var(--text); font-size: 15px; }
    .mobile-empty p { margin-top: 4px; font-size: 12px; }
    .pagination { padding: 12px; }
    .pagination .btn { padding: 8px; font-size: 11px; }
}

@media (max-width: 420px) {
    .page-shell { width: calc(100% - 22px); }
    .brand-wordmark { width: 126px; }
    .metric-card { padding: 15px; }
    .metric-icon { width: 40px; height: 40px; }
    .esp32-stat-grid { grid-template-columns: 1fr; }
    .output-bar-row { grid-template-columns: 1fr; gap: 5px; }
    .decision-main { grid-template-columns: 1fr; }
    .pagination { gap: 5px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
