* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #1a1a2e;
  color: #eee;
  min-height: 100vh;
}

/* Login */
.login-screen {
  background: #16213e;
  padding: 30px;
  border-radius: 12px;
  max-width: 350px;
  margin: 50px auto;
}
.login-screen h2 { margin-bottom: 20px; text-align: center; }
.login-screen input {
  width: 100%;
  padding: 12px 15px;
  border: 2px solid #374151;
  border-radius: 8px;
  background: #0f172a;
  color: #fff;
  font-size: 1rem;
  margin-bottom: 15px;
}
.login-screen input:focus { outline: none; border-color: #6366f1; }
.login-screen .btn-login {
  width: 100%;
  padding: 12px;
  background: #6366f1;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
}
.login-screen .btn-login:hover { background: #4f46e5; }
.login-screen .error { color: #f87171; text-align: center; margin-top: 10px; display: none; }

/* App */
.app { display: none; }
.app.visible { display: block; }

/* Header */
.header {
  background: #16213e;
  padding: 15px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #374151;
}
.header h1 { font-size: 1.3rem; }
.logout-btn, .settings-btn {
  background: none;
  border: 1px solid #64748b;
  color: #64748b;
  padding: 6px 10px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
}
.logout-btn:hover { border-color: #f87171; color: #f87171; }
.settings-btn:hover { border-color: #60a5fa; color: #60a5fa; }
.settings-panel {
  padding: 15px 20px;
  max-width: 600px;
  margin: 0 auto;
}

/* Tabs */
.tabs {
  display: flex;
  background: #16213e;
  border-bottom: 1px solid #374151;
}
.tab {
  flex: 1;
  padding: 15px;
  text-align: center;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.tab:hover { background: #1e293b; }
.tab.active { border-bottom-color: #6366f1; background: #1e293b; }
.tab .indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f87171;
}
.tab .indicator.connected { background: #4ade80; }

/* Tab Content */
.tab-content { display: none; padding: 20px; max-width: 600px; margin: 0 auto; }
.tab-content.active { display: block; }

/* Status Bar */
.status-bar {
  background: #16213e;
  padding: 12px 15px;
  border-radius: 10px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.status-bar .indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #f87171;
}
.status-bar .indicator.connected { background: #4ade80; }
.status-bar .indicator.connecting { background: #fbbf24; animation: pulse 1s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

/* State Box */
.state-box {
  background: #16213e;
  padding: 20px;
  border-radius: 10px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 20px;
}
.state-box.disconnected { opacity: 0.5; }
.color-preview {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  border: 3px solid #fff;
  flex-shrink: 0;
}
.state-info { flex: 1; }
.state-info .power { font-size: 1.5rem; font-weight: bold; }
.state-info .power.on { color: #4ade80; }
.state-info .power.off { color: #f87171; }
.state-info .power.unknown { color: #fbbf24; }
.state-info .mode { color: #94a3b8; margin-top: 4px; }
.state-info .rgb { color: #64748b; font-size: 0.85rem; margin-top: 2px; }

/* Section */
.section {
  background: #16213e;
  padding: 20px;
  border-radius: 10px;
  margin-bottom: 20px;
}
.section.disabled { opacity: 0.4; pointer-events: none; }
.section h2 { margin-bottom: 15px; font-size: 1.1rem; color: #94a3b8; }

/* Buttons */
.buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
button {
  padding: 15px 20px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 500;
  transition: transform 0.1s, opacity 0.2s;
}
button:hover { opacity: 0.9; }
button:active { transform: scale(0.95); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.active { box-shadow: 0 0 0 3px #fff; }

.btn-red { background: #ef4444; color: white; }
.btn-green { background: #22c55e; color: white; }
.btn-blue { background: #3b82f6; color: white; }
.btn-party { background: linear-gradient(45deg, #f43f5e, #8b5cf6, #06b6d4); color: white; }
.btn-off { background: #374151; color: white; }
.btn-lowlight { background: #6366f1; color: white; }
.btn-feed { background: #f59e0b; color: white; font-size: 1.2rem; padding: 20px; }
.btn-feed.feeding { background: #dc2626; animation: pulse 0.5s infinite; }
.btn-pump { background: #06b6d4; color: white; font-size: 1.2rem; padding: 20px; }
.btn-pump.running { background: #22c55e; }
.btn-primary { background: #6366f1; color: white; }
.btn-secondary { background: #374151; color: white; }
.btn-danger { background: #ef4444; color: white; }
.btn-success { background: #22c55e; color: white; }
.btn-small { padding: 6px 12px; font-size: 0.85rem; }
.btn-remove { background: #374151; color: #f87171; padding: 6px 10px; font-size: 0.8rem; min-width: auto; }

/* Pump Icon */
.pump-icon {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background: #374151;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  flex-shrink: 0;
}
.pump-icon.running { background: #06b6d4; animation: pulse 1s infinite; }

.color-picker-wrapper { display: flex; gap: 15px; align-items: center; flex-wrap: wrap; }
input[type="color"] { width: 80px; height: 50px; border: none; border-radius: 8px; cursor: pointer; }
.btn-apply { background: #10b981; color: white; flex: 1; min-width: 120px; }

/* Feeder Specific */
.feeder-icon {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background: #374151;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  flex-shrink: 0;
}
.feeder-icon.feeding { background: #f59e0b; animation: pulse 0.5s infinite; }

.schedule-item {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 12px;
  background: #0f172a;
  border-radius: 8px;
  margin-bottom: 10px;
}
.schedule-item input[type="checkbox"] {
  width: 20px;
  height: 20px;
  cursor: pointer;
}
.schedule-item input[type="time"],
.schedule-item select {
  padding: 8px 12px;
  border: 1px solid #374151;
  border-radius: 6px;
  background: #1e293b;
  color: #fff;
  font-size: 1rem;
}
.schedule-item .label { flex: 1; color: #94a3b8; }

/* Light Schedule */
.schedule-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 15px;
}
.switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 28px;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.switch .slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #374151;
  transition: 0.3s;
  border-radius: 28px;
}
.switch .slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: 0.3s;
  border-radius: 50%;
}
.switch input:checked + .slider {
  background-color: #4ade80;
}
.switch input:checked + .slider:before {
  transform: translateX(22px);
}
.schedule-settings {
  transition: opacity 0.3s;
}
.schedule-times {
  display: flex;
  gap: 15px;
  margin-bottom: 15px;
}
.time-group {
  flex: 1;
  min-width: 0;
}
.time-group label {
  display: block;
  color: #94a3b8;
  margin-bottom: 5px;
  font-size: 0.9rem;
}
.time-group input[type="time"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #374151;
  border-radius: 6px;
  background: #0f172a;
  color: #fff;
  font-size: 1rem;
  box-sizing: border-box;
}
.schedule-color label {
  display: block;
  color: #94a3b8;
  margin-bottom: 8px;
  font-size: 0.9rem;
}
.schedule-color .color-picker-wrapper {
  display: flex;
  gap: 10px;
}
.schedule-color select {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid #374151;
  border-radius: 6px;
  background: #1e293b;
  color: #fff;
  font-size: 1rem;
}
.schedule-option {
  margin-top: 12px;
}
.schedule-option label {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #94a3b8;
  cursor: pointer;
}
.schedule-option input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}
.schedule-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 15px;
  padding: 12px;
  background: #0f172a;
  border-radius: 8px;
}
.schedule-preview-swatch {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid #374151;
  flex-shrink: 0;
}
.schedule-preview span {
  color: #94a3b8;
  font-size: 0.95rem;
}

/* Light Schedule Cards */
.light-schedule-card {
  background: #0f172a;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
}
.light-schedule-card .schedule-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.light-schedule-card .schedule-header .label {
  flex: 1;
  color: #94a3b8;
}
.light-schedule-card .schedule-details {
  transition: opacity 0.3s;
}
.light-schedule-card .schedule-times {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}
.light-schedule-card .schedule-color {
  margin-bottom: 8px;
}

.duration-control {
  display: flex;
  align-items: center;
  gap: 15px;
}
.duration-control input[type="range"] {
  flex: 1;
  height: 8px;
  border-radius: 4px;
  background: #374151;
  cursor: pointer;
}
.duration-control .value {
  min-width: 50px;
  text-align: right;
  color: #94a3b8;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #374151;
  padding: 12px 24px;
  border-radius: 8px;
  opacity: 0;
  transition: opacity 0.3s;
  z-index: 100;
}
.toast.visible { opacity: 1; }
.toast.success { background: #22c55e; }
.toast.error { background: #ef4444; }

/* Aquarium Tab Specific */
.aquarium-icon {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background: #0ea5e9;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  flex-shrink: 0;
}

/* Tank Visualization */
.tank-visual {
  width: 70px;
  height: 90px;
  background: #1e293b;
  border: 3px solid #64748b;
  border-radius: 0 0 10px 10px;
  border-top: none;
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}
.tank-visual::before {
  content: '';
  position: absolute;
  top: -3px;
  left: -3px;
  right: -3px;
  height: 6px;
  background: #64748b;
  border-radius: 3px 3px 0 0;
}
.water-level {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(180deg, #38bdf8 0%, #0284c7 100%);
  transition: height 0.5s ease;
  height: 100%;
}
.water-level::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 8px;
  background: linear-gradient(180deg, rgba(255,255,255,0.3) 0%, transparent 100%);
}
.tank-info {
  position: absolute;
  bottom: 5px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.7rem;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
  z-index: 1;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 15px;
  margin-bottom: 20px;
}
.stat-card {
  background: #0f172a;
  padding: 15px;
  border-radius: 8px;
  text-align: center;
}
.stat-card .value {
  font-size: 1.8rem;
  font-weight: bold;
  color: #fff;
}
.stat-card .label {
  font-size: 0.85rem;
  color: #94a3b8;
  margin-top: 4px;
}

/* Fish Filter Buttons */
.btn-filter {
  padding: 8px 16px;
  background: #374151;
  color: #94a3b8;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s;
}
.btn-filter:hover { background: #4b5563; }
.btn-filter.active { background: #6366f1; color: white; }

/* Species List */
.species-list {
  max-height: none;
}
.species-group {
  background: #0f172a;
  border-radius: 10px;
  margin-bottom: 12px;
  overflow: hidden;
}
.species-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 15px;
  cursor: pointer;
  transition: background 0.2s;
}
.species-header:hover { background: #1e293b; }
.species-header .species-avatar {
  width: 45px;
  height: 45px;
  border-radius: 8px;
  background: #374151;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  flex-shrink: 0;
  overflow: hidden;
}
.species-header .species-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.species-header .species-info { flex: 1; min-width: 0; }
.species-header .species-name { font-weight: 500; font-size: 1rem; }
.species-header .species-count { color: #94a3b8; font-size: 0.85rem; }
.species-header .species-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.species-header .expand-icon {
  color: #64748b;
  font-size: 1.2rem;
  transition: transform 0.2s;
}
.species-group.expanded .expand-icon { transform: rotate(180deg); }

.species-fish-list {
  display: none;
  padding: 0 15px 15px;
  border-top: 1px solid #1e293b;
}
.species-group.expanded .species-fish-list { display: block; }

.species-fish-list .add-fish-btn {
  width: 100%;
  padding: 10px;
  margin-top: 10px;
  background: #1e293b;
  border: 2px dashed #374151;
  color: #94a3b8;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}
.species-fish-list .add-fish-btn:hover {
  background: #374151;
  border-color: #6366f1;
  color: #fff;
}

.fish-list {
  max-height: 400px;
  overflow-y: auto;
}
.fish-item {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 12px;
  background: #0f172a;
  border-radius: 8px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: background 0.2s;
}
.fish-item:hover { background: #1e293b; }
.fish-item.dead { opacity: 0.6; }
.fish-item.dead .fish-avatar { filter: grayscale(100%); }

.fish-avatar {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: #374151;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  flex-shrink: 0;
  overflow: hidden;
}
.fish-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.fish-avatar.male { border: 2px solid #3b82f6; }
.fish-avatar.female { border: 2px solid #ec4899; }
.fish-avatar.hermaphrodite { border: 2px solid #a855f7; }

.fish-item .fish-info { flex: 1; min-width: 0; }
.fish-item .fish-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fish-item .fish-species { color: #94a3b8; font-size: 0.85rem; }
.fish-item .fish-meta {
  display: flex;
  gap: 10px;
  color: #64748b;
  font-size: 0.8rem;
  margin-top: 2px;
}
.fish-item .fish-status {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
}
.fish-item .fish-status.alive { background: #166534; color: #4ade80; }
.fish-item .fish-status.dead { background: #7f1d1d; color: #fca5a5; }

.fish-item .fish-actions { display: flex; gap: 8px; flex-shrink: 0; }
.fish-item button {
  padding: 6px 12px;
  font-size: 0.85rem;
}

.add-fish-form {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 10px;
  align-items: end;
}
.add-fish-form input,
.add-fish-form select {
  padding: 10px 12px;
  border: 1px solid #374151;
  border-radius: 6px;
  background: #0f172a;
  color: #fff;
  font-size: 1rem;
}
.add-fish-form input:focus,
.add-fish-form select:focus {
  outline: none;
  border-color: #6366f1;
}

.feeding-history {
  max-height: 200px;
  overflow-y: auto;
}
.feeding-item {
  display: flex;
  justify-content: space-between;
  padding: 10px 12px;
  background: #0f172a;
  border-radius: 6px;
  margin-bottom: 8px;
}
.feeding-item .time { color: #94a3b8; }
.feeding-item .duration { color: #64748b; font-size: 0.9rem; }

.water-change-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px;
  background: #0f172a;
  border-radius: 8px;
  margin-bottom: 15px;
}
.water-change-info .days {
  font-size: 1.5rem;
  font-weight: bold;
}
.water-change-info .days.warning { color: #fbbf24; }
.water-change-info .days.danger { color: #ef4444; }

/* 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: flex-start;
  justify-content: center;
  overflow-y: auto;
  padding: 20px 10px;
}
.modal.visible { display: flex; }
.modal-content {
  background: #16213e;
  padding: 25px;
  border-radius: 12px;
  max-width: 400px;
  width: 100%;
  margin: auto;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}
.modal-content h3 {
  margin-bottom: 20px;
}
.modal-content .form-group {
  margin-bottom: 15px;
}
.modal-content label {
  display: block;
  margin-bottom: 5px;
  color: #94a3b8;
}
.modal-content input,
.modal-content textarea,
.modal-content select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #374151;
  border-radius: 6px;
  background: #0f172a;
  color: #fff;
  font-size: 1rem;
}
.modal-content textarea {
  min-height: 80px;
  resize: vertical;
}
.modal-body {
  /* Default - no special styling needed on desktop */
}
.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}
.modal-actions button {
  flex: 1;
}

/* Dimension inputs */
.dimension-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}
.dimension-inputs small {
  color: #64748b;
  display: block;
  margin-top: 4px;
}

/* Image preview */
.image-preview {
  text-align: center;
  margin-bottom: 15px;
}
.image-preview img {
  max-width: 100%;
  max-height: 150px;
  border-radius: 8px;
  object-fit: cover;
}

/* Sensors Tab */
.sensor-card {
  background: #16213e;
  padding: 20px;
  border-radius: 10px;
  margin-bottom: 20px;
}
.sensor-card h2 {
  margin-bottom: 15px;
  font-size: 1.1rem;
  color: #94a3b8;
}
.sensor-card.inactive {
  opacity: 0.5;
}
.sensor-value-box {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 20px;
  border-radius: 12px;
  background: #1e293b;
  margin-bottom: 12px;
}
.sensor-value {
  font-size: 3rem;
  font-weight: 700;
  line-height: 1;
}
.sensor-unit {
  font-size: 1.5rem;
  color: #94a3b8;
  align-self: flex-start;
  margin-top: 6px;
}
.sensor-status {
  font-size: 0.9rem;
  color: #64748b;
  text-align: center;
}
.temp-inactive {
  background: #1e293b;
  color: #64748b;
}

/* ========== Mobile Responsive ========== */

/* iOS safe area support */
html {
  /* Enable smooth scrolling but disable on modals */
  scroll-behavior: smooth;
}

body {
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  /* Prevent overscroll on iOS */
  overscroll-behavior: none;
}

/* Prevent body scroll when modal is open */
body.modal-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
  height: 100%;
  /* iOS specific - prevent rubber banding */
  -webkit-overflow-scrolling: auto;
}

@media (max-width: 600px) {
  /* Tabs - smaller on mobile */
  .tab {
    padding: 10px 6px;
    font-size: 0.75rem;
    flex-direction: column;
    gap: 3px;
  }
  .tab .indicator {
    width: 6px;
    height: 6px;
  }

  /* Tab content padding */
  .tab-content {
    padding: 15px 12px;
  }

  /* Stats grid */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  .stats-grid .stat-card:last-child {
    grid-column: span 2;
  }
  .stat-card {
    padding: 12px 10px;
  }
  .stat-card .value {
    font-size: 1.4rem;
  }
  .stat-card .label {
    font-size: 0.75rem;
  }

  /* Section */
  .section {
    padding: 15px;
    margin-bottom: 15px;
  }
  .section h2 {
    font-size: 1rem;
    margin-bottom: 12px;
  }

  /* Fish inventory header */
  .section > div:first-child {
    flex-wrap: wrap;
    gap: 10px;
  }
  .section > div:first-child h2 {
    flex: 1;
    min-width: 120px;
  }
  .section > div:first-child .btn-success {
    padding: 10px 14px !important;
    font-size: 0.9rem !important;
    white-space: nowrap;
  }

  /* Fish filters */
  .fish-filters {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px;
    padding-top: 15px;
    margin: 0 -15px;
    margin-top: 5px;
    background: #0f172a;
    border-radius: 8px;
  }
  .btn-filter {
    padding: 10px 16px;
    font-size: 0.85rem;
    white-space: nowrap;
    flex-shrink: 0;
    min-height: 40px;
    border: 1px solid #374151;
  }
  .btn-filter.active {
    border-color: #6366f1;
  }

  /* Fish count label on mobile */
  #fishCountLabel {
    width: 100%;
    text-align: left;
    font-size: 0.8rem;
    margin-left: 0 !important;
    margin-top: 5px;
  }

  /* Fish inventory - card layout */
  .fish-list {
    max-height: none;
  }
  .fish-item {
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto auto;
    gap: 8px 12px;
    padding: 12px;
    align-items: center;
  }
  .fish-item .fish-avatar {
    width: 45px;
    height: 45px;
    font-size: 1.3rem;
    grid-row: span 2;
  }
  .fish-item .fish-info {
    grid-column: 2;
    grid-row: 1;
    min-width: 0;
  }
  .fish-item .fish-name {
    font-size: 0.9rem;
  }
  .fish-item .fish-species {
    font-size: 0.8rem;
  }
  .fish-item .fish-meta {
    display: none; /* Hide meta on very small screens */
  }
  .fish-item .fish-status {
    grid-column: 3;
    grid-row: 1;
    font-size: 0.65rem;
    padding: 2px 6px;
  }
  .fish-item .fish-actions {
    grid-column: 2 / 4;
    grid-row: 2;
    justify-content: flex-end;
    gap: 6px;
  }
  .fish-item .fish-actions button {
    padding: 8px 14px;
    font-size: 0.85rem;
    min-height: 36px;
  }

  /* Schedule items - Pump & Feeder */
  .schedule-item {
    gap: 6px;
    padding: 10px;
  }
  .schedule-item .label {
    display: none;
  }
  .schedule-item input[type="checkbox"] {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
  }
  .schedule-item input[type="time"] {
    padding: 8px 6px;
    font-size: 0.85rem;
    flex: 1;
    min-width: 0;
  }
  .schedule-item select {
    padding: 8px 4px;
    font-size: 0.85rem;
    flex: 1;
    min-width: 0;
  }
  .schedule-item .btn-remove {
    padding: 6px 8px;
    font-size: 0.75rem;
    min-width: auto;
    flex-shrink: 0;
  }

  /* Light schedule cards */
  .light-schedule-card {
    overflow: hidden;
  }
  .light-schedule-card .schedule-times {
    gap: 6px;
  }
  .time-group input[type="time"] {
    padding: 8px 4px;
    font-size: 0.85rem;
  }
  .light-schedule-card .schedule-color .color-picker-wrapper {
    flex-wrap: wrap;
  }
  .schedule-color select {
    padding: 8px 6px;
    font-size: 0.85rem;
  }

  /* Modals - full screen on mobile */
  .modal {
    padding: 0;
    align-items: stretch;
    justify-content: flex-start;
  }
  .modal-content {
    width: 100%;
    max-width: 100%;
    min-height: 100%;
    min-height: -webkit-fill-available;
    max-height: none;
    border-radius: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    margin: 0;
  }
  .modal-content h3 {
    font-size: 1.1rem;
    margin-bottom: 0;
    padding: 15px;
    padding-top: calc(15px + env(safe-area-inset-top));
    background: #16213e;
    border-bottom: 1px solid #374151;
    position: sticky;
    top: 0;
    z-index: 10;
  }
  .modal-content .modal-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 15px;
    padding-bottom: 100px; /* Space for sticky actions */
  }
  .modal-content .form-group {
    margin-bottom: 18px;
  }
  .modal-content label {
    font-size: 0.9rem;
    margin-bottom: 8px;
  }
  .modal-content input,
  .modal-content textarea,
  .modal-content select {
    padding: 14px 12px;
    font-size: 16px; /* Prevents iOS zoom on focus */
    border-radius: 8px;
    min-height: 48px;
  }
  .modal-content textarea {
    min-height: 100px;
  }
  .modal-content input[type="range"] {
    height: 36px;
    min-height: 36px;
    padding: 0;
  }
  .modal-content input[type="date"] {
    -webkit-appearance: none;
    appearance: none;
  }
  .modal-actions {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #16213e;
    padding: 12px 15px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid #374151;
    margin: 0;
    display: flex;
    gap: 10px;
    z-index: 20;
  }
  .modal-actions button {
    padding: 14px;
    font-size: 1rem;
    min-height: 50px;
    border-radius: 10px;
    font-weight: 600;
  }

  /* Image preview in modals */
  .modal-content .image-preview {
    max-height: 120px;
    margin-bottom: 15px;
    border-radius: 8px;
    overflow: hidden;
  }
  .modal-content .image-preview img {
    width: 100%;
    height: 100%;
    max-height: 120px;
    object-fit: cover;
  }

  /* Water change info */
  .water-change-info {
    flex-direction: column;
    gap: 12px;
    text-align: center;
  }
  .water-change-info button {
    width: 100%;
    padding: 12px;
  }

  /* State box */
  .state-box {
    flex-wrap: wrap;
    gap: 12px;
    padding: 15px;
  }
  .state-box .state-info {
    flex: 1 1 auto;
    min-width: 120px;
  }
  .state-box .state-info .power {
    font-size: 1.2rem;
  }
  .state-box .state-info .mode {
    font-size: 0.85rem;
  }
  .state-box > div:last-child {
    width: 100%;
    flex-direction: row !important;
    gap: 10px;
  }
  .state-box > div:last-child button {
    flex: 1;
    padding: 10px;
  }

  /* Tank visual */
  .tank-visual {
    width: 55px !important;
    height: 70px !important;
  }
  .tank-info {
    font-size: 0.55rem;
  }

  /* Buttons grid - keep 3 columns for LED strip */
  .buttons {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }
  .buttons button {
    padding: 10px 8px;
    font-size: 0.85rem;
    min-height: 44px;
  }

  /* Duration control */
  .duration-control {
    gap: 10px;
  }
  .duration-control .value {
    font-size: 1rem;
    min-width: 45px;
  }

  /* Feed button */
  .btn-feed {
    padding: 16px !important;
    font-size: 1.1rem !important;
  }

  /* Header */
  .header {
    padding: 12px 15px;
  }
  .header h1 {
    font-size: 1.1rem;
  }
  .logout-btn, .settings-btn {
    padding: 5px 8px;
    font-size: 1rem;
  }

  /* Dimension inputs in aquarium modal */
  .dimension-inputs {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
  }
  .dimension-inputs small {
    color: #64748b;
    font-size: 0.75rem;
    display: block;
    margin-top: 4px;
    text-align: center;
  }

  /* Species list on mobile */
  .species-list {
    margin: 0 -12px; /* Extend to edges */
  }
  .species-group {
    border-radius: 0;
    margin-bottom: 1px;
    background: #1e293b;
  }
  .species-header {
    padding: 14px 15px;
    gap: 10px;
  }
  .species-header .species-avatar {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    font-size: 1.2rem;
  }
  .species-header .species-name {
    font-size: 0.95rem;
  }
  .species-header .species-count {
    font-size: 0.8rem;
  }
  .species-header .species-actions button {
    padding: 8px 10px;
    min-width: 36px;
    min-height: 36px;
    font-size: 0.85rem;
  }
  .species-header .expand-icon {
    font-size: 1rem;
    margin-left: 4px;
  }

  .species-fish-list {
    padding: 0 12px 12px;
    background: #0f172a;
  }
  .species-fish-list .fish-item {
    padding: 10px;
    margin-bottom: 8px;
    border-radius: 8px;
    background: #1e293b;
  }
  .species-fish-list .add-fish-btn {
    padding: 12px;
    font-size: 0.9rem;
    min-height: 44px;
  }

  /* Fish items on mobile - simplified layout */
  .fish-item {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
  }
  .fish-item .fish-avatar {
    width: 40px;
    height: 40px;
    font-size: 1.2rem;
  }
  .fish-item .fish-info {
    flex: 1;
    min-width: 100px;
  }
  .fish-item .fish-name {
    font-size: 0.9rem;
    line-height: 1.3;
  }
  .fish-item .fish-meta {
    font-size: 0.75rem;
    flex-wrap: wrap;
    gap: 6px;
  }
  .fish-item .fish-status {
    font-size: 0.7rem;
    padding: 3px 8px;
  }
  .fish-item .fish-actions {
    display: flex;
    gap: 6px;
  }
  .fish-item .fish-actions button {
    padding: 8px 12px;
    min-height: 40px;
    min-width: 40px;
    font-size: 0.9rem;
  }
}

/* Extra small screens (iPhone SE, etc) */
@media (max-width: 375px) {
  .tab {
    padding: 8px 4px;
    font-size: 0.7rem;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .species-header .species-avatar {
    width: 35px;
    height: 35px;
    font-size: 1rem;
  }
  .species-header .species-actions button {
    padding: 6px 8px;
    min-width: 32px;
    min-height: 32px;
    font-size: 0.8rem;
  }

  .fish-item .fish-avatar {
    width: 35px;
    height: 35px;
  }
  .fish-item .fish-actions button {
    padding: 6px 10px;
    min-height: 36px;
    font-size: 0.85rem;
  }

  .schedule-item input[type="time"],
  .schedule-item select {
    padding: 8px 4px;
    font-size: 0.8rem;
  }

  /* Modal adjustments for very small screens */
  .modal-content h3 {
    font-size: 1rem;
    padding: 12px;
  }
  .modal-body {
    padding: 12px;
  }
  .modal-actions button {
    padding: 12px;
    font-size: 0.95rem;
  }

  .dimension-inputs {
    gap: 8px;
  }
  .dimension-inputs input {
    padding: 10px 8px !important;
  }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
  /* Ensure all interactive elements are at least 44x44px (Apple guideline) */
  button,
  input[type="checkbox"],
  .tab,
  .species-header,
  .fish-item {
    min-height: 44px;
  }

  /* Remove hover effects that don't work well on touch */
  .species-header:hover {
    background: transparent;
  }
  .fish-item:hover {
    background: inherit;
  }

  /* Active states for touch feedback */
  .species-header:active {
    background: #2d3748;
  }
  .fish-item:active {
    background: #2d3748;
  }
  button:active {
    transform: scale(0.98);
    opacity: 0.9;
  }
}
