:root {
  --font-main: 'Inter', 'IBM Plex Sans Thai', sans-serif;
  
  /* Color Palette - Premium Dark Theme */
  --bg-app: #090d16;
  --bg-gradient: radial-gradient(circle at 50% 0%, #17223b 0%, #090d16 100%);
  --card-bg: rgba(21, 32, 54, 0.7);
  --card-border: rgba(255, 255, 255, 0.06);
  --card-border-glow: rgba(16, 185, 129, 0.15);
  
  --primary: #10b981; /* Emerald for clean solar */
  --primary-glow: rgba(16, 185, 129, 0.4);
  --primary-dark: #059669;
  
  --import: #3b82f6; /* Blue for imported electricity */
  --import-glow: rgba(59, 130, 246, 0.25);
  
  --export: #f59e0b; /* Amber/Orange for export */
  --export-glow: rgba(245, 158, 11, 0.25);
  
  --production: #10b981;
  --production-glow: rgba(16, 185, 129, 0.25);
  
  --warning: #ef4444; /* Red for alert */
  --warning-glow: rgba(239, 68, 68, 0.25);
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --nav-bg: rgba(13, 20, 35, 0.85);
  --border-radius: 20px;
  --border-radius-sm: 12px;
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reset & Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-app);
  background-image: var(--bg-gradient);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  overflow-x: hidden;
  line-height: 1.5;
}

/* App Container Layout */
.app-container {
  width: 100%;
  max-width: 480px; /* Standard premium mobile view */
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: rgba(9, 13, 22, 0.6);
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.6);
  position: relative;
  padding-bottom: 84px; /* Space for bottom nav */
  border-left: 1px solid rgba(255, 255, 255, 0.03);
  border-right: 1px solid rgba(255, 255, 255, 0.03);
}

/* Header */
.app-header {
  padding: 18px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: rgba(9, 13, 22, 0.4);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--card-border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cloud-status {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.04);
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 0.9rem;
  color: var(--text-muted);
  border: 1px solid rgba(255, 255, 255, 0.06);
  transition: var(--transition);
  cursor: help;
}

.cloud-status.connected {
  color: var(--primary);
  background: var(--primary-glow);
  border-color: rgba(16, 185, 129, 0.25);
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.2);
}

.cloud-status.local {
  color: var(--export);
  background: var(--export-glow);
  border-color: rgba(245, 158, 11, 0.25);
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--export));
  display: flex;
  justify-content: center;
  align-items: center;
  color: #fff;
  font-size: 1.15rem;
  box-shadow: 0 0 15px rgba(16, 185, 129, 0.3);
}

.logo-text h1 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1.2;
}

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

.cycle-indicator {
  background: rgba(255, 255, 255, 0.05);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 500;
  border: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--primary);
}

/* Main Content Area & Tab Control */
.app-content {
  flex: 1;
  padding: 16px;
}

.tab-content {
  display: none;
  animation: fadeIn 0.3s ease;
}

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

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

/* Tab 1: Dashboard Styles */

/* Hero Card (Glassmorphism & Glow) */
.hero-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--border-radius);
  padding: 22px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.2);
  margin-bottom: 16px;
}

.hero-bg-glow {
  position: absolute;
  top: -40px;
  right: -40px;
  width: 120px;
  height: 120px;
  background: var(--primary);
  filter: blur(55px);
  opacity: 0.25;
  pointer-events: none;
}

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

.badge {
  background: var(--primary-glow);
  color: var(--primary);
  border: 1px solid rgba(16, 185, 129, 0.2);
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.badge.warning {
  background: var(--warning-glow);
  color: var(--warning);
  border: 1px solid rgba(239, 68, 68, 0.25);
}

.cycle-title {
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.hero-main-stat {
  display: flex;
  flex-direction: column;
  margin-bottom: 22px;
}

.hero-main-stat .label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.hero-main-stat .value {
  font-size: 2.3rem;
  font-weight: 800;
  letter-spacing: -1px;
  color: var(--text-primary);
  line-height: 1.1;
}

.hero-main-stat .unit {
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-left: 4px;
}

.hero-footer-stats {
  display: flex;
  justify-content: space-between;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 14px;
}

.sub-stat {
  display: flex;
  flex-direction: column;
}

.sub-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.sub-value {
  font-size: 1rem;
  font-weight: 700;
}

.sub-value .unit {
  font-size: 0.72rem;
  font-weight: 400;
  color: var(--text-muted);
}

.text-import { color: var(--import); }
.text-export { color: var(--export); }
.text-production { color: var(--production); }
.text-saving { color: var(--primary); }

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.kpi-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--border-radius-sm);
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  transition: var(--transition);
}

