:root {
  --primary: #2196f3;
  --success: #4caf50;
  --danger: #f44336;
  --warning: #ff9800;
  --dark: #333;
  --light: #f5f5f5;
  --white: #ffffff;
  --gray: #666;
  --border: #ddd;
  --shadow: rgba(0, 0, 0, 0.1);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  padding: 20px;
  color: var(--dark);
  /* Mobile optimization */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

@media (max-width: 768px) {
  body {
    padding: 10px;
  }
}

.container {
  max-width: 1400px;
  margin: 0 auto;
}

/* Header */
header {
  background: var(--white);
  padding: 25px 30px;
  border-radius: 12px;
  margin-bottom: 25px;
  box-shadow: 0 4px 15px var(--shadow);
  position: relative;
  z-index: 9999;
}

@media (max-width: 768px) {
  header {
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 15px;
  }
}

header h1 {
  color: var(--primary);
  font-size: 32px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 15px;
}

@media (max-width: 768px) {
  header h1 {
    font-size: 22px;
    margin-bottom: 15px;
    gap: 10px;
  }
}

nav {
  display: flex;
  gap: 15px;
  margin-top: 15px;
  flex-wrap: wrap;
  position: relative;
}

@media (max-width: 768px) {
  nav {
    gap: 8px;
    margin-top: 10px;
  }
}

nav a {
  padding: 10px 20px;
  background: var(--light);
  color: var(--dark);
  text-decoration: none;
  border-radius: 6px;
  font-weight: 500;
  transition: all 0.3s;
  white-space: nowrap;
}

@media (max-width: 768px) {
  nav a {
    padding: 8px 12px;
    font-size: 13px;
    flex: 1 1 auto;
    text-align: center;
    min-width: calc(50% - 4px);
  }
}

nav a:hover {
  background: var(--primary);
  color: var(--white);
}

nav a.active {
  background: var(--primary);
  color: var(--white);
}

/* System Status */
.system-status {
  background: var(--white);
  padding: 25px;
  border-radius: 12px;
  margin-bottom: 25px;
  box-shadow: 0 4px 15px var(--shadow);
}

@media (max-width: 768px) {
  .system-status {
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 15px;
  }
}

.system-status h2 {
  font-size: 20px;
  margin-bottom: 20px;
  color: var(--dark);
}

@media (max-width: 768px) {
  .system-status h2 {
    font-size: 18px;
    margin-bottom: 15px;
  }
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 15px;
}

@media (max-width: 768px) {
  .status-grid {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
  }
}

@media (max-width: 480px) {
  .status-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.stat-card {
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  padding: 20px;
  border-radius: 10px;
  text-align: center;
}

.stat-label {
  font-size: 12px;
  color: var(--gray);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 28px;
  font-weight: bold;
  color: var(--dark);
}

.stat-value.online {
  color: var(--success);
}

.stat-value.offline {
  color: var(--danger);
}

/* Emergency Controls */
.emergency-controls {
  background: var(--white);
  padding: 20px 25px;
  border-radius: 12px;
  margin-bottom: 25px;
  box-shadow: 0 4px 15px var(--shadow);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.emergency-controls h3 {
  font-size: 18px;
  color: var(--dark);
}

.btn-stop-all {
  padding: 15px 40px;
  background: linear-gradient(135deg, #f44336 0%, #d32f2f 100%);
  color: var(--white);
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s;
  box-shadow: 0 4px 10px rgba(244, 67, 54, 0.3);
}

.btn-stop-all:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(244, 67, 54, 0.4);
}

.btn-stop-all:active {
  transform: translateY(0);
}

/* Valve Cards */
.valves-section {
  background: var(--white);
  padding: 25px;
  border-radius: 12px;
  margin-bottom: 25px;
  box-shadow: 0 4px 15px var(--shadow);
}

.valves-section h2 {
  font-size: 24px;
  margin-bottom: 20px;
  color: var(--dark);
}

.valves-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
}

.valve-card {
  background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
  border-radius: 12px;
  padding: 25px;
  box-shadow: 0 4px 12px var(--shadow);
  transition: all 0.3s;
  border: 3px solid transparent;
}

.valve-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 25px var(--shadow);
}

.valve-card.active {
  border-color: var(--success);
  background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%);
}

.valve-card.auto-enabled {
  border-top: 4px solid var(--warning);
}

