/* css/figures-premium.css — refined Figures & tables tab. Everything is scoped to #tab-figures. */

#tab-figures {
  --fx-ui: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --fx-surface: #ffffff;
  --fx-surface-2: #faf7f1;
  --fx-border: rgba(26, 22, 17, 0.09);
  --fx-border-strong: rgba(26, 22, 17, 0.17);
  --fx-ring: rgba(168, 52, 31, 0.14);
  --fx-accent-soft: rgba(168, 52, 31, 0.07);
  --fx-good: #1f7a4d;
  --fx-good-bg: #e3f4ea;
  --fx-warn: #9a6200;
  --fx-warn-bg: #fdf1d8;
  --fx-bad: #9b2c1b;
  --fx-bad-bg: #fbe7e3;
  --fx-radius: 14px;
  --fx-radius-sm: 10px;
  --fx-shadow: 0 1px 2px rgba(26, 22, 17, 0.04), 0 8px 24px -16px rgba(26, 22, 17, 0.18);
  font-family: var(--fx-ui);
}

body.fs-theme-dark #tab-figures {
  --fx-surface: var(--card);
  --fx-surface-2: #16181e;
  --fx-border: rgba(255, 255, 255, 0.07);
  --fx-border-strong: rgba(255, 255, 255, 0.14);
  --fx-ring: rgba(224, 105, 79, 0.22);
  --fx-accent-soft: rgba(224, 105, 79, 0.1);
  --fx-good: #6fd49b;
  --fx-good-bg: rgba(111, 212, 155, 0.12);
  --fx-warn: #f0c26b;
  --fx-warn-bg: rgba(240, 194, 107, 0.12);
  --fx-bad: #f08a76;
  --fx-bad-bg: rgba(240, 138, 118, 0.12);
  --fx-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px -16px rgba(0, 0, 0, 0.6);
}

#tab-figures > .panel-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
  max-width: 1180px;
  margin: 0 auto;
}

/* ── Page header ── */
#tab-figures .fx-page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px 24px;
  padding: 4px 2px 2px;
}

#tab-figures .fx-page-title {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 600;
  line-height: 1.2;
  color: var(--ink);
}

#tab-figures .fx-page-lead { margin: 0; font-size: 13.5px; color: var(--muted); }

#tab-figures .fx-stats { display: flex; flex-wrap: wrap; gap: 6px; }

#tab-figures .fx-stat {
  padding: 5px 11px;
  font-size: 12px;
  color: var(--ink-soft);
  background: var(--fx-surface);
  border: 1px solid var(--fx-border);
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}

#tab-figures .fx-stat--good { color: var(--fx-good); background: var(--fx-good-bg); border-color: transparent; }
#tab-figures .fx-stat--warn { color: var(--fx-warn); background: var(--fx-warn-bg); border-color: transparent; }

/* ── Cards ── */
#tab-figures .card {
  padding: 22px 24px;
  background: var(--fx-surface);
  border: 1px solid var(--fx-border);
  border-radius: var(--fx-radius);
  box-shadow: var(--fx-shadow);
}

#tab-figures .card::before { display: none; }

body.fs-density-compact #tab-figures .card { padding: 16px 18px; }

#tab-figures .fx-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px 20px;
  margin-bottom: 16px;
}

#tab-figures .card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 2px;
  font-family: var(--fx-ui);
  font-size: 15.5px;
  font-weight: 650;
}

#tab-figures .fx-count:not(:empty) {
  padding: 1px 8px;
  font-size: 11.5px;
  font-weight: 650;
  color: var(--ink-soft);
  background: var(--fx-surface-2);
  border: 1px solid var(--fx-border);
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}

#tab-figures .card-hint {
  max-width: 72ch;
  margin-bottom: 0;
  font-family: var(--fx-ui);
  font-size: 12.5px;
  font-style: normal;
  line-height: 1.55;
}

#tab-figures .card-hint code {
  padding: 1px 5px;
  font-size: 11.5px;
  background: var(--fx-surface-2);
  border: 1px solid var(--fx-border);
  border-radius: 5px;
}

#tab-figures .fx-empty {
  margin: 0;
  padding: 18px;
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
  color: var(--muted);
  background: var(--fx-surface-2);
  border: 1px dashed var(--fx-border-strong);
  border-radius: var(--fx-radius-sm);
}

/* ── Buttons ── */
#tab-figures .btn-primary,
#tab-figures .btn-ghost {
  min-height: 36px;
  padding: 7px 14px;
  border-radius: var(--fx-radius-sm);
  font-family: var(--fx-ui);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: normal;
  text-transform: none;
  white-space: nowrap;
}

#tab-figures .btn-ghost { background: var(--fx-surface); border-color: var(--fx-border-strong); }
#tab-figures .btn-ghost:hover { background: var(--fx-surface-2); }

#tab-figures .btn-tiny {
  min-height: 30px;
  padding: 4px 11px !important;
  font-size: 12px !important;
  border-radius: 8px;
}

body.fs-theme-dark #tab-figures .btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }

