html.modal-open,
body.modal-open {
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
}

.metadata-dialog dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border: none;
  border-radius: 12px;
  width: min(90vw, 600px);
  max-height: 90vh;
  background: #fff;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.25);
  overflow: hidden;
  padding: 0;
  display: none;
  z-index: 9999;
}

.metadata-dialog dialog[open] {
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: 90vh;
}

.metadata-dialog dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(3px);
}

.metadata-dialog header,
.metadata-dialog footer {
  flex-shrink: 0;
  padding: 12px 16px;
}

.metadata-dialog header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.metadata-dialog .content {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto; /* only this scrolls */
  -webkit-overflow-scrolling: touch;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: calc(90vh - 120px); /* Account for header and footer */
}

.metadata-dialog footer {
  border-top: 1px solid #eee;
  background: #fff;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.metadata-dialog .field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.metadata-dialog input,
.metadata-dialog textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 14px;
  background-color: #fff;
}

/* Keep native styling for select elements */
.metadata-dialog select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 14px;
  background-color: #fff;
  cursor: pointer;
}
.metadata-dialog textarea {
  resize: vertical;
  min-height: 80px;
}
.metadata-dialog input[readonly],
.metadata-dialog textarea[readonly] {
  background: #f3f3f3;
}
.metadata-dialog button {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
}
.metadata-dialog button:hover {
  background: #1565c0;
}
.metadata-dialog .cancel-btn {
  background: #6c757d;
  margin-right: 8px;
}
.metadata-dialog .cancel-btn:hover {
  background: #5a6268;
}

.pricing-cycle {
  border: 1px solid #ccc;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
}
.pricing-cycle h4 {
  margin: 0 0 8px 0;
}
.pricing-cycle label {
  display: block;
  margin-bottom: 6px;
}
.pricing-cycle input {
  width: 100%;
  padding: 6px;
  margin-top: 4px;
}

.field input[readonly],
.field input:disabled {
  background-color: #f3f3f3;
  color: #555;
  cursor: not-allowed;
}

.hidden {
  display: none !important;
}

.card {
  border: 2px solid #e0e0e0;
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
  background: linear-gradient(135deg, #f5f7fa 0%, #e9ecef 100%);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}
.card .title {
  font-weight: 600;
  margin-bottom: 8px;
  border-bottom: 1px solid #ddd;
  padding-bottom: 4px;
}

.field.trial-field {
  display: inline-flex;
  gap: 6px;
}

.switch {
  position: relative;
  width: 38px;
  height: 18px;
  display: inline-block;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  inset: 0;
  background: #ccc;
  border-radius: 20px;
  cursor: pointer;
  transition: 0.2s;
}
.slider::before {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  left: 2px;
  top: 2px;
  background: #fff;
  border-radius: 50%;
  transition: 0.2s;
}
input:checked + .slider {
  background: #0070ba;
}
input:checked + .slider::before {
  transform: translateX(20px);
}
input:disabled + .slider {
  background: #e5e5e5;
  cursor: not-allowed;
}

.card.no-border {
  border: none;
  box-shadow: none;
}

/* Additional UI Improvements */

.card .grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Cycle Title Color Styling */
.card .title .ongoing-info {
  color: #1976d2;
  font-weight: 600;
  background: #e3f2fd;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
}

.card .title .installment-info {
  color: #f57c00;
  font-weight: 600;
  background: #fff3e0;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
}

/* Frequency field styling */
.frequency-field .frequency-input-group {
  display: flex;
  gap: 8px;
  align-items: center;
}

.frequency-field input[data-k="billingFrequency"] {
  flex: 0 0 100px;
  max-width: 100px;
}

.frequency-field select[data-k="billingFrequencyUnit"] {
  flex: 1;
  min-width: 120px;
}

/* Total Amount Section */
.total-amount-section {
  margin-top: 0;
}

.total-amount-display {
  background: #f5f7fa;
  border-radius: 6px;
  padding: 8px 10px;
  margin-top: 4px;
  border: 1px solid #e0e0e0;
}

.total-amount-value {
  font-size: 16px;
  font-weight: 600;
  color: #2c2e2f;
  display: block;
  margin-bottom: 8px;
}

.total-amount-breakdown {
  font-size: 13px;
  color: #687173;
}

/* Inline Editable Breakdown Items */
.breakdown-item-editable {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid #e8e8e8;
}

.breakdown-item-editable:last-child {
  border-bottom: none;
}

.breakdown-item-editable label {
  font-size: 13px;
  color: #687173;
  font-weight: 500;
}

.inline-input-wrapper {
  display: flex;
  align-items: center;
  gap: 4px;
}

.currency-symbol {
  font-size: 13px;
  color: #687173;
}

.inline-amount-input {
  width: 80px;
  padding: 4px 6px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 13px;
  text-align: right;
  background: #fff;
}

.inline-amount-input:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.1);
}

