/* COLIFE 色号工具 - 简洁实用风格,车间/移动端友好 */

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #f5f6f8;
  color: #222;
  line-height: 1.5;
  padding: 16px;
  max-width: 1100px;
  margin: 0 auto;
}

header {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 16px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.04);
}

header h1 {
  font-size: 28px;
  color: #0F2A47;
  margin-bottom: 4px;
}

.subtitle {
  color: #666;
  font-size: 14px;
  margin-bottom: 12px;
}

.legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  align-items: center;
  font-size: 14px;
  color: #555;
}

.swatch {
  display: inline-block;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  color: #fff;
  text-align: center;
  line-height: 28px;
  font-weight: bold;
  font-size: 13px;
  font-family: monospace;
  margin-right: 4px;
}

.swatch.big {
  width: 36px;
  height: 36px;
  line-height: 36px;
  font-size: 16px;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 4px;
  background: #fff;
  border-radius: 12px 12px 0 0;
  padding: 8px 8px 0;
  box-shadow: 0 -2px 6px rgba(0,0,0,0.04);
}

.tab-btn {
  flex: 1;
  background: #eef0f3;
  border: none;
  padding: 14px 12px;
  font-size: 15px;
  font-weight: 500;
  color: #555;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  transition: all 0.15s;
}

.tab-btn:hover { background: #e0e4ea; }
.tab-btn.active {
  background: #0F2A47;
  color: #fff;
}

/* Tab panes */
main {
  background: #fff;
  border-radius: 0 0 12px 12px;
  padding: 24px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.04);
  min-height: 500px;
}

.tab-pane { display: none; }
.tab-pane.active { display: block; }

.tab-pane h2 {
  font-size: 20px;
  color: #0F2A47;
  margin-bottom: 16px;
}

/* Encode header: title + compact row on the same line */
.encode-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.encode-header h2 {
  margin-bottom: 0;
  flex-shrink: 0;
}

.encode-header .compact-row {
  flex: 1;
  min-width: 200px;
  margin: 0;
  padding: 6px 10px;
  background: #fffbe6;
  border: 1px solid #f0c800;
  border-radius: 6px;
  border-bottom: none;
}

.encode-header .compact-row code {
  border: none;
  background: transparent;
  padding: 0;
  font-size: 18px;
  font-weight: bold;
  color: inherit;  /* pick up white/black from the parent's dynamic style */
}

/* Collapsible section (recipe total) */
.output-box.collapsible {
  padding: 0;
}

.output-box.collapsible details {
  width: 100%;
}

.output-box.collapsible summary {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.output-box.collapsible summary::-webkit-details-marker {
  display: none;
}

.output-box.collapsible summary::before {
  content: '▶';
  display: inline-block;
  font-size: 11px;
  color: #888;
  transition: transform 0.15s;
}

.output-box.collapsible details[open] summary::before {
  transform: rotate(90deg);
}

.output-box.collapsible summary .summary-label {
  font-weight: 500;
  color: #555;
  font-size: 14px;
}

.output-box.collapsible summary code.big-code {
  font-size: 16px;
  font-weight: bold;
  padding: 4px 10px;
}

.output-box.collapsible details > div,
.output-box.collapsible details > .formula-preview {
  padding: 0 16px 14px 36px;
}

.output-box.collapsible details > .output-row {
  padding: 6px 0;
  border-bottom: 1px dashed #e0e3e8;
}

.output-box.collapsible details > .output-row:last-of-type {
  border-bottom: none;
}

.tab-pane h2 .hint {
  font-size: 13px;
  color: #888;
  font-weight: normal;
  margin-left: 8px;
}

/* recipe-total bar */
.recipe-total-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  margin-bottom: 16px;
  background: #eef3fa;
  border: 1px solid #c5d3e5;
  border-radius: 8px;
}

.recipe-total-bar label {
  font-weight: 500;
  font-size: 14px;
  color: #0F2A47;
  white-space: nowrap;
}

.recipe-total-bar input {
  width: 80px;
  padding: 6px 10px;
  border: 1px solid #b8c5d5;
  border-radius: 6px;
  font-size: 15px;
  font-family: monospace;
  text-align: right;
  background: #fff;
}

.recipe-total-bar input:focus {
  outline: none;
  border-color: #0F2A47;
  box-shadow: 0 0 0 2px rgba(15,42,71,0.15);
}

.recipe-total-bar .hint {
  font-size: 12px;
  color: #5b6b80;
}

