/* Sonar portal - base styles
 * Layout, sidebar, forms, feed cards, Market Watch, admin tables, modals.
 */

:root {
    /* Brand */
    --secondary: #e60005;
    --secondary-hover: #cc0004;
    --danger: #e60005;
    --success: #10b981;
    --warning: #f59e0b;
    --sidebar-width: 240px; /* same as Bridge / Radar / Pilot */

    /* Light theme (default) */
    --primary: #111827;          /* headings, strong text */
    --text: #374151;
    --text-2: #4b5563;
    --text-light: #6b7280;
    --text-faint: #9ca3af;
    --bg-color: #f3f4f6;         /* page background */
    --light: #ffffff;
    --surface: #ffffff;          /* panels, cards, modals */
    --surface-2: #f9fafb;        /* subtle fills: table heads, filter bars */
    --surface-3: #f3f4f6;        /* chips, hover */
    --input-bg: #fdfdfd;
    --border: #e5e7eb;
    --border-strong: #d1d5db;
    --dark: #1f2937;
    --sidebar-bg: #111827;
    --link: #e60005;
    --overlay: rgba(17, 24, 39, 0.7);
    --ok-bg: #dcfce7;   --ok-text: #166534;   --ok-border: #bbf7d0;
    --err-bg: #fee2e2;  --err-text: #991b1b;  --err-border: #fecaca;
    --warn-bg: #fef3c7; --warn-text: #92400e;
    --info-bg: #e0e7ff; --info-text: #3730a3;
    /* Chart ink (read by js/core.js for canvas charts) */
    --chart-text: #374151;
    --chart-muted: #6b7280;
    --chart-grid: #f3f4f6;
    --chart-ink: #111827;
    color-scheme: light;
}

/* Dark theme: chosen with the toggle in the sidebar (stored per browser); first visit follows the OS setting */
:root[data-theme="dark"] {
    --primary: #f3f4f6;
    --text: #d1d5db;
    --text-2: #c3c7ce;
    --text-light: #9ca3af;
    --text-faint: #6b7280;
    --bg-color: #111316;
    --light: #1a1d21;
    --surface: #1a1d21;
    --surface-2: #20242a;
    --surface-3: #282d34;
    --input-bg: #15181c;
    --border: #2e333b;
    --border-strong: #3b414a;
    --dark: #0b0d10;
    --sidebar-bg: #0b0d10;
    --link: #ff5a5f;
    --overlay: rgba(0, 0, 0, 0.7);
    --ok-bg: rgba(16, 185, 129, 0.16);  --ok-text: #6ee7b7;  --ok-border: rgba(16, 185, 129, 0.35);
    --err-bg: rgba(230, 0, 5, 0.18);    --err-text: #fca5a5; --err-border: rgba(230, 0, 5, 0.45);
    --warn-bg: rgba(245, 158, 11, 0.18); --warn-text: #fcd34d;
    --info-bg: rgba(99, 102, 241, 0.2); --info-text: #c7d2fe;
    --chart-text: #d1d5db;
    --chart-muted: #9ca3af;
    --chart-grid: #2a2f36;
    --chart-ink: #f3f4f6;
    color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; }
body { background-color: var(--bg-color); color: var(--text); -webkit-text-size-adjust: 100%; line-height: 1.5; }

/* Industrial Hazard Ribbon */
.axion-ribbon {
    height: 8px;
    width: 100%;
    background: repeating-linear-gradient(
        -45deg,
        var(--secondary),
        var(--secondary) 15px,
        #0f172a 15px,
        #0f172a 30px
    );
    flex-shrink: 0;
}

/* Auth Screen */
.auth-wrapper { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1rem; }
.auth-container { position: relative; overflow: hidden; width: 100%; max-width: 420px; background: var(--surface); padding: 3rem 2.5rem; border-radius: 16px; box-shadow: 0 20px 40px rgba(0,0,0,0.08); border: 1px solid rgba(0,0,0,0.02); }
.auth-container .axion-ribbon { position: absolute; top: 0; left: 0; }
.auth-logo { max-width: 80%; height: auto; margin: 1rem auto 1.5rem auto; display: block; }
.auth-container h2 { text-align: center; margin-bottom: 2rem; font-size: 1.5rem; color: var(--primary); letter-spacing: -0.5px; }
.auth-toggle { text-align: center; margin-top: 1.5rem; cursor: pointer; color: var(--text-light); font-size: 0.95rem; font-weight: 500; transition: color 0.2s; }
.auth-toggle:hover { color: var(--secondary); }

