/* ================================================================
   ORBIT COMPONENT LIBRARY (PRODUCTION CRAFT)
   Form Controls, WhatsApp Simulation Stage, Buttons Builder,
   Ledger Table, Modals, Document Renderer, and Toast Feedback
   ================================================================ */

/* Forms & Flow */
.form-flow {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

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

.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-tertiary);
  letter-spacing: 0.01em;
  text-transform: uppercase;
}

.field-meta {
  font-size: 11px;
  color: var(--color-text-placeholder);
  font-family: var(--font-mono);
  font-weight: 500;
}

.input-wrap {
  position: relative;
  display: flex;
  align-items: stretch;
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.input-wrap:hover {
  border-color: var(--color-border-hover);
}

.input-wrap:focus-within {
  border-color: var(--color-focus);
  box-shadow: 0 0 0 3px var(--color-primary-subtle);
}

.input-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-tertiary);
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.input-icon-top {
  top: 14px;
  transform: none;
}

.input-wrap input,
.input-wrap select,
.input-wrap textarea {
  width: 100%;
  padding: 9px 12px 9px 38px;
  color: var(--color-text-primary);
  font-size: 13.5px;
  background: transparent;
  min-height: var(--control-height-lg);
}

.input-wrap select {
  appearance: none;
  cursor: pointer;
}

.input-wrap select option {
  background: var(--color-surface);
  color: var(--color-text-primary);
}

.input-wrap textarea {
  resize: vertical;
  min-height: 100px;
  line-height: 1.5;
  padding-top: 10px;
}

/* WhatsApp Text Formatting Toolbar */
.formatting-bar {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 3px;
  margin-top: 4px;
  align-self: flex-start;
}

.format-btn {
  height: 26px;
  min-width: 28px;
  padding: 0 6px;
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-tertiary);
  border-radius: var(--radius-xs);
  cursor: pointer;
  background: transparent;
  border: none;
  transition: all var(--transition-fast);
  user-select: none;
}

.format-btn:hover {
  color: var(--color-text-primary);
  background: var(--color-surface);
  box-shadow: var(--shadow-subtle);
}

.format-btn-hint {
  font-size: 10px;
  color: var(--color-text-placeholder);
  margin-left: 6px;
  padding-right: 6px;
  font-family: var(--font-mono);
  font-weight: 500;
}

/* Multi-Buttons Builder in Module 2 */
.buttons-builder-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
}

.buttons-builder-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: 8px;
}

.button-item-card {
  background: var(--color-surface-subtle);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  animation: fadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: var(--shadow-subtle);
}

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

.button-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.button-item-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--color-primary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--color-primary-subtle);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
}

.button-item-remove {
  color: var(--color-danger-text);
  cursor: pointer;
  font-size: 11.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: transparent;
  border: none;
  padding: 3px 8px;
  border-radius: var(--radius-xs);
  transition: all var(--transition-fast);
}

.button-item-remove:hover {
  background: var(--color-danger-bg);
}

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

.input-flat {
  padding-left: 12px !important;
}

/* Date Shortcuts */
.date-shortcuts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.shortcut-pill {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--color-text-tertiary);
  background: var(--color-surface-alt);
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  user-select: none;
  border: 1px solid var(--color-border);
  transition: all var(--transition-fast);
}

.shortcut-pill:hover {
  color: var(--color-text-primary);
  background: var(--color-surface);
  border-color: var(--color-border-hover);
  box-shadow: var(--shadow-subtle);
}

/* Standard Buttons */
.btn {
  height: var(--control-height-lg);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 13.5px;
  font-weight: 600;
  padding: 0 18px;
  background: var(--color-surface-alt);
  color: var(--color-text-primary);
  border: 1px solid transparent;
  transition: all var(--transition-fast);
  user-select: none;
}

.btn:hover:not(:disabled) {
  background: var(--color-border-subtle);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn-accent {
  background: var(--color-primary);
  color: #FFFFFF;
  border: none;
  box-shadow: 0 2px 8px var(--color-primary-glow);
}

.btn-accent:hover:not(:disabled) {
  background: var(--color-primary-hover);
  box-shadow: 0 4px 14px var(--color-primary-glow);
}

.btn-accent:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-secondary {
  background: var(--color-surface);
  border: 1px solid var(--color-border-subtle);
  color: var(--color-text-primary);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--color-surface-subtle);
  border-color: var(--color-border-hover);
}

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

.btn-danger {
  color: var(--color-danger-text);
  background: var(--color-danger-bg);
  border: 1px solid var(--color-danger-border);
}

.btn-danger:hover:not(:disabled) {
  background: var(--color-danger-border);
}

