:root {
    --green: #7ed321;
    --lime: #caff8e;
    --blue-title: #dce6f3;
    --sidebar: 264px;
    --topbar: 72px;
    --tabs: 61px;
    --ink: #080808;
}

html { zoom: .8; }
* { box-sizing: border-box; }
html.auth-pending body { visibility: hidden; }
body { margin: 0; min-width: 1180px; background: #fff; color: var(--ink); font-family: Arial, Helvetica, sans-serif; font-size: 16px; }
button, select { font: inherit; }
button { color: inherit; }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar) 1fr; grid-template-rows: var(--topbar) var(--tabs) 1fr; border: 2px solid #8b9da5; }

.topbar { grid-column: 1 / -1; display: flex; align-items: center; height: var(--topbar); background: #fff; border-bottom: 1px solid #bac6c9; }
.sun-indicator { width: 38px; height: 38px; margin: 0 22px 0 -17px; border: 1px solid #e4e4e4; border-radius: 50%; background: #fff4da; }
.brand { width: 200px; display: flex; align-items: center; color: #70c72c; text-decoration: none; }
.brand img { display: block; width: 134px; max-height: 58px; object-fit: contain; }
.brand-mark { display: flex; gap: 3px; margin-right: 5px; }
.brand-mark i { display: block; width: 18px; height: 39px; border: 2px solid currentColor; border-radius: 9px 1px 9px 1px; background: repeating-linear-gradient(0deg, transparent 0 7px, currentColor 8px 9px); }
.brand-mark i:nth-child(2) { transform: scaleY(1.12); }
.brand-name { font-size: 30px; line-height: .75; letter-spacing: -2px; }
.brand-name small { display: block; font-size: 14px; letter-spacing: 0; margin-left: 3px; }
.lab-box { width: 250px; height: 47px; display: grid; place-items: center; margin-left: 6px; background: #292929; color: #00ef16; font-size: 23px; font-weight: 700; }
.top-spacer { flex: 1; }
.day-pill { height: 36px; min-width: 90px; display: flex; align-items: center; justify-content: center; gap: 8px; color: white; background: #ffd000; border-radius: 22px; font-family: Georgia, serif; font-size: 12px; }
.day-pill b { width: 31px; height: 31px; display: grid; place-items: center; border: 1px solid white; border-radius: 50%; font-size: 19px; }
.mode-pill { width: 138px; height: 35px; margin-left: 20px; border: 0; border-radius: 22px; background: var(--green); box-shadow: inset 0 -5px rgba(0,0,0,.18); font-family: Georgia, serif; cursor: pointer; }
.mode-pill.auto { background: var(--green); color: #000; }
.mode-pill.manual { background: #ed1c2b; color: #fff; }
.mode-pill.task { background: #ff8754; color: #000; }
.mode-pill.mode-unknown { background: #a8b1b6; color: #fff; }
.mode-pill:disabled { cursor: wait; opacity: .65; }
.mode-pill.pending { outline: 3px solid #f5b700; animation: pending-pulse .8s ease-in-out infinite alternate; }
.mode-pill[data-command-error="true"] { outline: 3px solid #ed1c2b; }
.mode-selection-popup { position: fixed; z-index: 1200; display: flex; align-items: center; gap: 17px; min-width: 476px; padding: 7px 8px; border: 6px solid #97f7a5; background: #fff; box-shadow: 0 5px 12px rgba(0,0,0,.2); }
.mode-selection-popup[hidden] { display: none !important; }
.mode-selection-option { width: 140px; height: 35px; border: 0; border-radius: 22px; box-shadow: inset 0 -5px rgba(0,0,0,.18); font-family: Georgia, serif; cursor: pointer; }
.mode-selection-option.auto { background: var(--green); color: #000; }
.mode-selection-option.manual { background: #ed1c2b; color: #fff; }
.mode-selection-option.task { background: #ff8754; color: #000; }
.mode-selection-option.active { outline: 3px solid #1e1e1e; outline-offset: 1px; }
.mode-selection-option:focus-visible { outline: 3px solid #2d78c4; outline-offset: 2px; }
.mode-selection-option:disabled { cursor: wait; opacity: .65; }
.plc-status-pill { min-width: 92px; margin-left: 12px; padding: 6px 10px; border: 1px solid transparent; border-radius: 16px; background: #e5e7eb; color: #4b5563; font-family: Georgia, serif; font-size: 11px; font-weight: 700; line-height: 1; text-align: center; white-space: nowrap; }
.plc-status-pill.online { border-color: #bdebb3; background: #d9f7d2; color: #18702a; }
.plc-status-pill.offline { border-color: #ffc5c5; background: #ffe0e0; color: #a41d1d; }
.plc-status-pill.waiting { border-color: #eadb9d; background: #fff1bd; color: #8a6000; }
.data-status { min-width: 92px; margin-left: 12px; padding: 6px 9px; border-radius: 12px; background: #e5e7eb; color: #4b5563; font-size: 11px; font-weight: 700; text-align: center; }
.data-status.online { background: #d9f7d2; color: #18702a; }
.data-status.offline { background: #ffe0e0; color: #a41d1d; }
.data-status.waiting { background: #fff1bd; color: #8a6000; }
.auth-logout { min-width: 82px; height: 30px; margin-left: 12px; border: 1px solid #b8c5bd; border-radius: 16px; background: #eef6eb; color: #245b10; font-size: 11px; font-weight: 700; cursor: pointer; }
.auth-logout:hover { background: #def3d5; }
.auth-logout:focus-visible { outline: 3px solid #2d78c4; outline-offset: 2px; }
.auth-logout:disabled { cursor: wait; opacity: .65; }
.date-time { width: 185px; margin-left: 27px; display: grid; gap: 6px; font-size: 19px; }
.date-time span { font-size: 18px; }

.sidebar { grid-row: 2 / 4; border-right: 4px solid #c7e8dc; background: white; }
.site-title { height: var(--tabs); display: flex; align-items: center; padding: 0 34px; gap: 14px; background: #c8e3d7; font-size: 20px; }
.home-icon { width: 48px; height: 46px; flex: 0 0 48px; display: grid; place-items: center; line-height: 1; }
.home-icon img { display: block; width: 100%; height: 100%; object-fit: contain; }
.farm-select-wrap { display: block; margin: 29px 26px 27px; }
.farm-select { width: 208px; height: 36px; border: 2px solid #aaa; background: linear-gradient(to right, #050505 calc(100% - 21px), #eee calc(100% - 21px)); }
.side-menu { display: grid; gap: 13px; }
.side-menu a { min-height: 77px; display: flex; align-items: center; gap: 18px; padding-left: 44px; color: #6a6a6a; text-decoration: none; }
.side-menu a:hover { background: #f1faeb; color: #111; }
.side-menu a.active { color: #079447; }
.side-menu span { width: 50px; height: 50px; flex: 0 0 50px; display: grid; place-items: center; text-align: center; color: #315843; }
.side-menu span img { display: block; width: 100%; height: 100%; object-fit: contain; }
.side-menu b { font-size: 19px; font-weight: 400; line-height: 1.35; }

.tabs { grid-column: 2; grid-row: 2; display: grid; grid-template-columns: repeat(6, minmax(120px, 1fr)); padding: 0 31px; background: var(--lime); border-bottom: 1px solid #2d2d2d; }
.tabs button, .tabs a { height: var(--tabs); border: 0; display: grid; place-items: center; background: transparent; color: #777; font-size: 23px; line-height: 1.05; text-align: center; text-decoration: none; cursor: pointer; }
.tabs button.active, .tabs a.active { color: #000; border-bottom: 4px solid #111; }

.dashboard { grid-column: 2; grid-row: 3; min-width: 0; padding: 24px 34px 15px; position: relative; }
.overview { display: grid; grid-template-columns: 255px 185px repeat(4, minmax(150px, 1fr)); align-items: center; gap: 28px; }
.climate-summary { height: 269px; background: #e7f6f8; align-self: stretch; }
.climate-summary h2, .panel h2 { height: 40px; margin: 0; display: grid; place-items: center; background: #94bee9; font-size: 22px; }
.summary-body { padding: 4px 18px; }
.summary-body h3 { margin: 0 0 14px 43px; font-size: 20px; font-weight: 400; }
.summary-body dl { margin: 0; display: grid; gap: 16px; font-size: 18px; }
.summary-body dl div { display: grid; grid-template-columns: 1fr 91px; }
.summary-body dd { margin: 0; text-align: left; }
.summary-body dd span { float: right; }

.climate-illustration { align-self: center; text-align: center; }
.notebook { width: 116px; height: 152px; margin: 0 auto; display: grid; place-items: center; position: relative; border: 3px solid #333; border-radius: 7px; color: #5ec9ef; background: white; font-size: 64px; box-shadow: 8px 0 0 -3px white, 8px 0 0 0 #444; }
.notebook::before { content: "☀"; position: absolute; top: 26px; right: 8px; color: #ffac17; font-size: 38px; }
.notebook span { position: absolute; font-size: 48px; }
.climate-recipe-name { margin-top: 12px; display: grid; gap: 4px; justify-items: stretch; }
.climate-recipe-name strong { font-size: 18px; line-height: 1.1; }
.climate-recipe-name output { min-height: 36px; padding: 6px 10px; display: grid; place-items: center; background: #dde8f6; font-size: 18px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none; user-select: none; }

.meter-card { text-align: center; }
.meter { --ring: #27c537; width: 145px; height: 145px; margin: 0 auto 8px; border-radius: 50%; display: flex; flex-direction: column; align-items: center; justify-content: center; position: relative; background: conic-gradient(var(--ring) 0 var(--level), #aaa var(--level) 100%); }
.meter::before { content: ""; position: absolute; inset: 12px; border-radius: 50%; background: white; }
.meter.red { --ring: #ff1010; }
.meter.light-meter { --ring: #00df13; }
.meter > * { position: relative; z-index: 1; }
.meter-icon { min-height: 55px; display: grid; place-items: center; font-size: 18px; line-height: 1; font-weight: 700; }
.meter-icon.co2 { font-size: 25px; font-weight: bold; border: 3px solid #111; border-radius: 50%; min-height: auto; padding: 5px; margin-bottom: 12px; }
.meter strong { font-size: 21px; font-weight: 400; }
.meter-label { width: 155px; height: 49px; margin: 0 auto; display: flex; align-items: center; justify-content: center; border: 5px solid var(--green); border-radius: 28px; background: white; font-size: 20px; }
.light-label { gap: 8px; }
.light-label i { width: 29px; height: 29px; border-radius: 50%; background: #c4e79d; }

.controls-grid { display: grid; grid-template-columns: 487px minmax(630px, 1fr) 311px; gap: 49px; margin-top: 15px; }
.panel h2 { background: var(--blue-title); height: 40px; }
.equipment-list { padding: 28px 4px 0; display: grid; gap: 10px; }
.equipment-row { height: 41px; display: grid; grid-template-columns: 56px 1fr 60px 64px 62px; align-items: center; column-gap: 8px; }
.equipment-row.motion { grid-template-columns: 56px 1fr 60px 133px; height: 51px; }
.equipment-icon { color: var(--green); font-size: 31px; text-align: center; font-weight: 700; }
.equipment-state-icon { width: 56px; height: 38px; display: grid; place-items: center; color: #111; }
.equipment-state-icon.on { color: var(--green); }
.equipment-state-image { display: block; max-width: 54px; max-height: 38px; object-fit: contain; }
.equipment-state-image[hidden], .equipment-icon-fallback[hidden] { display: none; }
.equipment-icon-fallback { max-width: 54px; overflow: hidden; font-size: 15px; line-height: 1; font-weight: 700; white-space: nowrap; }
.equipment-name { font-size: 18px; }
.auto-badge { width: 42px; height: 42px; padding: 0; display: grid; place-items: center; border: 2px solid white; outline: 2px solid var(--green); border-radius: 50%; background: var(--green); color: white; font-family: inherit; font-size: 11px; font-weight: 700; }
.auto-badge.command-badge { cursor: pointer; }
.auto-badge.command-badge:disabled { cursor: wait; }
.auto-badge.command-badge.pending { animation: pending-pulse .8s ease-in-out infinite alternate; }
.auto-badge.mode-badge { transition: background-color .15s ease, outline-color .15s ease; }
.auto-badge.mode-badge.mode-0 { background: #ed1c24; outline-color: #ed1c24; }
.auto-badge.mode-badge.mode-1 { background: var(--green); outline-color: var(--green); }
.auto-badge.mode-badge.mode-2 { background: #ff8a45; outline-color: #ff8a45; }
.auto-badge.mode-badge.mode-3 { background: #303033; outline-color: #303033; }
.auto-badge.mode-badge.mode-unknown { background: #9ca3af; outline-color: #9ca3af; }
.onoff-label { font-size: 18px; }
.switch { width: 58px; height: 29px; padding: 3px; border: 3px solid #2b2b2b; border-radius: 20px; background: #aaa; cursor: pointer; }
.switch::after { content: ""; display: block; width: 17px; height: 17px; border: 3px solid #222; border-radius: 50%; background: #777; transition: transform .15s ease; }
.switch.on { background: #6acb35; }
.switch.on::after { transform: translateX(27px); background: #39b70d; }
.switch:focus-visible { outline: 3px solid #2d78c4; outline-offset: 2px; }
.switch:disabled { cursor: wait; opacity: .65; }
.switch.feedback-only:disabled { cursor: default; opacity: 1; }
.switch.pending { outline: 3px solid #f5b700; animation: pending-pulse .8s ease-in-out infinite alternate; }
@keyframes pending-pulse { from { opacity: .55; } to { opacity: 1; } }
.motion-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 19px; }
.motion-side { display: grid; justify-items: start; gap: 3px; font-size: 13px; }

.schedule-head { padding: 29px 116px 22px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px 37px; font-size: 17px; }
.schedule-head > div { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.schedule-head .schedule-time { min-width: 68px; padding: 8px 10px; background: #f0f0f0; font-family: monospace; font-size: 19px; font-weight: 700; text-align: center; pointer-events: none; user-select: none; }
.schedule-head .schedule-hours { min-width: 59px; padding: 7px 12px; background: #575757; color: white; font-weight: 700; text-align: center; pointer-events: none; user-select: none; }
.schedule-badge { min-width: 80px; height: 36px; display: inline-flex; align-items: center; justify-content: center; border-radius: 20px; color: white; font-size: 11px; }
.schedule-badge.day { background: #ffd000; }
.schedule-badge.night { background: #164a88; }
.light-rows { display: grid; gap: 11px; }
.light-row { height: 50px; display: grid; grid-template-columns: 88px 52px 60px 64px 72px 68px 70px 68px 62px; align-items: center; gap: 7px; font-size: 16px; }
.row-state-icon { width: 41px; height: 38px; margin-left: 17px; }
.row-state-icon .equipment-state-image { max-width: 41px; max-height: 38px; }
.row-state-icon .equipment-icon-fallback { width: 41px; height: 38px; border-top: 5px solid #4e84ff; border-bottom: 5px solid #4e84ff; background: repeating-linear-gradient(0deg, #ff725a 0 3px, white 3px 6px); color: transparent; font-size: 0; }
.row-state-icon.on .equipment-icon-fallback { border-color: var(--green); background: repeating-linear-gradient(0deg, var(--green) 0 3px, white 3px 7px); }
.light-row .light-time { padding: 9px 2px; background: #f0f0f0; font-family: monospace; font-size: 16px; font-weight: 700; white-space: nowrap; text-align: center; pointer-events: none; user-select: none; }
.light-row strong { font-size: 13px; font-weight: 400; white-space: nowrap; }
.light-row output { padding: 7px; background: #f4d300; font-weight: bold; white-space: nowrap; }
.light-row .switch { width: 58px; }

.setpoints { padding: 37px 33px; display: grid; gap: 13px; }
.setpoints > div { height: 43px; display: grid; grid-template-columns: 51px 1fr 59px 29px; align-items: center; gap: 7px; }
.set-icon { width: 51px; height: 43px; display: grid; place-items: center; font-size: 35px; text-align: center; font-weight: bold; }
.setpoint-image { display: block; max-width: 47px; max-height: 41px; object-fit: contain; }
.setpoint-image[hidden], .setpoint-fallback[hidden] { display: none !important; }
.set-icon.heat, .set-icon.co2-day { color: #ffd000; }
.set-icon.cool, .set-icon.co2-night { color: #1d65ad; }
.set-icon.rh-day { color: #45cdbd; }
.set-icon.rh-night { color: #2f84be; }
.set-icon.co2-day .setpoint-fallback, .set-icon.co2-night .setpoint-fallback { display: grid; place-items: center; min-width: 45px; min-height: 37px; font-size: 15px; border-radius: 50%; background: currentColor; color: #111; }
.setpoints b { font-size: 17px; white-space: nowrap; }
.setpoints output { padding: 6px; background: #f1f1f1; font-weight: bold; text-align: center; }
.setpoints small { font-size: 16px; }

.connection-status { position: fixed; right: 18px; bottom: 14px; max-width: 480px; padding: 8px 14px; border-radius: 6px; background: rgba(20,20,20,.85); color: white; font-size: 13px; opacity: 0; transform: translateY(8px); pointer-events: none; transition: .2s ease; }
.connection-status.show { opacity: 1; transform: translateY(0); }
.connection-status.error { background: #a91f1f; }
.connection-status.success { background: #227c2d; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 1500px) {
    body { min-width: 1040px; }
    :root { --sidebar: 220px; }
    .side-menu a { padding-left: 25px; }
    .farm-select { width: 168px; }
    .overview { grid-template-columns: 230px 135px repeat(4, minmax(125px, 1fr)); gap: 14px; }
    .controls-grid { grid-template-columns: 420px 660px 290px; gap: 25px; }
    .dashboard { overflow-x: auto; }
    .meter { width: 128px; height: 128px; }
}

@media (max-width: 900px) {
    body { min-width: 0; }
    .app-shell { display: block; border: 0; }
    .topbar { position: sticky; top: 0; z-index: 5; padding: 0 12px; }
    .sun-indicator, .lab-box, .day-pill { display: none; }
    .brand { width: auto; }
    .mode-pill { margin-left: auto; width: 90px; }
    .date-time { width: auto; margin-left: 13px; font-size: 13px; }
    .date-time span { font-size: 13px; }
    .sidebar { display: none; }
    .tabs { overflow-x: auto; padding: 0; grid-template-columns: repeat(6, 130px); }
    .tabs button, .tabs a { font-size: 17px; }
    .dashboard { padding: 16px; overflow: visible; }
    .overview { grid-template-columns: repeat(2, 1fr); }
    .climate-summary { grid-column: 1 / -1; }
    .climate-illustration { display: none; }
    .controls-grid { grid-template-columns: 1fr; gap: 22px; }
    .equipment-row { grid-template-columns: 44px 1fr 50px 55px 58px; }
    .schedule-head { padding: 20px 0; }
    .lighting-panel { overflow-x: auto; }
    .light-rows { min-width: 650px; }
}