/* App Dashboard Layout */
.app-layout { display: none; height: 100vh; overflow: hidden; }

/* Sidebar Navigation */
.sidebar { width: var(--sidebar-width); flex: 0 0 var(--sidebar-width); background: var(--sidebar-bg); color: white; display: flex; flex-direction: column; border-right: 1px solid rgba(255,255,255,0.1); box-sizing: border-box; }
.sidebar-header { padding: 25px 15px 0; }
.sidebar-logo { display: block; height: 66px; width: 178px; object-fit: contain; object-position: left center; margin: 0 0 6px 10px; }
.sidebar-subtitle { color: #9ca3af; font-size: 10px; text-transform: uppercase; letter-spacing: 1px; font-weight: 600; margin: 0 0 20px 10px; }

.sidebar-user { padding: 0 15px 16px 25px; display: flex; align-items: center; gap: 10px; }
.user-avatar { width: 28px; height: 28px; background: var(--secondary); border-radius: 6px; display: flex; align-items: center; justify-content: center; font-weight: bold; font-size: 13px; flex: none; }
.user-greeting { font-weight: 600; font-size: 13px; }

.sidebar-nav { padding: 0 15px; flex: 1 1 auto; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; }
.nav-btn { display: flex; align-items: center; padding: 10px 15px; margin: 0 0 4px; color: #aab6c7; background: transparent; border: none; border-radius: 8px;
    font-size: 14px; font-weight: 500; line-height: 18px; text-align: left; width: 100%; box-sizing: border-box; cursor: pointer; transition: background 0.2s, color 0.2s; }
.nav-btn i { margin-right: 10px; font-size: 18px; flex: none; }
.nav-btn:hover { background: rgba(255,255,255,0.06); color: white; }
.nav-btn.active { background: var(--secondary); color: white; }

.sidebar-footer { padding: 8px 15px 25px; }

/* Main Content Area */
.main-content { flex: 1; overflow-y: auto; background: var(--bg-color); padding: 2.5rem; position: relative;}
.dashboard-split { display: flex; gap: 2rem; max-width: 1600px; margin: 0 auto; align-items: flex-start; }

/* Panels */
.panel { background: var(--surface); padding: 2rem; border-radius: 12px; box-shadow: 0 4px 20px rgba(0,0,0,0.03); border: 1px solid var(--border); }
.form-panel { flex: 1; min-width: 320px; position: sticky; top: 2.5rem; }
.feed-panel { flex: 2; min-width: 0; }
.admin-panel { width: 100%; max-width: 1200px; margin: 0 auto; display: none; }
.price-watch-panel { width: 100%; max-width: 1200px; margin: 0 auto; }

/* Market Watch */
.pw-stats-bar { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.pw-stat { flex: 1; min-width: 140px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 1rem 1.2rem; }
.pw-stat-value { font-size: 1.6rem; font-weight: 800; color: var(--primary); line-height: 1.2; }
.pw-stat-label { font-size: 0.8rem; color: var(--text-light); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; margin-top: 0.2rem; }
.pw-stat-value.pw-up { color: var(--success); }
.pw-stat-value.pw-down { color: var(--danger); }

.pw-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1.2rem; margin-top: 1.5rem; }
.pw-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 1.2rem; display: flex; flex-direction: column; gap: 0.6rem; cursor: pointer; transition: box-shadow 0.2s, transform 0.2s; }
.pw-card:hover { box-shadow: 0 8px 20px rgba(0,0,0,0.08); transform: translateY(-2px); }
.pw-card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.5rem; }
.pw-card-competitor { font-weight: 700; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-light); }
.pw-change-badge { font-weight: 700; font-size: 0.8rem; padding: 0.15rem 0.5rem; border-radius: 20px; white-space: nowrap; }
.pw-change-up { background: var(--ok-bg); color: var(--ok-text); }
.pw-change-down { background: var(--err-bg); color: var(--danger); }
.pw-change-flat { background: var(--surface-3); color: var(--text-light); }
.pw-card-product { font-weight: 700; color: var(--primary); font-size: 1.05rem; line-height: 1.3; }
.pw-card-price { font-size: 1.5rem; font-weight: 800; color: var(--text); }
.pw-card-price.pw-unchecked { font-size: 1rem; font-weight: 600; color: var(--text-light); font-style: italic; }
.pw-card-specs { display: flex; gap: 0.8rem; flex-wrap: wrap; font-size: 0.85rem; color: var(--text-light); }
.pw-card-specs span { background: var(--surface-3); padding: 0.2rem 0.6rem; border-radius: 6px; }
.pw-sparkline-wrap { position: relative; width: 100%; height: 40px; }
.pw-sparkline-wrap canvas { position: absolute; top: 0; left: 0; width: 100% !important; height: 100% !important; }
.pw-card-footer { display: flex; justify-content: space-between; align-items: center; font-size: 0.78rem; color: var(--text-light); border-top: 1px solid var(--border); padding-top: 0.6rem; margin-top: 0.2rem; }
.pw-card-actions { display: flex; gap: 0.6rem; align-items: center; }
.pw-card-actions a, .pw-card-actions button { color: var(--text-light); background: none; border: none; cursor: pointer; font-size: 0.9rem; padding: 0; }
.pw-card-actions a:hover, .pw-card-actions button:hover { color: var(--secondary); }
.pw-empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-light); }