.btn-sm {
  height: var(--control-height-sm);
  font-size: 12px;
  padding: 0 12px;
}

.btn-icon-md {
  padding: 0 12px;
  height: var(--control-height-md);
}

.filter-select {
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text-primary);
  padding: 0 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  min-width: 140px;
  height: var(--control-height-md);
  transition: all var(--transition-fast);
}

.filter-select:focus {
  border-color: var(--color-focus);
}

/* Table Container & Ledger */
.table-container {
  flex: 1;
  overflow: auto;
  padding: 0 32px 24px;
  -webkit-overflow-scrolling: touch;
}

.table-container::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

.table-container::-webkit-scrollbar-thumb {
  background: var(--color-border-subtle);
  border-radius: var(--radius-pill);
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  text-align: left;
}

th {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--color-text-tertiary);
  border-bottom: 1px solid var(--color-border);
  padding: 14px 16px;
  white-space: nowrap;
  background: var(--color-bg);
  position: sticky;
  top: 0;
  z-index: 10;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--color-border);
  font-size: 13.5px;
  vertical-align: middle;
  color: var(--color-text-body);
  transition: background-color var(--transition-fast);
}

tr.table-row-interactive {
  cursor: pointer;
}

tr.table-row-interactive:hover td {
  background: var(--color-surface);
}

.msg-cell {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--color-text-body);
}

/* Semantic Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: var(--color-surface-alt);
  color: var(--color-text-tertiary);
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge-enviado,
.badge-success {
  color: var(--color-success-text);
  background: var(--color-success-bg);
  border-color: var(--color-success-border);
}

.badge-agendado,
.badge-warning {
  color: var(--color-warning-text);
  background: var(--color-warning-bg);
  border-color: var(--color-warning-border);
}

.badge-erro,
.badge-danger {
  color: var(--color-danger-text);
  background: var(--color-danger-bg);
  border-color: var(--color-danger-border);
}

.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* Table Actions */
.actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.action-icon {
  color: var(--color-text-tertiary);
  cursor: pointer;
  transition: all var(--transition-fast);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
}

.action-icon:hover {
  color: var(--color-text-primary);
  background: var(--color-surface-alt);
  border-color: var(--color-border-subtle);
}

.action-icon.text-danger:hover {
  color: var(--color-danger-text);
  background: var(--color-danger-bg);
  border-color: var(--color-danger-border);
}

/* ================================================================
   WHATSAPP INTERACTIVE PREVIEW ENGINE (DIFFERENTIATION ANCHOR)
   ================================================================ */
.button-preview-stage {
  flex: 1;
  overflow-y: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 36px 20px;
  background: var(--wa-stage-bg);
  background-image: radial-gradient(rgba(0, 0, 0, 0.06) 1px, transparent 0);
  background-size: 20px 20px;
  -webkit-overflow-scrolling: touch;
}

[data-theme="dark"] .button-preview-stage {
  background-image: radial-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 0);
}