.valve-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
}

.valve-title {
  font-size: 22px;
  font-weight: bold;
  color: var(--dark);
}

.valve-badges {
  display: flex;
  gap: 8px;
}

.badge {
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge.status-on {
  background: var(--success);
  color: var(--white);
  animation: pulse 2s infinite;
}

.badge.status-off {
  background: #ccc;
  color: var(--gray);
}

.badge.auto-mode {
  background: var(--warning);
  color: var(--white);
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
}

.valve-info {
  margin-bottom: 15px;
  padding: 15px;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 8px;
}

.valve-info p {
  margin-bottom: 8px;
  font-size: 14px;
  color: var(--gray);
}

.valve-info p strong {
  color: var(--dark);
}

.remaining-time {
  font-size: 24px;
  font-weight: bold;
  color: var(--success);
  text-align: center;
  padding: 10px;
  background: rgba(76, 175, 80, 0.1);
  border-radius: 8px;
  margin-bottom: 15px;
}

.duration-selector {
  margin-bottom: 15px;
}

.duration-selector label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--gray);
  margin-bottom: 8px;
}

.duration-input {
  display: flex;
  gap: 10px;
  align-items: center;
}

.duration-input input {
  flex: 1;
  padding: 10px;
  border: 2px solid var(--border);
  border-radius: 6px;
  font-size: 16px;
}

.duration-presets {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.duration-presets button {
  padding: 6px 12px;
  background: var(--light);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.duration-presets button:hover {
  background: var(--primary);
  color: var(--white);
  border-color: var(--primary);
}

.valve-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.btn {
  padding: 14px;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-start {
  background: linear-gradient(135deg, #4caf50 0%, #45a049 100%);
  color: var(--white);
  box-shadow: 0 4px 10px rgba(76, 175, 80, 0.3);
}

.btn-start:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(76, 175, 80, 0.4);
}

.btn-stop {
  background: linear-gradient(135deg, #f44336 0%, #da190b 100%);
  color: var(--white);
  box-shadow: 0 4px 10px rgba(244, 67, 54, 0.3);
}

.btn-stop:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(244, 67, 54, 0.4);
}

.btn:active {
  transform: translateY(0);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Auto Mode Configuration */
.auto-config-section {
  background: var(--white);
  padding: 25px;
  border-radius: 12px;
  margin-bottom: 25px;
  box-shadow: 0 4px 15px var(--shadow);
}

.auto-config-section h2 {
  font-size: 24px;
  margin-bottom: 20px;
  color: var(--dark);
}

.config-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
  gap: 25px;
}

.config-card {
  background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
  border-radius: 12px;
  padding: 25px;
  box-shadow: 0 4px 12px var(--shadow);
}

.config-card h3 {
  font-size: 20px;
  margin-bottom: 20px;
  color: var(--dark);
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--gray);
  margin-bottom: 8px;
}

.form-control {
  width: 100%;
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: 6px;
  font-size: 15px;
  transition: all 0.3s;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
}

.switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 34px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: 0.4s;
  border-radius: 34px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 26px;
  width: 26px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: 0.4s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--success);
}

input:checked + .slider:before {
  transform: translateX(26px);
}

.session-times {
  margin-top: 20px;
  padding: 20px;
  background: var(--light);
  border-radius: 8px;
}

.session-times h4 {
  font-size: 16px;
  margin-bottom: 15px;
  color: var(--dark);
}

.session-row {
  display: grid;
  grid-template-columns: auto 1fr 1fr;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.session-row label {
  font-weight: 600;
  color: var(--gray);
}

.time-input {
  padding: 8px;
  border: 2px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
}

/* Loading Spinner */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 1s ease-in-out infinite;
}

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

