/* ========================================
   @neutralaiz/markdown-core — Canonical Styles
   Single source of truth for markdown rendering.
   Used by both AI Sidebar and Zammad plugin.
   ======================================== */

/* ========================================
   Dark Theme (default)
   ======================================== */
.nmd-dark {
  --nmd-text: #c8c8d0;
  --nmd-text-secondary: #a0a0a0;
  --nmd-text-muted: #6c6c8a;
  --nmd-bg: #0f0f23;
  --nmd-bg-secondary: #16213e;
  --nmd-bg-tertiary: #0a0a1a;
  --nmd-bg-hover: #252545;
  --nmd-border: #2d2d5a;
  --nmd-accent: #6366f1;
  --nmd-accent-hover: #818cf8;
  --nmd-mono: 'SF Mono', Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
}

/* ========================================
   Light Theme
   ======================================== */
.nmd-light {
  --nmd-text: #1a1a1a;
  --nmd-text-secondary: #555555;
  --nmd-text-muted: #888888;
  --nmd-bg: #ffffff;
  --nmd-bg-secondary: #f5f7f9;
  --nmd-bg-tertiary: #f0f2f5;
  --nmd-bg-hover: #e8edf2;
  --nmd-border: #d1d5db;
  --nmd-accent: #4f46e5;
  --nmd-accent-hover: #6366f1;
  --nmd-mono: 'SF Mono', Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
}

/* ========================================
   Base Container
   ======================================== */
.nmd-content {
  font-size: 13px;
  line-height: 1.6;
  color: var(--nmd-text);
  word-wrap: break-word;
}

/* ========================================
   Headers
   ======================================== */
.nmd-content h1 {
  font-size: 1.4em;
  font-weight: 600;
  margin: 1em 0 0.5em;
  padding-bottom: 0.3em;
  border-bottom: 1px solid var(--nmd-border);
  color: var(--nmd-text);
}

.nmd-content h2 {
  font-size: 1.25em;
  font-weight: 600;
  margin: 0.8em 0 0.4em;
  color: var(--nmd-text);
}

.nmd-content h3 {
  font-size: 1.1em;
  font-weight: 600;
  margin: 0.6em 0 0.3em;
  color: var(--nmd-text);
}

.nmd-content h4,
.nmd-content h5,
.nmd-content h6 {
  font-size: 1em;
  font-weight: 600;
  margin: 0.5em 0 0.25em;
  color: var(--nmd-text-secondary);
}

/* ========================================
   Text
   ======================================== */
.nmd-content p { margin: 0.5em 0; }
.nmd-content strong, .nmd-content b { font-weight: 600; color: var(--nmd-text); }
.nmd-content em { font-style: italic; }
.nmd-content del { text-decoration: line-through; opacity: 0.7; }

/* ========================================
   Links
   ======================================== */
.nmd-content a { color: var(--nmd-accent); text-decoration: none; transition: color 0.15s ease; }
.nmd-content a:hover { color: var(--nmd-accent-hover); text-decoration: underline; }

/* ========================================
   Lists
   ======================================== */
.nmd-content ul,
.nmd-content ol {
  margin: 0.5em 0;
  padding-left: 0;
  list-style: none;
}

.nmd-content li {
  margin: 0.25em 0;
  padding-left: 1.5em;
  position: relative;
  color: var(--nmd-text);
}

.nmd-content ul ul,
.nmd-content ul ol,
.nmd-content ol ul,
.nmd-content ol ol {
  margin: 0.25em 0;
  padding-left: 1em;
}

.nmd-content ul > li::before {
  content: "\2022";
  position: absolute;
  left: 0.5em;
  color: var(--nmd-accent);
}

.nmd-content ul ul > li::before { content: "\25E6"; }
.nmd-content ul ul ul > li::before { content: "\25AA"; }

/* Ordered list numbering — use native list-style so <ol start="N">
   works correctly for split lists (marked emits separate <ol> per
   group when blank lines appear between items). */
.nmd-content ol {
  list-style: decimal;
  padding-left: 1.5em;
}
.nmd-content ol > li {
  padding-left: 0.3em;
}
.nmd-content ol > li::before {
  content: none;
}
.nmd-content ol > li::marker {
  color: var(--nmd-accent);
  font-weight: 500;
}