.button-preview-shell {
  width: min(100%, 390px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.button-preview-kicker {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 4px;
  color: var(--color-text-tertiary);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* WhatsApp Message Bubble Container */
.button-message-card {
  border: 1px solid var(--wa-bubble-border);
  border-radius: var(--radius-bubble);
  border-top-right-radius: 2px;
  background: var(--wa-bubble-bg);
  padding: 14px 14px 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  position: relative;
  color: var(--wa-bubble-text);
}

/* WhatsApp Message Bubble Tail */
.button-message-card::before {
  content: '';
  position: absolute;
  top: 0;
  right: -8px;
  width: 0;
  height: 0;
  border-left: 8px solid var(--wa-bubble-bg);
  border-bottom: 8px solid transparent;
}

.button-preview-image {
  width: 100%;
  max-height: 200px;
  object-fit: cover;
  border-radius: 8px;
  margin-bottom: 10px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: rgba(0, 0, 0, 0.04);
}

.button-message-header {
  font-size: 14.5px;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--wa-bubble-text);
  word-break: break-word;
  font-family: var(--font-sans);
}

.button-message-content {
  color: var(--wa-bubble-text);
  font-size: 13.5px;
  line-height: 1.48;
  min-height: 24px;
  word-break: break-word;
  font-family: var(--font-sans);
}

.button-message-content strong {
  font-weight: 700;
}

.button-message-content em {
  font-style: italic;
}

.button-message-content del {
  text-decoration: line-through;
}

.wa-mono-block {
  font-family: var(--font-mono);
  background: rgba(0, 0, 0, 0.06);
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 12px;
}

[data-theme="dark"] .wa-mono-block {
  background: rgba(255, 255, 255, 0.1);
}

.button-message-footer {
  color: var(--wa-bubble-meta);
  font-size: 11px;
  margin-top: 10px;
  word-break: break-word;
}

/* WhatsApp Bubble Timestamp & Blue Ticks */
.wa-bubble-telemetry {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
  color: var(--wa-bubble-meta);
  font-size: 11px;
}

.wa-ticks {
  color: var(--wa-blue-tick);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: -2px;
  line-height: 1;
}

/* WhatsApp Action Buttons Stack */
.button-preview-actions-stack {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 10px;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  padding-top: 8px;
}

[data-theme="dark"] .button-preview-actions-stack {
  border-top-color: rgba(255, 255, 255, 0.08);
}

.button-message-action {
  width: 100%;
  height: 38px;
  border-radius: 6px;
  color: var(--wa-btn-text);
  background: var(--wa-btn-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
  border: 1px solid rgba(0, 0, 0, 0.04);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.button-message-action:hover {
  background: var(--wa-btn-hover);
  transform: translateY(-1px);
}

.button-message-action:active {
  transform: translateY(1px);
}

.button-preview-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 0 4px;
  color: var(--color-text-tertiary);
  font-size: 11.5px;
  font-weight: 500;
}

/* Markdown Display (Module 3) */
.md-content {
  font-size: 14px;
  line-height: 1.7;
  color: var(--color-text-body);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  padding: 36px;
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
}

.md-content h1,
.md-content h2,
.md-content h3 {
  color: var(--color-text-primary);
  margin-top: 1.5em;
  margin-bottom: 0.6em;
  font-weight: 700;
  font-family: var(--font-display);
}

.md-content h1 { font-size: 20px; }
.md-content h2 {
  font-size: 16px;
  border-bottom: 1px solid var(--color-border);
  padding-bottom: 8px;
}
.md-content h3 { font-size: 14.5px; }

.md-content p, .md-content ul, .md-content ol {
  margin-bottom: 1em;
}

.md-content ul, .md-content ol { margin-left: 24px; }
.md-content li { margin-bottom: 6px; }
.md-content strong { color: var(--color-text-primary); font-weight: 700; }

.md-content pre, .md-content code {
  background: var(--color-surface-alt);
  font-family: var(--font-mono);
  padding: 3px 6px;
  font-size: 12px;
  border-radius: var(--radius-xs);
}

.md-content pre {
  padding: 16px;
  overflow-x: auto;
  margin-bottom: 1.2em;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
}

/* Empty & Loading States */
.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--color-text-tertiary);
}

.empty-icon-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  margin-bottom: 14px;
  color: var(--color-primary);
  box-shadow: var(--shadow-subtle);
}

.empty h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--color-text-primary);
}

.empty p {
  font-size: 13px;
  max-width: 360px;
  margin: 0 auto;
}

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 16px;
}

.modal-content {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  padding: 28px;
  width: 100%;
  max-width: 460px;
  box-shadow: var(--shadow-modal);
  animation: modalPop 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalPop {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-content-lg {
  max-width: 520px;
}

.modal-header {
  font-size: 16px;
  font-weight: 700;
  color: var(--color-text-primary);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
}

.modal-body {
  color: var(--color-text-body);
  margin-bottom: 24px;
  font-size: 13.5px;
  line-height: 1.5;
}

.modal-detail-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-detail-row {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid var(--color-border);
  padding-bottom: 8px;
}

.modal-detail-label {
  color: var(--color-text-tertiary);
  font-size: 13px;
  font-weight: 500;
}

.modal-detail-value {
  font-weight: 600;
  color: var(--color-text-primary);
  font-size: 13px;
}

.modal-detail-box {
  background: var(--color-surface-alt);
  padding: 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  max-height: 160px;
  overflow-y: auto;
  white-space: pre-wrap;
  margin-top: 6px;
  border: 1px solid var(--color-border);
}

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

/* Toast System */
.toast-container {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 300;
  pointer-events: none;
  align-items: center;
}

.toast {
  background: var(--color-text-primary);
  color: var(--color-bg);
  border-radius: var(--radius-pill);
  padding: 10px 20px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 600;
  transform: translateY(16px);
  opacity: 0;
  transition: all var(--transition);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
  pointer-events: auto;
}

.toast.toast-success {
  background: var(--color-text-primary);
}

.toast.toast-error {
  background: var(--color-danger);
  color: #FFFFFF;
}

.toast.toast-warning {
  background: var(--color-warning);
  color: #FFFFFF;
}

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

@media (max-width: 860px) {
  .table-container {
    padding: 0 16px 16px;
  }
  .button-preview-stage {
    padding: 20px 12px;
  }
}