/* Hide spinner buttons */
.inline-amount-input::-webkit-inner-spin-button,
.inline-amount-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.inline-amount-input {
  -moz-appearance: textfield;
}

/* Quantity Control Styles */
.quantity-control {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid #ccc;
  border-radius: 6px;
  overflow: hidden;
  width: fit-content;
}

.quantity-control input[type="number"] {
  border: none;
  text-align: center;
  width: 60px;
  padding: 8px 4px;
  font-weight: 500;
}

/* Hide spinner buttons in number input */
.quantity-control input[type="number"]::-webkit-inner-spin-button,
.quantity-control input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.quantity-control input[type="number"] {
  -moz-appearance: textfield;
}

.quantity-btn {
  background: #f5f5f5;
  color: #333;
  border: none;
  width: 36px;
  height: 36px;
  cursor: pointer;
  font-size: 18px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  padding: 0;
}

.quantity-btn:hover:not(:disabled) {
  background: #e0e0e0;
}

.quantity-btn:active:not(:disabled) {
  background: #d0d0d0;
}

.quantity-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Simple Tooltip Styles */
.tooltip-wrapper {
  position: relative;
  display: inline-block;
  margin-left: 6px;
  vertical-align: middle;
}

.tooltip-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #0070ba;
  color: white;
  font-size: 11px;
  font-weight: bold;
  cursor: pointer;
  user-select: none;
}

.tooltip-icon:hover {
  background: #0056a0;
}

.tooltip-content {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: white;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  white-space: normal;
  word-wrap: break-word;
  width: max-content;
  max-width: 250px;
  min-width: 150px;
  z-index: 10000;
  opacity: 0;
  visibility: hidden;
  transition:
    opacity 0.2s,
    visibility 0.2s;
  pointer-events: none;
  line-height: 1.4;
}

/* Arrow pointing down */
.tooltip-content::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: #333;
}

/* Show tooltip on click */
.tooltip-wrapper.active .tooltip-content {
  opacity: 1;
  visibility: visible;
}

/* Adjust position if tooltip would go out of bounds */
.tooltip-content.tooltip-left {
  left: auto;
  right: -10px;
  transform: none;
}

.tooltip-content.tooltip-left::after {
  left: auto;
  right: 15px;
  transform: none;
}

.tooltip-content.tooltip-right {
  left: -10px;
  transform: none;
}

.tooltip-content.tooltip-right::after {
  left: 15px;
  transform: none;
}

/* Mobile adjustments for tooltips */
@media screen and (max-width: 768px) {
  .tooltip-content {
    white-space: normal;
    max-width: 200px;
    font-size: 12px;
  }
}

/* Mobile responsive styles */
@media screen and (max-width: 768px) {
  .metadata-dialog dialog {
    width: 95vw;
    max-height: 90vh;
  }

  .metadata-dialog dialog[open] {
    display: flex;
    flex-direction: column;
    min-height: 0;
    max-height: 90vh;
  }

  .metadata-dialog .content {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 12px;
    max-height: calc(90vh - 120px);
  }

  .card {
    padding: 12px;
    margin-bottom: 12px;
    background: linear-gradient(135deg, #f5f7fa 0%, #e9ecef 100%);
  }

  .metadata-dialog .field {
    margin-bottom: 12px;
  }

  /* Frequency field adjustments for mobile */
  .frequency-field .frequency-input-group {
    flex-direction: column;
    gap: 8px;
  }

  .frequency-field input[data-k="billingFrequency"] {
    flex: 1;
    width: 100%;
    max-width: none;
  }

  .frequency-field select[data-k="billingFrequencyUnit"] {
    width: 100%;
  }

  /* Button and input sizing for mobile */
  .metadata-dialog button {
    font-size: 16px;
    padding: 12px 24px;
  }

  .metadata-dialog input,
  .metadata-dialog select {
    font-size: 16px; /* Prevent zoom on iOS */
    min-height: 44px; /* Touch-friendly size */
  }
}

/* Close icon styles for dialog */
.metadata-dialog .close-icon {
  cursor: pointer;
  font-size: 1.8em;
  margin-left: auto;
  margin-right: 0;
  line-height: 1;
  user-select: none;
  padding-left: 16px;
  color: #fff;
  transition: color 0.2s;
}
.metadata-dialog .close-icon:hover {
  color: #ff5252;
}
.input-error {
  border: 1.5px solid #d32f2f !important;
  background: #fff0f0 !important;
}
