:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3348;
  --accent: #4f8ef7;
  --accent2: #3a6fd4;
  --green: #2ecc71;
  --red: #e74c3c;
  --purple: #9b59b6;
  --orange: #e67e22;
  --text: #e8eaf0;
  --muted: #8892a4;
  --radius: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; min-height: 100vh; }

/* ── Keyboard focus indicators ── */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }

/* ── Auth ── */
#auth-screen { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100vh; padding: 24px; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 32px 28px; width: 100%; max-width: 380px; }
.auth-card h1 { font-size: 1.4rem; margin-bottom: 4px; }
.subtitle { color: var(--muted); font-size: .85rem; margin-bottom: 24px; }
.auth-tabs { display: flex; gap: 8px; margin-bottom: 20px; }
.auth-tab { flex: 1; padding: 8px; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; color: var(--muted); cursor: pointer; font-size: .9rem; transition: all .2s; }
.auth-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── Forms ── */
label { display: block; font-size: .8rem; color: var(--muted); margin-bottom: 5px; margin-top: 14px; }
input[type=text], input[type=password], input[type=email], input[type=date], input[type=number], textarea {
  width: 100%; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); padding: 10px 12px; font-size: .95rem; transition: border .2s;
}
input:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 80px; }

/* ── Buttons ── */
.btn { display: block; width: 100%; padding: 11px; background: var(--accent); border: none; border-radius: 8px; color: #fff; font-size: 1rem; font-weight: 600; cursor: pointer; margin-top: 18px; transition: background .2s; }
.btn:hover { background: var(--accent2); }
.btn.secondary { background: var(--surface2); border: 1px solid var(--border); color: var(--text); }
.btn.secondary:hover { background: var(--border); }
.btn.danger { background: var(--red); }
.btn.danger:hover { background: #c0392b; }
.btn.sm { width: auto; padding: 6px 14px; font-size: .82rem; margin-top: 0; }
.add-btn { display: flex; align-items: center; gap: 6px; background: var(--accent); border: none; border-radius: 8px; color: #fff; padding: 8px 14px; font-size: .88rem; font-weight: 600; cursor: pointer; transition: background .2s; white-space: nowrap; }
.add-btn:hover { background: var(--accent2); }
.icon-btn { background: none; border: 1px solid var(--border); border-radius: 8px; color: var(--muted); padding: 6px 10px; font-size: .85rem; cursor: pointer; transition: all .2s; }
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.error-msg { color: var(--red); font-size: .82rem; margin-top: 10px; text-align: center; }

/* ── App shell ── */
#app-screen { display: none; flex-direction: column; min-height: 100vh; }
header { background: var(--surface); border-bottom: 1px solid var(--border); padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 10; }
header h1 { font-size: 1.05rem; font-weight: 700; }
.header-right { display: flex; align-items: center; gap: 8px; }
main { padding: 16px; width: 100%; flex: 1; }

/* ── Stats bar ── */
.stats-bar { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.stat-chip { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px 14px; font-size: .875rem; color: var(--muted); flex: 1; min-width: 70px; text-align: center; }
.stat-chip strong { display: block; font-size: 1.1rem; color: var(--text); }
.stat-chip .seg-bar { display: flex; height: 5px; border-radius: 4px; overflow: hidden; margin-top: 6px; gap: 1px; }
.stat-chip .seg-bar span { height: 100%; transition: width .4s ease; }
.stat-chip .seg-legend { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; justify-content: center; }
.stat-chip .seg-legend i { display: inline-block; width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; margin-top: 1px; }
.stat-chip .seg-legend small { font-size: .65rem; color: var(--muted); display: flex; align-items: center; gap: 3px; }

/* ── Section header ── */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.section-header h2 { font-size: .95rem; color: var(--muted); }

/* ── Weapon card ── */
.weapon-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 14px; overflow: hidden; }
.weapon-card-header { padding: 14px 16px; display: flex; align-items: center; gap: 12px; cursor: pointer; }
.weapon-card-header:hover { background: rgba(79,142,247,.05); }
.weapon-icon { font-size: 1.4rem; }
.weapon-info { flex: 1; min-width: 0; }
.weapon-info strong { font-size: 1rem; display: block; }
.weapon-info span { font-size: .78rem; color: var(--muted); }
.weapon-meta { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.chevron { color: var(--muted); font-size: .8rem; transition: transform .2s; }
.weapon-card.open .chevron { transform: rotate(180deg); }
.weapon-body { display: none; border-top: 1px solid var(--border); }
.weapon-card.open .weapon-body { display: block; }
.weapon-actions { display: flex; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface2); flex-wrap: wrap; }

/* ── Quick bar ── */
.quick-bar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--bg); flex-wrap: wrap; }
.quick-bar label { margin: 0; font-size: .78rem; color: var(--muted); }
.toggle-row-inline { display: flex; align-items: center; gap: 8px; }

/* ── Toggle ── */
.toggle { position: relative; width: 44px; height: 24px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: var(--border); border-radius: 24px; cursor: pointer; transition: .2s; }
.slider:before { content: ''; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
input:checked + .slider { background: var(--accent); }
input:checked + .slider:before { transform: translateX(20px); }
.toggle-row { display: flex; align-items: center; justify-content: space-between; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; margin-top: 14px; }
.toggle-row span { font-size: .92rem; }

/* ── Manual bar ── */
.manual-bar { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface2); flex-wrap: wrap; }
.manual-bar label { margin: 0; font-size: .78rem; color: var(--muted); white-space: nowrap; }
.manual-bar input[type=file] { display: none; }
.manual-name { font-size: .82rem; color: var(--text); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Record tabs ── */
.rec-tabs { display: flex; border-bottom: 1px solid var(--border); }
.rec-tab { flex: 1; padding: 10px 6px; font-size: .82rem; font-weight: 600; color: var(--muted); background: none; border: none; cursor: pointer; border-bottom: 2px solid transparent; transition: all .2s; }
.rec-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.rec-list { padding: 10px 12px 14px; }

/* ── Record items ── */
.rec-item { background: var(--surface2); border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px; overflow: hidden; cursor: pointer; }
.rec-item:hover { border-color: var(--accent); }
.rec-item-header { padding: 10px 14px; display: flex; align-items: center; gap: 10px; }
.rec-type-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.rec-type-dot.maint { background: var(--accent); }
.rec-type-dot.range { background: var(--purple); }
.rec-item-title { flex: 1; min-width: 0; }
.rec-item-title strong { font-size: .88rem; display: block; }
.rec-item-title span { font-size: .75rem; color: var(--muted); }
.rec-item-body { display: none; padding: 0 14px 12px; border-top: 1px solid var(--border); }
.rec-item.open .rec-item-body { display: block; }
.rec-item.open .chevron { transform: rotate(180deg); }
.rec-actions { display: flex; gap: 8px; margin-top: 10px; }

/* ── Detail grid ── */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.detail-item label { font-size: .8rem; color: var(--muted); display: block; margin-bottom: 2px; }
.detail-item span { font-size: .85rem; }
.detail-notes { margin-top: 10px; }
.detail-notes label { font-size: .8rem; color: var(--muted); display: block; margin-bottom: 4px; }
.detail-notes p { font-size: .85rem; line-height: 1.5; background: var(--surface); border-radius: 6px; padding: 8px 10px; }

/* ── Badges ── */
.badge { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: .75rem; font-weight: 600; }
.badge.yes, .badge.fmc { background: rgba(46,204,113,.15); color: var(--green); }
.badge.no, .badge.nfmc { background: rgba(231,76,60,.15); color: var(--red); }
.badge.range-badge { background: rgba(155,89,182,.15); color: var(--purple); }

/* ── Modal ── */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.65); z-index: 100; align-items: flex-end; justify-content: center; }
.modal-overlay.open { display: flex; }
.modal { background: var(--surface); border-radius: var(--radius) var(--radius) 0 0; width: 100%; max-width: 600px; max-height: 92vh; overflow-y: auto; padding: 24px 20px 32px; }
.modal h2 { font-size: 1.1rem; margin-bottom: 4px; }
.modal .modal-sub { font-size: .8rem; color: var(--muted); margin-bottom: 18px; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions .btn { margin-top: 0; }
.divider { height: 1px; background: var(--border); margin: 20px 0; }

/* ── Misc ── */
.empty-state { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty-state .icon { font-size: 2.5rem; margin-bottom: 12px; }
.empty-state p { font-size: .9rem; }
.empty-rec { text-align: center; padding: 24px; color: var(--muted); font-size: .85rem; }
#loading { text-align: center; padding: 40px; color: var(--muted); font-size: .9rem; }
.user-badge { background: var(--surface2); border: 1px solid var(--border); border-radius: 20px; padding: 4px 12px; font-size: .78rem; color: var(--muted); }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #333; color: #fff; padding: 10px 20px; border-radius: 8px; font-size: .85rem; z-index: 999; opacity: 0; transition: opacity .3s; pointer-events: none; white-space: nowrap; }
.toast.show { opacity: 1; }

/* ── Upload progress ── */
.upload-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 200; align-items: center; justify-content: center; }
.upload-overlay.open { display: flex; }
.upload-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px 24px; width: 90%; max-width: 340px; text-align: center; }
.upload-box h3 { font-size: 1rem; margin-bottom: 6px; }
.upload-box p { font-size: .82rem; color: var(--muted); margin-bottom: 18px; }
.upload-track { height: 8px; background: var(--border); border-radius: 8px; overflow: hidden; margin-bottom: 10px; }
.upload-fill { height: 100%; width: 0%; background: var(--accent); border-radius: 8px; transition: width .2s ease; }
.upload-pct { font-size: .85rem; color: var(--muted); }
.admin-table { width: 100%; border-collapse: collapse; font-size: .85rem; margin-top: 14px; }
.admin-table th { text-align: left; color: var(--muted); font-size: .75rem; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.admin-table td { padding: 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.admin-table tr:last-child td { border-bottom: none; }

/* ── Admin tab (legacy, unused but kept for safety) ── */
.admin-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.admin-tab { flex: 1; padding: 8px; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; color: var(--muted); cursor: pointer; font-size: .88rem; transition: all .2s; }
.admin-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── Helpdesk Page ── */
#helpdesk-page { display: none; position: fixed; inset: 0; background: var(--bg); z-index: 50; flex-direction: column; overflow-y: auto; }
#helpdesk-page.open { display: flex; }
.hd-page-header { background: var(--surface); border-bottom: 1px solid var(--border); padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 1; }
.hd-page-header h2 { font-size: 1.05rem; font-weight: 700; }
.hd-page-body { padding: 16px; max-width: 700px; margin: 0 auto; width: 100%; }

/* ── Helpdesk stats bar ── */
.hd-stats-bar { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.hd-stat-chip { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 16px; font-size: .8rem; color: var(--muted); flex: 1; min-width: 80px; text-align: center; cursor: pointer; transition: border-color .2s; }
.hd-stat-chip:hover { border-color: var(--accent); }
.hd-stat-chip strong { display: block; font-size: 1.15rem; margin-bottom: 2px; color: var(--text); }
.hd-stat-chip.open-stat strong { color: var(--accent); }
.hd-stat-chip.inprogress-stat strong { color: var(--orange); }
.hd-stat-chip.resolved-stat strong { color: var(--green); }
.hd-stat-chip.archived-stat strong { color: var(--muted); }

/* ── Helpdesk filters ── */
.hd-filters { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.hd-filter { padding: 6px 14px; background: var(--surface2); border: 1px solid var(--border); border-radius: 20px; color: var(--muted); cursor: pointer; font-size: .82rem; transition: all .2s; }
.hd-filter.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── Helpdesk items ── */
.hd-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 10px; overflow: hidden; }
.hd-item.open { border-left: 3px solid var(--accent); }
.hd-item.in_progress { border-left: 3px solid var(--orange); }
.hd-item.resolved { border-left: 3px solid var(--green); }
.hd-item.archived { opacity: .65; }
.hd-header { padding: 12px 16px; display: flex; align-items: center; gap: 10px; cursor: pointer; }
.hd-header:hover { background: rgba(79,142,247,.05); }
.hd-meta { flex: 1; min-width: 0; }
.hd-meta strong { font-size: .9rem; display: block; }
.hd-meta span { font-size: .75rem; color: var(--muted); }
.hd-status { padding: 2px 10px; border-radius: 20px; font-size: .72rem; font-weight: 600; white-space: nowrap; flex-shrink: 0; }
.hd-status.open { background: rgba(79,142,247,.15); color: var(--accent); }
.hd-status.in_progress { background: rgba(230,126,34,.15); color: var(--orange); }
.hd-status.resolved { background: rgba(46,204,113,.15); color: var(--green); }
.hd-status.archived { background: rgba(136,146,164,.15); color: var(--muted); }
.hd-body { display: none; border-top: 1px solid var(--border); padding: 14px 16px; }
.hd-item.open-detail .hd-body { display: block; }
.hd-item.open-detail .chevron { transform: rotate(180deg); }
.hd-screenshots { display: flex; gap: 10px; margin: 12px 0; flex-wrap: wrap; }
.hd-screenshots img { width: 150px; height: 110px; object-fit: cover; border-radius: 8px; cursor: pointer; border: 1px solid var(--border); transition: opacity .2s; display: block; }
.hd-screenshots img:hover { opacity: .8; }
.hd-admin-notes textarea { margin-top: 6px; }
.hd-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

/* ── Feedback button ── */
.feedback-btn { position: fixed; bottom: 20px; right: 20px; background: var(--accent); color: #fff; border: none; border-radius: 24px; padding: 10px 18px; font-size: .88rem; font-weight: 600; cursor: pointer; z-index: 40; box-shadow: 0 4px 16px rgba(0,0,0,.4); transition: background .2s; }
.feedback-btn:hover { background: var(--accent2); }

/* ── Screenshot slots ── */
.screenshot-row { display: flex; gap: 10px; margin-top: 8px; }
.screenshot-slot { flex: 1; border: 2px dashed var(--border); border-radius: 10px; min-height: 90px; display: flex; align-items: center; justify-content: center; cursor: pointer; position: relative; overflow: hidden; transition: border-color .2s; font-size: .82rem; color: var(--muted); flex-direction: column; gap: 4px; }
.screenshot-slot:hover { border-color: var(--accent); }
.screenshot-slot input[type=file] { display: none; }
.screenshot-slot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.rm-img { position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,.6); color: #fff; border: none; border-radius: 50%; width: 22px; height: 22px; font-size: .8rem; cursor: pointer; display: flex; align-items: center; justify-content: center; z-index: 2; }

/* ── Lightbox ── */
.lightbox { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 300; align-items: center; justify-content: center; cursor: zoom-out; }
.lightbox.open { display: flex; }
.lightbox img { max-width: 95vw; max-height: 90vh; border-radius: 8px; object-fit: contain; }

/* ── Header button badge wrappers ── */
.hd-btn-wrap, .cl-btn-wrap { position: relative; }
.badge-count { position: absolute; top: -6px; right: -6px; background: var(--red); color: #fff; border-radius: 50%; width: 18px; height: 18px; font-size: .65rem; font-weight: 700; display: flex; align-items: center; justify-content: center; pointer-events: none; }

/* ── Helpdesk list item ── */
.hd-meta-user { font-size: .88rem; font-weight: 600; display: block; }
.hd-meta-preview { font-size: .75rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.hd-date { font-size: .72rem; color: var(--muted); white-space: nowrap; flex-shrink: 0; margin-right: 2px; }

/* ── Changelog Page ── */
#changelog-page { display: none; position: fixed; inset: 0; background: var(--bg); z-index: 50; flex-direction: column; overflow-y: auto; }
#changelog-page.open { display: flex; }
.cl-page-header { background: var(--surface); border-bottom: 1px solid var(--border); padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 1; }
.cl-page-header h2 { font-size: 1.05rem; font-weight: 700; }
.cl-page-body { padding: 16px; max-width: 700px; margin: 0 auto; width: 100%; }
.cl-edit-form { background: var(--surface); border: 1px solid var(--accent); border-radius: var(--radius); padding: 16px; margin-bottom: 20px; }
.cl-form-actions { display: flex; gap: 8px; margin-top: 12px; }
.cl-entry { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 20px; margin-bottom: 12px; }
.cl-entry.cl-unread { border-left: 3px solid var(--accent); }
.cl-entry-header { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 8px; }
.cl-entry-title { flex: 1; min-width: 0; }
.cl-entry-title h3 { font-size: .95rem; font-weight: 700; }
.cl-entry-meta { font-size: .75rem; color: var(--muted); margin-top: 3px; }
.cl-version { display: inline-block; background: rgba(79,142,247,.15); color: var(--accent); padding: 1px 8px; border-radius: 12px; font-size: .72rem; font-weight: 600; margin-right: 6px; }
.cl-entry-body { font-size: .88rem; line-height: 1.65; color: var(--text); white-space: pre-wrap; word-break: break-word; }
.cl-entry-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ── Weapon icon ── */
.weapon-icon svg { width: 2rem; height: auto; color: var(--text); }
.weapon-img { width: 72px; height: 26px; object-fit: contain; display: block; }

/* ── Admin Page ── */
#admin-page { display: none; position: fixed; inset: 0; background: var(--bg); z-index: 50; flex-direction: column; overflow-y: auto; }
#admin-page.open { display: flex; }
.adm-page-header { background: var(--surface); border-bottom: 1px solid var(--border); padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 1; }
.adm-page-header h2 { font-size: 1.05rem; font-weight: 700; }
.adm-page-body { padding: 16px; max-width: 700px; margin: 0 auto; width: 100%; }
.adm-stats-bar { display: flex; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; }
.adm-stat-chip { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; font-size: .8rem; color: var(--muted); flex: 1; min-width: 90px; text-align: center; }
.adm-stat-chip strong { display: block; font-size: 1.25rem; margin-bottom: 2px; color: var(--accent); }
.adm-section-title { font-size: .92rem; font-weight: 700; margin-bottom: 12px; }

/* ── Responsive desktop layout ── */
@media (min-width: 768px) {
  /* Modals: centered sheet instead of bottom sheet */
  .modal-overlay { align-items: center; }
  .modal { border-radius: var(--radius); max-width: 580px; }

  /* Weapons grid: 2 columns */
  #weapons-list { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
  #weapons-list .weapon-card { margin-bottom: 0; }

  /* Stats bar: fixed-width chips */
  .stat-chip { min-width: 120px; }
}
@media (min-width: 1200px) {
  /* Weapons grid: 3 columns on large screens */
  #weapons-list { grid-template-columns: 1fr 1fr 1fr; }
}

/* ── Disabled button states ── */
.btn:disabled, .btn[disabled] { opacity: .55; cursor: not-allowed; pointer-events: none; }
.icon-btn:disabled, .icon-btn[disabled] { opacity: .55; cursor: not-allowed; }

/* ── Drag-and-drop upload slots ── */
.screenshot-slot.drag-over { border-color: var(--accent); background: rgba(79,142,247,.08); }

/* ── Keyboard-focusable weapon card headers ── */
.weapon-card-header:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ── Admin table column headers ── */
.admin-table th[scope] { font-weight: 700; }