/* Notifications */
.notification {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 15px 25px;
  background: var(--white);
  border-radius: 8px;
  box-shadow: 0 4px 15px var(--shadow);
  z-index: 1000;
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    transform: translateX(400px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.notification.success {
  border-left: 4px solid var(--success);
}

.notification.error {
  border-left: 4px solid var(--danger);
}

/* Responsive */
@media (max-width: 768px) {
  .valves-grid {
    grid-template-columns: 1fr;
  }

  .config-cards {
    grid-template-columns: 1fr;
    gap: 15px;
  }

  .config-card {
    padding: 15px;
  }

  .config-card h3 {
    font-size: 18px;
  }

  .status-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .emergency-controls {
    flex-direction: column;
    gap: 15px;
  }

  /* Form elements - touch friendly */
  .form-control,
  .time-input,
  select,
  input[type="text"],
  input[type="number"],
  input[type="email"],
  input[type="password"],
  textarea {
    padding: 12px;
    font-size: 15px;
    min-height: 44px;
  }

  textarea {
    min-height: 100px;
  }

  /* Session rows stacked on mobile */
  .session-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .session-row label {
    margin-bottom: 5px;
  }

  .time-input {
    width: 100%;
    padding: 12px;
  }

  /* Switch toggle larger on mobile */
  .switch {
    width: 60px;
    height: 34px;
  }

  .slider:before {
    height: 26px;
    width: 26px;
  }

  input:checked + .slider:before {
    transform: translateX(26px);
  }

  /* Session times grid */
  .session-times h4 {
    font-size: 16px;
  }

  /* Buttons full width on mobile */
  .btn,
  button {
    padding: 14px 20px;
    font-size: 15px;
    min-height: 48px;
  }

  .emergency-button {
    padding: 16px;
    font-size: 16px;
  }

  /* Notification positioning */
  .notification {
    top: 10px;
    right: 10px;
    left: 10px;
    padding: 12px 15px;
    font-size: 14px;
  }

  /* Auto config specific */
  .auto-config-section {
    padding: 10px;
  }

  .config-intro {
    padding: 15px;
  }

  .config-description {
    font-size: 14px;
  }
}

@media (max-width: 480px) {
  .status-grid {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 22px;
  }

  h2 {
    font-size: 20px;
  }

  h3 {
    font-size: 18px;
  }

  /* Navigation stacked */
  nav {
    flex-direction: column;
    gap: 8px;
  }

  nav a {
    width: 100%;
    text-align: center;
    padding: 12px;
  }

  /* Time inputs side by side even on small screens */
  .session-row {
    grid-template-columns: auto 1fr 1fr;
    gap: 8px;
  }

  .session-row label {
    grid-column: 1 / -1;
  }
}
/* ========== NEW NAVIGATION MENU ========== */
.main-header {
  background: var(--white);
  border-radius: 12px;
  margin-bottom: 25px;
  box-shadow: 0 4px 15px var(--shadow);
  overflow: visible;
  position: relative;
  z-index: 9999;
}

.header-brand {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 20px 30px;
  color: var(--white);
}

.header-brand h1 {
  color: var(--white);
  margin: 0;
  font-size: 28px;
}

.main-nav {
  display: flex;
  background: var(--white);
  border-top: 1px solid var(--border);
  padding: 0;
  position: relative;
  z-index: 10000;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 15px 20px;
  color: var(--dark);
  text-decoration: none;
  transition: all 0.3s;
  border-right: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}

.nav-link:hover {
  background: var(--light);
  color: var(--primary);
}

.nav-link.active {
  background: var(--primary);
  color: var(--white);
}

.nav-icon {
  font-size: 18px;
}

.nav-label {
  font-weight: 500;
  font-size: 14px;
}

.nav-dropdown {
  position: relative;
  z-index: 10000;
}

.nav-dropdown:hover {
  z-index: 99999;
}

.nav-dropdown:hover .dropdown-content {
  display: block;
}

.dropdown-arrow {
  font-size: 10px;
  margin-left: 4px;
  transition: transform 0.3s;
}

.nav-dropdown:hover .dropdown-arrow {
  transform: rotate(180deg);
}

.dropdown-content {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  background: var(--white);
  min-width: 200px;
  box-shadow: 0 4px 15px var(--shadow);
  border-radius: 0 0 8px 8px;
  z-index: 99998;
}

.dropdown-content a {
  display: block;
  padding: 12px 20px;
  color: var(--dark);
  text-decoration: none;
  transition: background 0.2s;
  border-bottom: 1px solid var(--light);
  position: relative;
  z-index: 99999;
}

.dropdown-content a:last-child {
  border-bottom: none;
}

.dropdown-content a:hover {
  background: var(--light);
  color: var(--primary);
}

.dropdown-content a.active {
  background: var(--primary);
  color: var(--white);
}

/* ========== DASHBOARD LAYOUT ========== */
.dashboard-container {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.connection-banner {
  background: var(--white);
  border-radius: 12px;
  padding: 15px 25px;
  box-shadow: 0 2px 8px var(--shadow);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 15px;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 500;
}

.status-icon {
  font-size: 18px;
}

/* ========== SENSORS SECTION ========== */
.sensors-section {
  position: relative;
  background: var(--white);
  border-radius: 12px;
  padding: 25px;
  box-shadow: 0 4px 15px var(--shadow);
}

.section-header {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 2px solid var(--light);
}

.section-header h2 {
  margin: 0;
  color: var(--primary);
  font-size: 24px;
}

.btn-read-sensor {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: var(--primary);
  color: var(--white);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.3s;
}

.btn-read-sensor:hover {
  background: #1976d2;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(33, 150, 243, 0.3);
}

.btn-read-sensor .icon {
  font-size: 16px;
}

.btn-read-sensor .label {
  font-size: 14px;
  font-weight: 500;
}

.sensors-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
}

.sensor-card {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 20px;
  background: var(--light);
  border-radius: 10px;
  border-left: 4px solid var(--primary);
  transition: all 0.3s;
}

.sensor-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 6px 20px var(--shadow);
}

.sensor-card.temperature {
  border-left-color: #f44336;
}

.sensor-card.humidity {
  border-left-color: #2196f3;
}

.sensor-card.moisture {
  border-left-color: #4caf50;
}

.sensor-card.flow {
  border-left-color: #00bcd4;
}

.sensor-icon {
  font-size: 36px;
  flex-shrink: 0;
}

.sensor-data {
  flex: 1;
}

.sensor-label {
  font-size: 12px;
  color: var(--gray);
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.5px;
  margin-bottom: 5px;
}

.sensor-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--dark);
  margin-bottom: 3px;
}