/* Task lists */
.nmd-content input[type="checkbox"] {
  margin-right: 6px;
  accent-color: var(--nmd-accent);
}
.nmd-content li:has(> input[type="checkbox"])::before { content: none; }

/* ========================================
   Tables
   ======================================== */
.nmd-content table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
  margin: 1em 0;
  border: 1px solid var(--nmd-border);
  overflow: hidden;
}

.nmd-content th,
.nmd-content td {
  border: 1px solid var(--nmd-border);
  padding: 6px 10px;
  text-align: left;
  color: var(--nmd-text);
}

.nmd-content th {
  background: var(--nmd-bg-secondary);
  font-weight: 600;
  color: var(--nmd-text);
}

.nmd-content tr:nth-child(even) { background: rgba(255, 255, 255, 0.02); }
.nmd-content tbody tr:hover,
.nmd-content tr:hover { background: var(--nmd-bg-hover) !important; }

/* Light theme: different alternating rows */
.nmd-light.nmd-content tr:nth-child(even) { background: rgba(0, 0, 0, 0.02); }

/* ========================================
   Code
   ======================================== */
.nmd-content code {
  background: var(--nmd-bg-hover);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--nmd-mono);
  font-size: 0.9em;
  color: var(--nmd-accent);
}

.nmd-content pre {
  background: var(--nmd-bg-tertiary);
  border: 1px solid var(--nmd-border);
  border-radius: 6px;
  padding: 12px;
  overflow-x: auto;
  margin: 1em 0;
}

.nmd-content pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  font-family: var(--nmd-mono);
  font-size: 13px;
  line-height: 1.5;
  color: var(--nmd-text);
  white-space: pre-wrap;
  word-break: break-word;
}

/* Code block wrapper with header */
.nmd-code {
  position: relative;
  margin: 1em 0;
}

.nmd-code pre {
  margin: 0;
  border-radius: 0 0 6px 6px;
}

.nmd-code__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--nmd-bg-secondary);
  border: 1px solid var(--nmd-border);
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  padding: 4px 10px;
  min-height: 28px;
}

.nmd-code__lang {
  font-family: var(--nmd-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--nmd-text-muted);
  text-transform: lowercase;
}

.nmd-code__copy {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--nmd-border);
  border-radius: 4px;
  color: var(--nmd-text-muted);
  font-size: 11px;
  font-family: inherit;
  padding: 2px 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.nmd-code__copy:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--nmd-text);
}

/* Light theme copy button */
.nmd-light .nmd-code__copy {
  background: rgba(0, 0, 0, 0.04);
}
.nmd-light .nmd-code__copy:hover {
  background: rgba(0, 0, 0, 0.08);
}

/* ========================================
   Syntax Highlighting — One Dark
   Force !important to override Zammad's global code/pre color styles
   ======================================== */
