/* Rechnungsimport-Modul: Styles aus den nginx-Pages, gescoped unter .ri-wrap
   damit Dolibarr-CSS unberuehrt bleibt.
   Farb-Varianten pro Mandant: PHP-Pages setzen zusaetzlich .ri-instance-{suffix}
   auf das .ri-wrap-Element, die jeweilige Override-Regel aktiviert die CI. */

:root {
  --ri-primary:        #aa2018;          /* CI Lagazo Weinrot (Default) */
  --ri-primary-dark:   #7a160f;
  --ri-primary-darker: #5e1109;
  --ri-primary-soft:   #fdf2f0;
  --ri-primary-shadow: rgba(170,32,24,0.15);
  --ri-accent-grey:    #252525;
}

/* CI BEZ — Bezerwiese Gruen */
.ri-wrap.ri-instance-bez {
  --ri-primary:        #089A18;
  --ri-primary-dark:   #066C11;
  --ri-primary-darker: #04550D;
  --ri-primary-soft:   #f1faf2;
  --ri-primary-shadow: rgba(8,154,24,0.15);
}

/* CI AZ — Agrarservice Blau */
.ri-wrap.ri-instance-az {
  --ri-primary:        #0344BD;
  --ri-primary-dark:   #023084;
  --ri-primary-darker: #022568;
  --ri-primary-soft:   #eef2fb;
  --ri-primary-shadow: rgba(3,68,189,0.15);
}

/* CI DKH — Dorfkaufhaus Rot */
.ri-wrap.ri-instance-dkh {
  --ri-primary:        #D6192F;
  --ri-primary-dark:   #961121;
  --ri-primary-darker: #760E1A;
  --ri-primary-soft:   #fbe9eb;
  --ri-primary-shadow: rgba(214,25,47,0.15);
}

.ri-wrap, .ri-wrap * { box-sizing: border-box; }
.ri-wrap { font-family: 'Segoe UI', Arial, sans-serif; color: var(--ri-accent-grey); }

.ri-wrap header {
  background: linear-gradient(135deg, var(--ri-primary), var(--ri-primary-dark));
  color: white;
  padding: 16px 24px;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  margin-bottom: 20px;
}
.ri-wrap header h1 { font-size: 1.4rem; font-weight: 600; margin: 0; }
.ri-wrap header .subtitle { opacity: 0.85; font-size: 0.9rem; margin-top: 4px; }
.ri-wrap header .badge {
  background: rgba(255,255,255,0.2);
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.8rem;
}
.ri-wrap header.with-badge { display: flex; align-items: center; gap: 12px; padding: 16px 24px; }

.ri-wrap .container { max-width: 1100px; margin: 0 auto; padding: 8px 0 24px; }

/* === Liste === */
.ri-wrap .actions { display: flex; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; align-items: center; }
.ri-wrap .btn {
  background: white; border: 1px solid #d1d5db; padding: 8px 16px;
  border-radius: 6px; cursor: pointer; font-size: 0.9rem;
  display: inline-flex; align-items: center; gap: 6px; transition: all 0.15s;
  text-decoration: none; color: #333;
}
.ri-wrap .btn:hover { border-color: var(--ri-primary); background: var(--ri-primary-soft); color: var(--ri-primary); }
.ri-wrap .btn.primary { background: var(--ri-primary); color: white; border-color: var(--ri-primary); }
.ri-wrap .btn.primary:hover { opacity: 0.9; color: white; background: var(--ri-primary); }

