/* ============================================
   Autotask Email Template Generator — Styles
   ============================================ */

:root {
  --ui-bg: #f5f5f7;
  --ui-surface: #ffffff;
  --ui-border: #e0e0e0;
  --ui-text: #1d1d1f;
  --ui-text-secondary: #6e6e73;
  --ui-accent: #c0392b;
  --ui-accent-hover: #a93226;
  --ui-success: #27ae60;
  --ui-radius: 8px;
  --ui-shadow: 0 1px 3px rgba(0,0,0,0.08);
  --ui-shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
  --sidebar-width: 380px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--ui-bg);
  color: var(--ui-text);
  height: 100vh;
  overflow: hidden;
}

/* ── Top Bar ── */
.top-bar {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--ui-surface);
  border-bottom: 1px solid var(--ui-border);
  height: 56px;
  z-index: 100;
}
.top-bar h1 {
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-prefix {
  font-style: italic;
  font-weight: 400;
  margin-right: 6px;
}
.top-bar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid var(--ui-border);
  border-radius: 6px;
  background: var(--ui-surface);
  color: var(--ui-text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn:hover { background: #f0f0f2; border-color: #ccc; }
.btn-primary {
  background: var(--ui-accent);
  color: #fff;
  border-color: var(--ui-accent);
}
.btn-primary:hover { background: var(--ui-accent-hover); }
.btn-success {
  background: var(--ui-success);
  color: #fff;
  border-color: var(--ui-success);
}
.btn-success:hover { background: #219a52; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ── Main Layout ── */
.app-layout {
  display: flex;
  height: calc(100vh - 56px - 34px);
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--ui-surface);
  border-right: 1px solid var(--ui-border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.sidebar-section {
  padding: 16px 20px;
  border-bottom: 1px solid var(--ui-border);
}
.sidebar-section:last-child { border-bottom: none; }
.sidebar-section h3 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--ui-text-secondary);
  margin-bottom: 12px;
}

/* ── Form Controls ── */
.form-group {
  margin-bottom: 12px;
}
.form-group:last-child { margin-bottom: 0; }
.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--ui-text-secondary);
  margin-bottom: 4px;
}
.form-group input[type="text"],
.form-group input[type="url"],
.form-group input[type="email"],
.form-group input[type="tel"],
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--ui-border);
  border-radius: 5px;
  font-size: 13px;
  font-family: inherit;
  color: var(--ui-text);
  background: #fff;
  transition: border-color 0.15s;
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--ui-accent);
  box-shadow: 0 0 0 2px rgba(192,57,43,0.12);
}
.form-group textarea {
  resize: vertical;
  min-height: 60px;
}
.form-group input[type="color"] {
  width: 36px;
  height: 30px;
  padding: 2px;
  border: 1px solid var(--ui-border);
  border-radius: 5px;
  cursor: pointer;
}
.color-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.color-input-row input[type="text"] {
  flex: 1;
}

/* ── Accordion Sections ── */
.sidebar-section-header {
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
}
.sidebar-section-header:hover {
  color: var(--ui-text);
}
.chevron {
  font-size: 9px;
  transition: transform 0.25s ease;
  color: var(--ui-text-secondary);
}
.sidebar-section:not(.collapsed) .chevron {
  transform: rotate(90deg);
}
.sidebar-section-header .badge-warn {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ui-accent);
  margin-left: 6px;
  flex-shrink: 0;
}
.btn-reset {
  color: var(--ui-text-secondary);
  border-color: var(--ui-border);
}
.btn-reset:hover {
  color: var(--ui-accent);
  border-color: var(--ui-accent);
}
.sidebar-section-content {
  overflow: hidden;
  max-height: 2000px;
  transition: max-height 0.35s ease;
}
.sidebar-section.collapsed .sidebar-section-content {
  max-height: 0;
}

/* ── Template Tabs ── */
.template-tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.template-tab {
  padding: 6px 12px;
  border: 1px solid var(--ui-border);
  border-radius: 5px;
  background: #f8f8fa;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.template-tab:hover { background: #eee; }
.template-tab.active {
  background: var(--ui-accent);
  color: #fff;
  border-color: var(--ui-accent);
}

/* ── Section Toggles ── */
.section-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
}
.section-toggle span {
  font-size: 13px;
}
.info-tooltip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--ui-border);
  color: var(--ui-text-secondary);
  font-size: 10px;
  font-weight: 700;
  font-style: italic;
  margin-left: 5px;
  cursor: help;
  vertical-align: middle;
}

/* Toggle switch */
.toggle {
  position: relative;
  width: 38px;
  height: 22px;
  flex-shrink: 0;
}
.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}
.toggle-slider {
  position: absolute;
  inset: 0;
  background: #ccc;
  border-radius: 11px;
  cursor: pointer;
  transition: 0.2s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.2s;
}
.toggle input:checked + .toggle-slider {
  background: var(--ui-accent);
}
.toggle input:checked + .toggle-slider::before {
  transform: translateX(16px);
}