.kpi-card:active {
  transform: scale(0.97);
}

.kpi-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.1rem;
}

.icon-solar { background: rgba(16, 185, 129, 0.1); color: var(--primary); }
.icon-home { background: rgba(59, 130, 246, 0.1); color: var(--import); }
.icon-saving { background: rgba(16, 185, 129, 0.12); color: var(--primary); }
.icon-net { background: rgba(245, 158, 11, 0.1); color: var(--export); }

.kpi-info {
  display: flex;
  flex-direction: column;
}

.kpi-label {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.kpi-value {
  font-size: 0.95rem;
  font-weight: 700;
}

.kpi-value .unit {
  font-size: 0.72rem;
  font-weight: 400;
  color: var(--text-muted);
}

/* Alert Box */
.alert-box {
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.18);
  border-radius: var(--border-radius-sm);
  padding: 14px 16px;
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  align-items: flex-start;
}

.alert-icon {
  color: var(--warning);
  font-size: 1.2rem;
  margin-top: 2px;
}

.alert-text h4 {
  font-size: 0.85rem;
  font-weight: 600;
  color: #fff;
  margin-bottom: 2px;
}

.alert-text p {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* Card General Styling */
.chart-container-card, .breakdown-card, .history-list-card, .settings-card, .about-card, .billing-report-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--border-radius);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.12);
}

.chart-header, .list-header, .report-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

h3 {
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--text-primary);
}

.chart-toggle {
  display: flex;
  background: rgba(255, 255, 255, 0.04);
  padding: 3px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.btn-toggle {
  border: none;
  background: none;
  color: var(--text-secondary);
  font-family: var(--font-main);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: var(--transition);
}

.btn-toggle.active {
  background: var(--primary);
  color: #000;
  box-shadow: 0 2px 8px var(--primary-glow);
}

.chart-body {
  position: relative;
  width: 100%;
  height: 200px;
}

/* Energy Breakdown Doughnut style */
.breakdown-card h3 {
  margin-bottom: 14px;
}

.breakdown-charts {
  display: flex;
  align-items: center;
  gap: 16px;
}

.breakdown-chart-wrapper {
  width: 100px;
  height: 100px;
  position: relative;
}

.breakdown-legend {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.76rem;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.legend-dot.color-import { background-color: var(--import); }
.legend-dot.color-self { background-color: var(--primary); }
.legend-dot.color-export { background-color: var(--export); }

.legend-text {
  color: var(--text-secondary);
}

.legend-text strong {
  color: var(--text-primary);
  font-weight: 600;
}

/* Tab 2: Add Entry Input Form */

.section-title {
  margin-bottom: 20px;
}

.section-title h2 {
  font-size: 1.3rem;
  font-weight: 700;
}

.section-title p {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.entry-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--border-radius);
  padding: 18px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}

.form-group label {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-group label i {
  margin-right: 4px;
}

input[type="date"], input[type="number"], select {
  font-family: var(--font-main);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--border-radius-sm);
  padding: 12px 14px;
  color: #fff;
  font-size: 0.92rem;
  outline: none;
  transition: var(--transition);
  width: 100%;
}

input[type="date"]:focus, input[type="number"]:focus, select:focus {
  border-color: var(--primary);
  background: rgba(255, 255, 255, 0.07);
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.15);
}

.form-row {
  display: flex;
  gap: 12px;
}

.helper-text {
  font-size: 0.68rem;
  color: var(--text-muted);
}

.form-toggle-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.toggle-label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-secondary);
}

/* Custom Radio Toggle Buttons */
.radio-toggle {
  display: flex;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--border-radius-sm);
  padding: 4px;
  width: 100%;
}

.radio-toggle input[type="radio"] {
  display: none;
}

.radio-toggle label {
  flex: 1;
  text-align: center;
  padding: 8px 6px;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-secondary);
  border-radius: 8px;
  cursor: pointer;
  transition: var(--transition);
}

.radio-toggle input[type="radio"]:checked + label {
  background: rgba(255, 255, 255, 0.08);
  color: var(--primary);
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.1);
}

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

/* Button UI */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-main);
  font-size: 0.88rem;
  font-weight: 600;
  padding: 12px 20px;
  border-radius: var(--border-radius-sm);
  border: none;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  flex: 1;
}

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

.btn-primary {
  background: var(--primary);
  color: #0b1320;
  box-shadow: 0 4px 15px rgba(16, 185, 129, 0.35);
}

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

