/* --- STEPPER UI --- */
.stepper-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 30px; position: relative; padding: 0 20px; }
.stepper-header::before { content: ''; position: absolute; top: 50%; left: 40px; right: 40px; height: 2px; background: #333; z-index: 0; }
.step-indicator { width: 35px; height: 35px; border-radius: 50%; background: #1a1a1a; border: 2px solid #333; display: flex; align-items: center; justify-content: center; font-weight: bold; color: #666; position: relative; z-index: 1; transition: 0.3s; }
.step-indicator.active { border-color: var(--accent-gold); color: var(--accent-gold); background: #2a2211; box-shadow: 0 0 10px rgba(197, 160, 89, 0.3); }
.step-indicator.completed { border-color: #4ade80; color: #4ade80; background: #0a3622; }
.step-label { position: absolute; top: 45px; width: 100px; text-align: center; font-size: 11px; left: -32px; color: #888; }
.step-indicator.active .step-label { color: var(--text-main); font-weight: bold; }

.step-container { display: none; animation: fadeIn 0.3s ease-in-out; }
.step-container.active { display: block; }

.stepper-footer { display: flex; justify-content: space-between; margin-top: 40px; padding-top: 20px; border-top: 1px solid #333; }
.btn-secondary { background: transparent; border: 1px solid #555; color: #a1a1aa; width: auto; padding: 12px 24px; margin-top: 0; }
.btn-secondary:hover { background: #222; color: #fff; border-color: #888; }
.btn-primary { width: auto; padding: 12px 30px; margin-top: 0; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

:root {
    --bg-main: #121212;
    --bg-card: #1e1e1e;
    --bg-input: #2d2d2d;
    --bg-disabled: #262626;
    --text-main: #e0e0e0;
    --text-muted: #8c8c8c;
    --text-disabled: #777;
    --accent-gold: #c5a059;
    --accent-hover: #e0b86b;
    --border-dark: #333;
}

body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background-color: var(--bg-main); color: var(--text-main); line-height: 1.6; margin: 0; padding: 40px 20px; }
.container { max-width: 1000px; margin: auto; background-color: var(--bg-card); padding: 30px 40px; border-radius: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8); border: 1px solid var(--border-dark); }

.hidden { display: none !important; }

/* Landing Page Cards */
.mode-card { background: #1a1a1a; border: 2px solid #333; border-radius: 12px; padding: 30px; cursor: pointer; transition: 0.2s; text-align: center; }
.mode-card:hover { border-color: var(--accent-gold); transform: translateY(-5px); box-shadow: 0 10px 20px rgba(0,0,0,0.5); }
/* In-card action buttons (Import from Template card): secondary-action pattern, matching
   .mke-modal-btn — normal weight, dark background — sized to sit inside a mode card. */
.mode-card-action { flex: 1; width: auto; margin-top: 0; padding: 8px 10px; font-size: 12px; background: var(--bg-input); color: var(--text-main); border: 1px solid var(--border-dark); text-transform: none; letter-spacing: 0; font-weight: normal; }
.mode-card-action:hover { background: #383838; }
.mode-icon { font-size: 48px; margin-bottom: 15px; }
.mode-card h3 { color: var(--accent-gold); margin: 0 0 10px 0; font-size: 24px; }
.mode-card p { color: var(--text-muted); font-size: 14px; margin: 0; }

.back-btn { background: none; border: none; color: var(--text-muted); padding: 0; margin-bottom: 20px; font-size: 14px; text-transform: none; text-align: left; cursor: pointer; width: auto; font-weight: normal; }
.back-btn:hover { background: none; color: var(--text-main); text-decoration: underline; }

.db-bar { background: #161616; padding: 20px; border-radius: 8px; margin-bottom: 30px; border: 1px solid var(--border-dark); display: flex; align-items: center; border-left: 4px solid var(--accent-gold); }

h1 { color: var(--text-main); font-size: 28px; margin-bottom: 5px; border-bottom: 2px solid var(--accent-gold); padding-bottom: 10px; display: inline-block; }
h2 { color: var(--accent-gold); font-size: 18px; margin-top: 25px; border-bottom: 1px solid var(--border-dark); padding-bottom: 8px; text-transform: uppercase; }
.subtitle { color: var(--text-muted); font-size: 14px; margin-top: -10px; margin-bottom: 20px; }

label { display: block; font-size: 14px; font-weight: 600; color: var(--text-muted); margin-top: 15px; margin-bottom: 5px; }
input[type="number"], input[type="text"], select, textarea { width: 100%; padding: 12px; background-color: var(--bg-input); color: var(--text-main); border: 1px solid var(--border-dark); border-radius: 6px; font-size: 16px; font-family: monospace; box-sizing: border-box; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent-gold); }
textarea { resize: vertical; color: var(--text-main); }

button { width: 100%; padding: 15px; margin-top: 25px; background-color: var(--accent-gold); color: #000; font-weight: bold; font-size: 16px; text-transform: uppercase; border: none; border-radius: 6px; cursor: pointer; transition: 0.2s; }
button:hover { background-color: var(--accent-hover); }

.keying-type-btn.active { background: var(--accent-gold) !important; color: #000 !important; border-color: transparent !important; font-weight: bold; }
input[readonly] { cursor: not-allowed; }

/* Standard key symbol (Worklist 4.1): the industry-coded identity (A, AA, AA1, …) leads every
   key/group label — bold monospace, value-forward, consistent with the bench's data typography. */
.key-symbol { font-family: monospace; font-weight: bold; color: var(--accent-gold); }

.expand-type-btn.active { background: var(--accent-gold) !important; color: #000 !important; border-color: transparent !important; font-weight: bold; }
.expand-type-btn:disabled { opacity: 0.6; cursor: not-allowed; background: var(--bg-disabled) !important; color: var(--text-disabled) !important; }
/* Inline "why this option is unavailable" note rendered inside a disabled expand-type button
   (Worklist 2.3). Warning-yellow matches the audit WARNING palette; sized/cased as body text
   so it reads as an explanation, not a button label. */
.expand-type-btn .expand-type-reason { display: block; margin-top: 8px; font-size: 11px; font-weight: normal; text-transform: none; letter-spacing: 0; line-height: 1.4; color: #facc15; }
.expand-existing-context { opacity: 0.45; }
.expand-existing-context .key-tag { cursor: default; }
.expand-new-badge { display: inline-block; background: #0a3622; color: #4ade80; border: 1px solid #166534; border-radius: 4px; padding: 2px 8px; font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; margin-left: 8px; }
/* RESERVED (Worklist 4.4) — deliberately a different hue (purple) and a dashed tag border, so
   it reads as distinct from the green solid "Added" badge at a glance, not just a text change. */
.reserved-badge { display: inline-block; background: #2a1a3d; color: #c084fc; border: 1px solid #6b21a8; border-radius: 4px; padding: 2px 8px; font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; margin-left: 8px; }
.key-tag.reserved { border-style: dashed; border-color: #6b21a8; color: #c084fc; }
.key-tag.reserved:hover { border-color: #c084fc; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 30px; }

/* --- Chamber/pin-stack visualization — shared by the Pinning Bench matrix and the
   Individual Cylinder View. One bordered container per chamber; pin-stack groups inside
   it are unboxed (no nested border/background), separated by a hairline + whitespace,
   with a thin status-colored accent instead of a full border-left. */
.bench-chamber { background: #161616; border: 1px solid var(--border-dark); border-radius: 8px; margin-bottom: 22px; overflow: hidden; }
.bench-chamber-header { padding: 10px 20px; font-size: 11px; font-weight: 700; color: var(--accent-gold); letter-spacing: 1.5px; text-transform: uppercase; border-bottom: 1px solid var(--border-dark); }

.bench-pin-group { position: relative; padding: 18px 20px 18px 26px; border-bottom: 1px solid rgba(255, 255, 255, 0.06); }
.bench-pin-group:last-child { border-bottom: none; }
.bench-pin-group::before { content: ''; position: absolute; left: 10px; top: 18px; bottom: 18px; width: 3px; border-radius: 2px; background: #4ade80; }
.bench-pin-group.ghosted::before { background: #f87171; }

.bench-pin-row { display: flex; gap: 36px; flex-wrap: wrap; margin-bottom: 12px; }
.bench-pin-stat { display: flex; flex-direction: column; gap: 2px; }
.bench-pin-label { font-size: 10px; font-weight: 700; letter-spacing: 1.2px; color: var(--text-muted); text-transform: uppercase; }
.bench-pin-value { font-family: monospace; font-size: 28px; font-weight: 700; line-height: 1; }
.bench-pin-value.v-bot { color: #facc15; }
.bench-pin-value.v-mas { color: #c084fc; }
.bench-pin-value.v-ctrl { color: #38bdf8; }
.bench-pin-value.v-top { color: #f87171; }

.key-list-header { font-size: 13px; color: var(--text-muted); margin-bottom: 8px; border-bottom: 1px dotted #444; padding-bottom: 4px;}
.tag-container { display: flex; flex-wrap: wrap; gap: 6px; }

.key-tag { background: #000; border: 1px solid #333; color: #a1a1aa; font-family: monospace; font-size: 12px; padding: 4px 8px; border-radius: 4px; cursor: pointer; transition: 0.2s; display: inline-block;}
.key-tag:hover { border-color: var(--accent-gold); color: #fff; }
.key-tag.issued { background: #3b1111; color: #f87171; border-color: #7f1d1d; text-decoration: line-through; opacity: 0.6; }

/* Bench "+N more" overflow: extra cores render up front and are just toggled via CSS, so a
   single delegated click handler (registered once) can expand/collapse them regardless of
   how many times the matrix re-renders. display:contents keeps the wrapper invisible to the
   flex layout so the extra tags wrap normally alongside the visible ones. */
.extra-cores { display: contents; }
.extra-cores.collapsed { display: none; }
.more-toggle { background: #333; }
.more-toggle:hover { background: #444; }

/* --- HIERARCHY TREE (Multi-Tier Property Layout / System Architecture Tree) ---
   Indentation + a single thin guide line carries the nesting, instead of every level
   having its own background fill + border-radius box stacked inside its parent's. */
.tree-folder { margin-left: 16px; margin-top: 6px; padding-left: 16px; border-left: 1px solid rgba(197, 160, 89, 0.35); }
.tree-folder-summary { list-style: none; padding: 8px 0; font-weight: 600; font-size: 14px; color: var(--text-main); cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.tree-folder-summary::-webkit-details-marker { display: none; }
.tree-folder-summary:hover { color: var(--accent-gold); }
.tree-folder-summary .folder-icon { opacity: 0.7; margin-right: 4px; }
.tree-folder-summary .folder-meta { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.8px; white-space: nowrap; }
.folder-master-bitting { font-size: 11px; color: var(--text-muted); font-weight: 400; margin-left: 4px; }
.tree-folder-body { padding-bottom: 4px; }

.tree-door-group { margin-left: 16px; margin-top: 6px; margin-bottom: 10px; padding: 10px 0 4px 16px; border-left: 1px solid rgba(74, 222, 128, 0.45); display: flex; flex-wrap: wrap; gap: 6px; cursor: pointer; }

.tree-root-bar { padding: 14px 18px; background: var(--accent-gold); color: #000; font-weight: bold; border-radius: 8px; cursor: pointer; text-align: center; margin-bottom: 15px; }
.tree-root-bar .root-bitting { font-family: monospace; font-size: 18px; font-weight: 700; margin-left: 6px; }

.key-info-bar { display: flex; gap: 24px; align-items: baseline; flex-wrap: wrap; padding: 12px 16px; background: #1a1a1a; border: 1px solid var(--border-dark); border-radius: 8px; margin-bottom: 15px; }
.key-info-label { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); margin-right: 6px; }
.key-info-value { font-family: monospace; font-size: 18px; font-weight: 700; color: var(--text-main); }
.key-info-value.v-ctrl { color: #38bdf8; }

.stat-strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; background: #1a1a1a; border: 1px solid var(--border-dark); border-radius: 8px; padding: 16px; margin-bottom: 15px; text-align: center; }
.stat-block-label { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); margin-bottom: 6px; }
.stat-block-value { font-family: monospace; font-size: 26px; font-weight: 700; line-height: 1; color: var(--text-main); }
.stat-block-value.v-good { color: #4ade80; }
.stat-block-value.v-bad { color: #f87171; }

/* Job Materials / Stamping List panels (Worklist 4.2/4.3) — collapsible, sits under the bench.
   Border/radius language matches .bench-chamber; header matches .tree-folder-summary. */
.job-panel { margin-top: 20px; background: #161616; border: 1px solid var(--border-dark); border-radius: 8px; overflow: hidden; }
.job-panel-summary { list-style: none; cursor: pointer; padding: 14px 20px; display: flex; align-items: baseline; gap: 10px; font-weight: 700; font-size: 14px; color: var(--accent-gold); text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 1px solid var(--border-dark); }
.job-panel-summary::-webkit-details-marker { display: none; }
.job-panel-summary .job-panel-sub { font-weight: normal; text-transform: none; font-size: 12px; color: var(--text-muted); letter-spacing: 0; }
.job-panel-body { padding: 18px 20px; }
.job-panel-note { font-size: 13px; color: var(--text-muted); margin-bottom: 14px; padding: 10px 12px; background: var(--bg-card); border-left: 3px solid var(--accent-gold); border-radius: 4px; }

.materials-table, .stamping-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.materials-table th, .stamping-table th { text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); padding: 6px 10px; border-bottom: 1px solid var(--border-dark); }
.materials-table td, .stamping-table td { padding: 8px 10px; border-bottom: 1px solid rgba(255,255,255,0.06); font-family: monospace; }
.materials-table td.qty, .stamping-table td.qty { text-align: right; font-weight: 700; color: var(--text-main); }

/* Print isolation for the Stamping List (Worklist 4.3): toggling this class on <body> hides
   everything except #stampingListPrintArea and its descendants, regardless of how deeply the
   panel is nested in the page — the standard "print only this element" pattern. */
@media print {
  .no-print { display: none !important; }
  body.printing-stamping-list * { visibility: hidden; }
  body.printing-stamping-list #stampingListPrintArea,
  body.printing-stamping-list #stampingListPrintArea * { visibility: visible; }
  body.printing-stamping-list #stampingListPrintArea { position: absolute; left: 0; top: 0; width: 100%; padding: 20px; }
}

/* --- CUSTOM MODAL SYSTEM (replaces native alert/confirm/prompt) --- */
.mke-modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.65); display: flex; align-items: center; justify-content: center; z-index: 9999; }
.mke-modal-box { background: var(--bg-card); border: 1px solid var(--border-dark); border-radius: 8px; padding: 20px; max-width: 440px; width: 90%; box-shadow: 0 10px 40px rgba(0,0,0,0.6); }
.mke-modal-title { font-weight: bold; font-size: 15px; margin-bottom: 10px; }
.mke-modal-message { font-size: 13px; color: var(--text-main); white-space: pre-wrap; margin-bottom: 16px; line-height: 1.5; }
.mke-modal-input { margin-bottom: 16px; margin-top: 0; }
.mke-modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.mke-modal-btn { width: auto; padding: 10px 20px; margin-top: 0; background: #2d2d2d; color: var(--text-main); border: 1px solid var(--border-dark); text-transform: none; font-weight: normal; font-size: 14px; }
.mke-modal-btn:hover { background: #383838; }
.mke-modal-btn.primary { background: var(--accent-gold); color: #000; font-weight: bold; border-color: transparent; }
.mke-modal-btn.primary:hover { background: var(--accent-hover); }

/* Cross-keying (Worklist 4.5) — searchable multi-select modal body */
.mke-modal-multiselect-list { max-height: 220px; overflow-y: auto; border: 1px solid var(--border-dark); border-radius: 6px; margin-bottom: 8px; background: #101010; }
.mke-modal-multiselect-row { display: flex; align-items: center; gap: 8px; padding: 7px 10px; font-size: 13px; cursor: pointer; border-bottom: 1px solid rgba(255,255,255,0.05); }
.mke-modal-multiselect-row:last-child { border-bottom: none; }
.mke-modal-multiselect-row:hover { background: #1c1c1c; }
.mke-modal-multiselect-row input { margin: 0; width: 14px; height: 14px; }
.mke-modal-multiselect-row.hidden-by-search { display: none; }
.mke-modal-multiselect-count { font-size: 12px; color: var(--text-muted); margin-bottom: 16px; }

/* Cross-keying (Worklist 4.5) — XKD badge + per-tag action icon, tree/bench/cylinder view */
.xkd-badge { display: inline-block; background: #3b1c00; color: #fb923c; border: 1px solid #9a3412; border-radius: 4px; padding: 2px 8px; font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; margin-left: 8px; }
.key-tag.xkd { border-style: double; border-width: 3px; border-color: #9a3412; }
.xkd-action-btn { display: inline-block; margin-left: 6px; opacity: 0.6; cursor: pointer; }
.xkd-action-btn:hover { opacity: 1; }

@media (max-width: 768px) { .grid { grid-template-columns: 1fr; } }