/* ==========================================================================
   1. Root Variables & Global Styles
   ========================================================================== */
:root {
  --google-blue: #1a73e8;
  --google-grey-border: #dadce0;
  --google-grey-text: #5f6368;
  --placeholder-color: #a0a0a0;
  --container-background: #ffffff;
  --body-text-color: #202124;
  --error-red: #d93025;
  --form-wrapper-bg: #ffffff;
  --input-bg: #ffffff;
  --button-active-bg: #1a73e8;
  --form-text-color: #202124;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
  color: var(--body-text-color);
  margin: 0;
  background-color: #f0f2f5;
}

h3 {
  font-size: 18px;
  font-weight: 500;
  margin-top: 0;
  margin-bottom: 15px;
  color: var(--body-text-color);
}

/* ==========================================================================
   2. Main Layout Containers
   ========================================================================== */

/* This is the main container for the demo page after login */
#demo-container {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2rem;
  padding: 2rem 4rem;
  box-sizing: border-box;
}

.form-wrapper {
  background-color: var(--form-wrapper-bg);
  padding: 1.5rem 2rem;
  border-radius: 8px;
  box-shadow: 0 1px 2px 0 rgba(60, 64, 67, 0.3),
    0 2px 6px 2px rgba(60, 64, 67, 0.15);
  max-height: calc(100vh - 4rem);
  overflow-y: auto;
  box-sizing: border-box;
  /* Flex properties for responsive behavior */
  flex: 1 1 600px; /* Let items grow and shrink from a 600px base */
  max-width: 1000px; /* Prevent containers from becoming too wide */
  min-width: 600px;
}

/* ==========================================================================
   3. Login Screen
   ========================================================================== */

/* These styles are for the Google Sign-In page that appears on first load. */
#login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    text-align: center;
    background-color: #f0f2f5; /* Matches the body background */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 2000; /* Ensure it's on top */
}

.login-box {
    background: white;
    padding: 40px 50px;
    border-radius: 8px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

.login-box h1 {
    margin-top: 0;
    font-size: 1.8em;
    color: #2c3e50;
}

.login-box p {
    color: #7f8c8d;
    margin-bottom: 25px;
}

.login-box .g_id_signin {
    margin-top: 20px;
    display: inline-block; /* Center the button */
}

/* ==========================================================================
   4. Main Form Layout & Components
   ========================================================================== */

/* --- Form Header & Structure --- */
.form-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

#oni-demo-title {
  font-size: 22px;
  font-weight: 600;
  margin: 0;
  color: var(--form-text-color);
}

#company-logo {
  height: 70px;
}

.form-layout {
  display: flex;
  gap: 2rem;
  margin-top: 1.5rem;
}

.form-column {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

#oni-demo-map {
  width: 100%;
  min-height: 20em; /* Fallback height */
  border-radius: 8px;
  margin-bottom: 1rem;
  border: 1px solid var(--google-grey-border); /* Make container visible */
  box-sizing: border-box;
}

/* --- Form Groups & Inputs --- */
.form-group {
  margin-bottom: 1rem;
  position: relative;
}

.form-group input {
  width: 100%;
  font-size: 16px;
  padding: 12px 15px;
  border: 1px solid var(--google-grey-border);
  border-radius: 8px;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-sizing: border-box;
  background-color: var(--input-bg);
  color: var(--form-text-color);
  margin-top: 0.3em
}

.form-group input:focus {
  outline: none;
  border-color: var(--google-blue);
  box-shadow: 0 0 0 1px var(--google-blue);
}

/* Add styling for disabled input fields to make them look non-interactive */
.form-group input:disabled {
  background-color: #f0f0f0; /* A light grey background */
  cursor: default;  
  opacity: 0.7;             /* Slightly transparent to look faded */
}

/* --- Widget-Specific Address Fields --- */
/* Styles for address fields when they are managed by the widget */
#oni-address-fields {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

#oni-address-fields .oni-address-fields-input,
#oni-address-fields button {
  width: 100%;
  box-sizing: border-box;
}

.oni-address-fields-input {
  width: 100%;
  font-size: 16px;
  padding: 12px 15px;
  border: 1px solid var(--google-grey-border);
  border-radius: 8px;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-sizing: border-box;
  background-color: var(--input-bg);
  color: var(--form-text-color);
}