h2 { margin-bottom: 1.5rem; color: var(--primary); font-weight: 700; letter-spacing: -0.5px; font-size: 1.4rem; }
.feed-header-wrapper { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.feed-header-wrapper h2 { margin-bottom: 0; }
.feed-header-buttons { display: flex; gap: 0.5rem; align-items: center; }

/* Feed Tabs (Source Filter) */
.feed-tabs { display: flex; gap: 1rem; border-bottom: 2px solid var(--border); margin-bottom: 1.5rem; overflow-x: auto; white-space: nowrap; padding-bottom: 2px; }
.feed-tab { background: none; border: none; padding: 0.5rem 1rem; cursor: pointer; font-weight: 600; font-size: 0.95rem; color: var(--text-light); border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all 0.2s; }
.feed-tab:hover { color: var(--text); }
.feed-tab.active { color: var(--secondary); border-bottom-color: var(--secondary); }

/* Inputs & Forms */
.form-group { margin-bottom: 1.2rem; }
label { display: block; margin-bottom: 0.4rem; font-weight: 600; font-size: 0.85rem; color: var(--text); }
input, select, textarea { width: 100%; padding: 0.7rem 1rem; border: 1px solid var(--border); border-radius: 8px; font-size: 0.95rem; min-height: 42px; background: var(--input-bg); transition: all 0.2s ease; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--secondary); background: var(--surface); box-shadow: 0 0 0 3px rgba(230, 0, 5, 0.1); }
textarea { resize: vertical; min-height: 100px; }
input[type="file"] { background: var(--surface-2); border: 1px dashed var(--border-strong); cursor: pointer; padding: 0.8rem; text-align: center; font-size: 0.85rem; }

button[type="submit"] { background: linear-gradient(135deg, var(--secondary) 0%, #b30004 100%); color: white; border: none; padding: 0.9rem 1.5rem; font-size: 1rem; border-radius: 8px; cursor: pointer; width: 100%; font-weight: 700; transition: all 0.2s ease; margin-top: 0.5rem; box-shadow: 0 4px 12px rgba(230, 0, 5, 0.2); }
button[type="submit"]:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(230, 0, 5, 0.3); }

/* Filter Bar */
.filter-bar { display: flex; gap: 0.8rem; margin-bottom: 2rem; background: var(--surface-2); padding: 1rem; border-radius: 8px; flex-wrap: wrap; border: 1px solid var(--border); }
.filter-bar input, .filter-bar select { flex: 1; min-width: 130px; }

/* Intel Cards */
.intel-card { background: var(--surface); padding: 1.8rem; margin-bottom: 1.2rem; border-radius: 12px; border: 1px solid var(--border); box-shadow: 0 2px 8px rgba(0,0,0,0.02); transition: transform 0.2s, box-shadow 0.2s; position: relative; }
.intel-card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,0.05); }
.intel-card::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--secondary); border-radius: 12px 0 0 12px; }
.intel-card.sticky-post { border-color: var(--warning); box-shadow: 0 4px 12px rgba(245, 158, 11, 0.15); }
.intel-card.sticky-post::before { background: var(--warning); }