#tab-figures .fx-icon-btn {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  font: 500 15px/1 var(--fx-ui);
  color: var(--ink-soft);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}

#tab-figures .fx-icon-btn:hover:not(:disabled) {
  color: var(--ink);
  background: var(--fx-surface-2);
  border-color: var(--fx-border);
}

#tab-figures .fx-icon-btn:disabled { opacity: 0.3; cursor: default; }
#tab-figures .fx-icon-btn--danger { font-size: 18px; color: var(--fx-bad); }
#tab-figures .fx-icon-btn--danger:hover:not(:disabled) { color: var(--fx-bad); background: var(--fx-bad-bg); border-color: transparent; }

/* ── Pills ── */
#tab-figures .fx-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
  border-radius: 999px;
}

#tab-figures .fx-pill[hidden] { display: none; }
#tab-figures .fx-pill--good { color: var(--fx-good); background: var(--fx-good-bg); }
#tab-figures .fx-pill--warn { color: var(--fx-warn); background: var(--fx-warn-bg); }
#tab-figures .fx-pill--muted { color: var(--muted); background: var(--fx-surface-2); border: 1px solid var(--fx-border); }

/* ── Inputs ── */
#tab-figures input[type="text"],
#tab-figures textarea {
  width: 100%;
  min-height: 38px;
  padding: 8px 11px;
  background: var(--fx-surface);
  border: 1px solid var(--fx-border-strong);
  border-radius: var(--fx-radius-sm);
  font-family: var(--fx-ui);
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--ink);
  box-sizing: border-box;
}

#tab-figures textarea { resize: vertical; }

#tab-figures input[type="text"]:focus,
#tab-figures textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--fx-ring);
}

#tab-figures input::placeholder,
#tab-figures textarea::placeholder { color: var(--muted); opacity: 0.65; }

#tab-figures .fx-field-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-family: var(--fx-ui);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: normal;
  text-transform: none;
  color: var(--ink);
}

/* Switch-style checkbox */
#tab-figures .fx-switch {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-family: var(--fx-ui);
  font-size: 12.5px;
  font-weight: 500;
  letter-spacing: normal;
  text-transform: none;
  color: var(--ink-soft);
  cursor: pointer;
}

#tab-figures .fx-switch input {
  appearance: none;
  position: relative;
  flex: none;
  width: 34px;
  height: 20px;
  margin: 0;
  background: var(--fx-border-strong);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s;
}

#tab-figures .fx-switch input::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  transition: transform 0.15s;
}

#tab-figures .fx-switch input:checked { background: var(--accent); }
#tab-figures .fx-switch input:checked::after { transform: translateX(14px); }
#tab-figures .fx-switch input:focus-visible { box-shadow: 0 0 0 3px var(--fx-ring); }

/* ── Dropzones ── */
#tab-figures .dropzone {
  margin: 14px 0 0;
  padding: 22px 20px;
  background: var(--fx-surface-2);
  border: 1.5px dashed var(--fx-border-strong);
  border-radius: var(--fx-radius-sm);
  transition: border-color 0.15s, background 0.15s;
}

#tab-figures .dropzone:hover,
#tab-figures .dropzone.drag,
#tab-figures .dropzone:focus-visible {
  outline: none;
  border-color: var(--accent);
  background: var(--fx-accent-soft);
}

#tab-figures .dz-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin: 0 auto 8px;
  font-size: 20px;
  color: var(--accent);
  background: var(--fx-surface);
  border: 1px solid var(--fx-border);
  border-radius: 12px;
}

#tab-figures .dz-text { font-size: 13.5px; font-weight: 600; color: var(--ink); }
#tab-figures .dz-link { text-decoration: none; border-bottom: 1px solid currentColor; }
#tab-figures .dz-meta { margin-top: 4px; font-family: var(--fx-ui); font-size: 12px; letter-spacing: normal; color: var(--muted); }

/* ── Figure cards ── */
#tab-figures .figures-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 0;
}

#tab-figures .figure-card {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 18px;
  padding: 14px;
  background: var(--fx-surface);
  border: 1px solid var(--fx-border);
  border-radius: 12px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

#tab-figures .figure-card:focus-within { border-color: var(--fx-border-strong); box-shadow: 0 4px 16px -10px rgba(26, 22, 17, 0.3); }
#tab-figures .figure-card.is-missing-caption { box-shadow: inset 3px 0 0 var(--fx-warn); }

#tab-figures .fx-thumb {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 160px;
  overflow: hidden;
  background-color: var(--fx-surface-2);
  background-image:
    linear-gradient(45deg, var(--fx-border) 25%, transparent 25%),
    linear-gradient(-45deg, var(--fx-border) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--fx-border) 75%),
    linear-gradient(-45deg, transparent 75%, var(--fx-border) 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  border: 1px solid var(--fx-border);
  border-radius: var(--fx-radius-sm);
}

#tab-figures .figure-card .fx-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  max-height: 200px;
  margin: 0;
  object-fit: contain;
  background: transparent;
}