.ri-wrap .stats { display: flex; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.ri-wrap .stat { background: white; border-radius: 10px; padding: 16px 20px; flex: 1; min-width: 150px; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
.ri-wrap .stat-value { font-size: 1.8rem; font-weight: 700; color: var(--ri-primary); }
.ri-wrap .stat-label { font-size: 0.85rem; color: #6b7280; text-transform: uppercase; margin-top: 4px; }

.ri-wrap .doc-list { background: white; border-radius: 10px; box-shadow: 0 1px 4px rgba(0,0,0,0.08); overflow: hidden; }
.ri-wrap .doc-item { padding: 18px 20px; border-bottom: 1px solid #f3f4f6; display: flex; align-items: center; gap: 16px; cursor: pointer; transition: background 0.1s; }
.ri-wrap .doc-item:hover { background: #fafbfc; }
.ri-wrap .doc-item:last-child { border-bottom: none; }
.ri-wrap .doc-icon { font-size: 2rem; flex-shrink: 0; }
.ri-wrap .doc-info { flex: 1; min-width: 0; }
.ri-wrap .doc-title { font-weight: 600; font-size: 1rem; margin-bottom: 4px; }
.ri-wrap .doc-meta { font-size: 0.85rem; color: #6b7280; display: flex; gap: 12px; flex-wrap: wrap; }
.ri-wrap .doc-meta span { display: inline-flex; align-items: center; gap: 3px; }
.ri-wrap .doc-actions { display: flex; gap: 8px; flex-shrink: 0; }
.ri-wrap .doc-badge { padding: 3px 10px; border-radius: 20px; font-size: 0.75rem; font-weight: 600; text-transform: uppercase; }
.ri-wrap .doc-badge.rechnung { background: #fef3c7; color: #92400e; }
.ri-wrap .doc-badge.angebot { background: #dbeafe; color: var(--ri-primary-darker); }
.ri-wrap .doc-badge.lieferschein { background: #d1fae5; color: #065f46; }
.ri-wrap .doc-badge.steuerbescheid { background: #fce7f3; color: #9d174d; }
.ri-wrap .doc-badge.vertrag { background: #ede9fe; color: #5b21b6; }

.ri-wrap .empty { text-align: center; padding: 80px 20px; color: #9ca3af; }
.ri-wrap .empty .icon { font-size: 4rem; margin-bottom: 16px; }
.ri-wrap .empty h3 { color: #6b7280; margin-bottom: 8px; }

.ri-wrap .auto-refresh { font-size: 0.8rem; color: #9ca3af; margin-left: auto; display: flex; align-items: center; gap: 6px; }
.ri-wrap .pulse { width: 8px; height: 8px; background: #10b981; border-radius: 50%; animation: ri-pulse 2s infinite; }
@keyframes ri-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

/* === Upload === */
.ri-wrap .upload-card {
  background: white; border-radius: 12px; box-shadow: 0 4px 20px rgba(0,0,0,0.07);
  padding: 30px; max-width: 700px; margin: 0 auto;
}
.ri-wrap .upload-area {
  border: 3px dashed #d1d5db; border-radius: 12px; padding: 40px 20px;
  text-align: center; cursor: pointer; transition: all 0.2s; background: #fafbfc;
}
.ri-wrap .upload-area:hover, .ri-wrap .upload-area.drag-over { border-color: var(--ri-primary); background: var(--ri-primary-soft); }
.ri-wrap .upload-icon { font-size: 2.5rem; margin-bottom: 10px; }
.ri-wrap .upload-text { font-size: 1rem; color: #374151; margin-bottom: 6px; font-weight: 500; }
.ri-wrap .upload-hint { font-size: 0.85rem; color: #9ca3af; }

.ri-wrap .file-list { margin-top: 20px; display: flex; flex-direction: column; gap: 8px; }
.ri-wrap .file-item { padding: 12px 14px; background: #f8fafc; border: 1px solid #e5e7eb; border-radius: 8px; display: flex; align-items: center; gap: 12px; transition: all 0.2s; }
.ri-wrap .file-item.uploading { background: #fef3c7; border-color: #fde68a; }
.ri-wrap .file-item.success { background: #d1fae5; border-color: #a7f3d0; }
.ri-wrap .file-item.error { background: #fee2e2; border-color: #fecaca; }
.ri-wrap .file-item.duplicate { background: #fef3c7; border-color: #f59e0b; }
.ri-wrap .file-icon { font-size: 1.3rem; }
.ri-wrap .file-details { flex: 1; min-width: 0; }
.ri-wrap .file-name { font-weight: 500; color: #374151; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ri-wrap .file-size { font-size: 0.78rem; color: #6b7280; }
.ri-wrap .file-status { font-size: 0.85rem; color: #6b7280; min-width: 80px; text-align: right; }
.ri-wrap .file-status.success { color: #065f46; font-weight: 600; }
.ri-wrap .file-status.error { color: #991b1b; font-weight: 600; }
.ri-wrap .file-status.duplicate { color: #92400e; font-weight: 600; }
.ri-wrap .file-remove { background: none; border: none; color: #9ca3af; cursor: pointer; font-size: 1.1rem; padding: 4px 8px; border-radius: 4px; }
.ri-wrap .file-remove:hover { background: #fee2e2; color: #ef4444; }
.ri-wrap .file-remove:disabled { opacity: 0.3; cursor: not-allowed; }

.ri-wrap .spinner-small {
  display: inline-block; width: 14px; height: 14px;
  border: 2px solid #fde68a; border-top-color: #92400e; border-radius: 50%;
  animation: ri-spin 0.8s linear infinite; vertical-align: middle;
}
@keyframes ri-spin { to { transform: rotate(360deg); } }

.ri-wrap .upload-actions { display: flex; gap: 10px; margin-top: 24px; flex-wrap: wrap; }
.ri-wrap .btn-upload {
  flex: 1; min-width: 200px; background: linear-gradient(135deg, var(--ri-primary), var(--ri-primary-dark));
  color: white; border: none; padding: 14px; border-radius: 8px;
  font-size: 1rem; font-weight: 600; cursor: pointer; transition: opacity 0.15s;
}
.ri-wrap .btn-upload:hover:not(:disabled) { opacity: 0.9; }
.ri-wrap .btn-upload:disabled { opacity: 0.4; cursor: not-allowed; }
.ri-wrap .btn-clear { background: white; border: 1.5px solid #d1d5db; padding: 14px 24px; border-radius: 8px; font-size: 0.95rem; cursor: pointer; }
.ri-wrap .btn-clear:hover:not(:disabled) { border-color: #ef4444; color: #ef4444; }
.ri-wrap .btn-clear:disabled { opacity: 0.4; cursor: not-allowed; }

.ri-wrap .summary { margin-top: 20px; padding: 14px 16px; border-radius: 8px; font-size: 0.9rem; display: none; }
.ri-wrap .summary.show { display: block; }
.ri-wrap .summary.info { background: var(--ri-primary-soft); color: var(--ri-primary-darker); border: 1px solid #bfdbfe; }
.ri-wrap .summary.success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }

.ri-wrap .view-all { display: block; margin-top: 16px; color: var(--ri-primary); text-decoration: none; text-align: center; padding: 10px; border-radius: 6px; transition: background 0.15s; }
.ri-wrap .view-all:hover { background: var(--ri-primary-soft); }

/* === Korrektur Split-Layout === */
.ri-wrap .split-layout {
  display: grid; grid-template-columns: 1fr; gap: 24px;
  margin: 0 auto; padding: 0 0 80px;
}
@media (min-width: 1200px) {
  .ri-wrap .split-layout { grid-template-columns: minmax(440px, 1fr) minmax(820px, 2.4fr); }
}
@media (min-width: 1800px) {
  .ri-wrap .split-layout { grid-template-columns: minmax(460px, 1fr) minmax(1000px, 3fr); }
}
.ri-wrap .form-column { min-width: 0; }
.ri-wrap .pdf-column { position: sticky; top: 24px; align-self: start; max-height: calc(100vh - 60px); display: flex; flex-direction: column; }
.ri-wrap .pdf-column-header { background: white; border: 1px solid #e5e7eb; border-bottom: none; border-radius: 8px 8px 0 0; padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; font-size: 0.9rem; color: #374151; font-weight: 500; }
.ri-wrap .pdf-viewer { flex: 1; width: 100%; border: 1px solid #e5e7eb; border-radius: 0 0 8px 8px; background: #f3f4f6; min-height: calc(100vh - 120px); }
.ri-wrap .pdf-placeholder { display: flex; align-items: center; justify-content: center; color: #9ca3af; font-size: 0.9rem; padding: 40px; text-align: center; }
.ri-wrap .pdf-open-btn { background: transparent; border: 1px solid #d1d5db; color: #4b5563; padding: 4px 10px; border-radius: 4px; cursor: pointer; font-size: 0.8rem; }
.ri-wrap .pdf-open-btn:hover { background: #f9fafb; }

.ri-wrap .card { background: white; border-radius: 10px; box-shadow: 0 1px 4px rgba(0,0,0,0.1); margin-bottom: 20px; overflow: hidden; }
.ri-wrap .card-header { background: #f8fafc; border-bottom: 1px solid #e5e7eb; padding: 14px 20px; font-weight: 600; font-size: 0.95rem; display: flex; align-items: center; gap: 8px; }
.ri-wrap .card-body { padding: 20px; }

.ri-wrap .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.ri-wrap .grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
@media (max-width: 700px) {
  .ri-wrap .grid-2, .ri-wrap .grid-3 { grid-template-columns: 1fr; }
}

.ri-wrap label { display: block; font-size: 0.8rem; font-weight: 600; color: #6b7280; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 5px; }
.ri-wrap input, .ri-wrap select, .ri-wrap textarea {
  width: 100%; border: 1.5px solid #d1d5db; border-radius: 6px;
  padding: 8px 11px; font-size: 0.9rem; transition: border-color 0.15s; background: white;
}
.ri-wrap input:focus, .ri-wrap select:focus, .ri-wrap textarea:focus { outline: none; border-color: var(--ri-primary); box-shadow: 0 0 0 3px var(--ri-primary-shadow); }
.ri-wrap .field-group { margin-bottom: 12px; }

.ri-wrap .doc-type-selector { display: flex; gap: 10px; flex-wrap: wrap; }
.ri-wrap .doc-type-btn { flex: 1; min-width: 120px; padding: 10px 16px; border: 2px solid #d1d5db; border-radius: 8px; background: white; cursor: pointer; text-align: center; font-size: 0.9rem; font-weight: 500; transition: all 0.15s; }
.ri-wrap .doc-type-btn:hover { border-color: var(--ri-primary); background: var(--ri-primary-soft); }
.ri-wrap .doc-type-btn.active { border-color: var(--ri-primary); background: var(--ri-primary-soft); color: var(--ri-primary); }

.ri-wrap .positions-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.ri-wrap .positions-table th { background: #f8fafc; padding: 8px 10px; text-align: left; font-size: 0.75rem; font-weight: 600; color: #6b7280; text-transform: uppercase; border-bottom: 2px solid #e5e7eb; }
.ri-wrap .positions-table td { padding: 6px 8px; border-bottom: 1px solid #f3f4f6; vertical-align: middle; }
.ri-wrap .positions-table tr:hover td { background: #fafafa; }
.ri-wrap .positions-table input { border: 1px solid #e5e7eb; padding: 5px 8px; font-size: 0.85rem; }
.ri-wrap .positions-table input:focus { border-color: var(--ri-primary); }

.ri-wrap .col-pos { width: 40px; text-align: center; color: #9ca3af; font-weight: 500; }
.ri-wrap .col-artnr { width: 110px; }
.ri-wrap .col-desc { min-width: 200px; }
.ri-wrap .col-type { width: 90px; }
.ri-wrap .col-num { width: 90px; text-align: right; }
.ri-wrap .col-unit { width: 70px; }
.ri-wrap .col-action { width: 40px; text-align: center; }

.ri-wrap .btn-add { margin-top: 12px; background: none; border: 2px dashed #d1d5db; color: #6b7280; padding: 8px 16px; border-radius: 6px; cursor: pointer; font-size: 0.875rem; width: 100%; transition: all 0.15s; }
.ri-wrap .btn-add:hover { border-color: var(--ri-primary); color: var(--ri-primary); background: var(--ri-primary-soft); }
.ri-wrap .btn-remove { background: none; border: none; color: #ef4444; cursor: pointer; font-size: 1.1rem; padding: 2px 6px; border-radius: 4px; opacity: 0.6; }
.ri-wrap .btn-remove:hover { opacity: 1; background: #fee2e2; }

.ri-wrap .totals { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; margin-top: 16px; }
.ri-wrap .total-row { display: flex; gap: 20px; align-items: center; min-width: 300px; }
.ri-wrap .total-row .total-label { flex: 1; text-align: right; color: #6b7280; font-size: 0.875rem; }
.ri-wrap .total-row .total-value { width: 120px; text-align: right; font-weight: 600; font-size: 0.9rem; }
.ri-wrap .total-row.brutto .total-value { font-size: 1.1rem; color: var(--ri-primary); border-top: 2px solid #e5e7eb; padding-top: 6px; }

.ri-wrap .ai-badge { display: inline-flex; align-items: center; gap: 4px; background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; border-radius: 20px; padding: 3px 10px; font-size: 0.75rem; font-weight: 600; }
.ri-wrap .ai-badge.warn { background: #fffbeb; color: #92400e; border-color: #fde68a; }

.ri-wrap .submit-bar {
  background: white; border-top: 2px solid #e5e7eb; padding: 16px 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  position: sticky; bottom: 0; z-index: 10; box-shadow: 0 -4px 12px rgba(0,0,0,0.08);
  margin: 0 -16px;
}
.ri-wrap .btn-submit { background: linear-gradient(135deg, var(--ri-primary), var(--ri-primary-dark)); color: white; border: none; padding: 12px 32px; border-radius: 8px; font-size: 1rem; font-weight: 600; cursor: pointer; transition: opacity 0.15s; display: flex; align-items: center; gap: 8px; }
.ri-wrap .btn-submit:hover { opacity: 0.9; }
.ri-wrap .btn-submit:active { opacity: 0.8; }
.ri-wrap .btn-reject { background: white; color: #ef4444; border: 2px solid #ef4444; padding: 11px 20px; border-radius: 8px; font-size: 0.9rem; font-weight: 600; cursor: pointer; transition: all 0.15s; }
.ri-wrap .btn-reject:hover { background: #fee2e2; }

.ri-wrap .file-info { background: #f8fafc; border: 1px solid #e5e7eb; border-radius: 6px; padding: 8px 12px; font-size: 0.85rem; color: #6b7280; display: flex; align-items: center; gap: 6px; }

.ri-wrap #ri-loading { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 1000; align-items: center; justify-content: center; }
.ri-wrap #ri-loading.show { display: flex; }
.ri-wrap .ri-spinner-box { background: white; border-radius: 12px; padding: 30px 40px; text-align: center; }
.ri-wrap .ri-spinner-box::before {
  content: ''; display: block; width: 40px; height: 40px;
  border: 4px solid #e5e7eb; border-top-color: var(--ri-primary); border-radius: 50%;
  animation: ri-spin 0.8s linear infinite; margin: 0 auto 12px;
}

.ri-wrap .success-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 1000; align-items: center; justify-content: center; }
.ri-wrap .success-overlay.show { display: flex; }
.ri-wrap .success-box { background: white; border-radius: 12px; padding: 40px; text-align: center; max-width: 400px; }
.ri-wrap .success-icon { font-size: 3rem; margin-bottom: 16px; }
.ri-wrap .success-box h2 { color: #065f46; margin-bottom: 8px; }
.ri-wrap .success-box p { color: #6b7280; }

.ri-wrap .duplicate-warning { background: #fef3c7; border: 2px solid #f59e0b; border-radius: 10px; padding: 16px 20px; margin-bottom: 16px; }
