/* OFM Mobile App Stylesheet - Modern Dark/Emerald Agro-Tech Theme */
:root {
  --bg-primary: #0a1412;
  --bg-secondary: #10221e;
  --bg-card: #152b26;
  --bg-card-hover: #1c3832;
  --bg-surface: #0e1e1a;
  
  --primary: #10b981;
  --primary-light: #34d399;
  --primary-dark: #059669;
  
  --gold: #f59e0b;
  --gold-light: #fbbf24;
  --gold-gradient: linear-gradient(135deg, #d97706, #fbbf24);
  
  --teal-gradient: linear-gradient(135deg, #0d9488, #10b981);
  --brand-gradient: linear-gradient(135deg, #d97706 0%, #10b981 100%);
  
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;
  
  --border-color: rgba(255, 255, 255, 0.08);
  --border-active: rgba(16, 185, 129, 0.35);
  
  --danger: #ef4444;
  --warning: #f59e0b;
  --success: #10b981;
  --info: #06b6d4;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-main);
  overflow-x: hidden;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

/* Splash Screen Overlay */
#splash-screen {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at center, #132e27 0%, #06120f 100%);
  z-index: 99999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

#splash-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.splash-logo-container {
  position: relative;
  width: 150px;
  height: 150px;
  margin-bottom: 24px;
}

.splash-logo-glow {
  position: absolute;
  inset: -12px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(16, 185, 129, 0.4) 0%, rgba(217, 119, 6, 0.25) 50%, transparent 70%);
  filter: blur(15px);
  animation: pulse-glow 2.5s infinite alternate;
}

.splash-logo {
  position: relative;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.6));
  animation: zoom-in 1.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes pulse-glow {
  0% { transform: scale(0.9); opacity: 0.5; }
  100% { transform: scale(1.15); opacity: 0.9; }
}

@keyframes zoom-in {
  0% { transform: scale(0.7); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.splash-title {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 0.5px;
  background: var(--brand-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 6px;
}

.splash-tagline {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 30px;
  letter-spacing: 0.3px;
}

.splash-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(16, 185, 129, 0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* App Container */
#app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding-bottom: calc(85px + var(--safe-bottom));
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: rgba(14, 30, 26, 0.96);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  padding: calc(8px + var(--safe-top)) 12px 8px;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  gap: 8px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.header-logo {
  width: 32px;
  height: 32px;
  object-fit: contain;
  flex-shrink: 0;
}

.header-title-box {
  min-width: 0;
  overflow: hidden;
}

.header-title-box h1 {
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-title-box p {
  font-size: 10.5px;
  color: var(--primary-light);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
}

.status-online {
  background: rgba(16, 185, 129, 0.15);
  color: var(--primary-light);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.status-offline {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.role-badge {
  padding: 3px 7px;
  border-radius: 6px;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  background: var(--gold-gradient);
  color: #0b1c18;
  white-space: nowrap;
}

/* Selectors row */
.selector-row {
  display: flex;
  gap: 8px;
  width: 100%;
}

.selector-box {
  flex: 1 1 0;
  min-width: 0;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 5px 8px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.selector-box label {
  font-size: 8.5px;
  text-transform: uppercase;
  color: var(--text-dim);
  font-weight: 700;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.selector-box select {
  background: transparent;
  border: none;
  color: var(--text-main);
  font-size: 11.5px;
  font-weight: 600;
  outline: none;
  cursor: pointer;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' fill='%239ca3af' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 2px center;
  padding-right: 14px;
}

.selector-box select option {
  background: var(--bg-card);
  color: var(--text-main);
}

/* Offline Banner */
.offline-banner {
  background: linear-gradient(90deg, #b91c1c, #991b1b);
  color: #fff;
  padding: 8px 16px;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  display: none;
}

.offline-banner.active {
  display: flex;
}

/* Main Content Views */
.tab-content {
  display: none;
  padding: 12px;
  animation: fadeIn 0.25s ease;
}

.tab-content.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Cards & Sections */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 14px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

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

.card-title {
  font-size: 13.5px;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  font-size: 9.5px;
  font-weight: 700;
  padding: 2.5px 7px;
  border-radius: 12px;
  text-transform: uppercase;
}

.badge-success { background: rgba(16, 185, 129, 0.2); color: #34d399; }
.badge-warning { background: rgba(245, 158, 11, 0.2); color: #fbbf24; }
.badge-danger  { background: rgba(239, 68, 68, 0.2); color: #f87171; }
.badge-info    { background: rgba(6, 182, 212, 0.2); color: #38bdf8; }

/* Solenoid Valve Banner */
.valve-card {
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.12) 0%, rgba(16, 185, 129, 0.08) 100%);
  border: 1px solid rgba(6, 182, 212, 0.3);
  border-radius: 12px;
  padding: 10px 14px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

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

.valve-info h3 {
  font-size: 12.5px;
  font-weight: 700;
  color: #fff;
}

.valve-info p {
  font-size: 10.5px;
  color: var(--text-muted);
  margin-top: 1px;
}

.valve-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 11px;
  border-radius: 20px;
  font-size: 10.5px;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}

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

.sensor-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 9px 11px;
  position: relative;
  overflow: hidden;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.sensor-card.highlight {
  border-color: var(--border-active);
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.08) 0%, var(--bg-surface) 100%);
}

.sensor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  margin-bottom: 4px;
}

.sensor-icon {
  font-size: 15px;
  color: var(--primary-light);
}

.sensor-name {
  font-size: 10.5px;
  color: var(--text-muted);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sensor-value-box {
  display: flex;
  align-items: baseline;
  gap: 4px;
  margin-bottom: 2px;
}

.sensor-value {
  font-size: 19px;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.5px;
}

.sensor-unit {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-dim);
}

.sensor-ideal {
  font-size: 9.5px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Kartu ganjil terakhir (Card #7: Intensitas Cahaya) membentang penuh 2 kolom */
.sensor-grid .sensor-card:last-child:nth-child(odd) {
  grid-column: span 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
}

.sensor-grid .sensor-card:last-child:nth-child(odd) .sensor-header {
  margin-bottom: 0;
  gap: 8px;
}

.sensor-grid .sensor-card:last-child:nth-child(odd) .sensor-value-box {
  margin-bottom: 0;
  gap: 6px;
}

.sensor-grid .sensor-card:last-child:nth-child(odd) .sensor-ideal {
  margin-left: 8px;
}


.valve-open {
  background: rgba(16, 185, 129, 0.25);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.4);
}

.valve-closed {
  background: rgba(107, 114, 128, 0.2);
  color: #d1d5db;
  border: 1px solid rgba(107, 114, 128, 0.3);
}

/* Recommendation Hero Banner */
.recommendation-banner {
  border-radius: 14px;
  padding: 18px;
  margin-bottom: 18px;
  position: relative;
  overflow: hidden;
}

.recommendation-banner.optimal {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.18) 0%, rgba(5, 150, 105, 0.08) 100%);
  border: 1px solid rgba(16, 185, 129, 0.4);
}

.recommendation-banner.tunda {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.22) 0%, rgba(185, 28, 28, 0.1) 100%);
  border: 1px solid rgba(239, 68, 68, 0.45);
}

.recommendation-banner.saatnya {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.22) 0%, rgba(217, 119, 6, 0.1) 100%);
  border: 1px solid rgba(245, 158, 11, 0.45);
}

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

.rec-title {
  font-size: 15px;
  font-weight: 800;
  color: #fff;
  line-height: 1.3;
}

.rec-desc {
  font-size: 12px;
  color: #e5e7eb;
  line-height: 1.5;
  margin-bottom: 12px;
}

.rec-details-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 10px;
  padding: 10px;
}

.rec-detail-item label {
  font-size: 9px;
  text-transform: uppercase;
  color: var(--text-dim);
  font-weight: 700;
  display: block;
}

.rec-detail-item span {
  font-size: 12px;
  font-weight: 700;
  color: #fff;
}

/* Tasks List */
.task-item {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 10px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.task-checkbox {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 2px solid var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  margin-top: 2px;
  flex-shrink: 0;
  transition: background 0.15s ease;
}

.task-checkbox.checked {
  background: var(--primary);
  color: #0b1c18;
}

.task-details {
  flex: 1;
}

.task-title {
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 4px;
}

.task-title.done {
  text-decoration: line-through;
  color: var(--text-dim);
}

.task-desc {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
  margin-bottom: 6px;
}

.task-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-dim);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
  border: none;
  cursor: pointer;
  outline: none;
  transition: filter 0.15s ease, transform 0.1s ease;
  width: 100%;
}

.btn:active {
  transform: scale(0.98);
}

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

.btn-gold {
  background: var(--gold-gradient);
  color: #121f1b;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-main);
}

.btn-outline:hover {
  border-color: var(--primary-light);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 11px;
  border-radius: 7px;
  width: auto;
}

/* Forms */
.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
}

.form-control {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  color: #fff;
  outline: none;
  transition: border-color 0.2s ease;
}

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

/* Photo Upload Box */
.photo-uploader {
  border: 2px dashed var(--border-color);
  border-radius: 12px;
  padding: 16px;
  text-align: center;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.15);
  margin-bottom: 14px;
  position: relative;
}

.photo-uploader.has-photo {
  border-color: var(--primary);
  background: rgba(16, 185, 129, 0.05);
}

.photo-preview {
  max-width: 100%;
  max-height: 180px;
  border-radius: 8px;
  display: none;
  margin: 0 auto 10px;
  object-fit: cover;
}

/* Bottom Navigation Bar */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(58px + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(12, 26, 23, 0.96);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 1000;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.bottom-nav::-webkit-scrollbar {
  display: none;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-dim);
  text-decoration: none;
  cursor: pointer;
  flex: 1 1 0;
  min-width: 44px;
  padding: 4px 1px;
  transition: color 0.15s ease;
}

.nav-item.active {
  color: var(--primary-light);
}

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

.nav-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: -0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  text-align: center;
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  z-index: 2000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.modal-overlay.open {
  opacity: 1;
  visibility: visible;
}

.modal-sheet {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 540px;
  max-height: 88vh;
  overflow-y: auto;
  padding: 20px;
  padding-bottom: calc(24px + var(--safe-bottom));
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-overlay.open .modal-sheet {
  transform: translateY(0);
}

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

.modal-title {
  font-size: 16px;
  font-weight: 800;
  color: #fff;
}

.modal-close {
  background: rgba(255, 255, 255, 0.08);
  border: none;
  color: var(--text-muted);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

/* Toast Notification */
#toast-notification {
  position: fixed;
  top: calc(18px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%) translateY(-30px);
  background: #112822;
  border: 1px solid var(--primary);
  color: #fff;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 12px;
  font-weight: 600;
  z-index: 9999;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.25s ease, opacity 0.25s ease;
}

#toast-notification.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* Responsive tweaks */
@media (min-width: 600px) {
  #app-container {
    max-width: 500px;
    margin: 0 auto;
    border-left: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    min-height: 100vh;
  }
  .bottom-nav {
    max-width: 500px;
    left: 50%;
    transform: translateX(-50%);
  }
}
