:root {
  --ink: #15342b;
  --muted: #667b73;
  --emerald: #0d5a43;
  --emerald-2: #167357;
  --mint: #dbeee5;
  --cream: #f6f3ea;
  --paper: #fffdf8;
  --line: #dbe3dc;
  --amber: #9a6714;
  --red: #a54036;
  --shadow: 0 18px 45px rgba(24, 62, 50, .08);
  --radius: 20px;
}

* { box-sizing: border-box; }
html { color-scheme: light; scroll-behavior: smooth; }
body { margin: 0; background: var(--cream); color: var(--ink); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; line-height: 1.5; }
button, input { font: inherit; }
button, label[for], summary { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.skip-link { position: fixed; left: 1rem; top: -4rem; z-index: 100; padding: .7rem 1rem; background: white; color: var(--emerald); border-radius: 8px; }
.skip-link:focus { top: 1rem; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.topbar { height: 82px; padding: 0 clamp(1.25rem, 4vw, 4rem); display: flex; align-items: center; justify-content: space-between; background: rgba(255,253,248,.93); border-bottom: 1px solid rgba(21,52,43,.1); position: sticky; top: 0; z-index: 20; backdrop-filter: blur(14px); }
.brand { display: flex; align-items: center; gap: .75rem; }
.brand-mark { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 14px; background: var(--emerald); color: #fff; box-shadow: 0 8px 20px rgba(13,90,67,.18); }
.brand-mark svg { width: 27px; height: 27px; }
.brand div { display: flex; flex-direction: column; line-height: 1.2; }
.brand strong { font-family: Georgia, serif; font-size: 1.25rem; letter-spacing: -.02em; }
.brand span { color: var(--muted); font-size: .74rem; letter-spacing: .04em; margin-top: 3px; }
.header-actions { display: flex; align-items: center; gap: .8rem; }
.session-user { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.15; }
.session-user span { color: var(--muted); font-size: .62rem; }
.session-user strong { max-width: 180px; overflow: hidden; text-overflow: ellipsis; font-size: .76rem; white-space: nowrap; }
.logout-button { min-height: 38px; padding: .5rem .8rem; }
.mode-control { display: flex; align-items: center; gap: .7rem; padding: .45rem .65rem .45rem .8rem; background: #ecebe3; border-radius: 99px; font-size: .82rem; }
.mode-label { color: var(--muted); }
.switch-row { display: flex; align-items: center; gap: .45rem; font-weight: 700; cursor: pointer; }
.switch-row input { position: absolute; opacity: 0; pointer-events: none; }
.switch { width: 34px; height: 20px; border-radius: 20px; background: #9ba8a3; padding: 3px; transition: .2s; }
.switch::after { content: ""; display: block; width: 14px; height: 14px; background: white; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px #0003; }
.switch-row input:checked + .switch { background: var(--emerald-2); }
.switch-row input:checked + .switch::after { transform: translateX(14px); }
.switch-row input:focus-visible + .switch { outline: 3px solid rgba(22,115,87,.25); outline-offset: 2px; }
.icon-button { width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 50%; background: var(--paper); display: grid; place-items: center; cursor: pointer; }
.icon-button:hover { background: var(--mint); }
.icon-button svg { width: 19px; }
.icon-button.busy svg { animation: spin 1s linear infinite; }

.shell { width: min(1180px, calc(100% - 2.5rem)); margin: 0 auto; padding: 3.25rem 0 4rem; }
.session-loading { min-height: calc(100vh - 82px); display: flex; align-items: center; justify-content: center; gap: .7rem; color: var(--muted); font-size: .85rem; }
.loading-leaf { width: 18px; height: 25px; border-radius: 90% 10% 80% 20%; background: var(--emerald-2); transform: rotate(-35deg); animation: leaf-pulse 1.1s ease-in-out infinite alternate; }
.login-shell { min-height: calc(100vh - 82px); padding: 3rem 1.25rem; display: grid; place-items: center; background: radial-gradient(circle at 50% 25%, #e2f0e5 0, transparent 38%), linear-gradient(155deg, #f6f3ea 35%, #e8eee4 100%); }
.login-card { width: min(100%, 440px); padding: clamp(1.5rem, 5vw, 2.4rem); box-shadow: 0 25px 70px rgba(24,62,50,.13); }
.login-mark { width: 54px; height: 54px; display: grid; place-items: center; margin-bottom: 1.4rem; border-radius: 17px; color: white; background: var(--emerald); box-shadow: 0 10px 24px rgba(13,90,67,.22); }
.login-mark svg { width: 32px; height: 32px; }
.login-card h1 { font-size: clamp(2rem, 8vw, 2.75rem); }
.login-copy { margin: .8rem 0 1.5rem; color: var(--muted); font-size: .88rem; }
.login-form { display: grid; gap: .9rem; }
.login-form label { display: grid; gap: .35rem; color: var(--muted); font-size: .72rem; font-weight: 750; }
.login-form input { width: 100%; min-height: 46px; padding: .65rem .75rem; color: var(--ink); background: #fbfaf5; border: 1px solid #cdd8d1; border-radius: 10px; outline: none; }
.login-form input:focus { border-color: var(--emerald-2); box-shadow: 0 0 0 3px rgba(22,115,87,.12); }
.login-submit { width: 100%; min-height: 46px; margin-top: .2rem; }
.login-error { padding: .7rem .8rem; color: #893b33; background: #fff1ee; border: 1px solid #edcbc5; border-radius: 9px; font-size: .76rem; }
.demo-entry { margin-top: 1.4rem; padding-top: 1.15rem; display: flex; flex-wrap: wrap; justify-content: center; gap: .35rem .6rem; color: var(--muted); border-top: 1px solid var(--line); font-size: .72rem; text-align: center; }
.demo-entry .text-button { font-size: .72rem; }
.intro { display: flex; align-items: flex-end; justify-content: space-between; gap: 2rem; margin-bottom: 1.6rem; }
.eyebrow { margin: 0 0 .45rem; color: var(--emerald-2); font-size: .7rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
h1, h2 { font-family: Georgia, "Times New Roman", serif; font-weight: 500; letter-spacing: -.025em; margin: 0; }
h1 { font-size: clamp(2.25rem, 5vw, 3.6rem); line-height: .98; }
h2 { font-size: 1.5rem; }
.intro-copy { color: var(--muted); margin: .75rem 0 0; }
.system-status { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .45rem; }
.status-pill { display: inline-flex; align-items: center; gap: .45rem; padding: .48rem .7rem; background: var(--paper); border: 1px solid var(--line); border-radius: 99px; color: var(--muted); font-size: .76rem; font-weight: 650; }
.status-pill i { width: 7px; height: 7px; border-radius: 50%; background: #93a09b; }
.status-pill.good { color: var(--emerald); background: #edf7f1; border-color: #c5e4d4; }
.status-pill.good i { background: #20a26f; box-shadow: 0 0 0 3px #20a26f1f; }
.status-pill.bad { color: var(--red); background: #fff2ef; border-color: #efd0cb; }
.status-pill.bad i { background: var(--red); }

.demo-banner, .message { border-radius: 14px; padding: .82rem 1rem; margin: 0 0 1.3rem; display: flex; align-items: center; gap: .7rem; font-size: .85rem; }
.demo-banner { color: #6c4a12; background: #fff5db; border: 1px solid #ead6a5; }
.demo-banner svg { width: 19px; flex: 0 0 auto; }
.message { background: #fff1ee; color: #893b33; border: 1px solid #edcbc5; }
[hidden] { display: none !important; }
.card { background: var(--paper); border: 1px solid rgba(31,75,61,.12); border-radius: var(--radius); box-shadow: var(--shadow); }
.overview-grid { display: grid; grid-template-columns: minmax(0, 1.52fr) minmax(310px, .9fr); gap: 1.25rem; }
.camera-card { padding: 1.25rem; }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.timestamp { color: var(--muted); font-size: .78rem; margin-top: .35rem; }
.camera-frame { position: relative; min-height: 390px; aspect-ratio: 16 / 10; overflow: hidden; border-radius: 15px; background: #e7e8df; }
.camera-frame img { width: 100%; height: 100%; object-fit: cover; display: block; }
.camera-empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 2rem; color: var(--muted); background: radial-gradient(circle at 50% 40%, #f7f5ec 0, #e6e8df 70%); }
.camera-icon { width: 46px; height: 46px; color: #84958e; margin-bottom: 1rem; }
.camera-empty strong { color: var(--ink); font-family: Georgia, serif; font-size: 1.22rem; font-weight: 500; }
.camera-empty span { max-width: 310px; font-size: .84rem; margin-top: .35rem; }
.demo-plant { position: absolute; inset: 0; overflow: hidden; background: linear-gradient(155deg, #d7e8c9 0%, #b8d2b2 45%, #7c9e70 100%); }
.demo-plant::before { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, transparent 49.6%, #ffffff14 50%, transparent 50.4%), linear-gradient(transparent 49.6%, #ffffff12 50%, transparent 50.4%); background-size: 55px 55px; }
.demo-plant > span { position: absolute; right: 1rem; top: 1rem; font-size: .65rem; letter-spacing: .15em; color: white; background: #15342b99; padding: .35rem .55rem; border-radius: 5px; }
.demo-sun { position: absolute; width: 155px; height: 155px; border-radius: 50%; right: -25px; top: -35px; background: #eff7d5; filter: blur(2px); opacity: .75; }
.demo-soil { position: absolute; left: 0; right: 0; bottom: 0; height: 27%; background: linear-gradient(#786243, #493c2d); }
.leaf { position: absolute; left: 50%; bottom: 14%; width: 34%; height: 48%; border-radius: 90% 12% 80% 15%; background: linear-gradient(135deg, #77a859, #275f42); transform-origin: 10% 90%; box-shadow: inset 0 0 25px #e7ffc52e, 0 12px 25px #284b2c30; }
.leaf::after { content: ""; position: absolute; width: 80%; height: 2px; background: #d4eab56b; left: 5%; top: 60%; transform: rotate(38deg); transform-origin: left; }
.leaf-1 { transform: translateX(-10%) rotate(-8deg); }
.leaf-2 { transform: translateX(-20%) rotate(42deg) scale(.95); filter: brightness(.95); }
.leaf-3 { transform: translateX(-65%) rotate(92deg) scale(.95); }
.leaf-4 { transform: translateX(-85%) rotate(138deg) scale(.88); filter: brightness(1.1); }
.leaf-5 { transform: translateX(-55%) rotate(190deg) scale(.8); }
.camera-actions { display: flex; gap: .7rem; margin-top: 1rem; }
.button { min-height: 42px; padding: .64rem .95rem; border-radius: 10px; border: 1px solid transparent; display: inline-flex; align-items: center; justify-content: center; gap: .5rem; font-weight: 750; font-size: .82rem; cursor: pointer; transition: transform .15s, background .15s; }
.button:hover { transform: translateY(-1px); }
.button:disabled { opacity: .55; cursor: wait; transform: none; }
.button svg { width: 17px; }
.button.primary { color: white; background: var(--emerald); border-color: var(--emerald); }
.button.primary:hover { background: #084733; }
.button.secondary { color: var(--emerald); background: var(--paper); border-color: #b9cdc4; }
.button.ghost { background: transparent; color: var(--muted); border-color: var(--line); }

.metrics-panel { display: flex; flex-direction: column; gap: .8rem; }
.metric-card { padding: 1.15rem; }
.moisture-card { position: relative; min-height: 157px; display: grid; grid-template-columns: auto 1fr; gap: 1rem; overflow: hidden; }
.metric-icon, .ai-icon { width: 42px; height: 42px; border-radius: 12px; background: var(--mint); color: var(--emerald); display: grid; place-items: center; }
.metric-icon svg, .ai-icon svg { width: 22px; height: 22px; }
.metric-copy { display: flex; flex-direction: column; }
.metric-copy > span, .compact > span, .ai-card span { color: var(--muted); font-size: .76rem; font-weight: 650; }
.metric-copy strong { font-size: 2.5rem; line-height: 1.08; letter-spacing: -.05em; margin-top: .25rem; }
.metric-copy small, .compact small, .ai-card small { color: var(--muted); font-size: .7rem; }
.gauge { position: absolute; left: 1.15rem; right: 1.15rem; bottom: 1rem; height: 6px; border-radius: 10px; overflow: hidden; background: #e5e9e5; }
.gauge span { display: block; width: 0; height: 100%; background: linear-gradient(90deg, #d4b254, #2a936a); border-radius: inherit; transition: width .5s ease; }
.compact { display: flex; flex-direction: column; min-height: 113px; }
.compact strong { font-size: 1.6rem; margin: .35rem 0 auto; letter-spacing: -.03em; }
.sensor-points { display: grid; gap: .55rem; }
.sensor-point { padding: .72rem .82rem; box-shadow: none; border-radius: 13px; }
.sensor-point > div:first-child, .point-footer { display: flex; align-items: center; justify-content: space-between; gap: .6rem; }
.sensor-point > div:first-child strong { font-size: .79rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.point-state { flex: 0 0 auto; padding: .2rem .42rem; border-radius: 99px; color: var(--muted); background: #e8ebe7; font-size: .59rem; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
.point-state.active { color: var(--emerald); background: #dff1e7; }
.point-state.offline { color: var(--red); background: #fae7e3; }
.point-values { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; margin: .48rem 0 .38rem; }
.point-values span { display: flex; flex-direction: column; }
.point-values small { color: var(--muted); font-size: .61rem; }
.point-values b { font-size: 1rem; letter-spacing: -.02em; }
.point-footer { color: var(--muted); font-size: .62rem; border-top: 1px solid #e8ece8; padding-top: .35rem; }
.point-footer .low { color: var(--amber); font-weight: 750; }
.point-footer .high { color: #8b5532; font-weight: 750; }
.update-card { padding: .9rem 1rem; display: flex; align-items: center; justify-content: space-between; gap: .8rem; font-size: .72rem; color: var(--muted); }
.update-card > div { display: flex; align-items: center; gap: .6rem; min-width: 0; }
.update-card > div > div { display: flex; flex-direction: column; min-width: 0; }
.update-card strong { color: var(--ink); font-size: .75rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pulse-dot { width: 8px; height: 8px; background: #9aa5a1; border-radius: 50%; flex: 0 0 auto; }
.pulse-dot.live { background: #25a774; box-shadow: 0 0 0 4px #25a77418; }
.ai-card { padding: .95rem 1rem; display: grid; grid-template-columns: auto 1fr; gap: .8rem; background: #f0f0e8; box-shadow: none; }
.ai-icon { background: #dfe4de; color: #6d7f77; }
.ai-card div:last-child { display: flex; flex-direction: column; }
.ai-card strong { font-size: .9rem; }

.history-card { margin-top: 1.25rem; padding: 1.35rem; }
.history-heading { align-items: center; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 1rem; color: var(--muted); font-size: .72rem; }
.chart-legend span { display: flex; align-items: center; gap: .4rem; }
.legend-line { width: 18px; border-top: 2px solid var(--emerald-2); }
.legend-band { width: 16px; height: 8px; background: #dfeee4; border-radius: 2px; }
.chart-wrap { position: relative; min-height: 280px; }
.chart { width: 100%; height: 280px; overflow: visible; }
.chart .grid-line { stroke: #dde4de; stroke-width: 1; stroke-dasharray: 3 5; }
.chart .axis-label { fill: #73847d; stroke: none; font: 11px system-ui, sans-serif; }
.chart .target-band { fill: #dfeee4; stroke: none; opacity: .75; }
.chart .line { fill: none; stroke: var(--emerald-2); stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: url(#areaGradient); stroke: none; }
.chart .point { fill: var(--paper); stroke: var(--emerald-2); stroke-width: 2; }
.chart-empty { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; color: var(--muted); font-size: .84rem; }
.history-footer { padding-top: .8rem; border-top: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: .72rem; }
.text-button { border: 0; background: none; color: var(--emerald); font-size: .78rem; font-weight: 750; display: flex; align-items: center; gap: .35rem; cursor: pointer; }
.text-button svg { width: 16px; }

.settings-section { margin-top: 3.2rem; }
.settings-title { align-items: flex-end; }
.settings-title > p { max-width: 340px; margin: 0; text-align: right; color: var(--muted); font-size: .78rem; }
.settings-grid { display: grid; grid-template-columns: minmax(260px, 1fr) minmax(0, 2fr); gap: 1rem; align-items: start; }
.settings-card { box-shadow: none; overflow: hidden; }
.settings-card summary { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: .75rem; padding: 1rem; cursor: pointer; list-style: none; }
.settings-card summary::-webkit-details-marker { display: none; }
.settings-card summary > span:nth-child(2) { display: flex; flex-direction: column; }
.settings-card summary strong { font-size: .86rem; }
.settings-card summary small { color: var(--muted); font-size: .69rem; }
.settings-icon { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; color: var(--emerald); background: var(--mint); }
.settings-icon svg { width: 19px; }
.chevron { width: 16px; color: var(--muted); transition: transform .2s; }
details[open] .chevron { transform: rotate(180deg); }
.form-grid { border-top: 1px solid var(--line); padding: 1rem; display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.form-grid label { display: flex; flex-direction: column; gap: .3rem; color: var(--muted); font-size: .7rem; font-weight: 700; }
.form-grid input { width: 100%; min-height: 40px; padding: .55rem .65rem; color: var(--ink); background: #fbfaf5; border: 1px solid #cdd8d1; border-radius: 8px; outline: none; }
.form-grid input:focus { border-color: var(--emerald-2); box-shadow: 0 0 0 3px rgba(22,115,87,.12); }
.form-help { grid-column: 1 / -1; color: var(--muted); font-size: .68rem; margin: 0; }
.form-grid .button { grid-column: 1 / -1; }
.sensor-settings-form { border-top: 1px solid var(--line); padding: 1rem; display: grid; gap: .85rem; }
.target-fields { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.sensor-settings-form label { display: flex; flex-direction: column; gap: .3rem; color: var(--muted); font-size: .67rem; font-weight: 700; }
.sensor-settings-form input { width: 100%; min-height: 38px; padding: .5rem .6rem; color: var(--ink); background: #fbfaf5; border: 1px solid #cdd8d1; border-radius: 8px; outline: none; }
.sensor-settings-form input:focus { border-color: var(--emerald-2); box-shadow: 0 0 0 3px rgba(22,115,87,.12); }
.sensor-settings-form input[readonly] { color: #6f7e78; background: #eef0eb; }
#sensorSettingsRows { display: grid; gap: .7rem; }
.sensor-setting-row { margin: 0; padding: .7rem; min-width: 0; border: 1px solid var(--line); border-radius: 11px; display: grid; grid-template-columns: 1.35fr 1fr .58fr .72fr 1fr 1fr; gap: .55rem; align-items: end; }
.sensor-setting-row legend { padding: 0 .35rem; color: var(--emerald); font-size: .66rem; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.sensor-setting-row .enabled-field { min-height: 38px; flex-direction: row; align-items: center; justify-content: center; gap: .35rem; border: 1px solid #cdd8d1; border-radius: 8px; background: #fbfaf5; }
.sensor-setting-row .enabled-field input { width: 16px; min-height: 16px; accent-color: var(--emerald); }
.sensor-settings-form > .button { width: 100%; }

footer { width: min(1180px, calc(100% - 2.5rem)); margin: 0 auto; padding: 1.5rem 0 2.5rem; border-top: 1px solid var(--line); color: var(--muted); font-size: .7rem; display: flex; justify-content: space-between; gap: 1rem; }
.toast-region { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: .6rem; z-index: 50; pointer-events: none; }
.toast { width: min(360px, calc(100vw - 2rem)); padding: .8rem 1rem; background: #173f33; color: white; border-radius: 11px; box-shadow: 0 12px 35px #102d2460; font-size: .8rem; animation: toast-in .25s ease; }
.toast.error { background: #873e35; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }
@keyframes leaf-pulse { to { transform: rotate(-25deg) scale(1.08); opacity: .65; } }

@media (max-width: 900px) {
  .overview-grid { grid-template-columns: 1fr; }
  .metrics-panel { display: grid; grid-template-columns: 1.2fr 1fr; }
  .moisture-card { grid-row: span 2; }
  .ai-card { grid-column: 1 / -1; }
  .settings-grid { grid-template-columns: 1fr; }
  .sensor-setting-row { grid-template-columns: 1.2fr 1fr 1fr; }
  .sensor-setting-row .device-field { grid-column: span 2; }
}
@media (max-width: 640px) {
  .topbar { height: 68px; padding: 0 1rem; }
  .brand-mark { width: 38px; height: 38px; }
  .brand strong { font-size: 1.05rem; }
  .brand div span { display: none; }
  .session-user { display: none; }
  .logout-button { min-height: 36px; padding: .45rem .65rem; }
  .mode-label { display: none; }
  .mode-control { padding-left: .55rem; }
  .shell { width: min(100% - 1.25rem, 1180px); padding-top: 2rem; }
  .intro { align-items: flex-start; flex-direction: column; gap: 1.2rem; }
  .system-status { justify-content: flex-start; }
  .status-pill { font-size: .68rem; }
  .camera-card, .history-card { padding: .85rem; border-radius: 16px; }
  .camera-frame { min-height: 260px; aspect-ratio: 4 / 3; }
  .camera-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .metrics-panel { display: flex; }
  .sensor-point { padding: .68rem .75rem; }
  .update-card { align-items: flex-start; }
  .update-card > span { max-width: 40%; text-align: right; }
  .history-heading { align-items: flex-start; flex-direction: column; }
  .chart-wrap, .chart { min-height: 230px; height: 230px; }
  .settings-title { align-items: flex-start; flex-direction: column; }
  .settings-title > p { text-align: left; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid label, .form-grid .button, .form-help { grid-column: 1; }
  .sensor-setting-row { grid-template-columns: 1fr 1fr; gap: .5rem; }
  .sensor-setting-row .device-field { grid-column: 1 / -1; }
  footer { width: calc(100% - 1.25rem); flex-direction: column; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
/* O controle visual não deve interceptar o checkbox acessível. */
.switch { pointer-events: none; }