.sensor-age {
  font-size: 11px;
  color: var(--gray);
  font-style: italic;
}

/* ========== VALVES SECTION ========== */
.valves-section {
  background: var(--white);
  border-radius: 12px;
  padding: 25px;
  box-shadow: 0 4px 15px var(--shadow);
}

.zone-count {
  background: var(--primary);
  color: var(--white);
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
}

.valve-card {
  background: var(--light);
  border-radius: 10px;
  padding: 20px;
  border-left: 4px solid var(--gray);
  transition: all 0.3s;
}

.valve-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px var(--shadow);
}

.valve-card.valve-active {
  border-left-color: var(--success);
  background: linear-gradient(135deg, #f5fff6 0%, #e8f5e9 100%);
}

.valve-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.valve-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.zone-badge {
  background: var(--primary);
  color: var(--white);
  padding: 4px 10px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 600;
}

.valve-name {
  font-size: 18px;
  font-weight: 600;
  color: var(--dark);
}

.valve-status {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 20px;
  font-weight: 600;
  font-size: 13px;
}

.valve-status.status-on {
  background: var(--success);
  color: var(--white);
}

.valve-status.status-off {
  background: var(--gray);
  color: var(--white);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.valve-description {
  color: var(--gray);
  font-size: 14px;
  margin-bottom: 12px;
  font-style: italic;
}

.valve-details {
  display: flex;
  gap: 15px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--gray);
}

.detail-item {
  display: flex;
  align-items: center;
  gap: 5px;
}

.detail-icon {
  font-size: 14px;
}

.time-remaining {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--warning);
  color: var(--white);
  padding: 8px 15px;
  border-radius: 8px;
  font-weight: 600;
  margin-bottom: 12px;
}

.time-icon {
  font-size: 16px;
}

.time-label {
  font-size: 12px;
}

.valve-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.btn-valve {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
  font-size: 14px;
}

.btn-valve:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn-on {
  background: var(--success);
  color: var(--white);
}

.btn-on:hover {
  background: #45a049;
}

.btn-off {
  background: var(--danger);
  color: var(--white);
}

.btn-off:hover {
  background: #e53935;
}

.btn-icon {
  font-size: 16px;
}

.btn-duration {
  font-size: 12px;
  opacity: 0.9;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
  .main-nav {
    flex-direction: column;
  }

  .nav-link {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .connection-banner {
    padding: 12px 15px;
  }

  .sensors-grid {
    grid-template-columns: 1fr;
  }

  .sensor-value {
    font-size: 24px;
  }

  .section-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
}
