/* components.css — buttons, badge, modal, toast, stats, toggle, info note */

/* ================================================================
   BUTTONS
   ================================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius);
  transition: background .15s, opacity .15s;
  white-space: nowrap;
  line-height: 1;
}
.btn:hover { opacity: .88; }
.btn:active { opacity: .75; }
.btn:disabled { opacity: .4; pointer-events: none; }

.btn svg {
  width: 15px;
  height: 15px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

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

.btn-danger {
  background: var(--red-dim);
  color: var(--red);
}
.btn-danger:hover { background: var(--red); color: #fff; }

.btn-ghost {
  background: transparent;
  color: var(--text2);
}
.btn-ghost:hover { background: var(--bg3); color: var(--text); }

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

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  background: transparent;
  color: var(--text3);
  border-radius: 6px;
}
.btn-icon:hover { background: var(--bg3); color: var(--text); }

/* ================================================================
   BADGE
   ================================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 20px;
  line-height: 1;
  white-space: nowrap;
}

.badge-blue  { background: var(--accent-dim); color: var(--accent); }
.badge-green { background: var(--green-dim);  color: var(--green);  }
.badge-amber { background: var(--amber-dim);  color: var(--amber);  }
.badge-red   { background: var(--red-dim);    color: var(--red);    }
.badge-gray  { background: var(--bg3);        color: var(--text3);  }

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.dot-green { background: var(--green); }
.dot-amber { background: var(--amber); }
.dot-red   { background: var(--red); }
.dot-blue  { background: var(--accent); }
.dot-gray  { background: var(--text3); }

/* ================================================================
   MODAL
   ================================================================ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 24px;
}
.modal-backdrop[hidden] { display: none !important; }
.modal {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-lg, 12px);
  width: 100%;
  max-width: 600px;
  /* Stała wysokość — modal nie skacze przy zmianie taba */
  height: 90vh;
  max-height: 780px;
  /* Flex-kolumna: header zafixowany, body scrolluje, footer zafixowany */
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modal-in .15s ease;
}
/* Szerszy modal (opts.wide) */
.modal[style*="800px"] {
  max-width: 800px;
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(-8px) scale(.98); }
  to   { opacity: 1; transform: none; }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;  /* nigdy się nie kurczy */
}
.modal-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--heading);
}
.modal-body {
  padding: 20px;
  overflow-y: auto;   /* scroll tylko tu */
  flex: 1;            /* zajmuje całą wolną przestrzeń */
  min-height: 0;      /* konieczne żeby flex-child mógł się kurczyć */
}
/* Scrollbar w modal-body — subtelny */
.modal-body::-webkit-scrollbar { width: 5px; }
.modal-body::-webkit-scrollbar-track { background: transparent; }
.modal-body::-webkit-scrollbar-thumb {
  background: var(--border2);
  border-radius: 3px;
}
.modal-body::-webkit-scrollbar-thumb:hover {
  background: var(--text3);
}

/* ================================================================
   TOAST
   ================================================================ */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 2000;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  pointer-events: auto;
  animation: toast-in .25s ease-out;
  max-width: 360px;
}

.toast-success { border-left: 3px solid var(--green); }
.toast-error   { border-left: 3px solid var(--red); }
.toast-info    { border-left: 3px solid var(--accent); }

.toast svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.toast-success svg { stroke: var(--green); }
.toast-error svg   { stroke: var(--red); }
.toast-info svg    { stroke: var(--accent); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px) translateX(10px); }
  to   { opacity: 1; transform: translateY(0) translateX(0); }
}

/* ================================================================
   STAT CARDS
   ================================================================ */
.stats-row {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
}

.stat-card {
  flex: 1;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-card-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text3);
}

.stat-card-value {
  font-size: 24px;
  font-weight: 600;
  font-family: var(--mono);
  color: var(--heading);
  line-height: 1.2;
}

/* ================================================================
   TOGGLE (boolean switch)
   ================================================================ */
.toggle {
  position: relative;
  width: 36px;
  height: 20px;
  background: var(--border2);
  border-radius: 12px;
  cursor: pointer;
  transition: background .2s;
  flex-shrink: 0;
}

.toggle::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text3);
  transition: transform .2s, background .2s;
}

.toggle.on {
  background: var(--accent);
}
.toggle.on::after {
  transform: translateX(16px);
  background: #fff;
}

/* ================================================================
   INFO NOTE
   ================================================================ */
.info-note {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--accent-dim);
  border: 1px solid var(--accent-hover);
  font-size: 12px;
  line-height: 1.55;
  color: var(--text2);
}

.info-note svg {
  width: 16px;
  height: 16px;
  stroke: var(--accent);
  fill: none;
  stroke-width: 2;
  flex-shrink: 0;
  margin-top: 1px;
}

/* ================================================================
   MEDIA WIDGET
   ================================================================ */