/* ── Preview Panel ── */
.preview-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: var(--ui-surface);
  border-bottom: 1px solid var(--ui-border);
  gap: 12px;
}
.preview-toolbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
}
.preview-toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.device-toggle {
  display: flex;
  border: 1px solid var(--ui-border);
  border-radius: 5px;
  overflow: hidden;
}
.device-toggle button {
  padding: 5px 12px;
  border: none;
  background: #f8f8fa;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}
.device-toggle button:not(:last-child) {
  border-right: 1px solid var(--ui-border);
}
.device-toggle button.active {
  background: var(--ui-accent);
  color: #fff;
}
.preview-container {
  flex: 1;
  overflow: auto;
  padding: 24px;
  background: var(--ui-bg);
  display: flex;
  justify-content: center;
  align-items: flex-start;
}
.preview-frame {
  background: #fff;
  box-shadow: var(--ui-shadow-lg);
  border-radius: 4px;
  overflow: hidden;
  transition: width 0.3s;
  width: 660px;
}
.preview-frame.mobile {
  width: 375px;
}

/* ── Code Panel ── */
.code-panel {
  display: none;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}
.code-panel.active {
  display: flex;
}
.preview-panel.hidden {
  display: none;
}
.code-output {
  flex: 1;
  overflow: auto;
  padding: 20px;
  background: #1e1e2e;
}
.code-output pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-all;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 12px;
  line-height: 1.6;
  color: #cdd6f4;
}

/* ── Variable Picker ── */
.var-picker-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 200;
  justify-content: center;
  align-items: center;
}
.var-picker-overlay.active {
  display: flex;
}
.var-picker {
  background: var(--ui-surface);
  border-radius: var(--ui-radius);
  box-shadow: var(--ui-shadow-lg);
  width: 520px;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
}
.var-picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--ui-border);
}
.var-picker-header h3 {
  font-size: 15px;
  font-weight: 600;
}
.var-picker-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--ui-text-secondary);
  padding: 4px;
}
.var-picker-search {
  padding: 12px 20px;
  border-bottom: 1px solid var(--ui-border);
}
.var-picker-search input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--ui-border);
  border-radius: 5px;
  font-size: 13px;
}
.var-picker-search input:focus {
  outline: none;
  border-color: var(--ui-accent);
}
.var-picker-body {
  overflow-y: auto;
  padding: 8px 0;
}
.var-category {
  padding: 4px 20px;
}
.var-category-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ui-text-secondary);
  padding: 8px 0 4px;
}
.var-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.1s;
}
.var-item:hover { background: #f5f5f7; }
.var-item-name {
  font-size: 13px;
  font-weight: 500;
  font-family: 'SF Mono', 'Fira Code', monospace;
}
.var-item-desc {
  font-size: 11px;
  color: var(--ui-text-secondary);
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  background: #1d1d1f;
  color: #fff;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--ui-shadow-lg);
  z-index: 300;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.3s;
  pointer-events: none;
}
.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ── Subject field ── */
.subject-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.subject-row input {
  flex: 1;
}
.subject-row .btn {
  flex-shrink: 0;
}

/* ── Scrollbar ── */
.sidebar::-webkit-scrollbar,
.preview-container::-webkit-scrollbar,
.var-picker-body::-webkit-scrollbar,
.code-output::-webkit-scrollbar {
  width: 6px;
}
.sidebar::-webkit-scrollbar-thumb,
.preview-container::-webkit-scrollbar-thumb,
.var-picker-body::-webkit-scrollbar-thumb,
.code-output::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 3px;
}

/* ── Responsive ── */
@media (max-width: 900px) {
  .app-layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    min-width: 100%;
    max-height: 40vh;
  }
  .preview-frame { width: 100% !important; }
}

/* ── Template Config Section (custom texts) ── */
.template-config-group {
  margin-bottom: 10px;
}
.template-config-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--ui-text-secondary);
  margin-bottom: 4px;
}
.template-config-group input,
.template-config-group textarea {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--ui-border);
  border-radius: 5px;
  font-size: 13px;
  font-family: inherit;
}
.template-config-group input:focus,
.template-config-group textarea:focus {
  outline: none;
  border-color: var(--ui-accent);
  box-shadow: 0 0 0 2px rgba(192,57,43,0.12);
}

/* ── Insert Variable Button ── */
.btn-insert-var {
  font-size: 12px;
  padding: 4px 8px;
}

/* ── Hidden file input ── */
#import-file { display: none; }

