/* Shopify Polaris / Clean Admin App Styling for MOA Watermark App */
:root {
  --p-color-bg-app: #f1f2f4;
  --p-color-bg-surface: #ffffff;
  --p-color-bg-surface-secondary: #f7f8f9;
  --p-color-border: #e1e3e5;
  --p-color-border-subdued: #ebebeb;
  --p-color-text: #202223;
  --p-color-text-subdued: #6d7175;
  --p-color-primary: #008060;
  --p-color-primary-hover: #006e52;
  --p-color-primary-surface: #f1f8f5;
  --p-color-critical: #d82c0d;
  --p-color-critical-surface: #fff4f2;
  --p-color-gold: #c59b27;
  --p-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
  --p-radius-base: 8px;
  --p-radius-large: 12px;
  --p-shadow-card: 0 0 0 1px rgba(63, 63, 68, 0.05), 0 1px 3px 0 rgba(63, 63, 68, 0.15);
  --p-shadow-modal: 0 10px 30px rgba(0, 0, 0, 0.2);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--p-font-family);
  background-color: var(--p-color-bg-app);
  color: var(--p-color-text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* App Header */
.app-topbar {
  background: #ffffff;
  border-bottom: 1px solid var(--p-color-border);
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-logo-badge {
  width: 32px;
  height: 32px;
  background: #1c1c1c;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #e2b142;
  font-weight: bold;
  font-size: 16px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.app-brand-title {
  font-size: 16px;
  font-weight: 600;
  color: #202223;
}

.app-top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--p-radius-base);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
  text-decoration: none;
}

.btn-primary {
  background-color: var(--p-color-primary);
  color: #ffffff;
  box-shadow: 0 1px 0 rgba(0,0,0,0.08);
}

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

.btn-secondary {
  background-color: #ffffff;
  border-color: #c9cccf;
  color: #202223;
  box-shadow: 0 1px 0 rgba(0,0,0,0.05);
}

.btn-secondary:hover {
  background-color: #f6f6f7;
}

.btn-destructive {
  background-color: #ffffff;
  border-color: #f1a9a0;
  color: var(--p-color-critical);
}

.btn-destructive:hover {
  background-color: var(--p-color-critical-surface);
  border-color: var(--p-color-critical);
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

/* Main Layout */
.app-container {
  display: flex;
  min-height: calc(100vh - 53px);
}

/* Sidebar */
.app-sidebar {
  width: 230px;
  background: #ffffff;
  border-right: 1px solid var(--p-color-border);
  padding: 16px 8px;
  flex-shrink: 0;
}

.nav-group-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--p-color-text-subdued);
  padding: 8px 12px 4px;
  letter-spacing: 0.5px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 6px;
  color: var(--p-color-text);
  text-decoration: none;
  font-weight: 500;
  font-size: 13px;
  margin-bottom: 2px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.nav-item:hover {
  background: #f6f6f7;
}

.nav-item.active {
  background: #edf3f0;
  color: var(--p-color-primary);
  font-weight: 600;
}

.nav-item-icon {
  font-size: 16px;
  opacity: 0.85;
}

/* Content Area */
.app-main {
  flex: 1;
  padding: 24px 32px 60px;
  max-width: 1200px;
  margin: 0 auto;
}

/* Top Header Bar inside Main */
.rule-page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.rule-title-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-back {
  background: transparent;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--p-color-text);
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
}

.btn-back:hover {
  background: #e4e5e7;
}

.rule-main-title {
  font-size: 20px;
  font-weight: 600;
  color: #202223;
}

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

/* Grid layout for cards and preview */
.rule-grid {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 20px;
  align-items: start;
}

@media (max-width: 960px) {
  .rule-grid {
    grid-template-columns: 1fr;
  }
}

/* Cards */
.polaris-card {
  background: #ffffff;
  border-radius: var(--p-radius-base);
  box-shadow: var(--p-shadow-card);
  padding: 20px;
  margin-bottom: 16px;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  color: #202223;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-checkbox-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}

.card-checkbox-title input[type="checkbox"] {
  width: 17px;
  height: 17px;
  accent-color: var(--p-color-primary);
  cursor: pointer;
}

/* Form Controls */
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 14px;
}

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

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: #202223;
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  padding: 8px 12px;
  font-size: 13px;
  border: 1px solid #c9cccf;
  border-radius: var(--p-radius-base);
  background: #ffffff;
  color: #202223;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-control:focus {
  border-color: var(--p-color-primary);
  box-shadow: 0 0 0 1px var(--p-color-primary);
}

select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235c5f62' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 14px;
  padding-right: 32px;
}

.input-suffix-group {
  position: relative;
  display: flex;
  align-items: center;
}

