/* Shadowrun Character Viewer - theme and layout
   Palette: near-black slate background, amber primary accent (classic SR orange),
   cyan secondary accent (matrix/decker flavor), restrained use of red for warnings. */

:root {
    --bg: #15171c;
    --bg-elevated: #1c1f27;
    --bg-panel: #20242e;
    --bg-input: #272b36;
    --border: #343a48;
    --border-soft: #2a2f3b;
    --text: #e8e6e1;
    --text-dim: #9aa0ad;
    --text-faint: #6b7280;
    --accent: #e0943a;
    --accent-strong: #f0a94a;
    --accent-dim: #8a5a24;
    --cyan: #4fd1c5;
    --red: #e25555;
    --green: #5ec98b;
    --radius: 8px;
    --font-display: 'Oswald', 'Arial Narrow', sans-serif;
    --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

html, body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    margin: 0;
    padding: 0;
}

h1, h2, h3, h4 {
    font-family: var(--font-display);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--accent-strong);
    margin: 0 0 8px 0;
}

a { color: var(--cyan); text-decoration: none; }
a:hover { text-decoration: underline; }

#blazor-error-ui {
    background: var(--red);
    color: white;
    bottom: 0;
    box-shadow: 0 -2px 8px rgba(0,0,0,.4);
    display: none;
    left: 0;
    padding: 0.8rem 1.2rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}
#blazor-error-ui .reload { color: white; text-decoration: underline; margin-left: 8px; }
#blazor-error-ui .dismiss { cursor: pointer; float: right; }

/* ---------- Home / upload page ---------- */
.home-page { max-width: 1100px; margin: 0 auto; padding: 32px 20px 60px; }
.home-header { text-align: center; margin-bottom: 28px; }
.home-header h1 { font-size: 2rem; }
.home-header .subtitle { color: var(--text-dim); margin: 0; }

.upload-box { margin: 0 auto 28px; max-width: 640px; }
.file-input { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
.upload-dropzone {
    display: flex; align-items: center; justify-content: center;
    border: 2px dashed var(--border); border-radius: var(--radius);
    padding: 36px 20px; cursor: pointer; text-align: center;
    color: var(--text-dim); background: var(--bg-elevated);
    transition: border-color .15s, color .15s;
}
.upload-dropzone:hover { border-color: var(--accent); color: var(--text); }
.upload-dropzone strong { color: var(--accent-strong); }
.upload-dropzone.busy { border-color: var(--cyan); color: var(--cyan); cursor: wait; }

.upload-results { list-style: none; margin: 14px 0 0; padding: 0; font-size: 0.9rem; }
.upload-results li { padding: 4px 0; }
.upload-results li.ok { color: var(--green); }
.upload-results li.error { color: var(--red); }

.sample-section { text-align: center; margin-bottom: 32px; }
.sample-section h3 { font-size: 1rem; color: var(--text-dim); }
.sample-buttons { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }

.roster-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.roster-card {
    display: flex; align-items: center; gap: 12px; background: var(--bg-panel);
    border: 1px solid var(--border-soft); border-radius: var(--radius); padding: 12px;
    cursor: pointer; position: relative; transition: border-color .15s, transform .1s;
}
.roster-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.roster-portrait {
    width: 48px; height: 48px; border-radius: 50%; background: var(--bg-input);
    display: flex; align-items: center; justify-content: center; overflow: hidden;
    flex-shrink: 0; font-family: var(--font-display); color: var(--accent); font-size: 1.1rem;
}
.roster-portrait img { width: 100%; height: 100%; object-fit: cover; }
.roster-info { min-width: 0; flex: 1; }
.roster-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.roster-meta { font-size: 0.8rem; color: var(--text-dim); }
.roster-remove {
    position: absolute; top: 6px; right: 6px; opacity: 0.5;
}
.roster-card:hover .roster-remove { opacity: 1; }

.empty-hint { color: var(--text-faint); font-style: italic; }
.not-found { max-width: 500px; margin: 60px auto; text-align: center; color: var(--text-dim); }

/* ---------- Sheet toolbar ---------- */
.sheet-toolbar {
    display: flex; align-items: center; gap: 14px; padding: 10px 16px;
    background: var(--bg-elevated); border-bottom: 1px solid var(--border-soft);
    position: sticky; top: 0; z-index: 20;
}
.back-link { color: var(--text-dim); font-size: 0.9rem; }
.toolbar-spacer { flex: 1; }
.char-switcher {
    background: var(--bg-input); color: var(--text); border: 1px solid var(--border);
    border-radius: 5px; padding: 5px 8px;
}

/* ---------- Buttons ---------- */
.btn-secondary, .link-btn {
    background: var(--bg-input); color: var(--text); border: 1px solid var(--border);
    border-radius: 6px; padding: 7px 14px; cursor: pointer; font-size: 0.85rem;
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent-strong); }
.btn-secondary:disabled { opacity: 0.5; cursor: wait; }
.link-btn { background: none; border: none; color: var(--cyan); text-decoration: underline; padding: 0; font-size: 0.8rem; }