.mw-container {
  background: var(--bg3);
  border: 2px dashed var(--border2);
  border-radius: 8px;
  padding: 14px;
  transition: border-color .15s;
  min-height: 76px;
}
.mw-container:hover { border-color: var(--accent); }
.mw-container.has-file {
  background: var(--bg2);
  border-style: solid;
  border-color: var(--border);
}
.mw-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 6px;
  text-align: center;
  color: var(--text3);
  font-size: 12px;
}
.mw-empty svg { width: 26px; height: 26px; stroke: var(--text3); fill: none; }
.mw-upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 5px;
  padding: 5px 12px;
  font-size: 12px;
  font-family: var(--mono);
  color: var(--accent);
  cursor: pointer;
  transition: background .15s;
}
.mw-upload-btn:hover { background: var(--accent-dim); }
.mw-preview {
  display: flex;
  align-items: center;
  gap: 12px;
}
.mw-preview-img {
  width: 120px;
  height: 80px;
  object-fit: cover;
  border-radius: 5px;
  border: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg3);
}
.mw-preview-info { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.mw-preview-name {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--heading);
  word-break: break-all;
}
.mw-preview-actions { display: flex; gap: 6px; }
.mw-btn-replace {
  font-size: 11px;
  font-family: var(--mono);
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 4px;
  padding: 3px 9px;
  cursor: pointer;
  color: var(--text2);
}
.mw-btn-replace:hover { color: var(--accent); border-color: var(--accent); }
.mw-btn-remove {
  font-size: 11px;
  font-family: var(--mono);
  background: var(--red-dim);
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 3px 9px;
  cursor: pointer;
  color: var(--red);
}
.mw-btn-remove:hover { background: var(--red); color: #fff; }
/* pdf list */
.mw-pdf-list { display: flex; flex-direction: column; gap: 5px; }
.mw-pdf-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 6px 10px;
}
.mw-pdf-item svg { width: 14px; height: 14px; stroke: var(--amber); fill: none; flex-shrink: 0; }
.mw-pdf-name { flex: 1; font-family: var(--mono); font-size: 11px; color: var(--text); word-break: break-all; }
.mw-pdf-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text3);
  font-size: 15px;
  line-height: 1;
  padding: 0 2px;
}
.mw-pdf-remove:hover { color: var(--red); }
/* image multi grid */
.mw-multi-grid { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 2px; }
.mw-multi-item { position: relative; width: 110px; }
.mw-multi-item img {
  width: 110px;
  height: 75px;
  object-fit: cover;
  border-radius: 5px;
  border: 1px solid var(--border);
  display: block;
}
.mw-multi-name {
  display: block;
  font-family: var(--mono);
  font-size: 9px;
  color: var(--text3);
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mw-multi-remove {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 18px;
  height: 18px;
  background: rgba(0,0,0,.55);
  color: #fff;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.mw-multi-remove:hover { background: var(--red); }
/* upload spinner */
.mw-uploading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px;
  color: var(--text3);
  font-size: 12px;
}
.mw-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: mw-spin .7s linear infinite;
}
@keyframes mw-spin { to { transform: rotate(360deg); } }

/* ================================================================
   RELATION WIDGET
   ================================================================ */
.rw-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.rw-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 20px;
}
.rw-empty {
  font-size: 12px;
  color: var(--text3);
  padding: 4px 0;
  font-style: italic;
}
.rw-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 13px;
  transition: border-color .12s;
}
.rw-item:hover { border-color: var(--border2); }
.rw-art-nr {
  font-family: var(--mono);
  font-size: 11px;
  background: rgba(37,99,235,.1);
  color: var(--accent);
  padding: 1px 6px;
  border-radius: 3px;
  flex-shrink: 0;
}
html.dark .rw-art-nr { background: rgba(79,142,247,.15); }
.rw-name {
  flex: 1;
  font-size: 12px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rw-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text3);
  font-size: 16px;
  line-height: 1;
  padding: 0 2px;
  flex-shrink: 0;
  transition: color .12s;
}
.rw-remove:hover { color: var(--red); }
.rw-search-wrap { position: relative; }
.rw-search-row  { position: relative; }
.rw-search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 13px;
  height: 13px;
  color: var(--text3);
  pointer-events: none;
}
.rw-search-input {
  width: 100%;
  padding: 8px 12px 8px 30px;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 6px;
  font-size: 13px;
  color: var(--text);
  font-family: var(--sans);
  outline: none;
  transition: border-color .15s;
  box-sizing: border-box;
}
.rw-search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
html.dark .rw-search-input:focus { box-shadow: 0 0 0 3px rgba(79,142,247,.15); }
.rw-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,.08);
  z-index: 100;
  overflow: hidden;
}
html.dark .rw-dropdown { box-shadow: 0 4px 16px rgba(0,0,0,.4); }
.rw-dd-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  transition: background .1s;
  font-size: 13px;
}
.rw-dd-item:hover { background: var(--bg3); }
.rw-dd-item + .rw-dd-item { border-top: 1px solid var(--border); }
.rw-dd-name {
  flex: 1;
  color: var(--text2);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rw-dd-empty {
  padding: 10px 12px;
  font-size: 12px;
  color: var(--text3);
  font-style: italic;
}

/* ================================================================
   FORM TABS
   ================================================================ */
.form-tabs {
  display: flex;
  gap: 28px;
  border-bottom: 1.5px solid var(--border);
  margin-bottom: 20px;
}
.form-tab {
  position: relative;
  padding: 0 0 10px;
  font-size: 13px;
  font-family: var(--sans);
  font-weight: 400;
  color: var(--text3);
  background: none;
  border: none;
  cursor: pointer;
  transition: color .15s;
  white-space: nowrap;
  outline: none;
  text-decoration: none !important;
  -webkit-text-decoration: none !important;
  text-decoration-line: none !important;
}
.form-tab:hover {
  color: var(--text2);
}
.form-tab:focus,
.form-tab:focus-visible {
  outline: none;
}
.form-tab::after {
  content: '';
  position: absolute;
  bottom: -1.5px;
  left: 0;
  right: 0;
  height: 3px;
  background: transparent;
  transition: background .15s;
}
.form-tab.active {
  color: var(--accent);
  font-weight: 500;
}
.form-tab.active::after {
  background: var(--accent);
}
.form-tab-content {
  /* display toggled by JS */
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg2);
  flex-shrink: 0;
}