.input-suffix-group .form-control {
  padding-right: 36px;
}

.input-suffix {
  position: absolute;
  right: 12px;
  color: var(--p-color-text-subdued);
  font-size: 12px;
  font-weight: 500;
  pointer-events: none;
}

/* Image Watermark Section */
.image-uploader-box {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px;
  background: #fbfbfb;
  border: 1px dashed #d2d5d8;
  border-radius: var(--p-radius-base);
  margin-bottom: 16px;
}

.image-thumb-preview {
  width: 60px;
  height: 60px;
  background-color: #f4f5f6;
  background-image: 
    linear-gradient(45deg, #e0e0e0 25%, transparent 25%), 
    linear-gradient(-45deg, #e0e0e0 25%, transparent 25%), 
    linear-gradient(45deg, transparent 75%, #e0e0e0 75%), 
    linear-gradient(-45deg, transparent 75%, #e0e0e0 75%);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0px;
  border: 1px solid #e1e3e5;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.image-thumb-preview img {
  max-width: 90%;
  max-height: 90%;
  object-fit: contain;
}

.image-uploader-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.link-btn {
  background: none;
  border: none;
  color: var(--p-color-critical);
  font-size: 12px;
  cursor: pointer;
  text-align: left;
  padding: 0;
  text-decoration: underline;
}

.link-btn:hover {
  color: #b01f05;
}

/* Radio Layout selector */
.radio-group {
  margin-bottom: 14px;
}

.radio-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}

.radio-item input[type="radio"] {
  accent-color: var(--p-color-primary);
  width: 16px;
  height: 16px;
}

.sub-input-container {
  margin-left: 24px;
  margin-bottom: 12px;
}

/* More Options Collapsible */
.collapsible-trigger {
  color: #005bd3;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
  user-select: none;
}

.collapsible-trigger:hover {
  text-decoration: underline;
}

.collapsible-content {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--p-color-border-subdued);
  display: none;
}

.collapsible-content.open {
  display: block;
}

/* Checkbox Item */
.checkbox-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
  cursor: pointer;
  font-size: 13px;
  user-select: none;
}

.checkbox-item input[type="checkbox"] {
  accent-color: var(--p-color-primary);
  width: 16px;
  height: 16px;
  margin-top: 2px;
}

.helper-text {
  font-size: 12px;
  color: var(--p-color-text-subdued);
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Preview Column (Right Side) */
.preview-card {
  position: sticky;
  top: 74px;
}

.preview-canvas-wrapper {
  background-color: #f7f8f9;
  background-image: 
    linear-gradient(45deg, #ebebeb 25%, transparent 25%), 
    linear-gradient(-45deg, #ebebeb 25%, transparent 25%), 
    linear-gradient(45deg, transparent 75%, #ebebeb 75%), 
    linear-gradient(-45deg, transparent 75%, #ebebeb 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
  border: 1px solid var(--p-color-border);
  border-radius: var(--p-radius-base);
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 420px;
  margin-bottom: 12px;
  position: relative;
  overflow: hidden;
  cursor: pointer;
}

.preview-image-container {
  position: relative;
  max-width: 100%;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.preview-base-img {
  width: 100%;
  max-height: 380px;
  object-fit: cover;
  display: block;
}

/* Watermark Overlay on Preview */
.preview-watermark-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  display: flex;
  overflow: hidden;
}

.preview-watermark-logo {
  position: absolute;
  max-width: 100%;
  transition: all 0.1s ease;
}

.preview-watermark-text {
  position: absolute;
  font-family: 'Montserrat', sans-serif;
  font-weight: 700;
  color: #ffffff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.6);
  white-space: nowrap;
  pointer-events: none;
  transform-origin: center;
}

.preview-instructions {
  font-size: 12px;
  color: var(--p-color-text-subdued);
  text-align: center;
  margin-bottom: 12px;
}

.preview-button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* Progress / Toast Notification */
.toast-banner {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1c1c1c;
  color: #ffffff;
  padding: 14px 20px;
  border-radius: 8px;
  box-shadow: var(--p-shadow-modal);
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  z-index: 1000;
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.toast-banner.show {
  transform: translateY(0);
  opacity: 1;
}

.toast-banner.success {
  border-left: 4px solid #008060;
}

/* Modal for Large Preview */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.modal-backdrop.open {
  display: flex;
}

.modal-content {
  background: #ffffff;
  border-radius: 12px;
  padding: 20px;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  box-shadow: var(--p-shadow-modal);
}

.modal-close-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(0,0,0,0.1);
  border: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-img-preview {
  max-width: 100%;
  max-height: 75vh;
  object-fit: contain;
  border-radius: 6px;
}