.icon-btn {
    background: none; border: 1px solid transparent; color: var(--text-dim);
    cursor: pointer; border-radius: 4px; padding: 2px 6px; font-size: 0.9rem; line-height: 1;
}
.icon-btn:hover { color: var(--accent-strong); background: rgba(255,255,255,0.06); }
.icon-btn.tiny { font-size: 0.7rem; padding: 1px 4px; }

/* ---------- Dashboard grid ---------- */
.dashboard-grid {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px;
    padding: 16px; max-width: 1400px; margin: 0 auto;
}
.dashboard-cell { grid-column: span 1; min-width: 0; }
.dashboard-cell.span-1 { grid-column: span 1; }
.dashboard-cell.span-2 { grid-column: span 2; }
.dashboard-cell.span-3 { grid-column: span 3; }
.dashboard-cell.dragging { opacity: 0.4; }
.dashboard-cell.drag-over > .panel-container { border-color: var(--cyan); box-shadow: 0 0 0 1px var(--cyan); }

.empty-dashboard-hint { text-align: center; color: var(--text-faint); padding: 40px; }

@media (max-width: 860px) {
    .dashboard-grid { grid-template-columns: 1fr; }
    .dashboard-cell.span-1, .dashboard-cell.span-2, .dashboard-cell.span-3 { grid-column: span 1; }
}

.panel-container {
    background: var(--bg-panel); border: 1px solid var(--border-soft); border-radius: var(--radius);
    height: 100%; display: flex; flex-direction: column; overflow: hidden;
}
.panel-header {
    display: flex; align-items: center; gap: 8px; padding: 9px 12px;
    background: var(--bg-elevated); border-bottom: 1px solid var(--border-soft);
    cursor: grab; user-select: none;
}
.panel-header:active { cursor: grabbing; }
.drag-handle { color: var(--text-faint); font-size: 0.75rem; letter-spacing: -2px; }
.panel-title {
    font-family: var(--font-display); text-transform: uppercase; letter-spacing: 0.03em;
    font-size: 0.85rem; color: var(--accent); flex: 1;
}
.panel-actions { display: flex; gap: 2px; }
.panel-body { padding: 12px 14px; overflow-x: auto; }
.panel-footnote { color: var(--text-faint); font-size: 0.75rem; margin-top: 10px; }

/* ---------- Settings drawer ---------- */
.settings-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.45); opacity: 0; pointer-events: none;
    transition: opacity .15s; z-index: 30;
}
.settings-overlay.open { opacity: 1; pointer-events: auto; }
.settings-drawer {
    position: fixed; top: 0; right: 0; height: 100%; width: 340px; max-width: 90vw;
    background: var(--bg-elevated); border-left: 1px solid var(--border);
    transform: translateX(100%); transition: transform .2s ease; z-index: 31;
    display: flex; flex-direction: column;
}
.settings-drawer.open { transform: translateX(0); }
.settings-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 16px; border-bottom: 1px solid var(--border-soft);
}
.settings-header h3 { margin: 0; font-size: 1rem; }
.settings-body { padding: 14px 16px; overflow-y: auto; flex: 1; }
.settings-body section { margin-bottom: 22px; }
.settings-body h4 { font-size: 0.85rem; color: var(--text-dim); margin-bottom: 6px; }
.hint { color: var(--text-faint); font-size: 0.78rem; margin: 0 0 10px; }

.toggle-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 0.88rem; cursor: pointer; }
.toggle-row.small { font-size: 0.82rem; }
.toggle-row.inline { display: inline-flex; margin-left: 10px; }
.category-list { display: flex; flex-wrap: wrap; gap: 0 14px; }

