/* ==========================================================================
   AquaControl Pro — Botanical Telemetry Precision System
   Áp dụng Anti-Slop Design (Archetype A/B), Design Taste Frontend & Frontend Design:
   - Bề mặt đơn sắc Obsidian Carbon (#09090B) / Porcelain Studio (#FAFAFA)
   - 1 điểm nhấn Botanical Emerald duy nhất, không neon glow, không gradient blob
   - Đường viền hairline 1px tinh tế, chuyển động nhanh sắc gọn < 180ms
   ========================================================================== */

:root,
html.dark {
  color-scheme: dark;

  /* --- Obsidian Carbon Neutral Scale (Zero generic slate-900/indigo tint) --- */
  --c-bg: 9 9 11;                      /* #09090B */
  --c-surface: 17 17 20;               /* #111114 */
  --c-surface-elevated: 22 22 26;      /* #16161A */
  --c-surface-sub: 13 13 16;           /* #0D0D10 */
  --c-input: 12 12 15;                 /* #0C0C0F */
  --c-muted: 24 24 28;                 /* #18181C */
  --c-muted-high: 32 32 38;            /* #202026 */
  --c-muted-highest: 46 46 54;         /* #2E2E36 */

  --c-fg: 244 244 245;                 /* #F4F4F5 */
  --c-fg-muted: 161 161 170;           /* #A1A1AA (contrast >= 7.2:1 on #111114) */
  --c-border: 39 39 42;                /* #27272A */
  --c-border-strong: 63 63 70;         /* #3F3F46 */

  /* Signature Accent: Precision Botanical Emerald */
  --c-primary: 16 185 129;             /* #10B981 */
  --c-on-primary: 6 24 18;             /* #061812 (contrast 8.1:1 on emerald) */
  --c-primary-container: 16 185 129;   /* dùng kèm opacity /12 */
  --c-on-primary-container: 110 231 183; /* #6EE7B7 */

  /* Active/Healthy Green */
  --c-secondary: 16 185 129;           /* #10B981 */
  --c-on-secondary: 6 24 18;
  --c-secondary-container: 16 185 129;
  --c-on-secondary-container: 110 231 183;

  /* Hydration / Air Humidity (Desaturated Cool Cyan) */
  --c-tertiary: 56 189 248;            /* #38BDF8 */
  --c-on-tertiary: 8 47 73;

  /* Restrained Semantic Alerts */
  --c-warning: 245 158 11;             /* #F59E0B */
  --c-warning-container: 245 158 11;
  --c-on-warning-container: 252 211 77; /* #FCD34D */

  --c-error: 244 63 94;                /* #F43F5E (crisp rose, less garish than pure red) */
  --c-on-error: 255 255 255;
  --c-error-container: 244 63 94;
  --c-on-error-container: 253 164 175; /* #FDA4AF */

  /* Schedule accent (Neutralized Slate-Teal instead of AI Purple) */
  --c-schedule: 56 189 248;
  --c-schedule-container: 56 189 248;

  /* Component tokens */
  --panel-bg: #111114;
  --panel-elevated: #16161A;
  --panel-border: rgba(255, 255, 255, 0.08);
  --panel-border-hover: rgba(255, 255, 255, 0.16);
  --panel-shadow: 0 1px 0 0 rgba(255, 255, 255, 0.03) inset, 0 8px 24px -12px rgba(0, 0, 0, 0.7);
  --chrome-bg: rgba(9, 9, 11, 0.86);
  --focus-ring: #10B981;
}

html.light {
  color-scheme: light;

  /* --- Porcelain Studio Neutral Scale --- */
  --c-bg: 248 248 247;                 /* #F8F8F7 (warm architectural paper) */
  --c-surface: 255 255 255;            /* #FFFFFF */
  --c-surface-elevated: 255 255 255;   /* #FFFFFF */
  --c-surface-sub: 244 244 242;        /* #F4F4F2 */
  --c-input: 255 255 255;              /* #FFFFFF */
  --c-muted: 241 241 239;              /* #F1F1EF */
  --c-muted-high: 233 233 230;         /* #E9E9E6 */
  --c-muted-highest: 212 212 216;      /* #D4D4D8 */

  --c-fg: 24 24 27;                    /* #18181B */
  --c-fg-muted: 101 101 110;           /* #65656E (contrast >= 5.7:1 on white) */
  --c-border: 228 228 231;             /* #E4E4E7 */
  --c-border-strong: 161 161 170;      /* #A1A1AA */

  /* Signature Accent: Deep Botanical Emerald */
  --c-primary: 5 150 105;              /* #059669 */
  --c-on-primary: 255 255 255;
  --c-primary-container: 5 150 105;
  --c-on-primary-container: 6 95 70;   /* #065F46 */

  --c-secondary: 5 150 105;
  --c-on-secondary: 255 255 255;
  --c-secondary-container: 5 150 105;
  --c-on-secondary-container: 6 95 70;

  --c-tertiary: 2 132 199;             /* #0284C7 */
  --c-on-tertiary: 255 255 255;

  --c-warning: 180 83 9;               /* #B45309 */
  --c-warning-container: 217 119 6;
  --c-on-warning-container: 146 64 14;

  --c-error: 225 29 72;                /* #E11D48 */
  --c-on-error: 255 255 255;
  --c-error-container: 225 29 72;
  --c-on-error-container: 159 18 57;

  --c-schedule: 2 132 199;
  --c-schedule-container: 2 132 199;

  --panel-bg: #FFFFFF;
  --panel-elevated: #FFFFFF;
  --panel-border: rgba(24, 24, 27, 0.09);
  --panel-border-hover: rgba(24, 24, 27, 0.2);
  --panel-shadow: 0 1px 2px rgba(24, 24, 27, 0.04), 0 8px 24px -14px rgba(24, 24, 27, 0.08);
  --chrome-bg: rgba(248, 248, 247, 0.88);
  --focus-ring: #059669;
}

