/* AquaNode PWA Styles */
:root {
  --primary: #00D9FF;
  --primary-dark: #00B8D4;
  --primary-light: #64FFDA;
  --background: #0A1929;
  --background-light: #132F4C;
  --card: #1A2F42;
  --card-hover: #234056;
  --text: #E7EBF0;
  --text-secondary: #8B9CAD;
  --text-muted: #5B6B7C;
  --success: #4CAF50;
  --warning: #FF9800;
  --error: #F44336;
  --border: #2D3F52;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--background);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* Screens */
.screen {
  display: none;
  min-height: 100vh;
}
.screen.active {
  display: block;
}

/* Login Screen */
.login-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.logo {
  text-align: center;
  margin-bottom: 40px;
}

.logo-icon {
  font-size: 64px;
  display: block;
  margin-bottom: 10px;
}

.logo h1 {
  font-size: 32px;
  color: var(--primary);
  margin-bottom: 8px;
}

.logo p {
  color: var(--text-secondary);
  font-size: 14px;
}

/* Forms */
form {
  width: 100%;
  max-width: 320px;
}

input[type="text"],
input[type="email"],
input[type="password"] {
  width: 100%;
  padding: 14px 16px;
  margin-bottom: 16px;
  background: var(--background-light);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
}

input:focus {
  border-color: var(--primary);
}

input::placeholder {
  color: var(--text-muted);
}

/* Buttons */
.btn {
  padding: 14px 24px;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
}

.btn-primary {
  background: var(--primary);
  color: var(--background);
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--background-light);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--card);
}

.login-error {
  color: var(--error);
  font-size: 14px;
  text-align: center;
  margin-top: 16px;
  min-height: 20px;
}

.login-success {
  color: var(--success);
  font-size: 14px;
  text-align: center;
  margin-top: 16px;
  min-height: 20px;
}

.login-footer .separator {
  margin: 0 10px;
  color: var(--text-muted);
}

.login-footer {
  margin-top: 24px;
  color: var(--text-secondary);
  font-size: 14px;
}

.login-footer a {
  color: var(--primary);
  text-decoration: none;
}

/* App Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--background-light);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-title {
  display: flex;
  flex-direction: column;
}

.app-header h1 {
  font-size: 20px;
  color: var(--primary);
  margin: 0;
}

.welcome-text {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  background: transparent;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  transition: background 0.2s;
}

.icon-btn:hover {
  background: var(--card);
}

/* Stats Bar */
.stats-bar {
  display: flex;
  justify-content: space-around;
  padding: 20px;
  background: var(--background-light);
  margin: 16px;
  border-radius: 16px;
}

.stat {
  text-align: center;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  display: block;
  color: var(--text);
}

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

.stat-value.alerts {
  color: var(--warning);
}

.stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* Devices List */
.devices-list {
  padding: 0 16px 100px;
}

.device-card {
  background: var(--card);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid var(--border);
}

.device-card:hover {
  background: var(--card-hover);
  transform: translateY(-2px);
}

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

.device-card-name {
  font-size: 18px;
  font-weight: 600;
}

.device-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 20px;
}

.device-status.online {
  background: rgba(76, 175, 80, 0.2);
  color: var(--success);
}

.device-status.offline {
  background: rgba(139, 156, 173, 0.2);
  color: var(--text-secondary);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.device-readings {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.reading {
  display: flex;
  flex-direction: column;
}

.reading-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.reading-value {
  font-size: 20px;
  font-weight: 600;
}

.reading-value.temp { color: #E8B4B8; }
.reading-value.ph { color: #B4D4CE; }
.reading-value.tds { color: #C4E3D4; }
.reading-value.turb { color: #E8C4C8; }

/* Alert Badge */
.alert-badge {
  background: var(--error);
  color: white;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: 8px;
}

/* FAB */
.fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--background);
  font-size: 28px;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 217, 255, 0.3);
  transition: all 0.2s;
}

.fab:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 16px rgba(0, 217, 255, 0.4);
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--background-light);
  border-radius: 20px;
  width: 100%;
  max-width: 400px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 20px;
}

.close-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 28px;
  cursor: pointer;
  line-height: 1;
}

.modal-body {
  padding: 20px;
}

/* Claim Instructions */
.claim-instructions {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 16px;
  text-align: center;
}

/* Upgrade Modal */
.upgrade-modal-content {
  max-width: 360px;
  text-align: center;
}

.upgrade-modal-body {
  padding: 30px 20px;
}