.intel-meta { font-size: 0.85rem; color: var(--text-light); margin-bottom: 1rem; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding-right: 220px; }
.intel-title { font-weight: 800; margin-bottom: 0.8rem; font-size: 1.25rem; color: var(--primary); display: flex; align-items: center; }
.intel-body { margin-bottom: 1.2rem; line-height: 1.6; font-size: 0.95rem; color: var(--text-2); }
.intel-footer { font-size: 0.85rem; color: var(--text-2); background: var(--surface-2); padding: 1rem; border-radius: 8px; border-left: 3px solid var(--border-strong); margin-bottom: 1rem; }

.tag { display: inline-block; padding: 0.25rem 0.6rem; border-radius: 6px; font-size: 0.75rem; font-weight: 700; background: var(--border); color: var(--text); text-transform: uppercase; letter-spacing: 0.5px; }
.category-tag { background: rgba(230, 0, 5, 0.1); color: var(--secondary); }
.author-tag { background: transparent; color: var(--text-light); border: 1px solid var(--border); }
.saved-tag { background: var(--ok-bg); color: var(--ok-text); border: 1px solid var(--ok-border); }

.upvote-btn { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 0.25rem 0.6rem; cursor: pointer; font-weight: 700; color: var(--text); display: flex; align-items: center; gap: 0.4rem; transition: all 0.2s; font-size: 0.85rem; }
.upvote-btn:hover { background: var(--surface-3); }
.upvote-btn.voted { background: var(--secondary); color: white; border-color: var(--secondary); }

.intel-image { max-width: 100%; height: auto; border-radius: 8px; margin-top: 0.5rem; margin-bottom: 1rem; border: 1px solid var(--border); }
.intel-link { color: var(--link); text-decoration: none; word-break: break-all; font-weight: 600; }
.intel-link:hover { text-decoration: underline; color: var(--secondary-hover); }

/* Actions (Edit/Delete/Pin/Save) - Absolute Top Right */
.intel-actions-top { position: absolute; top: 1.5rem; right: 1.5rem; display: flex; gap: 0.4rem; z-index: 10; flex-wrap: wrap; justify-content: flex-end; }
.action-btn-sm { background: var(--surface); border: 1px solid var(--border); padding: 0.35rem 0.7rem; border-radius: 6px; cursor: pointer; font-size: 0.8rem; font-weight: 600; color: var(--text-light); transition: all 0.2s; box-shadow: 0 1px 2px rgba(0,0,0,0.05); }
.action-btn-sm:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }
.btn-delete-sm:hover { background: var(--err-bg); color: var(--danger); border-color: var(--err-border); }
.btn-save-sm { background: var(--ok-bg); border-color: var(--ok-border); color: var(--ok-text); }
.btn-save-sm:hover { background: var(--ok-bg); }
.btn-save-sm.active-saved { background: #10b981; color: white; border-color: #10b981; }

/* Edit Modal UI */
.modal-overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: var(--overlay); z-index: 1000; align-items: center; justify-content: center; backdrop-filter: blur(2px); }
.modal-content { background: var(--surface); padding: 2rem; border-radius: 12px; width: 90%; max-width: 500px; max-height: 90vh; overflow-y: auto; position: relative; box-shadow: 0 20px 40px rgba(0,0,0,0.2); }
.modal-close { position: absolute; top: 1.5rem; right: 1.5rem; background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text-light); line-height: 1; }
.modal-close:hover { color: var(--danger); }