.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
}

.btn-secondary-outline {
  background: none;
  color: var(--text-secondary);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.btn-danger-outline {
  background: none;
  color: var(--warning);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.btn-danger-outline:hover {
  background: rgba(239, 68, 68, 0.08);
}

.btn-small {
  padding: 6px 12px;
  font-size: 0.72rem;
  border-radius: 8px;
}

.mobile-helper-card {
  margin-top: 16px;
  background: rgba(16, 185, 129, 0.04);
  border: 1px solid rgba(16, 185, 129, 0.08);
  border-radius: var(--border-radius);
  padding: 14px;
}

.mobile-helper-card h4 {
  font-size: 0.8rem;
  color: var(--primary);
  margin-bottom: 4px;
}

.mobile-helper-card p {
  font-size: 0.72rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* Tab 3: History & Cycles Styles */

.section-title-with-actions {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 20px;
}

.cycle-selector-wrapper {
  max-width: 140px;
}

.form-select {
  font-family: var(--font-main);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 6px 20px 6px 10px;
  color: #fff;
  font-size: 0.76rem;
  font-weight: 500;
  outline: none;
  cursor: pointer;
}

/* Billing Report Card */
.billing-report-card {
  border: 1px solid var(--card-border-glow);
  position: relative;
  background: linear-gradient(180deg, rgba(16, 185, 129, 0.03) 0%, rgba(21, 32, 54, 0.7) 100%);
}

.report-dates {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: -12px;
  margin-bottom: 16px;
}

.report-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 16px;
  margin-bottom: 14px;
}

.report-col {
  display: flex;
  flex-direction: column;
}

.rep-label {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.rep-value {
  font-size: 1.05rem;
  font-weight: 700;
}

.report-details-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: rgba(0, 0, 0, 0.15);
  padding: 10px 12px;
  border-radius: var(--border-radius-sm);
}

.rep-detail-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.74rem;
  color: var(--text-secondary);
}

.rep-detail-row strong {
  color: var(--text-primary);
}

/* History Logs Table */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  margin-top: 8px;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.72rem;
}

.history-table th {
  color: var(--text-muted);
  font-weight: 500;
  padding: 10px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.history-table td {
  padding: 12px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  vertical-align: middle;
}

.history-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

.table-badge {
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 0.65rem;
  font-weight: 600;
}

.table-badge.badge-r {
  background: rgba(59, 130, 246, 0.15);
  color: #93c5fd;
}

.table-badge.badge-u {
  background: rgba(16, 185, 129, 0.15);
  color: #6ee7b7;
}

.action-btns {
  display: flex;
  gap: 6px;
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  font-size: 0.8rem;
  transition: var(--transition);
}

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

.btn-icon.btn-delete:hover {
  color: var(--warning);
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
  gap: 12px;
}

.empty-state i {
  font-size: 2.2rem;
  color: rgba(255, 255, 255, 0.08);
}

.empty-state p {
  font-size: 0.76rem;
  max-width: 240px;
}

/* Tab 4: Settings Custom Grid Styles */
.settings-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.btn-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 14px;
}

.file-import-box {
  margin-top: 10px;
}

.about-card {
  background: rgba(255, 255, 255, 0.01);
  border: 1px dashed rgba(255, 255, 255, 0.06);
  text-align: center;
}

.about-card h4 {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.about-card p {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.dev-info {
  margin-top: 10px;
  font-size: 0.65rem;
  color: var(--text-muted);
}

/* Bottom Tab Navigation Bar */
.app-navbar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: 68px;
  background-color: var(--nav-bg);
  backdrop-filter: blur(15px);
  border-top: 1px solid var(--card-border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 200;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.35);
  padding: 0 10px;
}

.nav-item {
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  cursor: pointer;
  flex: 1;
  height: 100%;
  gap: 4px;
  transition: var(--transition);
  font-family: var(--font-main);
}

.nav-item i {
  font-size: 1.15rem;
  transition: var(--transition);
}

.nav-item span {
  font-size: 0.68rem;
  font-weight: 500;
}

.nav-item:active {
  transform: scale(0.9);
}

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

.nav-item.active i {
  transform: translateY(-2px);
  text-shadow: 0 0 10px var(--primary-glow);
}

/* Floating add design accent */
#nav-btn-add {
  position: relative;
}

#nav-btn-add i {
  font-size: 1.3rem;
}

/* Custom Scrollbar for Premium Feel */
::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--primary);
}