.upgrade-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.upgrade-modal-body h2 {
  font-size: 22px;
  margin-bottom: 10px;
  color: var(--text);
}

.upgrade-modal-body p {
  color: var(--text-secondary);
  margin-bottom: 20px;
  font-size: 14px;
}

.upgrade-features {
  background: var(--card);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 20px;
  text-align: left;
}

.upgrade-feature {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  font-size: 14px;
  color: var(--text-secondary);
}

.upgrade-feature span {
  color: var(--success);
  font-weight: bold;
}

.btn-upgrade-cta {
  width: 100%;
  padding: 14px 20px;
  font-size: 16px;
  font-weight: 600;
  background: linear-gradient(135deg, var(--primary), #9c27b0);
  border: none;
}

.btn-upgrade-cta:hover {
  background: linear-gradient(135deg, var(--primary-dark), #7b1fa2);
}

/* Premium locked badge on buttons */
.btn-locked {
  position: relative;
}

.btn-locked::after {
  content: '🔒';
  position: absolute;
  top: -5px;
  right: -5px;
  font-size: 12px;
}

/* Sensor Grid */
.sensor-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.sensor-card {
  background: var(--card);
  border-radius: 12px;
  padding: 16px;
  text-align: center;
}

.sensor-card-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

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

.sensor-card-unit {
  font-size: 12px;
  color: var(--text-muted);
}

.device-actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.device-actions .btn {
  font-size: 13px;
  padding: 10px 8px;
  white-space: nowrap;
}

/* Loading */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* Empty State */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.empty-state-icon {
  font-size: 64px;
  margin-bottom: 16px;
}

.empty-state h3 {
  margin-bottom: 8px;
  color: var(--text);
}

/* Notification Badge */
.notification-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--error);
  color: white;
  font-size: 10px;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--card);
  color: var(--text);
  padding: 12px 24px;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  z-index: 300;
  opacity: 0;
  transition: opacity 0.3s;
}

.toast.show {
  opacity: 1;
}

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

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

/* Push Notification Alert (foreground) */
.push-alert {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  color: white;
  z-index: 400;
  transform: translateY(-100%);
  transition: transform 0.3s ease;
  box-shadow: 0 4px 20px rgba(0, 217, 255, 0.3);
}

.push-alert.show {
  transform: translateY(0);
}

.push-alert-content {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  padding-top: max(16px, env(safe-area-inset-top));
  gap: 12px;
}

.push-alert-icon {
  font-size: 24px;
  flex-shrink: 0;
}

.push-alert-text {
  flex: 1;
  min-width: 0;
}

.push-alert-title {
  font-weight: 600;
  font-size: 16px;
  margin-bottom: 2px;
}

.push-alert-body {
  font-size: 14px;
  opacity: 0.9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.push-alert-close {
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
}

/* System Message Banner */
.message-banner {
  display: flex;
  align-items: center;
  margin: 12px 16px;
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--card);
  border-left: 4px solid var(--primary);
  gap: 12px;
  animation: bannerSlideIn 0.3s ease;
}

.message-banner.hidden {
  display: none;
}

@keyframes bannerSlideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message-banner.info {
  border-left-color: var(--primary);
}

.message-banner.success {
  border-left-color: var(--success);
}

.message-banner.warning {
  border-left-color: var(--warning);
}

.message-banner.error {
  border-left-color: var(--error);
}

.message-banner-icon {
  font-size: 24px;
  flex-shrink: 0;
}

.message-banner-content {
  flex: 1;
  min-width: 0;
}

.message-banner-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  margin-bottom: 2px;
}

.message-banner-body {
  font-size: 13px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.message-banner-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  flex-shrink: 0;
}

.message-banner-close:hover {
  background: var(--background-light);
  color: var(--text);
}

.message-banner-content {
  cursor: pointer;
}

/* Message Detail Modal */
.message-modal-content {
  max-width: 360px;
}

.message-modal-content .modal-header {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.message-modal-icon {
  font-size: 28px;
  flex-shrink: 0;
}

.message-modal-content .modal-header h2 {
  flex: 1;
  min-width: 0;
  font-size: 18px;
  word-wrap: break-word;
}

.message-modal-content .modal-close {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 24px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

.message-modal-body {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
  word-wrap: break-word;
}

.message-modal-time {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.modal-footer .btn {
  width: 100%;
}

/* PWA Install Banner */
.install-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card);
  padding: 16px 20px;
  display: none;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--border);
  z-index: 150;
}

.install-banner.show {
  display: flex;
}