.nmd-dark code.hljs, .nmd-dark .hljs { color: #abb2bf !important; background: transparent !important; }
.nmd-dark .hljs-comment, .nmd-dark .hljs-quote { color: #7f848e !important; font-style: italic; }
.nmd-dark .hljs-keyword, .nmd-dark .hljs-selector-tag { color: #c678dd !important; }
.nmd-dark .hljs-string, .nmd-dark .hljs-attribute, .nmd-dark .hljs-addition { color: #98c379 !important; }
.nmd-dark .hljs-number, .nmd-dark .hljs-literal { color: #d19a66 !important; }
.nmd-dark .hljs-function, .nmd-dark .hljs-title { color: #61afef !important; }
.nmd-dark .hljs-variable, .nmd-dark .hljs-template-variable { color: #e06c75 !important; }
.nmd-dark .hljs-type, .nmd-dark .hljs-class .hljs-title { color: #e5c07b !important; }
.nmd-dark .hljs-built_in { color: #56b6c2 !important; }
.nmd-dark .hljs-attr { color: #e06c75 !important; }
.nmd-dark .hljs-punctuation { color: #abb2bf !important; }
.nmd-dark .hljs-meta { color: #61afef !important; }
.nmd-dark .hljs-symbol { color: #56b6c2 !important; }
.nmd-dark .hljs-selector-class { color: #e5c07b !important; }
.nmd-dark .hljs-subst { color: #e06c75 !important; }

/* Syntax Highlighting — One Light */
.nmd-light .hljs-comment, .nmd-light .hljs-quote { color: var(--nmd-text-muted); font-style: italic; }
.nmd-light .hljs-keyword, .nmd-light .hljs-selector-tag { color: #a626a4; }
.nmd-light .hljs-string, .nmd-light .hljs-attribute, .nmd-light .hljs-addition { color: #50a14f; }
.nmd-light .hljs-number, .nmd-light .hljs-literal { color: #986801; }
.nmd-light .hljs-function, .nmd-light .hljs-title { color: #4078f2; }
.nmd-light .hljs-variable, .nmd-light .hljs-template-variable { color: #e45649; }
.nmd-light .hljs-type, .nmd-light .hljs-class .hljs-title { color: #c18401; }
.nmd-light .hljs-built_in { color: #0184bc; }

/* ========================================
   Blockquotes
   ======================================== */
.nmd-content blockquote {
  border-left: 4px solid var(--nmd-accent);
  margin: 1em 0;
  padding: 6px 12px;
  background: rgba(99, 102, 241, 0.08);
  color: var(--nmd-text-secondary);
  border-radius: 0 4px 4px 0;
}

.nmd-content blockquote p { margin: 0; }
.nmd-content blockquote blockquote { margin: 0.5em 0; }

/* ========================================
   Images
   ======================================== */
.nmd-content img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  margin: 1em 0;
  display: block;
}

.nmd-content svg {
  max-width: 100%;
  height: auto;
  margin: 1em 0;
  display: block;
}

/* ========================================
   Horizontal Rule
   ======================================== */
.nmd-content hr {
  border: none;
  border-top: 1px solid var(--nmd-border);
  margin: 1.5em 0;
}

/* ========================================
   Margins
   ======================================== */
.nmd-content > *:first-child { margin-top: 0; }
.nmd-content > *:last-child { margin-bottom: 0; }

/* ========================================
   AI Article Branded Container (Zammad)
   ======================================== */
.nmd-ai-article {
  background: var(--nmd-bg);
  border: 1px solid var(--nmd-border);
  border-radius: 8px;
  padding: 12px 16px;
  margin: 4px 0;
}

.nmd-ai-article__header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--nmd-border);
}

.nmd-ai-article__label {
  font-size: 11px;
  font-weight: 600;
  color: var(--nmd-accent);
}

.nmd-ai-article__icon {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--nmd-accent);
  flex-shrink: 0;
}

/* ========================================
   Action Buttons
   ======================================== */
.nmd-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--nmd-border);
}

.nmd-actions__btn {
  display: inline-flex;
  align-items: center;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
  color: #c4b5fd;
  background: rgba(99, 102, 241, 0.15);
  border: 1px solid rgba(99, 102, 241, 0.3);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, opacity 0.15s ease;
  white-space: nowrap;
}

.nmd-actions__btn:hover {
  background: rgba(99, 102, 241, 0.25);
  border-color: rgba(129, 140, 248, 0.5);
  color: #ddd6fe;
}

.nmd-actions__btn:focus-visible { outline: 2px solid #6366f1; outline-offset: 2px; }
.nmd-actions__btn--loading { opacity: 0.7; cursor: wait; }
.nmd-actions__btn--sent { color: #86efac; background: rgba(34, 197, 94, 0.15); border-color: rgba(34, 197, 94, 0.3); cursor: default; }
.nmd-actions__btn--error { color: #fca5a5; background: rgba(239, 68, 68, 0.15); border-color: rgba(239, 68, 68, 0.3); cursor: pointer; }

/* Light theme action buttons */
.nmd-light .nmd-actions__btn { color: #4f46e5; background: rgba(79, 70, 229, 0.08); border-color: rgba(79, 70, 229, 0.2); }
.nmd-light .nmd-actions__btn:hover { background: rgba(79, 70, 229, 0.15); border-color: rgba(79, 70, 229, 0.4); }

/* ========================================
   Interactive Components — Submitted State
   ======================================== */
.nmd-interactive--submitted {
  opacity: 0.6;
  pointer-events: none;
}

/* ========================================
   Product Card
   ======================================== */
.nmd-product-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--nmd-bg-secondary);
  border: 1px solid var(--nmd-border);
  border-radius: 8px;
  padding: 12px;
  margin: 8px 0;
}

.nmd-product-card__image {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
  background: var(--nmd-bg-tertiary);
}

.nmd-product-card__details {
  flex: 1;
  min-width: 0;
}

.nmd-product-card__title {
  font-weight: 600;
  font-size: 13px;
  color: var(--nmd-text);
  margin-bottom: 2px;
}

.nmd-product-card__sku {
  font-size: 11px;
  font-family: var(--nmd-mono);
  color: var(--nmd-text-secondary);
  margin-bottom: 4px;
}

.nmd-product-card__specs {
  font-size: 12px;
  color: var(--nmd-text-muted);
  line-height: 1.4;
}

.nmd-product-card__price {
  font-weight: 600;
  font-size: 13px;
  color: var(--nmd-accent);
  margin-top: 4px;
}

.nmd-product-card__actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
  align-self: center;
}

/* ========================================
   Product Picker
   ======================================== */
.nmd-product-picker {
  margin: 8px 0;
}

.nmd-product-picker__prompt {
  font-size: 13px;
  font-weight: 500;
  color: var(--nmd-text);
  margin-bottom: 10px;
}

.nmd-product-picker__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.nmd-product-picker__item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: var(--nmd-bg-secondary);
  border: 1px solid var(--nmd-border);
  border-radius: 8px;
  padding: 10px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.nmd-product-picker__item:hover {
  background: var(--nmd-bg-hover);
}

.nmd-product-picker__item--selected {
  border-color: var(--nmd-accent);
  background: rgba(99, 102, 241, 0.08);
}

.nmd-product-picker__input {
  margin-top: 3px;
  accent-color: var(--nmd-accent);
  flex-shrink: 0;
}

.nmd-product-picker__label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  cursor: pointer;
  flex: 1;
  min-width: 0;
}

.nmd-product-picker__image {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
  background: var(--nmd-bg-tertiary);
}

.nmd-product-picker__info {
  flex: 1;
  min-width: 0;
}

.nmd-product-picker__title {
  font-weight: 600;
  font-size: 12px;
  color: var(--nmd-text);
}

.nmd-product-picker__sku {
  font-size: 11px;
  font-family: var(--nmd-mono);
  color: var(--nmd-text-secondary);
}

.nmd-product-picker__price {
  font-size: 12px;
  font-weight: 600;
  color: var(--nmd-accent);
  margin-top: 2px;
}

.nmd-product-picker__submit {
  margin-top: 4px;
}

/* ========================================
   Quantity Adjuster
   ======================================== */
.nmd-qty-adjuster {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  background: var(--nmd-bg-secondary);
  border: 1px solid var(--nmd-border);
  border-radius: 8px;
  padding: 12px;
  margin: 8px 0;
}

.nmd-qty-adjuster__product {
  font-size: 13px;
  font-weight: 500;
  color: var(--nmd-text);
  flex: 1;
  min-width: 120px;
}

.nmd-qty-adjuster__controls {
  display: inline-flex;
  align-items: center;
  gap: 0;
  border: 1px solid var(--nmd-border);
  border-radius: 6px;
  overflow: hidden;
}

.nmd-qty-adjuster__minus,
.nmd-qty-adjuster__plus {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--nmd-bg-tertiary);
  border: none;
  color: var(--nmd-text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}

.nmd-qty-adjuster__minus:hover,
.nmd-qty-adjuster__plus:hover {
  background: var(--nmd-bg-hover);
}

.nmd-qty-adjuster__input {
  width: 48px;
  height: 32px;
  text-align: center;
  border: none;
  border-left: 1px solid var(--nmd-border);
  border-right: 1px solid var(--nmd-border);
  background: var(--nmd-bg);
  color: var(--nmd-text);
  font-size: 13px;
  font-weight: 500;
  font-family: var(--nmd-mono);
  -moz-appearance: textfield;
}

.nmd-qty-adjuster__input::-webkit-inner-spin-button,
.nmd-qty-adjuster__input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.nmd-qty-adjuster__submit {
  flex-shrink: 0;
}

/* ========================================
   Confirmation
   ======================================== */
.nmd-confirmation {
  background: var(--nmd-bg-secondary);
  border: 1px solid var(--nmd-border);
  border-radius: 8px;
  padding: 14px 16px;
  margin: 8px 0;
}

.nmd-confirmation__title {
  font-size: 14px;
  font-weight: 600;
  color: var(--nmd-text);
  margin-bottom: 10px;
}

.nmd-confirmation__summary {
  border: 1px solid var(--nmd-border);
  border-radius: 6px;
  padding: 10px 12px;
  background: var(--nmd-bg-tertiary);
  margin-bottom: 12px;
}

.nmd-confirmation__actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.nmd-confirmation__cancel {
  color: var(--nmd-text-secondary) !important;
  background: rgba(255, 255, 255, 0.04) !important;
  border-color: var(--nmd-border) !important;
}

.nmd-confirmation__cancel:hover {
  background: var(--nmd-bg-hover) !important;
  color: var(--nmd-text) !important;
}

.nmd-confirmation__confirm {
  color: #fff !important;
  background: var(--nmd-accent) !important;
  border-color: var(--nmd-accent) !important;
}

.nmd-confirmation__confirm:hover {
  background: var(--nmd-accent-hover) !important;
  border-color: var(--nmd-accent-hover) !important;
}

/* Light theme — confirmation buttons */
.nmd-light .nmd-confirmation__cancel {
  background: rgba(0, 0, 0, 0.04) !important;
}
.nmd-light .nmd-confirmation__cancel:hover {
  background: rgba(0, 0, 0, 0.08) !important;
}

/* Light theme — quantity adjuster */
.nmd-light .nmd-qty-adjuster__minus,
.nmd-light .nmd-qty-adjuster__plus {
  background: rgba(0, 0, 0, 0.04);
}
.nmd-light .nmd-qty-adjuster__minus:hover,
.nmd-light .nmd-qty-adjuster__plus:hover {
  background: rgba(0, 0, 0, 0.08);
}

/* Light theme — product picker selected */
.nmd-light .nmd-product-picker__item--selected {
  border-color: var(--nmd-accent);
  background: rgba(79, 70, 229, 0.06);
}

/* ========================================
   Form Controls
   ======================================== */
.nmd-form {
  background: var(--nmd-bg-secondary);
  border: 1px solid var(--nmd-border);
  border-radius: 8px;
  padding: 12px 14px;
  margin: 8px 0;
}
.nmd-form__title {
  font-size: 14px;
  font-weight: 600;
  color: var(--nmd-text);
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--nmd-border);
}
.nmd-form__fields { display: flex; flex-direction: column; gap: 8px; }
.nmd-form__field { display: flex; flex-direction: column; gap: 2px; }
.nmd-form__label { font-size: 12px; font-weight: 500; color: var(--nmd-text-secondary); }
.nmd-form__req { color: #ef4444; margin-left: 2px; }
.nmd-form__input {
  background: var(--nmd-bg);
  border: 1px solid var(--nmd-border);
  border-radius: 4px;
  color: var(--nmd-text);
  font-size: 13px;
  padding: 5px 8px;
  font-family: inherit;
  transition: border-color 0.15s;
}
.nmd-form__input:focus { outline: none; border-color: var(--nmd-accent); }
.nmd-form__input:disabled { opacity: 0.6; }
.nmd-form__input--error { border-color: #ef4444 !important; }
.nmd-form__select { appearance: auto; }
.nmd-form__textarea { resize: vertical; min-height: 60px; }
.nmd-form__checkbox-wrap {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--nmd-text); cursor: pointer;
}
.nmd-form__checkbox { accent-color: var(--nmd-accent); width: 16px; height: 16px; }
.nmd-form__submit { margin-top: 8px; width: 100%; }
