  :root {
    --bg: #0e0e12;
    --surface: #16161d;
    --surface2: #1e1e28;
    --border: #2a2a38;
    --accent: #ffcb05;
    --accent2: #3b5bdb;
    --red: #ff4d6d;
    --green: #51cf66;
    --orange: #ff922b;
    --text: #f0f0f5;
    --muted: #888899;
    --raw: #51cf66;
    --graded: #74c0fc;
  }
  [data-theme="light"] {
    --bg: #f4f4f8;
    --surface: #ffffff;
    --surface2: #eaeaf0;
    --border: #d0d0da;
    --accent: #d4a800;
    --accent2: #3b5bdb;
    --red: #d63050;
    --green: #2b8a3e;
    --orange: #e67700;
    --text: #1a1a2e;
    --muted: #666680;
    --raw: #2b8a3e;
    --graded: #1971c2;
    --grid-line: rgba(0,0,0,0.04);
  }
  * { margin: 0; padding: 0; box-sizing: border-box; }
  body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Syne', sans-serif;
    min-height: 100vh;
    overflow-x: hidden;
  }
  body::before {
    content: '';
    position: fixed;
    inset: 0;
    background-image:
      linear-gradient(var(--grid-line, rgba(255,203,5,0.03)) 1px, transparent 1px),
      linear-gradient(90deg, var(--grid-line, rgba(255,203,5,0.03)) 1px, transparent 1px);
    background-size: 40px 40px;
    pointer-events: none;
    z-index: 0;
  }
  .app { position: relative; z-index: 1; max-width: 1160px; margin: 0 auto; padding: 24px 20px; }

  header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 16px; padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap; gap: 12px;
  }
  .logo { display: flex; align-items: center; gap: 12px; }
  .logo img { height: 40px; width: auto; object-fit: contain; display: block; }
  .logo h1 { font-size: 22px; font-weight: 800; letter-spacing: -0.5px; }
  .logo span { color: var(--accent); }
  .header-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

  .currency-toggle { display: flex; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
  .cur-btn { padding: 7px 14px; border: none; background: transparent; color: var(--muted); font-family: 'DM Mono', monospace; font-size: 12px; font-weight: 500; cursor: pointer; transition: all 0.15s; border-right: 1px solid var(--border); }
  .cur-btn:last-child { border-right: none; }
  .cur-btn.active { background: var(--accent); color: #000; font-weight: 700; }
  .cur-btn:hover:not(.active) { color: var(--text); background: var(--surface2); }

  .date-badge { font-family: 'DM Mono', monospace; font-size: 12px; color: var(--muted); background: var(--surface); padding: 6px 12px; border-radius: 6px; border: 1px solid var(--border); }

  .fx-bar { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 14px; font-size: 11px; font-family: 'DM Mono', monospace; color: var(--muted); margin-bottom: 6px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
  .fx-rates { display: flex; gap: 14px; }
  .fx-rate { color: var(--text); }
  .fx-rate em { color: var(--muted); font-style: normal; }

  .fx-editor { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; margin-bottom: 10px; display: none; }
  .fx-editor-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin-top: 10px; }

  .fx-toggle-btn { background: none; border: none; color: var(--muted); font-size: 11px; cursor: pointer; font-family: 'DM Mono', monospace; margin-bottom: 16px; display: block; margin-left: auto; }
  .fx-toggle-btn:hover { color: var(--accent); }

  .summary-bar { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
  .stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; transition: border-color 0.15s; }
  .stat-card:hover { border-color: var(--accent); }
  .stat-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--muted); margin-bottom: 6px; }
  .stat-value { font-size: 20px; font-weight: 800; color: var(--text); font-family: 'DM Mono', monospace; }
  .stat-value.accent { color: var(--accent); }
  .stat-value.green { color: var(--green); }

  .main-grid { display: grid; grid-template-columns: 1fr 390px; gap: 20px; align-items: start; }

  .panel { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }
  .panel-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 13px; letter-spacing: 0.5px; text-transform: uppercase; color: var(--muted); }
  .panel-header .dot { width: 8px; height: 8px; border-radius: 50%; }
  .panel-body { padding: 20px; }

  .type-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 20px; }
  .type-btn { padding: 12px; border-radius: 10px; border: 2px solid var(--border); background: transparent; color: var(--muted); font-family: 'Syne', sans-serif; font-weight: 700; font-size: 14px; cursor: pointer; transition: all 0.2s; display: flex; align-items: center; justify-content: center; gap: 8px; }
  .type-btn.active[data-type="raw"] { border-color: var(--raw); color: var(--raw); background: rgba(81,207,102,0.08); }
  .type-btn.active[data-type="graded"] { border-color: var(--graded); color: var(--graded); background: rgba(116,192,252,0.08); }
  .type-btn.active[data-type="sealed"] { border-color: #ffb86c; color: #ffb86c; background: rgba(255,184,108,0.08); }
  .type-btn:hover { border-color: var(--muted); color: var(--text); }

  .form-group { margin-bottom: 16px; }
  label { display: block; font-size: 11px; font-weight: 700; letter-spacing: 0.8px; text-transform: uppercase; color: var(--muted); margin-bottom: 7px; }
  input, select { width: 100%; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-family: 'DM Mono', monospace; font-size: 14px; padding: 11px 14px; outline: none; transition: border-color 0.2s; }
  input:focus, select:focus { border-color: var(--accent); }
  select option { background: var(--surface2); }
  .form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

  #graded-fields { display: none; }
  #graded-fields.show { display: block; }

  @keyframes fadeIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }

  .price-input-wrap { position: relative; }
  .price-input-wrap input { padding-left: 40px; }
  .currency-prefix { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-family: 'DM Mono', monospace; font-size: 12px; pointer-events: none; white-space: nowrap; }

  /* Search links */
  .search-links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
  .search-link { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 5px; font-size: 11px; font-family: 'DM Mono', monospace; font-weight: 500; text-decoration: none; cursor: pointer; border: 1px solid; transition: all 0.15s; background: transparent; }
  .link-ebay  { color: #e5a00d; border-color: rgba(229,160,13,0.35); }
  .link-ebay:hover  { background: rgba(229,160,13,0.1); }
  .link-alt   { color: #a78bfa; border-color: rgba(167,139,250,0.35); }
  .link-alt:hover   { background: rgba(167,139,250,0.1); }
  .link-tcg   { color: #4ade80; border-color: rgba(74,222,128,0.35); }
  .link-tcg:hover   { background: rgba(74,222,128,0.1); }
  .link-pc    { color: #38bdf8; border-color: rgba(56,189,248,0.35); }
  .link-pc:hover    { background: rgba(56,189,248,0.1); }
  .link-yuyu  { color: #fb7185; border-color: rgba(251,113,133,0.35); }
  .link-yuyu:hover  { background: rgba(251,113,133,0.1); }

  .liquidity-section { margin-bottom: 20px; }
  .liquidity-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); font-family: 'DM Mono', monospace; margin-bottom: 6px; }
  .liquidity-value { font-size: 28px; font-weight: 800; color: var(--accent); font-family: 'Syne', sans-serif; line-height: 1; margin-bottom: 10px; }
  .liquidity-value span { font-size: 16px; color: var(--muted); font-weight: 400; margin-left: 4px; }
  input[type="range"] { -webkit-appearance: none; width: 100%; height: 6px; background: var(--border); border-radius: 3px; padding: 0; cursor: pointer; }
  input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; border-radius: 50%; background: var(--accent); cursor: pointer; box-shadow: 0 0 0 3px rgba(255,203,5,0.2); }
  .liquidity-presets { display: flex; gap: 6px; margin-top: 10px; }
  .preset-btn { flex: 1; padding: 6px 4px; border-radius: 6px; border: 1px solid var(--border); background: transparent; color: var(--muted); font-family: 'DM Mono', monospace; font-size: 11px; cursor: pointer; transition: all 0.15s; }
  .preset-btn:hover, .preset-btn.active { border-color: var(--accent); color: var(--accent); background: rgba(255,203,5,0.06); }

  .divider { height: 1px; background: var(--border); margin: 4px 0 16px; }

  .result-box { background: var(--surface2); border: 1px solid var(--border); border-radius: 10px; padding: 16px; margin-bottom: 12px; display: none; }
  .result-box.show { display: block; animation: fadeIn 0.2s ease; }
  .result-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
  .result-row:last-child { border-bottom: none; }
  .result-row .label { color: var(--muted); font-family: 'DM Mono', monospace; font-size: 12px; }
  .result-row .value { font-weight: 700; font-family: 'DM Mono', monospace; }

  .buy-price-display { background: linear-gradient(135deg, rgba(255,203,5,0.12), rgba(255,203,5,0.05)); border: 1px solid rgba(255,203,5,0.3); border-radius: 10px; padding: 16px; text-align: center; margin-bottom: 12px; display: none; }
  .buy-price-display.show { display: block; animation: fadeIn 0.2s ease; }
  .buy-price-display .bp-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--muted); margin-bottom: 6px; }
  .buy-price-display .amount { font-size: 42px; font-weight: 800; color: var(--accent); line-height: 1; }
  .buy-price-display .sub { font-size: 12px; color: var(--muted); font-family: 'DM Mono', monospace; margin-top: 8px; }

  .buy-price-currencies {
    display: flex; align-items: center; justify-content: center;
    gap: 0; margin-top: 12px; margin-bottom: 4px;
    background: rgba(0,0,0,0.2); border-radius: 8px; overflow: hidden;
  }
  .bpc-item {
    flex: 1; padding: 8px 6px; text-align: center;
  }
  .bpc-item.active-cur { background: rgba(255,203,5,0.1); }
  .bpc-cur { display: block; font-size: 9px; font-family: 'DM Mono', monospace; color: var(--muted); letter-spacing: 0.8px; text-transform: uppercase; margin-bottom: 3px; }
  .bpc-val { display: block; font-size: 15px; font-weight: 700; font-family: 'DM Mono', monospace; color: var(--text); }
  .bpc-item.active-cur .bpc-val { color: var(--accent); }
  .bpc-divider { width: 1px; height: 36px; background: var(--border); flex-shrink: 0; }

  /* Margin projection */
  .margin-box { background: var(--surface2); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; margin-bottom: 12px; display: none; }
  .margin-box.show { display: block; animation: fadeIn 0.2s ease; }
  .margin-box-title { font-size: 10px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--muted); margin-bottom: 12px; font-weight: 700; }
  .margin-scenarios { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
  .margin-scenario { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 8px; text-align: center; }
  .ms-label { font-size: 10px; color: var(--muted); font-family: 'DM Mono', monospace; margin-bottom: 4px; }
  .ms-profit { font-size: 15px; font-weight: 800; font-family: 'DM Mono', monospace; }
  .ms-pct { font-size: 10px; color: var(--muted); margin-top: 2px; font-family: 'DM Mono', monospace; }
  .col-green { color: var(--green); }
  .col-orange { color: var(--orange); }
  .col-red { color: var(--red); }

  .margin-bar-label { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted); font-family: 'DM Mono', monospace; margin-bottom: 5px; }
  .margin-bar-track { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
  .margin-bar-fill { height: 100%; border-radius: 3px; transition: width 0.4s ease, background 0.4s; }

  /* Buttons */
  .btn { width: 100%; padding: 13px; border-radius: 10px; border: none; font-family: 'Syne', sans-serif; font-weight: 700; font-size: 14px; cursor: pointer; transition: all 0.2s; letter-spacing: 0.3px; }
  .btn-primary { background: var(--accent); color: #000; margin-bottom: 8px; }
  .btn-primary:hover { background: #ffd93d; transform: translateY(-1px); }
  .btn-secondary { background: transparent; color: var(--muted); border: 1px solid var(--border); }
  .btn-secondary:hover { border-color: var(--muted); color: var(--text); }
  .btn-log { background: rgba(59,91,219,0.15); color: var(--graded); border: 1px solid rgba(59,91,219,0.3); margin-bottom: 8px; }
  .btn-log:hover { background: rgba(59,91,219,0.25); }

  /* Log */
  .log-empty { text-align: center; padding: 32px; color: var(--muted); font-size: 13px; }
  .log-item { display: grid; grid-template-columns: 1fr auto auto auto; gap: 10px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 13px; }
  .log-item:last-child { border-bottom: none; }
  .log-item:hover { background: rgba(255,255,255,0.02); }
  .log-card-name { font-weight: 700; font-size: 13px; }
  .log-card-meta { font-size: 11px; color: var(--muted); font-family: 'DM Mono', monospace; margin-top: 2px; }
  .log-type-badge { font-size: 10px; padding: 3px 8px; border-radius: 4px; font-weight: 700; letter-spacing: 0.5px; text-transform: uppercase; }
  .badge-raw    { background: rgba(81,207,102,0.12);  color: var(--raw);    }
  .badge-graded { background: rgba(116,192,252,0.12); color: var(--graded); }
  .badge-sealed { background: rgba(255,184,108,0.15); color: #ffb86c;       }
  .log-price { text-align: right; font-family: 'DM Mono', monospace; }
  .log-buy-price { font-weight: 700; font-size: 14px; color: var(--accent); }
  .log-market { font-size: 11px; color: var(--muted); margin-top: 2px; }
  .log-margin-pill { font-size: 10px; padding: 2px 7px; border-radius: 4px; font-family: 'DM Mono', monospace; font-weight: 700; display: inline-block; margin-top: 3px; }
  .pill-green  { background: rgba(81,207,102,0.12); color: var(--green); }
  .pill-orange { background: rgba(255,146,43,0.12);  color: var(--orange); }
  .pill-red    { background: rgba(255,77,109,0.12);  color: var(--red); }
  .log-delete { background: none; border: none; color: var(--border); cursor: pointer; font-size: 16px; padding: 4px 6px; border-radius: 4px; transition: all 0.15s; line-height: 1; }
  .log-delete:hover { color: var(--red); background: rgba(255,77,109,0.1); }

  .export-row { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }
  .btn-export { flex: 1; padding: 9px; border-radius: 8px; border: 1px solid var(--border); background: transparent; color: var(--muted); font-family: 'Syne', sans-serif; font-weight: 600; font-size: 12px; cursor: pointer; transition: all 0.15s; }
  .btn-export:hover { border-color: var(--accent); color: var(--accent); }

  .condition-guide { font-size: 11px; color: var(--muted); font-family: 'DM Mono', monospace; margin-top: 6px; line-height: 1.6; }

  /* Serial number */
  .serial-wrap { display: flex; gap: 8px; align-items: center; }
  .serial-wrap input { flex: 1; }
  .psa-cert-btn {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 9px 13px; border-radius: 8px; white-space: nowrap;
    background: rgba(200,30,30,0.12); border: 1px solid rgba(200,30,30,0.35);
    color: #ff6b6b; font-family: 'DM Mono', monospace; font-size: 12px;
    font-weight: 600; text-decoration: none; transition: all 0.15s; cursor: pointer;
  }
  .psa-cert-btn:hover { background: rgba(200,30,30,0.22); border-color: #ff6b6b; color: #fff; }
  .serial-hint { font-size: 11px; font-family: 'DM Mono', monospace; margin-top: 6px; color: var(--muted); }
  .optional-note { font-size: 10px; color: var(--muted); font-weight: 400; text-transform: none; letter-spacing: 0; }

  .toast { position: fixed; top: 24px; right: 24px; background: var(--surface); border: 1px solid var(--green); color: var(--green); padding: 12px 18px; border-radius: 8px; font-size: 13px; font-weight: 600; opacity: 0; transform: translateY(-10px); transition: all 0.3s; z-index: 100; pointer-events: none; }
  .toast.show { opacity: 1; transform: translateY(0); pointer-events: auto; }

  /* Tab nav */
  .tab-nav { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 4px; margin-bottom: 24px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tab-btn { flex: 0 0 auto; padding: 9px 16px; border-radius: 7px; border: none; background: transparent; color: var(--muted); font-family: 'Syne', sans-serif; font-weight: 700; font-size: 13px; cursor: pointer; transition: all 0.18s; display: flex; align-items: center; justify-content: center; gap: 7px; white-space: nowrap; }
  .tab-btn.active { background: var(--accent); color: #000; }
  .tab-btn:hover:not(.active) { color: var(--text); background: var(--surface2); }
  .tab-count { background: rgba(0,0,0,0.2); border-radius: 10px; padding: 1px 7px; font-size: 11px; font-family: 'DM Mono', monospace; }
  .tab-btn.active .tab-count { background: rgba(0,0,0,0.15); }

  /* Sub-tab nav */
  .sub-tab-nav { display: flex; gap: 2px; margin-bottom: 18px; border-bottom: 1px solid var(--border); padding-bottom: 0; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .sub-tab-btn { flex: 0 0 auto; padding: 8px 16px; border: none; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); font-family: 'Syne', sans-serif; font-weight: 700; font-size: 12px; cursor: pointer; transition: all 0.18s; display: flex; align-items: center; gap: 6px; white-space: nowrap; }
  .sub-tab-btn.active { color: var(--text); border-bottom-color: var(--accent); }
  .sub-tab-btn:hover:not(.active) { color: var(--text); }
  .sub-tab-btn .tab-count { background: rgba(255,255,255,0.08); border-radius: 10px; padding: 1px 7px; font-size: 11px; font-family: 'DM Mono', monospace; }
  .sub-tab-btn.active .tab-count { background: rgba(255,203,5,0.15); color: var(--accent); }

  /* Inventory tab */
  .inv-tab { display: none; }
  .inv-tab.active { display: block; }

  .inv-summary { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 20px; }

  .inv-controls { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
  .inv-search { flex: 1; min-width: 180px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-family: 'DM Mono', monospace; font-size: 13px; padding: 9px 14px; outline: none; transition: border-color 0.2s; }
  .inv-search:focus { border-color: var(--accent); }
  .inv-filter { display: flex; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
  .inv-filter-btn { padding: 8px 13px; border: none; background: transparent; color: var(--muted); font-family: 'DM Mono', monospace; font-size: 11px; font-weight: 600; cursor: pointer; transition: all 0.15s; border-right: 1px solid var(--border); white-space: nowrap; }
  .inv-filter-btn:last-child { border-right: none; }
  .inv-filter-btn.active { background: var(--surface2); color: var(--text); }

  /* Status badges */
  .status-badge { font-size: 10px; padding: 3px 9px; border-radius: 4px; font-weight: 700; letter-spacing: 0.4px; text-transform: uppercase; white-space: nowrap; display: inline-block; }
  .status-pending  { background: rgba(255,146,43,0.12);  color: var(--orange); }
  .status-holding  { background: rgba(255,203,5,0.12);  color: var(--accent); }
  .status-resale   { background: rgba(81,207,102,0.12); color: var(--raw); }
  .status-grading  { background: rgba(116,192,252,0.12);color: var(--graded); }
  .status-sold     { background: rgba(136,136,153,0.12);color: var(--muted); }

  /* Inventory table */
  .inv-table { width: 100%; border-collapse: collapse; font-size: 12px; }
  .inv-table th { padding: 7px 8px; text-align: left; font-size: 9px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); border-bottom: 1px solid var(--border); font-weight: 700; white-space: nowrap; }
  .inv-table th[data-col]:hover { color: var(--accent); }
  .sort-arrow { font-size: 9px; opacity: 0.6; }
  .inv-table td { padding: 7px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
  .inv-table th.sticky-cb, .inv-table td.sticky-cb { position: sticky; left: 0; z-index: 2; background: var(--surface); }
  .inv-table th.sticky-card, .inv-table td.sticky-card { position: sticky; left: 28px; z-index: 2; background: var(--surface); box-shadow: 3px 0 8px rgba(0,0,0,0.35); }
  .inv-table thead th.sticky-cb, .inv-table thead th.sticky-card { z-index: 3; background: var(--surface); }
  .inv-table tr:last-child td { border-bottom: none; }
  .inv-table tr:hover td { background: rgba(255,255,255,0.02); }
  .inv-table tr:hover td.sticky-cb, .inv-table tr:hover td.sticky-card { background: color-mix(in srgb, var(--surface) 95%, white 5%); }
  .inv-card-name { font-weight: 700; font-size: 13px; }
  .inv-card-meta { font-size: 11px; color: var(--muted); font-family: 'DM Mono', monospace; margin-top: 2px; }
  .inv-price { font-family: 'DM Mono', monospace; font-weight: 700; }
  .inv-profit-pos { color: var(--green); font-family: 'DM Mono', monospace; font-weight: 700; }
  .inv-profit-neg { color: var(--red);   font-family: 'DM Mono', monospace; font-weight: 700; }
  .inv-profit-pen { color: var(--muted); font-family: 'DM Mono', monospace; }

  .inv-action-row { display: flex; gap: 6px; }
  .inv-btn { padding: 5px 10px; border-radius: 6px; border: 1px solid var(--border); background: transparent; color: var(--muted); font-family: 'DM Mono', monospace; font-size: 11px; cursor: pointer; transition: all 0.15s; white-space: nowrap; }
  .inv-btn:hover { border-color: var(--accent); color: var(--accent); }
  .inv-btn.danger:hover { border-color: var(--red); color: var(--red); }

  /* Sell modal */
  .modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.7); z-index: 200; display: none; align-items: center; justify-content: center; }
  .modal-overlay.show { display: flex; }
  .modal { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 24px; width: 100%; max-width: 420px; animation: fadeIn 0.2s ease; }
  .modal-title { font-size: 16px; font-weight: 800; margin-bottom: 4px; }
  .modal-sub { font-size: 12px; color: var(--muted); font-family: 'DM Mono', monospace; margin-bottom: 20px; }
  .modal-field { margin-bottom: 14px; }
  .modal-field label { display: block; font-size: 11px; font-weight: 700; letter-spacing: 0.7px; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
  .modal-field input, .modal-field select { width: 100%; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-family: 'DM Mono', monospace; font-size: 14px; padding: 10px 13px; outline: none; }
  .modal-field input:focus { border-color: var(--accent); }
  .modal-field .price-input-wrap input { padding-left: 40px; }
  .modal-profit-preview { background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; margin-bottom: 16px; display: none; }
  .modal-profit-preview.show { display: block; }
  .modal-profit-row { display: flex; justify-content: space-between; font-size: 13px; padding: 4px 0; font-family: 'DM Mono', monospace; }
  .modal-profit-row.total { font-weight: 700; border-top: 1px solid var(--border); margin-top: 4px; padding-top: 8px; }
  .modal-btns { display: flex; gap: 8px; }
  .modal-btn { flex: 1; padding: 11px; border-radius: 9px; border: none; font-family: 'Syne', sans-serif; font-weight: 700; font-size: 13px; cursor: pointer; transition: all 0.15s; }
  .modal-btn-confirm { background: var(--accent); color: #000; }
  .modal-btn-confirm:hover { background: #ffd93d; }
  .modal-btn-cancel { background: transparent; color: var(--muted); border: 1px solid var(--border); }
  .modal-btn-cancel:hover { border-color: var(--muted); color: var(--text); }

  .inv-empty { text-align: center; padding: 48px 20px; color: var(--muted); font-size: 13px; }
  .inv-empty-icon { font-size: 36px; margin-bottom: 10px; }
  #marketConversions [id^="mktConv"]:hover { border-color: var(--accent) !important; background: rgba(255,203,5,0.08) !important; }

  /* ── Photos ─────────────────────────────────────────────── */
  .photo-thumb {
    width: 72px; height: 72px; object-fit: cover;
    border-radius: 8px; border: 1px solid var(--border);
    cursor: pointer; transition: transform 0.15s, border-color 0.15s;
    position: relative;
  }
  .photo-thumb:hover { transform: scale(1.05); border-color: var(--accent); }
  .photo-wrap { position: relative; display: inline-block; }

  /* Hover preview popup */
  #photoHoverPreview {
    position: fixed; z-index: 9998; pointer-events: none;
    display: none;
    background: var(--surface2); border: 2px solid var(--accent);
    border-radius: 12px; padding: 6px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.7);
    transition: opacity 0.15s;
  }
  #photoHoverPreview img {
    width: 380px; height: 380px; object-fit: contain;
    border-radius: 8px; display: block;
  }
  .photo-del {
    position: absolute; top: -6px; right: -6px;
    width: 18px; height: 18px; border-radius: 50%;
    background: var(--red); color: #fff; border: none;
    font-size: 11px; font-weight: 700; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    line-height: 1;
  }
  /* Lightbox */
  .lightbox {
    position: fixed; inset: 0; z-index: 999;
    background: rgba(0,0,0,0.92);
    display: none; align-items: center; justify-content: center;
    flex-direction: column; gap: 12px;
  }
  .lightbox.show { display: flex; }
  .lightbox img { max-width: 92vw; max-height: 80vh; border-radius: 10px; object-fit: contain; }
  .lightbox-close {
    position: absolute; top: 16px; right: 16px;
    background: rgba(255,255,255,0.1); border: none; color: #fff;
    font-size: 22px; width: 40px; height: 40px; border-radius: 50%;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
  }
  .lightbox-nav {
    display: flex; gap: 16px;
  }
  .lightbox-nav button {
    background: rgba(255,255,255,0.1); border: none; color: #fff;
    font-size: 20px; padding: 8px 18px; border-radius: 8px; cursor: pointer;
  }
  .lightbox-counter { color: rgba(255,255,255,0.5); font-size: 12px; font-family: 'DM Mono', monospace; }

  /* ── Mobile responsive ──────────────────────────────────── */
  @media (max-width: 640px) {
    /* Stack New Quote and Today's Log vertically on mobile */
    .main-grid { grid-template-columns: 1fr; gap: 16px; }

    /* Layout */
    .app { padding: 12px 12px 120px; } /* bottom padding for fixed tab bar */

    /* Header */
    header { flex-direction: column; align-items: flex-start; gap: 8px; margin-bottom: 14px; }
    .header-right { width: 100%; justify-content: space-between; }
    header h1 { font-size: 20px; }
    #cloudBadge { font-size: 10px; padding: 4px 8px; }

    /* Tab nav — fixed to bottom on mobile */
    .tab-nav {
      position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
      border-radius: 0; border: none; border-top: 1px solid var(--border);
      background: var(--surface); padding: 6px 8px;
      margin-bottom: 0;
      padding-bottom: calc(6px + env(safe-area-inset-bottom));
    }
    .tab-btn { padding: 8px 4px; font-size: 11px; flex-direction: column; gap: 3px; }
    .tab-count { font-size: 9px; padding: 1px 5px; }

    /* FX bar */
    .fx-bar { flex-direction: column; gap: 6px; font-size: 11px; }
    .fx-bar > * { width: 100%; }

    /* Stats */
    .stats-bar { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .stat-card { padding: 10px 12px; }
    .stat-value { font-size: 18px; }

    /* Form */
    .form-group { margin-bottom: 14px; }
    input[type=number], input[type=text], select, textarea {
      font-size: 16px !important; /* prevent iOS zoom on focus */
    }
    .currency-toggle { transform: scale(1) !important; transform-origin: right center; }
    .cur-btn { padding: 6px 10px; font-size: 12px; }
    .preset-btn { padding: 5px 8px; font-size: 11px; }

    /* Result boxes */
    .buy-price-display { padding: 14px 12px; }
    .offer-amount { font-size: 36px; }
    .margin-box, .result-box { padding: 12px; }

    /* Profit projection pills */
    .proj-row { flex-wrap: wrap; gap: 6px; }

    /* Log items */
    .log-item { grid-template-columns: 1fr auto auto; gap: 6px; padding: 10px 12px; }
    .log-price { display: none; } /* hide price column on mobile log — visible in inventory */
    .log-card-name { font-size: 12px; }
    .log-card-meta { font-size: 10px; }

    /* Inventory controls */
    .inv-controls { flex-direction: column; gap: 8px; }
    .inv-search { width: 100%; }
    .inv-filter { flex-wrap: wrap; }
    .inv-filter-btn { padding: 7px 10px; font-size: 10px; }

    /* Inventory table → card layout */
    .inv-table thead { display: none; }
    .inv-table, .inv-table tbody, .inv-table tr, .inv-table td { display: block; width: 100%; }
    .inv-table tr {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 10px;
      margin-bottom: 10px;
      padding: 12px;
      position: relative;
    }
    .inv-table tr:last-child { margin-bottom: 80px; }
    .inv-table td {
      padding: 3px 0;
      border: none;
      font-size: 12px;
    }
    .inv-table td:empty { display: none; }
    .inv-table td::before {
      content: attr(data-label);
      font-size: 9px;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 0.6px;
      color: var(--muted);
      display: block;
      margin-bottom: 2px;
    }
    /* Actions cell full width at bottom */
    .inv-table td:last-child { margin-top: 10px; border-top: 1px solid var(--border); padding-top: 10px; }
    .inv-btn { padding: 7px 10px; font-size: 11px; }

    /* Modals — full screen on mobile */
    .modal-overlay { align-items: flex-end; }
    .modal {
      max-width: 100%;
      border-radius: 18px 18px 0 0;
      padding: 20px 16px;
      max-height: 90vh;
      overflow-y: auto;
    }
    .modal-btns { gap: 8px; }
    .modal-btn { padding: 13px; font-size: 14px; }

    /* Cloud settings */
    #sheetsUrlInput, #sheetsTokenInput { font-size: 13px !important; }

    /* Selection bars — push above the fixed tab bar on mobile */
    #selectionBar, #csgSelectionBar, #soldCsgSelectionBar {
      bottom: 90px;
      min-width: unset;
      width: calc(100% - 24px);
      left: 12px;
      right: 12px;
      transform: none;
      border-radius: 12px;
      padding: 14px 16px;
      gap: 12px;
      font-size: 13px;
    }

    /* Extra bottom margin on last inventory card to clear both tab bar + selection bar */
    .inv-table tr:last-child { margin-bottom: 180px; }
  }

/* ── PIN/Label Styles ──────────────────────────────── */

  .pin-dot {
    width: 14px; height: 14px; border-radius: 50%;
    border: 2px solid var(--border);
    background: transparent;
    transition: background 0.15s, border-color 0.15s;
  }
  .pin-dot.filled { background: var(--accent); border-color: var(--accent); }
  .pin-dot.error  { background: var(--red);    border-color: var(--red); }
  .pin-key {
    padding: 18px; border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-family: 'Syne', sans-serif;
    font-size: 20px; font-weight: 700;
    cursor: pointer;
    transition: background 0.12s, transform 0.08s;
    -webkit-tap-highlight-color: transparent;
  }
  .pin-key:active { background: var(--surface2); transform: scale(0.94); }
  .pin-key-blank  { background: transparent; border-color: transparent; cursor: default; }
  .pin-key-del    { font-size: 18px; }

  @keyframes pinShake {
    0%,100% { transform: translateX(0); }
    20%     { transform: translateX(-8px); }
    40%     { transform: translateX(8px); }
    60%     { transform: translateX(-6px); }
    80%     { transform: translateX(6px); }
  }
  .pin-shake { animation: pinShake 0.4s ease; }

/* ── Print Styles (QR Labels) ────────────────────────── */
@media print {
  body > *:not(#qrPrintSheet) { display: none !important; }
  #qrPrintSheet {
    display: block !important;
    position: fixed;
    inset: 0;
    background: #fff;
    padding: 20px;
    font-family: 'DM Mono', monospace;
  }
  #qrPrintSheet .print-label {
    display: inline-block;
    width: 62mm;
    border: 1px solid #ccc;
    border-radius: 6px;
    padding: 10px;
    margin: 6px;
    text-align: center;
    vertical-align: top;
    page-break-inside: avoid;
  }
  #qrPrintSheet .print-label canvas { display: block; margin: 0 auto 6px; }
  #qrPrintSheet .print-label .pl-id   { font-size: 9px;  color: #777; margin-bottom: 3px; }
  #qrPrintSheet .print-label .pl-name { font-size: 11px; font-weight: 700; color: #111; margin-bottom: 2px; line-height: 1.3; }
  #qrPrintSheet .print-label .pl-meta { font-size: 9px;  color: #666; margin-bottom: 2px; }
  #qrPrintSheet .print-label .pl-loc  { font-size: 10px; font-weight: 600; color: #333; margin-bottom: 2px; }
  #qrPrintSheet .print-label .pl-store{ font-size: 9px;  color: #999; }
}
#qrPrintSheet { display: none; }

/* ── Item Layout (Rack Display) ────────────────────────── */
.rack-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 16px;
  overflow: hidden;
}
.rack-header {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
  user-select: none;
}
.rack-header:hover { background: var(--surface2); }
.rack-title {
  font-family: 'Syne', sans-serif;
  font-size: 14px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text);
}
.rack-count {
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  color: var(--muted);
  background: var(--surface2);
  padding: 2px 8px;
  border-radius: 6px;
}
.rack-chevron { margin-left: auto; transition: transform 0.15s; color: var(--muted); font-size: 12px; }
.rack-collapsed .rack-body { display: none; }
.rack-collapsed .rack-header { border-bottom: none; }
.rack-collapsed .rack-chevron { transform: rotate(-90deg); }
.rack-body { padding: 8px 12px; }

/* Display half (Top / Bottom) */
.rack-display { margin-bottom: 4px; }
.rack-display-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: 'Syne', sans-serif;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  padding: 4px 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.rack-display-count {
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  color: var(--muted);
  background: var(--surface2);
  padding: 1px 6px;
  border-radius: 4px;
}
.rack-divider {
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
  margin: 10px 0;
}

/* Row within a display */
.rack-row {
  display: flex;
  align-items: center;
  gap: 3px;
  margin-bottom: 3px;
}
.rack-row-label {
  font-family: 'DM Mono', monospace;
  font-size: 9px;
  color: var(--muted);
  width: 22px;
  text-align: right;
  flex-shrink: 0;
}
.rack-row-slots {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 3px;
  flex: 1;
  min-width: 0;
}
.rack-row-overflow {
  font-family: 'DM Mono', monospace;
  font-size: 9px;
  color: var(--orange);
  flex-shrink: 0;
  margin-left: 2px;
}
.rack-col-headers { margin-bottom: 2px; }
.rack-col-label {
  font-family: 'DM Mono', monospace;
  font-size: 8px;
  color: var(--muted);
  text-align: center;
  opacity: 0.6;
}

/* Individual card slot */
.rack-slot {
  height: 36px;
  border-radius: 3px;
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
  transition: border-color 0.15s, transform 0.1s;
}
.rack-slot-empty {
  background: var(--bg);
  opacity: 0.3;
}
.rack-slot-filled {
  background: var(--surface2);
  cursor: pointer;
}
.rack-slot-filled:hover {
  border-color: var(--accent);
  transform: scale(1.15);
  z-index: 2;
}
.rack-slot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.rack-slot-text {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 7px;
  color: var(--muted);
  text-align: center;
  padding: 2px;
  font-family: 'DM Mono', monospace;
  line-height: 1.1;
  height: 100%;
  word-break: break-all;
}
.rack-slot-dot {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.4);
}
.rack-slot-tooltip {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 11px;
  color: var(--text);
  white-space: nowrap;
  z-index: 10;
  pointer-events: none;
  font-family: 'DM Mono', monospace;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.rack-slot-filled:hover .rack-slot-tooltip { display: block; }

/* Other (non-rack) locations */
.rack-other-section { margin-bottom: 12px; }
.rack-other-header {
  font-family: 'Syne', sans-serif;
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.rack-other-slots {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  gap: 4px;
}

@media (max-width: 768px) {
  #dashStoreColumns { grid-template-columns: 1fr !important; }
  .rack-row-slots { grid-template-columns: repeat(10, 1fr); gap: 2px; }
  .rack-slot-tooltip { display: none !important; }
  .rack-slot-text { font-size: 6px; }
  .rack-slot-dot { width: 4px; height: 4px; }
}

/* Hide up/down spinners on listing price inputs — direct number entry only */
#listPrice::-webkit-inner-spin-button,
#listPrice::-webkit-outer-spin-button,
#csgListPrice::-webkit-inner-spin-button,
#csgListPrice::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
#listPrice,
#csgListPrice {
  -moz-appearance: textfield;
  appearance: textfield;
}