.install-banner p {
  font-size: 14px;
}

.install-banner button {
  padding: 8px 16px;
  font-size: 14px;
}

/* Profile Modal */
.profile-info {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}

.profile-avatar {
  font-size: 48px;
  width: 80px;
  height: 80px;
  background: var(--card);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.profile-details {
  flex: 1;
}

.profile-name {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 4px;
}

.profile-email {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 2px;
}

.profile-username {
  color: var(--text-muted);
  font-size: 13px;
}

.profile-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.btn-danger {
  background: rgba(244, 67, 54, 0.2);
  color: var(--error);
  border: 1px solid var(--error);
}

/* Subscription Section */
.subscription-section {
  background: var(--card);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 20px;
  border: 1px solid var(--border);
}

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

.subscription-tier {
  display: flex;
  align-items: center;
  gap: 8px;
}

.subscription-tier .tier-icon {
  font-size: 24px;
}

.subscription-tier .tier-name {
  font-size: 18px;
  font-weight: 600;
}

.subscription-tier.premium .tier-name {
  color: #FFD700;
}

.subscription-features {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--text-secondary);
}

.subscription-features span {
  background: var(--background-light);
  padding: 4px 8px;
  border-radius: 4px;
}

.btn-upgrade {
  width: 100%;
  background: linear-gradient(135deg, #FFD700 0%, #FFA500 100%);
  color: #1a1a1a;
  font-weight: 600;
  border: none;
  padding: 14px 20px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.btn-upgrade:hover {
  transform: scale(1.02);
  box-shadow: 0 4px 20px rgba(255, 215, 0, 0.3);
}

.btn-upgrade:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* Tier Badge in Header */
.tier-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 12px;
  background: var(--card);
  color: var(--text-secondary);
  margin-left: 8px;
  vertical-align: middle;
}

.tier-badge.premium {
  background: linear-gradient(135deg, #FFD700 0%, #FFA500 100%);
  color: #1a1a1a;
  font-weight: 600;
}

/* Edit Profile Form */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group input {
  width: 100%;
  padding: 12px;
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
}

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

.form-divider {
  height: 1px;
  background: var(--border);
  margin: 20px 0;
}

.form-section-title {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.form-actions .btn {
  flex: 1;
}

/* Trends Modal */
.modal-large {
  max-width: 600px;
}

.trends-period {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.period-btn {
  flex: 1;
  min-width: 50px;
  padding: 10px 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
}

.period-btn.active {
  background: var(--primary);
  color: var(--background);
  border-color: var(--primary);
}

.custom-range-picker {
  background: var(--card);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 16px;
}

.custom-range-picker .date-inputs {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.date-input-group {
  flex: 1;
  min-width: 140px;
}

.date-input-group label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.date-input-group input {
  width: 100%;
  padding: 8px 10px;
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
}

.date-input-group input:focus {
  outline: none;
  border-color: var(--primary);
}

.btn-small {
  padding: 8px 16px;
  font-size: 14px;
}

.metric-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.metric-checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.metric-checkbox input {
  display: none;
}

.metric-label {
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 600;
  background: var(--card);
  border: 2px solid var(--metric-color);
  color: var(--text-muted);
  transition: all 0.2s;
}

.metric-checkbox input:checked + .metric-label {
  background: var(--metric-color);
  color: #1a1a2e;
}

.trends-chart {
  background: var(--card);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
  position: relative;
}

#trends-canvas {
  width: 100%;
  height: 280px;
  display: block;
  cursor: crosshair;
}

.trends-info {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* Chart Tooltip */
.chart-tooltip {
  position: fixed;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  color: #e2e8f0;
  z-index: 10000;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  min-width: 140px;
  max-width: 200px;
}

.chart-tooltip-time {
  font-weight: 600;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid #334155;
  color: #94a3b8;
}

.chart-tooltip-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0;
}

.chart-tooltip-color {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}

.chart-tooltip-label {
  color: #94a3b8;
}

.chart-tooltip-value {
  font-weight: 600;
  margin-left: auto;
}

.trends-data {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.trend-stat {
  background: var(--card);
  border-radius: 8px;
  padding: 12px;
  text-align: center;
}

.trend-stat-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 4px;
}

.trend-stat-value {
  font-size: 18px;
  font-weight: 600;
}

/* Settings Modal */
.setting-group {
  margin-bottom: 20px;
}

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

/* Toggle Switch */
.toggle-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.toggle-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--card);
  border-radius: 8px;
}

.toggle-item span {
  font-size: 14px;
}

.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
}

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

.switch-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--border);
  border-radius: 26px;
  transition: 0.3s;
}

