Solar timer project to charge an EV

OK, this code uses the digital pin of the Ldr and has hysteresis to control the relay. As set for testing, it waits ten seconds before deactivating or reactivating relay based on the results it gets from the digital pin. In the real world, I would set it for at least 10 minutes.
The override switch is immediate however, both on and off.

I could use the analog pin and then use actual LDR readings to adjust, but this would mean I would have to manually set the high and low values by writing it into the code. Using digital, I can manually adjust the potentiometer to easily adjust the state settings.
I had included links to the wokwi earlier, but have discovered that the LDR module in wokwi doesn't work correctly; I could not get it to drive the circuit; but on my breadboard it is working just fine. So I won't bother updating that.

I'm sure this could be improved. Ideas?

//==============================================================================
const int LDR_DIGITAL_PIN = 34;  // Digital output from LDR module (DO pin)
const int SWITCH_PIN      = 23;  // Manual override switch (active LOW)
const int RELAY_PIN       = 4;   // SSR control pin

const unsigned long ON_DELAY  = 10UL * 1000UL;  // Brightness hold time before turning ON
const unsigned long OFF_DELAY = 10UL * 1000UL;  // Darkness hold time before turning OFF

unsigned long brightStartTime = 0;
unsigned long darkStartTime   = 0;

bool relayState = false;
bool prev_state = false;
bool prev_ovr = false;
//==============================================================================
void setup() {
  Serial.begin(115200);
  pinMode(RELAY_PIN, OUTPUT);
  pinMode(SWITCH_PIN, INPUT_PULLUP);
  pinMode(LDR_DIGITAL_PIN, INPUT);
  digitalWrite(RELAY_PIN, LOW);
  Serial.println("System Initialized");
}
//==============================================================================
void loop() {
  bool ovr = !digitalRead(SWITCH_PIN);         // Manual override active?
  bool isBright = digitalRead(LDR_DIGITAL_PIN) == LOW;  // LOW = bright (depends on module)

  // Manual override status change
  if (ovr != prev_ovr) {
    Serial.print("Manual switch turned ");
    Serial.println(ovr ? "ON" : "OFF");
    prev_ovr = ovr;

    // Reset timers when override ends
    if (!ovr) {
      brightStartTime = 0;
      darkStartTime = 0;
      relayState = false;  // Force relay OFF immediately
      Serial.println("Manual override ended — relay OFF");
    }
  }

  // Hysteresis logic
  if (ovr) {
    relayState = true;
    brightStartTime = 0;
    darkStartTime = 0;
  } else if (!relayState) {
    // Relay is OFF, wait for sustained brightness
    if (isBright) {
      if (brightStartTime == 0) brightStartTime = millis();
      else if (millis() - brightStartTime >= ON_DELAY) {
        relayState = true;
        brightStartTime = 0;
        Serial.println("Sustained brightness — relay ON");
      }
    } else {
      brightStartTime = 0;
    }
  } else {
    // Relay is ON, wait for sustained darkness
    if (!isBright) {
      if (darkStartTime == 0) darkStartTime = millis();
      else if (millis() - darkStartTime >= OFF_DELAY) {
        relayState = false;
        darkStartTime = 0;
        Serial.println("Sustained darkness — relay OFF");
      }
    } else {
      darkStartTime = 0;
    }
  }

  // Print relay status changes
  if (relayState != prev_state) {
    if (ovr) {
      Serial.println("Relay manually turned ON");
    } else if (relayState) {
      Serial.println("Relay activated due to sustained brightness");
    } else {
      Serial.println("Relay deactivated due to sustained darkness");
    }
    prev_state = relayState;
  }

  digitalWrite(RELAY_PIN, relayState);  // Final relay control
  delay(20);  // Smooth polling loop
}
//==============================================================================