/* ── Sponsor Button & Dropdown ── */
.btn-sponsor {
  background: linear-gradient(135deg, #ff813f 0%, #e6559a 100%) !important;
  color: #fff !important;
  border: none !important;
  border-radius: 20px !important;
  padding: 7px 16px !important;
  font-weight: 600 !important;
  box-shadow: 0 2px 8px rgba(255, 129, 63, 0.3);
  transition: all 0.2s ease !important;
}
.btn-sponsor:hover {
  box-shadow: 0 4px 14px rgba(255, 129, 63, 0.45) !important;
  transform: translateY(-1px);
  background: linear-gradient(135deg, #ff9254 0%, #e966a6 100%) !important;
}
.sponsor-dropdown {
  position: relative;
}
.sponsor-dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--ui-surface);
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius);
  box-shadow: var(--ui-shadow-lg);
  min-width: 200px;
  z-index: 150;
  overflow: hidden;
}
.sponsor-dropdown-menu.open {
  display: block;
}
.sponsor-option {
  display: block;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ui-text);
  text-decoration: none;
  transition: background 0.1s;
}
.sponsor-option:hover {
  background: #f5f5f7;
}
.sponsor-option + .sponsor-option {
  border-top: 1px solid var(--ui-border);
}

/* ── App Footer ── */
.app-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 34px;
  padding: 0 24px;
  background: var(--ui-surface);
  border-top: 1px solid var(--ui-border);
  text-align: center;
  font-size: 12px;
  color: var(--ui-text-secondary);
  z-index: 50;
}
.app-footer a {
  color: var(--ui-text-secondary);
  text-decoration: none;
  font-weight: 500;
}
.app-footer a:hover {
  color: var(--ui-text);
  text-decoration: underline;
}

/* ── Responsive: sponsor button ── */
@media (max-width: 900px) {
  .btn-sponsor {
    padding: 7px 10px !important;
    font-size: 0 !important;
  }
  .btn-sponsor::before {
    content: '☕';
    font-size: 16px;
  }
  .top-bar h1 {
    font-size: 13px;
  }
}

/* Mobile Warning Overlay */
.mobile-warning {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.6);
  z-index: 10000;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.mobile-warning-content {
  background: var(--ui-surface);
  border-radius: 16px;
  padding: 40px 30px;
  max-width: 340px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  margin: 20px;
}

.mobile-warning-icon {
  font-size: 48px;
  display: block;
  margin-bottom: 16px;
}

.mobile-warning h2 {
  font-size: 20px;
  margin: 0 0 12px 0;
  color: var(--ui-text);
}

.mobile-warning p {
  font-size: 14px;
  color: var(--ui-text-secondary);
  line-height: 1.5;
  margin: 0 0 24px 0;
}

.mobile-warning .btn-primary {
  background: var(--ui-accent, #c0392b);
  color: #fff;
  border: none;
  padding: 12px 28px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

@media (max-width: 768px) {
  .mobile-warning {
    display: flex;
  }
  .mobile-warning.dismissed {
    display: none;
  }
}

/* ── Share Popover ───────────────────────────────────────── */
.share-popover-wrapper {
  position: relative;
}

.share-popover {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--ui-surface);
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius);
  box-shadow: var(--ui-shadow-lg);
  min-width: 320px;
  z-index: 150;
  overflow: hidden;
}
.share-popover.open {
  display: block;
}

.share-popover-header {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--ui-border);
  font-size: 13px;
  font-weight: 600;
}

.share-popover-close {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: inherit;
}

.share-popover-body {
  padding: 16px;
}

.share-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.share-spinner {
  width: 24px;
  height: 24px;
  border: 3px solid #e0e0e0;
  border-top-color: var(--ui-accent, #c0392b);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.share-url-input {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid #d0d0d0;
  border-radius: 5px;
  font-size: 12px;
  font-family: monospace;
  background: #f8f8fa;
  box-sizing: border-box;
}

.share-expiry {
  font-size: 11px;
  color: #888;
  margin-top: 4px;
  text-align: center;
}

.share-error-msg {
  font-size: 13px;
  color: var(--ui-accent, #c0392b);
  text-align: center;
}

/* ── Confirm Modal ───────────────────────────────────────── */
.confirm-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 200;
  justify-content: center;
  align-items: center;
}
.confirm-modal-overlay.active {
  display: flex;
}

.confirm-modal {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  padding: 24px;
  max-width: 420px;
  width: 90%;
}
.confirm-modal h3 {
  font-size: 16px;
  margin: 0 0 12px 0;
}
.confirm-modal p {
  font-size: 13px;
  color: #666;
  line-height: 1.5;
  margin: 0 0 20px 0;
}

.confirm-modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.field-hint {
  font-size: 11px;
  color: var(--ui-text-secondary, #888);
  margin: 2px 0 0 0;
}

.template-group {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 10px;
  width: 100%;
}

.template-group-heading {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--ui-text-secondary, #888);
  margin: 8px 0 6px 0;
  letter-spacing: 0.5px;
  width: 100%;
}

.template-group-heading:first-child {
  margin-top: 0;
}

.template-tab:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