.switch-slider::before {
  content: '';
  position: absolute;
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: 0.3s;
}

.switch input:checked + .switch-slider {
  background: var(--primary);
}

.switch input:checked + .switch-slider::before {
  transform: translateX(22px);
}

/* Threshold Grid */
.threshold-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.threshold-item {
  background: var(--card);
  border-radius: 8px;
  padding: 12px;
}

.threshold-label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.threshold-inputs {
  display: flex;
  align-items: center;
  gap: 4px;
}

.threshold-inputs input {
  width: 55px;
  padding: 8px 6px;
  margin-bottom: 0;
  font-size: 14px;
  text-align: center;
  border-radius: 6px;
}

.threshold-sep {
  color: var(--text-muted);
  font-size: 12px;
}

.threshold-unit {
  font-size: 11px;
  color: var(--text-muted);
  min-width: 24px;
}

/* Settings Extras */
.input-full {
  width: 100%;
}

.setting-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
}

.setting-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 20px;
}

.setting-actions .btn-danger {
  background: transparent;
  font-size: 14px;
}

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

/* Calibration Mode */
.calibration-info {
  background: var(--background-light);
  border-radius: 8px;
  padding: 12px;
}

.calibration-timer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding: 10px;
  background: rgba(255, 152, 0, 0.15);
  border: 1px solid rgba(255, 152, 0, 0.3);
  border-radius: 6px;
  color: #ffb74d;
  font-size: 14px;
  font-weight: 500;
}

.calibration-timer .timer-icon {
  font-size: 18px;
}

.calibration-timer #calibration-time-left {
  font-weight: 700;
  font-family: 'Courier New', monospace;
}

.calibration-timer.expired {
  background: rgba(244, 67, 54, 0.15);
  border-color: rgba(244, 67, 54, 0.3);
  color: #ef5350;
}

/* Calibration Modal */
.calibration-section {
  background: var(--background-light);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

/* Local Calibration Card */
.local-cal-card {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  background: linear-gradient(135deg, #00D9FF15, #64FFDA15);
  border: 1px solid var(--primary);
  border-radius: 12px;
  padding: 20px;
}

.local-cal-icon {
  font-size: 32px;
  flex-shrink: 0;
}

.local-cal-content h3 {
  color: var(--primary);
  margin: 0 0 8px 0;
  font-size: 18px;
}

.local-cal-content p {
  color: var(--text-secondary);
  font-size: 14px;
  margin: 0 0 12px 0;
  line-height: 1.4;
}

.local-cal-content .btn {
  display: inline-block;
  margin-bottom: 8px;
}

.local-cal-hint {
  color: var(--text-muted) !important;
  font-size: 12px !important;
  margin: 0 !important;
}

.calibration-section h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--primary);
  margin: 0 0 8px 0;
}

.calibration-mode-toggle {
  padding: 0;
}

.calibration-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.calibration-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.calibration-field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.calibration-field input {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  color: var(--text);
  font-size: 14px;
}

.calibration-field input:focus {
  outline: none;
  border-color: var(--primary);
}

.field-hint {
  font-size: 10px;
  color: var(--text-muted);
}

.raw-values-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 12px 0;
}

.raw-value-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px;
  background: var(--card);
  border-radius: 6px;
}

.raw-label {
  font-size: 12px;
  color: var(--text-secondary);
}

.raw-value {
  font-size: 14px;
  font-weight: 600;
  font-family: 'Courier New', monospace;
  color: var(--primary);
}

.calibration-actions {
  display: flex;
  justify-content: center;
  margin-top: 16px;
}

.calibration-actions .btn {
  min-width: 200px;
}

/* pH Calibration Status */
.ph-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  background: rgba(139, 156, 173, 0.2);
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.ph-status.calibrated {
  background: rgba(76, 175, 80, 0.2);
  color: var(--success);
}

/* Calibration Steps */
.cal-step {
  background: var(--card);
  border-radius: 10px;
  margin-bottom: 12px;
  overflow: hidden;
}

.cal-step-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: rgba(0, 217, 255, 0.1);
  border-bottom: 1px solid var(--border);
}

.step-number {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--background);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
}

.step-title {
  font-weight: 600;
  font-size: 14px;
}

.cal-step-body {
  padding: 14px;
}