.text-input {
    width: 100%; background: var(--bg-input); color: var(--text); border: 1px solid var(--border);
    border-radius: 5px; padding: 6px 9px; font-size: 0.85rem; margin: 6px 0;
}
.text-input.small { width: 160px; margin: 0; }

.quick-filters { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }

/* ---------- Header panel ---------- */
.header-panel { display: flex; gap: 18px; align-items: flex-start; }
.portrait-box { flex-shrink: 0; width: 96px; height: 96px; border-radius: var(--radius); overflow: hidden; background: var(--bg-input); display: flex; align-items: center; justify-content: center; border: 1px solid var(--border-soft); }
.portrait-img { width: 100%; height: 100%; object-fit: cover; }
.portrait-placeholder { font-family: var(--font-display); font-size: 2rem; color: var(--accent-dim); }
.header-info { flex: 1; min-width: 0; }
.header-top-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.char-name { font-size: 1.6rem; margin: 0; }
.char-realname { color: var(--text-dim); font-size: 0.9rem; margin-top: -4px; margin-bottom: 4px; }
.mode-badge { font-size: 0.68rem; padding: 3px 8px; border-radius: 10px; text-transform: uppercase; letter-spacing: 0.05em; }
.mode-badge.career { background: rgba(94,201,139,0.15); color: var(--green); }
.mode-badge.creation { background: rgba(224,148,58,0.15); color: var(--accent-strong); }
.meta-line { color: var(--text-dim); margin: 2px 0 6px; }
.archetype-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.tag { background: rgba(79,209,197,0.12); color: var(--cyan); border-radius: 10px; padding: 2px 9px; font-size: 0.72rem; }
.tag.small { font-size: 0.65rem; padding: 1px 7px; }
.tag.warn { background: rgba(226,85,85,0.15); color: var(--red); }
.resource-bar { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 6px; }
.resource { display: flex; flex-direction: column; }
.r-label { font-size: 0.68rem; color: var(--text-faint); text-transform: uppercase; }
.r-value { font-weight: 600; font-size: 1.05rem; }
.player-line { color: var(--text-faint); font-size: 0.78rem; margin-top: 8px; }

/* ---------- Attributes ---------- */
.attr-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.attr-grid.secondary { margin-top: 10px; grid-template-columns: repeat(3, 1fr); }
.attr-box {
    background: var(--bg-elevated); border: 1px solid var(--border-soft); border-radius: 6px;
    padding: 8px 4px; text-align: center;
}
.attr-box.essence-box { border-color: var(--accent-dim); }
.attr-name { font-family: var(--font-display); font-size: 0.75rem; color: var(--text-dim); letter-spacing: 0.05em; }
.attr-value { font-size: 1.5rem; font-weight: 700; color: var(--text); line-height: 1.1; }
.attr-fullname { font-size: 0.62rem; color: var(--text-faint); }

/* ---------- Derived stats ---------- */
.derived-stats { display: flex; flex-direction: column; gap: 12px; }
.derived-row { display: flex; gap: 18px; flex-wrap: wrap; }
.derived-stat { display: flex; flex-direction: column; min-width: 64px; }
.d-label { font-size: 0.68rem; color: var(--text-faint); text-transform: uppercase; }
.d-value { font-size: 1.3rem; font-weight: 700; }
.d-value.small { font-size: 1rem; }
.d-sub { font-size: 0.75rem; color: var(--text-dim); font-weight: 400; }
.limits-row { display: flex; gap: 10px; }
.limit-box { flex: 1; background: var(--bg-elevated); border: 1px solid var(--border-soft); border-radius: 6px; padding: 6px 8px; text-align: center; }
.movement-row { border-top: 1px solid var(--border-soft); padding-top: 10px; }
.limit-mods-detail { font-size: 0.78rem; color: var(--text-dim); }
.limit-mods-detail summary { cursor: pointer; color: var(--cyan); }
.limit-mods-detail ul { margin: 6px 0 0 18px; padding: 0; }