/* Comments */
.comments-section { border-top: 1px solid var(--border); padding-top: 1.2rem; margin-top: 1rem; }
.comment-item { font-size: 0.9rem; margin-bottom: 0.8rem; background: var(--surface-2); padding: 0.8rem 1rem; border-radius: 8px; }
.comment-meta { font-size: 0.75rem; color: var(--text-light); margin-bottom: 0.3rem; font-weight: 600; }
.comment-form { display: flex; gap: 0.5rem; margin-top: 1rem; }
.comment-form input { flex: 1; padding: 0.6rem 1rem; border-radius: 20px; font-size: 0.9rem; min-height: 38px; }
.comment-form button { background: var(--sidebar-bg); color: white; border: none; padding: 0 1.2rem; border-radius: 20px; cursor: pointer; font-size: 0.85rem; font-weight: 600; transition: background 0.2s; }
.comment-form button:hover { background: #1f2937; }

/* Admin Table & Keyword Chips */
.admin-table { width: 100%; border-collapse: collapse; display: block; overflow-x: auto; white-space: nowrap; }
.admin-table th, .admin-table td { padding: 1rem; text-align: left; border-bottom: 1px solid var(--border); }
.admin-table th { background-color: var(--surface-2); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.5px; }
.action-btn { padding: 0.4rem 0.8rem; border: none; border-radius: 6px; cursor: pointer; color: white; font-size: 0.8rem; font-weight: 600; margin-right: 0.5rem; }
.btn-reset { background-color: #f59e0b; }
.btn-delete { background-color: var(--danger); }
.btn-export { background: transparent; color: var(--text-light); border: 1px solid var(--border); font-size: 0.9rem; padding: 0.5rem 1rem;}
.btn-export:hover { background: var(--surface-3); color: var(--primary); }
.btn-clear-scans { background: var(--err-bg); color: var(--danger); border: 1px solid var(--err-border); font-size: 0.85rem; padding: 0.5rem 0.9rem; font-weight: 600; border-radius: 6px; cursor: pointer; }
.btn-clear-scans:hover { background: var(--danger); color: white; }

/* Keyword Chip Styling */
.keyword-chip { display: inline-flex; align-items: center; gap: 0.5rem; background: var(--surface-3); border: 1px solid var(--border); padding: 0.4rem 0.8rem; border-radius: 20px; font-weight: 600; font-size: 0.85rem; color: var(--text); }
.keyword-chip-remove { background: none; border: none; color: var(--text-light); cursor: pointer; font-size: 1.1rem; line-height: 1; font-weight: bold; }
.keyword-chip-remove:hover { color: var(--danger); }

.empty-state { text-align: center; color: var(--text-light); padding: 3rem; background: var(--surface-2); border-radius: 8px; border: 1px dashed var(--border); }
.status-msg { margin-bottom: 1.5rem; padding: 1rem; border-radius: 8px; display: none; font-weight: 600; text-align: center; font-size: 0.9rem;}
.status-success { background: var(--ok-bg); color: var(--ok-text); border: 1px solid var(--ok-border); display: block; }
.status-error { background: var(--err-bg); color: var(--err-text); border: 1px solid var(--err-border); display: block; }

/* Mobile Responsive Adjustments */
@media (max-width: 900px) {
    .app-layout { flex-direction: column; overflow-y: auto; height: auto; min-height: 100vh; }
    .sidebar { width: 100%; padding: 0; border-right: none; border-bottom: 1px solid rgba(255,255,255,0.1); }
    .sidebar-header, .sidebar-user, .sidebar-nav, .sidebar-footer { padding: 1rem; border: none; }
    .sidebar-nav { flex-direction: row; flex-wrap: wrap; justify-content: center; }
    .nav-btn { flex: 1; justify-content: center; text-align: center; min-width: 120px; width: auto; }
    .sidebar-footer { display: flex; gap: 8px; }
    .sidebar-header { padding: 16px 15px 0; }
    .sidebar-logo { height: 44px; margin-bottom: 2px; }
    .sidebar-subtitle { margin-bottom: 10px; }
    .sidebar-user { padding: 0 15px 10px 25px; }
    .sidebar-nav { padding: 0 15px; }
    .sidebar-footer { padding: 4px 15px 12px; }
    .sidebar-footer .nav-btn { margin: 0; }
    .dashboard-split { flex-direction: column; }
    .form-panel { position: static; width: 100%; }
    .main-content { padding: 1rem; }
    
    .intel-actions-top { 
        position: static; 
        margin-bottom: 1rem; 
        justify-content: flex-start;
        flex-wrap: wrap;
        width: 100%;
    }
    .intel-meta { padding-right: 0; }
}

/* View-only rights: edit controls of a read-only module are hidden (the server blocks the actions too) */
body.ro-feed .edit-feed,
body.ro-pricewatch .edit-pricewatch,
body.ro-marketing .edit-marketing { display: none !important; }

/* User management */
.um-add-form { display: none; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.8rem; align-items: end; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 1.2rem; margin-bottom: 1.5rem; }
.um-add-form .form-group { margin-bottom: 0; }
.um-table select { min-height: 34px; padding: 0.3rem 0.5rem; font-size: 0.85rem; width: auto; min-width: 110px; }
.um-table select:disabled { background: var(--surface-3); color: var(--text-light); }
.um-actions { display: flex; gap: 0.4rem; }
.um-actions .action-btn { margin-right: 0; }
.um-save { background-color: var(--success); }
.um-save:disabled { background-color: var(--border-strong); cursor: default; }
.um-table th, .um-table td { padding: 0.7rem 0.6rem; }

/* Theme toggle (sidebar) */
.theme-toggle { margin-bottom: 8px; }
/* Dark mode details that plain tokens do not cover */
:root[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(0.8); }
:root[data-theme="dark"] .intel-image, :root[data-theme="dark"] .mkt-file img { border-color: var(--border); }
:root[data-theme="dark"] .panel, :root[data-theme="dark"] .pw-card, :root[data-theme="dark"] .intel-card { box-shadow: none; }
:root[data-theme="dark"] .auth-logo { filter: brightness(1.1); }

/* Market Watch: comparison with our projector (datasheet database) */
.pw-compare { display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem 0.6rem; margin-top: 0.6rem; padding-top: 0.6rem; border-top: 1px dashed var(--border); font-size: 0.82rem; color: var(--text-light); }
.pw-compare strong { color: var(--text); font-weight: 600; }
.pw-compare-label { text-transform: uppercase; font-size: 0.68rem; letter-spacing: 0.5px; font-weight: 700; color: var(--text-faint); }
.pw-cmp-diff { display: inline-block; margin-left: 0.25rem; padding: 0 0.35rem; border-radius: 4px; background: var(--surface-3); color: var(--text); font-size: 0.75rem; font-weight: 600; }
.pw-compare-preview { margin-top: 0.35rem; font-size: 0.82rem; color: var(--text-light); min-height: 1em; }

/* Market Watch: insights + compact table */
.pw-stats-bar .pw-stat .mkt-sub { font-size: 0.75rem; margin-top: 0.2rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pw-insights { margin: -0.5rem 0 1.5rem; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.pw-insights > summary { cursor: pointer; padding: 0.7rem 1.2rem; font-weight: 700; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-light); }
.pw-insights-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; padding: 0 1.2rem 1.2rem; }
.pw-insight { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 0.9rem 1rem; min-width: 0; }
.pw-insight-wide { grid-column: 1 / -1; }
.pw-insight h4 { margin: 0 0 0.6rem; font-size: 0.95rem; color: var(--primary); display: flex; gap: 0.5rem; align-items: baseline; flex-wrap: wrap; }
.pw-insight h4 .mkt-sub { font-weight: 400; }
.pw-insight-sub { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-faint); font-weight: 700; margin: 0.4rem 0 0.2rem; }
.pw-insight-list { list-style: none; margin: 0; padding: 0; font-size: 0.85rem; }
.pw-insight-list li { display: flex; justify-content: space-between; gap: 0.6rem; align-items: center; padding: 0.3rem 0; border-bottom: 1px solid var(--border); color: var(--text); }
.pw-insight-list li:last-child { border-bottom: none; }
.pw-insight-summary { margin: 0 0 0.4rem; font-size: 0.88rem; color: var(--text); }
@media (max-width: 900px) { .pw-insights-grid { grid-template-columns: 1fr; } }
.pw-view-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; flex: none; }
.pw-view-toggle button { background: var(--surface); color: var(--text-light); border: none; padding: 0 0.9rem; min-height: 42px; margin: 0; font: inherit; font-size: 0.85rem; font-weight: 600; cursor: pointer; box-shadow: none; width: auto; }
.pw-view-toggle button + button { border-left: 1px solid var(--border); }
.pw-view-toggle button.active { background: var(--surface-3); color: var(--primary); }
.pw-table-wrap { margin-top: 1.5rem; overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; }
.pw-table { font-size: 0.85rem; }
.pw-table tbody tr { cursor: pointer; }
.pw-table tbody tr:hover { background: var(--surface-2); }
.pw-table td, .pw-table th { white-space: nowrap; }
.pw-sortable { cursor: pointer; user-select: none; }
.pw-sortable.sorted { color: var(--primary); }
.pw-td-product { white-space: normal !important; min-width: 180px; font-weight: 600; color: var(--primary); }
.pw-td-competitor { display: block; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.4px; color: var(--text-light); font-weight: 700; }
.pw-td-vs { white-space: normal !important; min-width: 140px; }
.pw-td-actions { text-align: right; }
.pw-td-actions a, .pw-td-actions button { background: none; border: none; padding: 0 0.25rem; margin: 0; cursor: pointer; font-size: 0.95rem; color: var(--text-light); text-decoration: none; box-shadow: none; width: auto; min-height: 0; }
.pw-table .pw-change-badge { font-size: 0.75rem; }
.pw-insight .an-chart-wrap + .mkt-hint, .pw-insight .mkt-hint { margin-top: 0.6rem; }
.pw-table th, .pw-table td { padding: 0.55rem 0.6rem; }
.pw-table td:nth-child(6), .pw-td-vs { white-space: normal !important; min-width: 110px; }
.pw-td-product { min-width: 150px; }
.pw-table td.pw-td-actions { white-space: normal !important; width: 52px; min-width: 52px; line-height: 1.6; }
.pw-td-product { min-width: 120px; }