.step-instruction {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.cal-input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.cal-input-group {
  flex: 1;
  min-width: 80px;
}

.cal-input-group label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.cal-input-group input {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--background);
  color: var(--text);
  font-size: 14px;
  margin-bottom: 0;
}

.cal-input-group input:focus {
  outline: none;
  border-color: var(--primary);
}

.mv-display {
  background: var(--background-light) !important;
  font-family: 'Courier New', monospace;
  font-weight: 600;
  color: var(--primary) !important;
  text-align: center;
}

.captured-indicator {
  margin-top: 10px;
  padding: 8px 12px;
  background: rgba(76, 175, 80, 0.15);
  border: 1px solid rgba(76, 175, 80, 0.3);
  border-radius: 6px;
  font-size: 13px;
  color: var(--success);
}

.cal-result {
  margin-top: 12px;
  padding: 14px;
  background: rgba(76, 175, 80, 0.1);
  border: 1px solid var(--success);
  border-radius: 8px;
}

.result-header {
  font-weight: 600;
  color: var(--success);
  margin-bottom: 8px;
}

.result-values {
  display: flex;
  gap: 20px;
  font-size: 14px;
}

.result-values strong {
  color: var(--primary);
  font-family: 'Courier New', monospace;
}

.cal-current-value {
  margin-top: 10px;
  font-size: 13px;
  color: var(--text-secondary);
}

.cal-current-value strong {
  color: var(--primary);
  font-family: 'Courier New', monospace;
}

.cal-refresh-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}

.last-update {
  font-size: 11px;
  color: var(--text-muted);
}

#clear-ph-cal {
  margin-top: 12px;
}

/* Responsive adjustments */
@media (max-width: 420px) {
  .cal-input-row {
    flex-direction: column;
    align-items: stretch;
  }

  .cal-input-row .btn {
    width: 100%;
  }

  .result-values {
    flex-direction: column;
    gap: 4px;
  }
}

/* Light Control */
.light-control-panel {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.light-toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.light-status-label {
  font-size: 18px;
  font-weight: 600;
}

.toggle-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 24px;
  border: 2px solid var(--border);
  border-radius: 30px;
  background: var(--card);
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
}

.toggle-btn.on {
  background: rgba(255, 193, 7, 0.2);
  border-color: #FFC107;
  color: #FFC107;
}

.toggle-icon {
  font-size: 24px;
}

.light-brightness label,
.light-mode label,
.light-schedules label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 16px;
}

.slider-row input[type="range"] {
  flex: 1;
  height: 8px;
  -webkit-appearance: none;
  background: var(--border);
  border-radius: 4px;
  outline: none;
}

.slider-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  background: var(--primary);
  border-radius: 50%;
  cursor: pointer;
}

#brightness-value {
  min-width: 50px;
  text-align: right;
  font-weight: 600;
  color: var(--primary);
}

.mode-buttons {
  display: flex;
  gap: 12px;
}

.mode-btn {
  flex: 1;
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.mode-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--background);
}

.schedules-list {
  background: var(--card);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
  max-height: 200px;
  overflow-y: auto;
}

.schedule-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.schedule-item:last-child {
  border-bottom: none;
}

.schedule-time {
  font-weight: 600;
}

.schedule-day {
  font-size: 12px;
  color: var(--text-secondary);
}

.schedule-delete {
  background: none;
  border: none;
  color: var(--error);
  cursor: pointer;
  font-size: 18px;
}

.btn-sm {
  padding: 10px 16px;
  font-size: 14px;
}

.text-muted {
  color: var(--text-muted);
  font-size: 14px;
}

/* Sharing Section */
.shared-users-list {
  background: var(--card);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
  max-height: 150px;
  overflow-y: auto;
}

.shared-user-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.shared-user-item:last-child {
  border-bottom: none;
}

.shared-user-info {
  flex: 1;
  min-width: 0;
}

.shared-user-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}

.shared-user-permission {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: capitalize;
}

.shared-user-revoke {
  background: transparent;
  border: none;
  color: var(--error);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
}

.share-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.input-share {
  flex: 1;
  padding: 10px 12px;
  margin-bottom: 0;
  font-size: 14px;
}

.select-permission {
  padding: 10px 8px;
  background: var(--background-light);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  outline: none;
}

.select-permission:focus {
  border-color: var(--primary);
}

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

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

/* Safe area for notched phones */
@supports (padding-top: env(safe-area-inset-top)) {
  .app-header {
    padding-top: calc(16px + env(safe-area-inset-top));
  }

  .fab {
    bottom: calc(24px + env(safe-area-inset-bottom));
  }
}