.cm-track-wrap { display: flex; flex-direction: column; gap: 4px; }
.cm-label { font-size: 0.75rem; color: var(--text-dim); }
.cm-count { color: var(--text-faint); }
.cm-track { display: flex; gap: 3px; flex-wrap: wrap; }
.cm-box { width: 16px; height: 16px; border: 1px solid var(--border); border-radius: 3px; background: var(--bg-input); }
.cm-box.filled { background: var(--red); border-color: var(--red); }
.cm-box.overflow { border-style: dashed; }
.cm-box.overflow.filled { background: #7a1f1f; border-color: #7a1f1f; }
.cm-gap { width: 8px; }

/* ---------- Tables ---------- */
.sr-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.sr-table th {
    text-align: left; font-family: var(--font-display); font-size: 0.7rem; letter-spacing: 0.04em;
    color: var(--text-faint); text-transform: uppercase; border-bottom: 1px solid var(--border-soft); padding: 4px 6px;
}
.sr-table td { padding: 5px 6px; border-bottom: 1px solid var(--border-soft); vertical-align: top; }
.sr-table tbody tr:hover { background: rgba(255,255,255,0.03); }
.sr-table .num { text-align: center; white-space: nowrap; }
.sr-table tr.broken-row { color: var(--red); }
.sub-category { font-size: 0.72rem; color: var(--text-faint); }
.sub-accessories { font-size: 0.72rem; color: var(--cyan); }

/* ---------- Qualities ---------- */
.qualities-panel { display: flex; gap: 20px; flex-wrap: wrap; }
.quality-col { flex: 1; min-width: 160px; }
.quality-col h4.positive { color: var(--green); }
.quality-col h4.negative { color: var(--red); }
.quality-list { list-style: none; margin: 0; padding: 0; font-size: 0.88rem; }
.quality-list li { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; border-bottom: 1px solid var(--border-soft); }
.q-bp { color: var(--text-faint); font-size: 0.78rem; white-space: nowrap; }

.plain-list { margin: 4px 0 0 18px; padding: 0; font-size: 0.88rem; }

/* ---------- Gear tree ---------- */
.gear-tree { font-size: 0.88rem; }
.gear-node { display: flex; align-items: baseline; gap: 8px; padding: 3px 0; border-bottom: 1px solid var(--border-soft); }
.gear-name { flex: 1; }
.gear-rating { color: var(--cyan); font-size: 0.78rem; }
.gear-qty { color: var(--text-dim); font-size: 0.78rem; }
.gear-cost { color: var(--text-faint); font-size: 0.78rem; white-space: nowrap; }

/* ---------- Contacts ---------- */
.contact-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.contact-card { background: var(--bg-elevated); border: 1px solid var(--border-soft); border-radius: 6px; padding: 10px; }
.contact-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.contact-name { font-weight: 600; }
.contact-role { color: var(--text-dim); font-size: 0.82rem; margin: 2px 0 6px; }
.contact-ratings { display: flex; gap: 14px; font-size: 0.75rem; color: var(--text-faint); }
.contact-ratings span { display: flex; align-items: center; gap: 4px; }
.contact-notes { font-size: 0.78rem; color: var(--text-dim); margin-top: 6px; white-space: pre-wrap; }

.rating-dots { display: inline-flex; gap: 2px; }
.rating-dots .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--bg-input); border: 1px solid var(--border); }
.rating-dots .dot.on { background: var(--accent); border-color: var(--accent); }

/* ---------- Vehicles / Lifestyle ---------- */
.vehicle-card, .lifestyle-card { background: var(--bg-elevated); border: 1px solid var(--border-soft); border-radius: 6px; padding: 10px; margin-bottom: 10px; }
.vehicle-head, .lifestyle-head { display: flex; justify-content: space-between; align-items: baseline; }
.vehicle-name, .lifestyle-name { font-weight: 600; }
.vehicle-stats, .lifestyle-stats { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.82rem; color: var(--text-dim); margin-top: 4px; }
.vehicle-mods { font-size: 0.78rem; color: var(--text-faint); margin-top: 4px; }
.lifestyle-location { font-size: 0.78rem; color: var(--text-faint); margin-top: 2px; }

/* ---------- Biography ---------- */
.biography-grid { display: flex; flex-direction: column; gap: 14px; }
.bio-block h4 { font-size: 0.82rem; color: var(--text-dim); margin-bottom: 4px; }
.bio-block p { white-space: pre-wrap; margin: 0; line-height: 1.5; color: var(--text); }

/* ---------- View mode toggle ---------- */
.home-topbar { display: flex; justify-content: flex-end; max-width: 1100px; margin: 0 auto 8px; padding: 0 20px; }
.view-mode-toggle {
    display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
    background: rgba(79,209,197,0.1); color: var(--cyan); border: 1px solid var(--cyan);
    border-radius: 20px; padding: 6px 14px; font-size: 0.82rem; cursor: pointer;
}
.view-mode-toggle:hover { background: rgba(79,209,197,0.2); }