#tab-figures .fx-thumb-replace {
  position: absolute;
  right: 8px;
  bottom: 8px;
  padding: 5px 10px;
  font: 600 11.5px var(--fx-ui);
  color: #fff;
  background: rgba(20, 17, 13, 0.72);
  border: 0;
  border-radius: 7px;
  cursor: pointer;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.15s, transform 0.15s;
}

#tab-figures .fx-thumb:hover .fx-thumb-replace,
#tab-figures .fx-thumb-replace:focus-visible { opacity: 1; transform: none; }

@media (hover: none) {
  #tab-figures .fx-thumb-replace { opacity: 1; transform: none; }
}

#tab-figures .fx-fig-body { display: flex; flex-direction: column; gap: 10px; min-width: 0; }

#tab-figures .fx-fig-head,
#tab-figures .table-card-head-left {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

#tab-figures .fx-head-spacer { flex: 1; }

#tab-figures .figure-card .fig-label,
#tab-figures .table-label {
  margin: 0 4px 0 0;
  font-family: var(--fx-ui);
  font-size: 14px;
  font-weight: 650;
  letter-spacing: normal;
  text-transform: none;
  color: var(--ink);
}

#tab-figures .fx-fig-file {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin-top: -4px;
  font-size: 11.5px;
  color: var(--muted);
}

#tab-figures .figure-filename {
  overflow: hidden;
  max-width: 100%;
  font-family: var(--fx-ui);
  font-size: 11.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#tab-figures .fx-fig-dims:not(:empty)::before { content: "·"; margin-right: 12px; }
#tab-figures .fx-fig-file .figure-filename:empty + .fx-fig-dims::before { display: none; }

#tab-figures .figure-meta-fields,
#tab-figures .table-meta-fields {
  display: grid;
  grid-template-columns: minmax(140px, 200px) minmax(0, 1fr);
  gap: 12px;
  margin: 0;
}

#tab-figures .figure-card textarea,
#tab-figures .table-card textarea.table-meta-textarea { min-height: 60px; }

/* ── Table cards ── */
#tab-figures .tables-list { gap: 12px; margin: 0; }

#tab-figures .table-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 16px;
  background: var(--fx-surface);
  border: 1px solid var(--fx-border);
  border-radius: 12px;
}

#tab-figures .table-card.is-missing-caption { box-shadow: inset 3px 0 0 var(--fx-warn); }
#tab-figures .table-card--edit { border-color: var(--accent); box-shadow: 0 0 0 3px var(--fx-ring); }

#tab-figures .table-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin: 0;
}

#tab-figures .fx-table-tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

#tab-figures .fx-step {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px 2px 2px 10px;
  background: var(--fx-surface-2);
  border: 1px solid var(--fx-border);
  border-radius: 10px;
}

#tab-figures .fx-step-label {
  margin-right: 4px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
}

#tab-figures .fx-step .fx-icon-btn { width: 26px; height: 26px; font-size: 13px; }

#tab-figures .table-card .row-edit {
  color: var(--ink);
  background: var(--fx-surface);
  border: 1px solid var(--fx-border-strong);
}

#tab-figures .table-card .row-edit:hover { color: var(--accent); border-color: var(--accent); background: var(--fx-surface); }

#tab-figures .table-preview-wrap {
  max-height: 320px;
  overflow: auto;
  padding: 10px 12px;
  background: var(--fx-surface-2);
  border: 1px solid var(--fx-border);
  border-radius: var(--fx-radius-sm);
}

#tab-figures .table-preview-wrap table { font-size: 12.5px; }

#tab-figures .table-card--edit .table-label { color: var(--accent); }

#tab-figures .row-save,
#tab-figures .row-cancel { border-radius: 8px; }

/* ── Import tables card ── */
#tab-figures .table-import-panel {
  margin-top: 0;
  padding-top: 22px;
  border-top: 1px solid var(--fx-border);
}

#tab-figures .table-import-panel .fx-switch { margin-bottom: 2px; }

#tab-figures .table-import-meta:empty { display: none; }

#tab-figures .table-import-meta {
  margin-top: 10px;
  padding: 8px 12px;
  font-size: 12.5px;
  color: var(--ink-soft);
  background: var(--fx-surface-2);
  border-radius: 8px;
}

#tab-figures .table-import-meta[data-tone="good"] { color: var(--fx-good); background: var(--fx-good-bg); }
#tab-figures .table-import-meta[data-tone="warn"] { color: var(--fx-warn); background: var(--fx-warn-bg); }
#tab-figures .table-import-meta[data-tone="bad"] { color: var(--fx-bad); background: var(--fx-bad-bg); }

/* ── Responsive ── */
@media (max-width: 760px) {
  #tab-figures .figure-card { grid-template-columns: 1fr; }
  #tab-figures .figure-meta-fields,
  #tab-figures .table-meta-fields { grid-template-columns: 1fr; }
  #tab-figures .fx-page-title { font-size: 22px; }
}

@media (max-width: 900px) {
  #tab-figures > .panel-grid { grid-template-columns: minmax(0, 1fr); }
}