.oni-address-fields-input:focus {
  outline: none;
  border-color: var(--google-blue);
  box-shadow: 0 0 0 1px var(--google-blue);
}

/* Use a more specific selector to override browser default styles consistently */
input.oni-address-fields-input:disabled {
  background-color: #f0f0f0;
  color: var(--placeholder-color);
}

.oni-address-fields-input::placeholder {
  color: var(--placeholder-color); /* Set placeholder text color */
}

/* When the widget provides address fields, the submit button is moved under them. */
#oni-address-fields .submit-button {
    margin-top: 0;
}

/* --- Validation --- */
.form-group.is-required > label::after {
  content: "*";
  color: var(--error-red);
  font-weight: bold;
  padding-left: 2px;
}

.validation-popup {
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  background-color: var(--error-red);
  color: white;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  z-index: 10;
  width: max-content;
  max-width: 100%;
  box-sizing: border-box;
  animation: fadeIn 0.3s ease-in-out;
}

.validation-popup::before {
  content: "";
  position: absolute;
  bottom: 100%;
  left: 15px;
  border-width: 5px;
  border-style: solid;
  border-color: transparent transparent var(--error-red) transparent;
}

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

/* --- Layout Management --- */
/* Toggles visibility based on whether address fields are self-managed or widget-managed */
.form-layout[data-layout="self-managed"] #widget-address-fields-container {
  display: none;
}

.form-layout[data-layout="widget-managed"] #client-address-fields-wrapper {
  display: none;
}

/* Ensure the submit button has appropriate margin when moved to the left column */
.form-layout[data-layout="widget-managed"]
  .form-column:first-of-type
  > .submit-button {
  margin-top: 1rem;
}

/* --- Self-Managed Fields Grid Layout --- */
/* When in self-managed mode, use a grid to reorder fields visually */
.form-layout[data-layout="self-managed"] #client-address-fields-wrapper {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 2rem; /* No vertical gap, 2rem horizontal gap */
  align-items: start; /* Align items to the top of their grid cell */
}

/* Remove the flexbox columns when grid is active */
.form-layout[data-layout="self-managed"] #client-address-fields-wrapper .form-column {
  display: contents; /* Makes the columns' children direct children of the grid */
}

/* The submit button should span both columns */
.form-layout[data-layout="self-managed"] #client-address-fields-wrapper > .form-group:has(#oni-feedback-submit-btn),
.form-layout #client-address-fields-wrapper > .form-group:has(#oni-feedback-submit-btn) {
    grid-column: 1 / -1; /* Span from the first to the last column line, regardless of layout state */
}


/* ==========================================================================
   5. Sidebar & Hamburger Menu
   ========================================================================== */

/* --- Hamburger --- */
.hamburger-menu {
  position: fixed;
  top: 20px;
  left: 20px;
  width: 30px;
  height: 25px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
  z-index: 1060; /* Ensure it's above the modal (1055) */
}

.hamburger-menu .bar {
  width: 100%;
  height: 3px;
  background-color: var(--google-grey-text);
  transition: all 0.3s ease;
}

.hamburger-menu.active .bar:nth-child(1) {
  transform: translateY(11px) rotate(45deg);
}

.hamburger-menu.active .bar:nth-child(2) {
  opacity: 0;
}

.hamburger-menu.active .bar:nth-child(3) {
  transform: translateY(-11px) rotate(-45deg);
}