/* Market Watch: product detail popup */
.pw-detail-tiles { margin: 1rem 0; gap: 0.6rem; }
.pw-detail-tiles .pw-stat { min-width: 110px; padding: 0.7rem 0.9rem; }
.pw-detail-sub { font-size: 1rem; color: var(--primary); margin: 1.4rem 0 0.6rem; }
.pw-detail-source { display: grid; grid-template-columns: 2fr 1fr 1fr 1.3fr; gap: 0.8rem; padding: 0.8rem 1rem; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); font-size: 0.88rem; color: var(--text); }
.pw-detail-label { display: block; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.5px; font-weight: 700; color: var(--text-light); margin-bottom: 0.15rem; }
.pw-detail-url { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.pw-detail-source > div { min-width: 0; }
.pw-detail-specs td:first-child { font-weight: 600; color: var(--text-light); width: 110px; }
@media (max-width: 700px) { .pw-detail-source { grid-template-columns: 1fr 1fr; } }
.pw-detail-tiles .pw-stat-value { white-space: nowrap; font-size: 1.05rem !important; }

/* Market Watch: a value moved from an XPath field into the manual field briefly lights up */
.pw-manual.pw-flash select, .pw-manual.pw-flash input { box-shadow: 0 0 0 3px var(--info-bg); border-color: var(--info-text); transition: box-shadow 0.2s; }

/* Market Watch: "Our projectors" view */
.pw-ours-wrap { margin-top: 1.5rem; }
.pw-ours-summary { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 0.6rem; margin-bottom: 1rem; font-size: 0.9rem; color: var(--text); }
.pw-ours-toggle { display: inline-flex; align-items: center; gap: 0.4rem; margin: 0; font-size: 0.85rem; color: var(--text-light); cursor: pointer; }
.pw-ours-toggle input { width: auto; min-height: 0; margin: 0; }
.pw-ours-list { display: grid; grid-template-columns: 1fr; gap: 1rem; }
.pw-ours-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 1rem 1.1rem; min-width: 0; }
.pw-ours-head { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 0.7rem; }
.pw-ours-name strong { font-size: 1.05rem; color: var(--primary); }
.pw-ours-name .pw-card-competitor { display: block; }
.pw-ours-rank { font-weight: 600; }
.pw-ours-rank.top { color: var(--ok-text) !important; background: var(--ok-bg) !important; }
.pw-ours-table { font-size: 0.82rem; }
.pw-match { display: inline-block; margin-left: 0.3rem; padding: 0 0.35rem; border-radius: 4px; font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.3px; vertical-align: middle; }
.pw-match-compared { background: var(--info-bg); color: var(--info-text); }
.pw-match-similar { background: var(--surface-3); color: var(--text-light); }