/* ================================================================
   Mobile layout mode - everything below applies only when the site
   is actively rendering in mobile mode (device-detected or chosen
   via the toggle above), never just because a desktop window
   happens to be narrow. Set on <html> by ViewModeService via
   srvView.setMode() in wwwroot/js/interop.js.
   ================================================================ */

html[data-viewmode="mobile"] .sheet-toolbar { flex-wrap: wrap; gap: 8px 10px; }
html[data-viewmode="mobile"] .char-switcher { font-size: 0.95rem; padding: 8px 10px; }
html[data-viewmode="mobile"] .btn-secondary,
html[data-viewmode="mobile"] .view-mode-toggle { padding: 9px 14px; font-size: 0.88rem; }
html[data-viewmode="mobile"] .icon-btn { padding: 6px 9px; }
html[data-viewmode="mobile"] .icon-btn.tiny { padding: 5px 8px; font-size: 0.8rem; }
html[data-viewmode="mobile"] .text-input.small { width: 100%; }

html[data-viewmode="mobile"] .home-page { padding: 20px 14px 50px; }
html[data-viewmode="mobile"] .roster-grid { grid-template-columns: 1fr; }
html[data-viewmode="mobile"] .header-panel { flex-direction: column; align-items: center; text-align: center; }
html[data-viewmode="mobile"] .header-top-row { justify-content: center; }
html[data-viewmode="mobile"] .resource-bar { justify-content: center; }
html[data-viewmode="mobile"] .attr-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
html[data-viewmode="mobile"] .attr-grid.secondary { grid-template-columns: repeat(2, 1fr); }
html[data-viewmode="mobile"] .attr-value { font-size: 1.7rem; }
html[data-viewmode="mobile"] .settings-drawer { width: 100%; }

/* Accordion stack replaces the drag/drop grid as the mobile dashboard shell. Reuses the same
   LayoutService order/visibility as the desktop grid - only the chrome differs. */
.accordion-stack { padding: 12px; max-width: 700px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }
.accordion-section { background: var(--bg-panel); border: 1px solid var(--border-soft); border-radius: var(--radius); overflow: hidden; }
.accordion-header {
    display: flex; align-items: center; gap: 8px; padding: 12px 14px;
    background: var(--bg-elevated); cursor: pointer; user-select: none;
}
.accordion-chevron { color: var(--text-faint); font-size: 0.8rem; width: 14px; flex-shrink: 0; text-align: center; }
.accordion-header .panel-title { font-size: 0.85rem; }
.accordion-header .panel-actions { display: flex; gap: 2px; }
.accordion-header .icon-btn:disabled { opacity: 0.3; cursor: default; }
.accordion-body { padding: 12px 14px; overflow-x: auto; }

/* Responsive "card" tables: the header row becomes a label stacked above each value instead
   of a column, since several cells here hold more than one line of content (name + category
   sub-line) and a left-label/right-value flex split only reads correctly for a single value. */
html[data-viewmode="mobile"] .sr-table,
html[data-viewmode="mobile"] .sr-table tbody,
html[data-viewmode="mobile"] .sr-table tr,
html[data-viewmode="mobile"] .sr-table td { display: block; width: auto; }
html[data-viewmode="mobile"] .sr-table thead { display: none; }
html[data-viewmode="mobile"] .sr-table tr {
    border: 1px solid var(--border-soft); border-radius: 6px; padding: 10px 12px; margin-bottom: 8px;
    background: rgba(255,255,255,0.02);
}
html[data-viewmode="mobile"] .sr-table tr.broken-row { background: rgba(226,85,85,0.1); }
html[data-viewmode="mobile"] .sr-table td {
    padding: 5px 0; border-bottom: 1px dotted var(--border-soft); text-align: left; white-space: normal;
}
html[data-viewmode="mobile"] .sr-table td:last-child { border-bottom: none; }
html[data-viewmode="mobile"] .sr-table td[data-label]::before {
    content: attr(data-label); display: block; font-family: var(--font-display);
    font-size: 0.65rem; letter-spacing: 0.04em; text-transform: uppercase;
    color: var(--text-faint); margin-bottom: 1px;
}
html[data-viewmode="mobile"] .sr-table td:not([data-label]) { padding-top: 6px; text-align: right; }