/* --- Sidebar Container --- */
.sidebar {
  position: fixed;
  top: 0;
  left: -9999px;
  width: auto;
  height: 100%;
  background-color: #f9f9f9;
  box-shadow: 2px 0 5px rgba(0, 0, 0, 0.2);
  padding: 20px 20px 20px 70px;
  box-sizing: border-box;
  transition: left 0.3s ease-in-out;
  z-index: 1000;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.sidebar.active {
  left: 0;
}

.sidebar h2 {
  margin-top: 0;
  color: var(--body-text-color);
  font-size: 20px;
  margin-bottom: 20px;
}

/* --- Sidebar Content & Layout --- */
.sidebar-content {
  display: flex;
  flex-direction: row;
  gap: 20px;
  flex-grow: 1;
  justify-content: flex-start;
  align-items: flex-start;
}

.sidebar-column {
  flex: 1 0 200px;
  min-width: 200px;
  padding-right: 10px;
  border-right: 1px solid var(--google-grey-border);
}

.sidebar-column:last-of-type {
  border-right: none;
  padding-right: 0;
}

.sidebar-column > h3 {
  margin-top: 2rem;
}

.sidebar-column > h3:first-of-type {
  margin-top: 0;
}

/* --- Sidebar Sections & Controls --- */
.sidebar-section {
  margin-bottom: 15px;
}

.sidebar-section label {
  display: block;
  font-size: 14px;
  color: var(--google-grey-text);
  margin-bottom: 5px;
}

.sidebar-section input[type="text"],
.sidebar-section input[type="color"] {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--google-grey-border);
  border-radius: 4px;
  box-sizing: border-box;
}

.sidebar-section input[type="color"] {
  height: 34px;
  padding: 2px;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-color: transparent;
  cursor: pointer;
}

/* Style for the color input's inner box (WebKit/Blink) */
.sidebar-section input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}
.sidebar-section input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 3px;
}

/* Style for the color input's inner box (Mozilla Firefox) */
.sidebar-section input[type="color"]::-moz-color-swatch {
  border: none;
  border-radius: 3px;
}

.sidebar-details > summary {
  font-weight: bold;
  margin: 1.5rem 0 0.5rem;
  cursor: pointer;
}

.sidebar-section.switch-section {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.sidebar-section.switch-section > span {
  margin-bottom: 5px;
  font-size: 14px;
  color: var(--google-grey-text);
}

.checkbox-group-controls {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-top: 5px;
}

.checkbox-option {
  display: flex;
  align-items: center;
}

/* Override the default block display for labels within the checkbox group */
.checkbox-option label {
  display: inline;
  margin-bottom: 0;
  margin-left: 5px;
  font-weight: normal;
}
.checkbox-option input[type="checkbox"] {
  width: auto; /* override default input width */
}

.field-config-section {
  display: flex;
  flex-direction: column;
  margin-bottom: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--google-grey-border);
}

.field-config-section:first-of-type {
  border-top: none;
  padding-top: 0;
}

.field-config-section label {
  margin-bottom: 5px;
  font-weight: 500;
  color: var(--body-text-color);
  display: block;
}

.field-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 5px;
}

.field-controls .checkbox-label {
  display: flex;
  align-items: center;
  margin-bottom: 0;
  font-weight: normal;
  color: var(--google-grey-text);
  cursor: pointer;
  font-size: 13px;
}

.field-controls .checkbox-label input[type="checkbox"] {
  width: auto;
  margin-right: 3px;
  cursor: pointer;
}