/* Market Watch: our price vs theirs (text + arrow, never colour alone) */
.pw-cmp-diff.pw-cmp-cheaper { background: var(--ok-bg); color: var(--ok-text); }
.pw-cmp-diff.pw-cmp-dearer { background: var(--warn-bg); color: var(--warn-text); }

/* Market Watch: price converted to our currency */
.pw-fx { display: inline-block; margin-left: 0.3rem; font-size: 0.75em; font-weight: 500; color: var(--text-light); white-space: nowrap; }
td.num .pw-fx, .pw-stat .pw-fx { margin-left: 0; }

/* Market Watch: roles */
.pw-roles { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.35rem; }
.pw-role { display: inline-block; padding: 0.1rem 0.5rem; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-light); font-size: 0.72rem; font-weight: 600; white-space: nowrap; }
.pw-ours-roles { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.pw-ours-roles .pw-roles { margin-top: 0; }
.pw-ours-roles .mkt-tagpick { width: 100%; }
.pw-roles-edit { background: none; border: 1px dashed var(--border-strong); border-radius: 999px; color: var(--text-light); font: inherit; font-size: 0.72rem; font-weight: 600; padding: 0.1rem 0.6rem; cursor: pointer; width: auto; min-height: 0; margin: 0; box-shadow: none; }
.pw-roles-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.pw-card-fx { font-size: 1rem; line-height: 1.2; } .pw-card-fx .pw-fx { margin-left: 0; font-size: 0.8rem; }
.pw-detail-specs td, .pw-detail-specs th { white-space: normal; }
#priceWatchContent .filter-bar { flex-wrap: wrap; }
#priceWatchContent .filter-bar #pwSearchFilter { flex: 2 1 240px; }
#priceWatchContent .filter-bar select { flex: 1 1 150px; }

.pw-card-specs .pw-rgb { font-weight: 600; }

.pw-rgb-diff { display: inline-block; margin-top: 0.2rem; padding: 0 0.35rem; border-radius: 4px; background: var(--warn-bg); color: var(--warn-text); font-size: 0.72rem; font-weight: 600; }

/* Market Watch: the same product at several shops */
.pw-shops { display: flex; flex-wrap: wrap; gap: 0.2rem 0.6rem; margin-top: 0.3rem; font-size: 0.75rem; font-weight: 400; }
.pw-shops a { color: var(--link); text-decoration: none; white-space: nowrap; }
.pw-shops a:hover { text-decoration: underline; }
.pw-other-shops { margin-top: 0.5rem; font-size: 0.78rem; color: var(--text-light); }

.pw-insight h4 .pw-ppl-show { margin-left: auto; font-weight: 500; }

/* Market Watch: one of our projectors */
.pw-ours-open { color: inherit; text-decoration: none; }
.pw-ours-open:hover strong { text-decoration: underline; }
.pw-our-head { display: flex; gap: 1.2rem; align-items: flex-start; justify-content: space-between; }
.pw-our-title { min-width: 0; }
.pw-our-image { max-width: 200px; max-height: 130px; object-fit: contain; border-radius: 8px; background: #fff; padding: 6px; }
.pw-our-links { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.6rem; }
.pw-our-link { display: inline-block; padding: 0.25rem 0.6rem; border: 1px solid var(--border); border-radius: 6px; font-size: 0.8rem; font-weight: 600; color: var(--text); text-decoration: none; background: var(--surface-2); }
.pw-our-link:hover { border-color: var(--border-strong); }
#ourProjectorBody .pw-detail-tiles .pw-stat-value { white-space: normal; overflow-wrap: anywhere; }