/* ENCODE: color rows */
.color-inputs {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

.color-row {
  display: grid;
  grid-template-columns: 50px 80px 100px 1fr 60px;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: #fafbfc;
  border-radius: 8px;
  border: 1px solid #e8eaed;
}

.color-row label {
  font-weight: 500;
  font-size: 14px;
}

.color-row input.amount {
  padding: 8px 10px;
  border: 1px solid #d0d4da;
  border-radius: 6px;
  font-size: 15px;
  font-family: monospace;
  text-align: right;
}

.color-row input.amount:focus {
  outline: none;
  border-color: #0F2A47;
  box-shadow: 0 0 0 2px rgba(15,42,71,0.15);
}

.color-row input.amount.invalid {
  border-color: #c62828;
  background: #ffebee;
  color: #b71c1c;
}

.color-row input[type="range"] {
  width: 100%;
  accent-color: #888;
}

/* Slider fill color matches the row's color swatch. */
.color-row[data-color="R"] input[type="range"] { accent-color: #740117; }
.color-row[data-color="Y"] input[type="range"] { accent-color: #A08000; }
.color-row[data-color="K"] input[type="range"] { accent-color: #424242; }
.color-row[data-color="B"] input[type="range"] { accent-color: #1E88E5; }
.color-row[data-color="G"] input[type="range"] { accent-color: #184813; }

.color-row .value-display {
  text-align: right;
  font-family: monospace;
  font-size: 14px;
  color: #333;
  font-weight: 500;
  white-space: nowrap;
}

.color-row .value-display .pct {
  display: inline-block;
  margin-left: 4px;
  padding: 2px 8px;
  color: #fff;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  background: #888; /* default fallback */
}

/* Percent badge matches the row's color swatch. */
.color-row[data-color="R"] .value-display .pct { background: #740117; }
.color-row[data-color="Y"] .value-display .pct { background: #FDD835; color: #333; }
.color-row[data-color="K"] .value-display .pct { background: #212121; }
.color-row[data-color="B"] .value-display .pct { background: #1E88E5; }
.color-row[data-color="G"] .value-display .pct { background: #184813; }

/* output box */
.output-box {
  background: #f8f9fb;
  border: 1px solid #e8eaed;
  border-radius: 10px;
  padding: 16px;
  margin-top: 16px;
}

.output-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px dashed #e0e3e8;
}

.output-row:last-child { border-bottom: none; }

.output-label {
  font-weight: 500;
  color: #555;
  min-width: 140px;
  font-size: 14px;
}

code, .big-code {
  font-family: "SF Mono", Consolas, monospace;
  background: #fff;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid #d0d4da;
  font-size: 15px;
  color: #0F2A47;
  flex: 1;
  word-break: break-all;
}

.big-code {
  font-size: 18px;
  font-weight: bold;
  padding: 10px 14px;
  background: #fffbe6;
  border-color: #f0c800;
}

/* input groups */
.input-group {
  margin-bottom: 16px;
}

.input-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 500;
  font-size: 14px;
  color: #555;
}

.input-group input[type="text"],
.input-group textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid #d0d4da;
  border-radius: 8px;
  font-size: 16px;
  font-family: "SF Mono", Consolas, monospace;
}

.input-group input[type="text"]:focus,
.input-group textarea:focus {
  outline: none;
  border-color: #0F2A47;
  box-shadow: 0 0 0 2px rgba(15,42,71,0.15);
}

/* buttons */
button {
  font-family: inherit;
}

.copy-btn {
  background: #fff;
  border: 1px solid #d0d4da;
  border-radius: 6px;
  padding: 6px 14px;
  cursor: pointer;
  font-size: 13px;
  color: #555;
  transition: all 0.1s;
}

.copy-btn:hover {
  background: #0F2A47;
  color: #fff;
  border-color: #0F2A47;
}

.copy-btn.copied {
  background: #184813;
  color: #fff;
  border-color: #184813;
}

/* Save button (next to Compact output) */
.save-btn {
  background: #0F2A47;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 6px 14px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  margin-left: 4px;
}
.save-btn:hover { background: #1a3d6b; }
.save-btn:disabled {
  background: #ccc;
  cursor: not-allowed;
}

/* Inline name input (shown when user clicks Save) */
.save-name-row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-left: 6px;
}
.save-name-row input {
  width: 140px;
  padding: 4px 8px;
  border: 1px solid #f0c800;
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
}
.save-name-row button {
  padding: 4px 10px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}
.save-name-row .confirm { background: #184813; color: #fff; }
.save-name-row .cancel { background: #ddd; color: #333; }

/* Transient message under save button (e.g. duplicate warning) */
.save-msg {
  display: inline-block;
  margin-left: 8px;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 13px;
  background: #fff8e1;
  color: #5d4037;
  border: 1px solid #ffe0b2;
}
.save-msg.err {
  background: #ffebee;
  color: #b71c1c;
  border-color: #ffcdd2;
}

/* Records list */
.records-box { margin-top: 12px; }
.records-count {
  display: inline-block;
  background: #0F2A47;
  color: #fff;
  border-radius: 12px;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 600;
  margin-left: 8px;
}
.records-list { padding: 0 16px; }
.record-row {
  display: grid;
  grid-template-columns: 140px 28px 1fr 200px 70px;
  gap: 12px;
  align-items: center;
  padding: 10px 4px;
  border-bottom: 1px dashed #e0e3e8;
  font-size: 14px;
}
.record-row:last-child { border-bottom: none; }
.record-row .rec-date {
  color: #888;
  font-family: monospace;
  font-size: 12px;
}
.record-row .rec-code {
  font-family: "SF Mono", Consolas, monospace;
  font-weight: 500;
  color: #0F2A47;
  word-break: break-all;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 3px;
  transition: background 0.1s;
}
.record-row .rec-code:hover {
  background: #e8eaed;
}

.record-row .rec-swatch {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  border: 1px solid rgba(0,0,0,0.15);
  display: inline-block;
  flex-shrink: 0;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
}
.record-row .rec-swatch:hover {
  transform: scale(1.2);
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}
.record-row .rec-code {
  font-family: "SF Mono", Consolas, monospace;
  font-weight: 500;
  color: #0F2A47;
  word-break: break-all;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 3px;
  transition: background 0.1s;
}
.record-row .rec-code:hover {
  background: #e8eaed;
}
.record-row .rec-name {
  font-weight: 500;
  color: #222;
  cursor: text;
  padding: 4px 6px;
  border-radius: 4px;
  border: 1px solid transparent;
}
.record-row .rec-name:hover { background: #f5f6f8; }
.record-row .rec-name:focus {
  background: #fff;
  border-color: #0F2A47;
  outline: none;
}
.record-row .rec-actions {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
}
.record-row .rec-delete {
  background: transparent;
  border: 1px solid #ddd;
  color: #c62828;
  border-radius: 4px;
  padding: 3px 8px;
  cursor: pointer;
  font-size: 12px;
}
.record-row .rec-delete:hover {
  background: #c62828;
  color: #fff;
  border-color: #c62828;
}

.record-row .rec-archive {
  background: #0F2A47;
  border: 1px solid #0F2A47;
  color: #fff;
  border-radius: 4px;
  padding: 3px 8px;
  cursor: pointer;
  font-size: 12px;
}
.record-row .rec-archive:hover { background: #1a3d6b; border-color: #1a3d6b; }

/* Archive rows: no date column, simpler grid */
.record-row.archive-row {
  grid-template-columns: 28px 1fr 1fr 70px;
}
.records-actions {
  display: flex;
  gap: 8px;
  padding: 10px 16px 14px 36px;
  border-top: 1px solid #e8eaed;
}
@media (max-width: 720px) {
  .record-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}

.primary-btn {
  background: #0F2A47;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 24px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 500;
}

.primary-btn:hover { background: #1a3d6b; }

/* formula preview */
.formula-preview {
  margin-top: 12px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 13px;
}

.formula-preview .seg {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  background: #fff;
  border-radius: 4px;
  border: 1px solid #e0e3e8;
}

.formula-preview .seg .swatch {
  width: 18px;
  height: 18px;
  line-height: 18px;
  font-size: 11px;
  margin-right: 0;
}

/* decode/compare/rank results */
.placeholder {
  color: #999;
  text-align: center;
  padding: 24px;
  font-style: italic;
}

.result-success {
  color: #1b5e20;
}

.result-error {
  color: #c62828;
  background: #ffebee;
  padding: 10px 14px;
  border-radius: 6px;
  border: 1px solid #ffcdd2;
}

.metric {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px dashed #e0e3e8;
}

.metric:last-child { border-bottom: none; }

.metric-label {
  color: #666;
  font-size: 14px;
}

.metric-value {
  font-family: "SF Mono", Consolas, monospace;
  font-weight: 500;
  color: #0F2A47;
}

.rank-row {
  display: grid;
  grid-template-columns: 30px 1fr 80px 80px 1fr;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px dashed #e0e3e8;
  font-size: 14px;
}

.rank-row:last-child { border-bottom: none; }

.rank-row .rank-num {
  font-family: monospace;
  color: #888;
  text-align: center;
}

.rank-row .rank-code {
  font-family: "SF Mono", Consolas, monospace;
  font-weight: 500;
  color: #0F2A47;
}

.rank-row .rank-sim {
  font-family: monospace;
  text-align: right;
  color: #184813;
  font-weight: 500;
}

.rank-row .rank-dist {
  font-family: monospace;
  text-align: right;
  color: #888;
}

.rank-row .rank-bar {
  height: 8px;
  background: #e8eaed;
  border-radius: 4px;
  overflow: hidden;
}

.rank-row .rank-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #184813, #0d2c0a);
  transition: width 0.3s;
}

/* rank options */
.rank-options {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.rank-options label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: #555;
}

.rank-options input[type="number"] {
  width: 70px;
  padding: 6px 10px;
  border: 1px solid #d0d4da;
  border-radius: 6px;
  font-size: 14px;
  font-family: monospace;
}

/* ===== 调色预览 (swatch grid + white mixer) ===== */
.base-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.base-row label {
  margin-bottom: 0;
  white-space: nowrap;
  font-weight: 500;
  color: #555;
  font-size: 14px;
}
.base-row select {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid #d0d4da;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
}
.base-row select:focus {
  outline: none;
  border-color: #0F2A47;
  box-shadow: 0 0 0 2px rgba(15,42,71,0.15);
}

.white-mixer-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.white-mixer-row input[type="range"] {
  flex: 1;
  accent-color: #888;
}
.white-mixer-value {
  display: inline-block;
  min-width: 0;
  width: 80px !important;
  max-width: 80px;
  box-sizing: border-box;
  padding: 4px 8px;
  background: #f5f6f8;
  border: 1px solid #d0d4da;
  border-radius: 4px;
  font-family: monospace;
  font-size: 12px;
  text-align: center;
}
.white-mixer-value:focus {
  outline: none;
  border-color: #0F2A47;
  background: #fff;
  box-shadow: 0 0 0 2px rgba(15,42,71,0.15);
}

.swatch-grid {
  margin-top: 16px;
}
.swatch-grid-inner {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
}
.swatch-tile {
  aspect-ratio: 1 / 1.2;
  border-radius: 8px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 10px;
  font-size: 12px;
  font-weight: 500;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.4);
  border: 2px solid transparent;
  transition: transform 0.1s, box-shadow 0.1s;
}
.swatch-tile.active {
  border-color: #0F2A47;
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(15,42,71,0.3);
}
.swatch-tile .swatch-label {
  background: rgba(0,0,0,0.35);
  padding: 2px 8px;
  border-radius: 4px;
}

.archive-context {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px dashed #e0e3e8;
}
.archive-context-label {
  font-size: 12px;
  color: #888;
  margin-bottom: 8px;
}
.archive-context-grid {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.archive-context-tile {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  border: 1px solid rgba(0,0,0,0.15);
  cursor: help;
  transition: transform 0.1s;
}
.archive-context-tile:hover {
  transform: scale(1.15);
}

/* Large live swatch (current white-slider value) */
.current-swatch {
  margin-top: 16px;
  width: 100%;
  height: 360px;
  border-radius: 12px;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  padding: 0 24px 20px 0;
  color: #fff;
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
  border: 2px solid rgba(0,0,0,0.1);
  transition: background 0.15s;
}
.current-swatch-label {
  font-size: 28px;
  font-weight: 600;
}

@media (max-width: 720px) {
  .swatch-grid-inner { grid-template-columns: repeat(3, 1fr); }
}

/* footer */
footer {
  margin-top: 24px;
  padding: 16px;
  text-align: center;
  font-size: 12px;
  color: #999;
  line-height: 1.6;
}

/* diff visualization */
.diff-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
  font-size: 14px;
}

.diff-table th, .diff-table td {
  padding: 8px 12px;
  text-align: center;
  border-bottom: 1px solid #e8eaed;
}

.diff-table th {
  background: #f5f6f8;
  color: #555;
  font-weight: 500;
}

.diff-positive { color: #1B5E20; }
.diff-negative { color: #B71C1C; }
.diff-zero { color: #999; }

.note-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

.note-almost { background: #C8E6C9; color: #1B5E20; }
.note-close   { background: #DCEDC8; color: #33691E; }
.note-notice  { background: #FFF9C4; color: #F57F17; }
.note-signif  { background: #FFE0B2; color: #E65100; }
.note-diff    { background: #FFCDD2; color: #B71C1C; }

/* mobile */
@media (max-width: 720px) {
  .color-row {
    grid-template-columns: 36px 1fr;
    grid-template-areas: "swatch label" "swatch input" "swatch slider" "swatch display";
    row-gap: 6px;
  }
  .color-row .swatch { grid-area: swatch; }
  .color-row label { grid-area: label; }
  .color-row input[type="number"] { grid-area: input; }
  .color-row input[type="range"] { grid-area: slider; }
  .color-row .value-display { grid-area: display; text-align: left; }
  .rank-row {
    grid-template-columns: 25px 1fr 60px;
    grid-template-areas: "num code sim" "num bar bar";
    row-gap: 4px;
  }
  .rank-row .rank-num { grid-area: num; }
  .rank-row .rank-code { grid-area: code; }
  .rank-row .rank-sim { grid-area: sim; }
  .rank-row .rank-bar { grid-area: bar; }
  .rank-row .rank-dist { display: none; }
}