/* ---------- Nền phẳng tĩnh lặng (Zero AI blobs, zero visual noise) ---------- */
body {
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  background-color: rgb(var(--c-bg));
  color: rgb(var(--c-fg));
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.tabular-nums {
  font-variant-numeric: tabular-nums;
}

.font-mono {
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;
  font-variant-numeric: tabular-nums;
}

/* ---------- Bề mặt kiến trúc hairline (Quiet Luxury / Linear-grade) ---------- */
.panel,
.glass-card {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  box-shadow: var(--panel-shadow);
}

/* Hiệu ứng phản hồi gọn (< 160ms, ease-out chuẩn Emil Kowalski) */
.panel-interactive,
.glass-card.lift {
  transition: border-color 140ms cubic-bezier(0.23, 1, 0.32, 1),
              background-color 140ms cubic-bezier(0.23, 1, 0.32, 1),
              transform 120ms cubic-bezier(0.23, 1, 0.32, 1);
}

.panel-interactive:hover,
.glass-card.lift:hover {
  border-color: var(--panel-border-hover);
}

/* Chrome thanh điều hướng (chỉ áp blur trên fixed header/sidebar) */
.iot-chrome {
  background: var(--chrome-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-color: var(--panel-border);
}

/* Phản hồi bấm vật lý (Tactile 8-state feedback) */
button:not(:disabled):active {
  transform: scale(0.97);
}

:is(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

button,
a,
select,
label.switch,
[role="button"] {
  touch-action: manipulation;
}

button:not(:disabled),
a[href],
[role="button"] {
  cursor: pointer;
}

.skip-link {
  position: fixed;
  top: -64px;
  left: 16px;
  z-index: 200;
  padding: 8px 14px;
  border-radius: 8px;
  background: rgb(var(--c-primary));
  color: rgb(var(--c-on-primary));
  font-weight: 600;
  font-size: 13px;
  transition: top 120ms ease-out;
}
.skip-link:focus {
  top: 12px;
}

/* Icon nét mảnh tinh tế (wght 300, opsz 20 thay vì icon dày thô) */
.material-symbols-outlined {
  font-variation-settings: 'FILL' 0, 'wght' 300, 'GRAD' 0, 'opsz' 20;
  user-select: none;
  line-height: 1;
}
.fill-icon {
  font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 20;
}

/* ---------- Toggle switch tối giản ---------- */
.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.switch-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: rgb(var(--c-muted-highest));
  border-radius: 9999px;
  transition: background-color 160ms ease-out;
}
.switch-slider:before {
  content: '';
  position: absolute;
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background: #ffffff;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  transition: transform 160ms cubic-bezier(0.23, 1, 0.32, 1);
}
.switch input:focus-visible + .switch-slider {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}
.switch input:checked + .switch-slider {
  background: rgb(var(--c-primary));
}
.switch input:checked + .switch-slider:before {
  transform: translateX(18px);
}
.switch input:disabled + .switch-slider {
  opacity: 0.45;
  cursor: not-allowed;
}
.switch-sm {
  width: 34px;
  height: 19px;
}
.switch-sm .switch-slider:before {
  height: 13px;
  width: 13px;
  left: 3px;
  bottom: 3px;
}
.switch-sm input:checked + .switch-slider:before {
  transform: translateX(15px);
}
.switch-light input:checked + .switch-slider {
  background: rgb(var(--c-warning));
}

/* ---------- Trạng thái đặc biệt trên thẻ Zone (tiết chế, không chói) ---------- */
.zone-tile-pumping {
  border-color: rgba(16, 185, 129, 0.45) !important;
}
.zone-tile-offline {
  opacity: 0.68;
  border-style: dashed !important;
}

/* Chớp nhẹ khi số liệu mới về */
@keyframes value-pulse {
  0% { color: rgb(var(--c-primary)); }
  100% { color: inherit; }
}
.value-flash {
  animation: value-pulse 600ms ease-out;
}

/* Thanh dòng chảy mảnh 2px khi bơm đang chạy */
@keyframes flow-slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(250%); }
}
.pump-flow-track {
  position: relative;
  overflow: hidden;
  background: rgba(16, 185, 129, 0.14);
}
.pump-flow-track::after {
  content: '';
  position: absolute;
  inset: 0;
  width: 45%;
  background: linear-gradient(90deg, transparent, rgb(var(--c-primary)), transparent);
  animation: flow-slide 1.8s linear infinite;
}

/* ---------- Bể đo độ ẩm 3 chậu dạng cột nước dọc (Differentiation Anchor) ---------- */
.pot-well {
  background: rgb(var(--c-surface-sub));
  border: 1px solid var(--panel-border);
}

/* ---------- Slide-over Drawer ---------- */
.iot-drawer {
  transform: translateX(100%);
  transition: transform 220ms cubic-bezier(0.23, 1, 0.32, 1);
}
.iot-drawer.open {
  transform: translateX(0);
}

/* Thanh cuộn tinh gọn */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(161, 161, 170, 0.24);
  border-radius: 9999px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(161, 161, 170, 0.42);
}

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