.sidebar-section label.required::after {
    content: " *";
    color: var(--error-red, #d93025);
    font-weight: bold;
    padding-left: 2px;
}

.sidebar-section input.highlight-error {
    border-color: var(--error-red, #d93025);
    box-shadow: 0 0 0 2px rgba(217, 48, 37, 0.3);
}

.api-key-error-message {
    background-color: rgba(217, 48, 37, 0.1);
    border: 1px solid var(--error-red, #d93025);
    border-radius: 8px;
    color: var(--error-red, #d93025);
    padding: 1rem;
    margin-bottom: 1.5rem;
    text-align: center;
    font-size: 15px;
}

.api-key-error-message strong {
    font-weight: 600;
}

/* ==========================================================================
   6. Buttons
   ========================================================================== */

/* --- Base Styles --- */
.submit-button,
.location-button,
.action-button,
#prompt-modal-close-btn {
  background-color: var(--button-active-bg);
  color: white;
  border: none;
  border-radius: 8px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.2s;
}

/* --- Specific Button Styles --- */
.submit-button {
  padding: 12px 24px;
  font-size: 16px;
  transition: opacity 0.2s, background-color 0.2s;
  width: 100%;
  margin-top: 1.5rem;
}

.location-button {
  padding: 10px 20px;
  font-size: 14px;
  margin: 0 0 1rem 0;
  width: auto; /* Don't take full width */
}

.action-button {
  padding: 10px 20px;
  font-size: 14px;
  width: 100%;
  margin-top: 25px;
}

.text-button {
  background: none;
  border: none;
  padding: 0;
  margin: 0 0 1rem 0;
  color: var(--google-blue);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
}

.reset-button {
  background-color: #f44336;
}

.copy-button {
  background-color: #f1f3f4;
  border: 1px solid transparent;
  color: var(--google-grey-text);
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s, border-color 0.2s;
}

#prompt-modal-close-btn {
  padding: 12px 24px;
  font-size: 16px;
}

/* --- Button States (Hover, Disabled, etc.) --- */
.submit-button:hover,
.location-button:hover,
#prompt-modal-close-btn:hover {
  opacity: 0.9;
}

.submit-button:disabled {
  background-color: #cccccc;
  cursor: not-allowed;
}

.text-button:hover {
  text-decoration: underline;
}

.reset-button:hover {
  opacity: 0.8;
}

.copy-button:hover {
  background-color: #e8eaed;
}

.copy-button.copied {
  background-color: #e6f4ea;
  color: #137333;
  border-color: #137333;
}

/* ==========================================================================
   7. Output Display
   ========================================================================== */
.output-container {
  display: flex;
  flex-direction: column;
}

.output-wrapper {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.output-container .form-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  margin-bottom: 0; /* Override default since we use gap on parent */
}

.form-group-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Latest Output Display Styles */
.output-container .latest-output {
  font-family: monospace;
  background-color: #f4f4f4;
  border: 1px solid var(--google-grey-border);
  padding: 12px 15px;
  border-radius: 8px;
  color: var(--form-text-color);
  white-space: pre-wrap;
  word-wrap: break-word;
  margin: 0;
  margin-top: 0.3em;
  overflow-y: auto;
  height: 180px; /* A fixed height for the latest output */
}

/* Historical Output Styles */
.output-history {
  margin-top: 0.75rem;
}

.output-history > summary {
  cursor: pointer;
  color: var(--body-text-color);
  font-size: 14px;
  font-weight: 500;
  padding: 5px 0;
  list-style: none; /* Remove default marker */
  outline: none;
}

.output-history > summary::-webkit-details-marker {
  display: none; /* Remove default marker for Chrome */
}

.output-history > summary::before {
  content: '▶';
  display: inline-block;
  font-size: 0.65em;
  margin-right: 0.5em;
  transition: transform 0.2s;
  vertical-align: middle;
}

.output-history[open] > summary::before {
  transform: rotate(90deg);
}

.output-history-container {
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--google-grey-border);
  border-radius: 8px;
  padding: 1rem;
  margin-top: 0.5rem;
  background-color: #f8f9fa;
}

.output-history-container > pre {
  background-color: #fff;
  border: 1px solid #e0e0e0;
  padding: 10px;
  border-radius: 4px;
  margin: 0 0 10px 0;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 13px;
}

.output-history-container > pre:last-child {
  margin-bottom: 0;
}

/* ==========================================================================
   8. Modal (for Prompts)
   ========================================================================== */

/* The modal container, which sits on top of the backdrop. */
#promptModal.modal {
  display: none; /* Hidden by default */
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1055; /* Higher than backdrop's z-index of 1050 */
  width: 100%;
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  outline: 0;
}

#promptModal.modal.show {
  display: block;
}

.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1050;
  width: 100vw;
  height: 100vh;
  background-color: #000;
  opacity: 0;
}

.modal-backdrop.show {
  opacity: 0.5;
}

#promptModal .modal-dialog {
  position: relative;
  top: 50%;
  transform: translateY(-50%);
  max-width: 550px;
  width: 90%;
  margin: 0 auto;
}

#promptModal .modal-content {
  background-color: var(--container-background, #fff);
  border-radius: 12px;
  border: none;
  box-shadow: 0 8px 20px rgba(0,0,0,0.25);
  overflow: hidden; /* Ensures content respects the border radius */
}

#promptModal .modal-body {
  padding: 2rem 2.5rem;
  font-size: 16px;
  line-height: 1.6;
  color: var(--body-text-color);
}

#promptModal .modal-footer {
  border-top: 1px solid #e9ecef;
  padding: 1rem 2.5rem;
  display: flex;
  justify-content: flex-end;
  background-color: #f8f9fa;
}