/* style.css */

:root {
    --bg-dark: #2b2b2b;
    --bg-panel: #343638;
    --bg-input: #404040;
    --text-main: #ffffff;
    --text-muted: #aaaaaa;
    --accent: #1f538d;
    --success: #28a745;
    --danger: #dc3545;
    --warning: #ffc107;
    --border: #4a4a4a;
}

/* ===== GLOBAL SAFETY (prevents weird overflow on smaller widths) ===== */
*, *::before, *::after { box-sizing: border-box; }

html, body { max-width: 100%; overflow-x: hidden; }

img, video, canvas, svg { max-width: 100%; height: auto; }

/* ===== LAYOUT ===== */
body {
    margin: 0;
    font-family: 'Segoe UI', sans-serif;
    background: var(--bg-dark);
    color: var(--text-main);
    height: 100vh;
    overflow-x: hidden;
    overflow-y: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
    min-width: 0; /* allow children to shrink */
}

/* Sidebar Layout */
.sidebar {
    width: 350px;
    background: #212121;
    padding: 15px;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 15px;
    flex-shrink: 0;
    min-width: 0;
}

.panel {
    background: var(--bg-panel);
    padding: 15px;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.header { display: flex; justify-content: space-between; align-items: center; }

/* Panel sizing logic */
.panel-add {
    flex: 0 0 auto;
    max-height: 70vh;
    overflow-y: auto;
    min-width: 0;
}

.panel-monitors {
    flex: 1 1 auto;
    min-height: 150px;
    overflow: hidden;
    min-width: 0;
}

.scroll-list {
    overflow-y: auto;
    height: 100%;
    padding-right: 5px;
    min-width: 0;
}

/* Inputs & Forms */
h4 {
    margin: 0 0 10px 0;
    font-size: 1.1em;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

input, select {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: white;
    padding: 8px;
    margin: 4px 0 10px;
    border-radius: 4px;
    box-sizing: border-box;
}

.row { display: flex; gap: 10px; min-width: 0; }
.row > * { min-width: 0; }

/* COMPACT CONDITIONS GRID */
.conditions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 6px;
    background: rgba(0,0,0,0.2);
    padding: 8px;
    border-radius: 4px;
    margin-bottom: 10px;
    border: 1px solid var(--border);
}

.conditions-grid label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8em;
    cursor: pointer;
    background: #3a3a3a;
    padding: 4px 6px;
    border-radius: 3px;
    transition: background 0.2s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.conditions-grid label:hover { background: #4a4a4a; }
.conditions-grid input { margin: 0; width: auto; }

/* Buttons */
button {
    width: 100%;
    padding: 10px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    color: white;
    font-weight: bold;
    transition: 0.2s;
    margin-top: 5px;
}

.btn-primary { background: var(--accent); }
.btn-success { background: var(--success); }
.btn-secondary { background: #6c757d; }
.btn-danger { background: var(--danger); }
.btn-warning { background: var(--warning); color: black; }
.hidden { display: none !important; }

/* Mobile Menu Button (Hidden on PC) */
.hidden-pc { display: none; }

/* Content Area */
.content {
    flex-grow: 1;
    padding: 20px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0; /* IMPORTANT: prevents flex overflow on narrower screens */
}

/* Top bar */
.top-bar {
    background: var(--bg-panel);
    padding: 10px;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    flex-wrap: wrap;
    gap: 10px;
    min-width: 0;
}

.filters, .status-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    min-width: 0;
}

/* === LAST UPDATED TIMER STYLE (PC & Mobile) === */
.status-box {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    min-width: 0;   /* allow shrink */
    margin-right: 10px;
    background: rgba(0,0,0,0.2);
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid #444;
    max-width: 100%;
}

#last-updated {
    font-size: 0.9em;
    color: #ffd700;
    font-weight: bold;
    margin-bottom: 2px;
}

#status-text {
    font-size: 0.8em;
    color: white;
    overflow-wrap: anywhere;
}

#results-view, #history-view, #hidden-view {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

/* Results Grid */
.results-grid {
    overflow-y: auto;
    flex-grow: 1;
    display: grid;

    /* Fallback */
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));

    /* Better: never overflow, and looks consistent at 1080p */
    grid-template-columns: repeat(auto-fit, minmax(min(420px, 100%), 1fr));

    gap: 15px;
    padding-right: 5px;
    align-content: start;
    width: 100%;
    max-width: 100%;
    min-width: 0;
}

/* Item Card */
.item-card {
    background: var(--bg-panel);
    display: flex;
    padding: 12px;
    border-radius: 6px;

    /* contain everything inside card */
    overflow: hidden;

    /* smoother */
    border: 1px solid rgba(255,255,255,0.06);
    transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;

    height: auto;
    position: relative;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);

    max-width: 100%;
    min-width: 0;
}

.item-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 14px rgba(0,0,0,0.35);
    border-color: rgba(79,170,230,0.35);
}

.item-card.new-item { border-color: var(--success); background: #2f3e33; }

/* UPDATED: Pinned Item Styles (single definition) */
.item-card.pinned {
    border: 2px solid #ffd700;
    background: #2a2a20;
    order: -1;
}

/* Keep gold border even when hovered */
.item-card.pinned:hover { border-color: #ffd700 !important; }

/* Pin badge */
.item-card.pinned::after {
    content: "📌";
    position: absolute;
    top: 8px;
    right: 8px;
    font-size: 1.1em;
    background: #2b2b2b;
    border-radius: 50%;
    width: 26px;
    height: 26px;
    text-align: center;
    line-height: 26px;
    border: 1px solid #ffd700;
    box-shadow: 0 2px 5px rgba(0,0,0,0.5);
    z-index: 5;
    pointer-events: none;
}

/* Image */
.item-img {
    width: 110px;
    height: 110px;
    object-fit: cover;
    background: #000;
    border-radius: 4px;
    flex-shrink: 0;
}

/* Details column */
.item-details {
     padding-left: 18px;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    gap: 6px;
    min-width: 0; /* IMPORTANT: allow shrink so text wraps instead of overflowing */
    max-width: 100%;
}

/* Make all content inside details allowed to shrink */
.item-details > * { min-width: 0; max-width: 100%; }

/* Title */
.item-title {
    font-weight: bold;
    font-size: 1em;
    color: #4faae6;
    text-decoration: none;

    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;

    overflow: hidden;
    line-height: 1.3;

    /* prevent long tokens forcing overflow */
    overflow-wrap: anywhere;
}

.text-green { color: #90EE90; font-weight: bold; }
.text-red { color: #FF6A6A; font-weight: bold; }

.item-meta {
    font-size: 0.85em;
    color: var(--text-muted);
    line-height: 1.4;
    margin-top: auto;
    overflow-wrap: anywhere;
}

.seller-info { color: #FFD700; font-size: 0.9em; overflow-wrap: anywhere; }

/* Condition Badge */
.condition-badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.8em;
    font-weight: bold;
    color: white;
    background: #555;
    margin-right: 5px;
    text-transform: capitalize;
    max-width: 100%;
    overflow-wrap: anywhere;
}
.cond-new { background: var(--success); }
.cond-used { background: #6c757d; }
.cond-parts { background: var(--danger); }
.cond-refurb { background: var(--accent); }

/* Monitor Item */
.mon-item {
    background: #444;
    padding: 10px;
    margin-bottom: 6px;
    border-radius: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.95em;
    min-width: 0;
    overflow-wrap: anywhere;
}
/* .mon-btns styles are defined below to prevent icon wrapping */

/* Modal */
.modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.7); display: flex; justify-content: center; align-items: center; z-index: 1000;
}
.modal-content {
    background: var(--bg-panel); padding: 25px; border-radius: 8px; width: 320px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
}
.history-header { display: flex; gap: 10px; margin-bottom: 10px; align-items: center; }

/* FIX: Force status bar buttons to be horizontal and auto-sized */
.status-bar button {
    width: auto;
    margin: 0;
    padding: 8px 15px;
}

/* IMPORTANT FIX: remove nowrap that can cause horizontal overflow on 1080p */
.status-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    white-space: normal;
    max-width: 100%;
    min-width: 0;
}

#filter-status {
    font-size: 0.8em;
    background: var(--accent);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    margin-left: 10px;
    vertical-align: middle;
    font-weight: normal;
    max-width: 100%;
    overflow-wrap: anywhere;
}

/* ===== Card structure upgrades ===== */
.item-badges{
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
    margin-top: 2px;
    min-width: 0;
}

.item-price-row{ margin-top: 2px; min-width: 0; }

.item-submeta{
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    font-size: 0.85em;
    color: var(--text-muted);

    /* key: allow wrap instead of pushing width */
    flex-wrap: wrap;
    min-width: 0;
    overflow-wrap: anywhere;
}

.item-footer{
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-top: auto;
    padding-top: 6px;
    border-top: 1px solid rgba(255,255,255,0.06);

    /* key: allow wrap instead of overflow */
    flex-wrap: wrap;
    min-width: 0;
    overflow-wrap: anywhere;
}

/* Make listed time POP */
.listed-time{
    font-size: 0.92em;
    font-weight: 700;
    color: #ffd700;
    background: rgba(255, 215, 0, 0.12);
    border: 1px solid rgba(255, 215, 0, 0.25);
    padding: 4px 8px;
    border-radius: 999px;
    line-height: 1;
    white-space: nowrap;
}

/* Show monitor/source as a pill on the right */
.source-pill{
    font-size: 0.78em;
    color: #cfe6ff;
    background: rgba(31,83,141,0.25);
    border: 1px solid rgba(31,83,141,0.45);
    padding: 4px 8px;
    border-radius: 999px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;

    /* key: don't force card wider */
    max-width: 100%;
    min-width: 0;
}

/* Auction box */
.listing-type { font-weight: bold; color: #9ecbff; overflow-wrap: anywhere; }

.auction-box{
    display: flex;
    justify-content: space-between;
    background: rgba(255, 193, 7, 0.15);
    border: 1px solid #ffc107;
    border-radius: 4px;
    padding: 4px 6px;
    margin: 4px 0;
    font-size: 0.9em;

    /* key: wrap so it never pushes width */
    flex-wrap: wrap;
    gap: 6px;
    min-width: 0;
    overflow-wrap: anywhere;
}

.auction-left { color: #ffc107; font-weight: bold; }
.auction-right { color: #ddd; }

/* ========================================= */
/* MOBILE / TABLET OPTIMIZATIONS             */
/* ========================================= */
@media (max-width: 900px) {
    body { overflow-y: auto; overflow-x: hidden; }
    .app-container { flex-direction: column; height: auto; display: block; }

    /* Toggle Button */
    .hidden-pc { display: block; margin: 10px; width: calc(100% - 20px); text-align: center; }

    /* Hide Sidebar by default on mobile */
    .sidebar {
        display: none;
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding: 10px;
        box-sizing: border-box;
        height: auto;
    }

    /* When active, show it */
    .sidebar.active { display: flex; }

    .panel-add { max-height: none; overflow: visible; }
    .panel-monitors { min-height: 200px; }

    /* Content Area */
    .content { padding: 10px; height: auto; overflow: visible; }

    .top-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 15px;
    }

    .filters { justify-content: space-between; }
    .filters label { flex: 1; min-width: 0; }

    /* Status Bar Mobile */
    .status-bar {
        justify-content: space-between;
        background: rgba(0,0,0,0.2);
        padding: 8px;
        border-radius: 6px;
    }
    .status-box { align-items: flex-start; margin-right: 0; }

    .btn-secondary, .btn-primary, .btn-warning, .btn-success { font-size: 0.9em; padding: 12px; }

    /* Grid becomes 1 column */
    .results-grid {
        grid-template-columns: 1fr;
        overflow: visible;
        height: auto;
    }

    .item-card { padding: 10px; }
    .item-img { width: 90px; height: 90px; }
    .item-title { font-size: 1.1em; }
}


/* =========================================
   1080p FIX: allow vertical PAGE scrolling
   (paste at very end of style.css)
========================================= */

/* Let the page grow vertically (no more "fit into 100vh") */
body{
  height: auto !important;
  min-height: 100vh;
  overflow-y: auto !important;   /* allow vertical page scroll */
  overflow-x: hidden !important; /* never allow horizontal scroll */
}

/* App no longer forced to viewport height */
.app-container{
  height: auto !important;
  min-height: 100vh;
}

/* Stop trapping scroll inside inner panels */
.content,
#results-view,
#history-view,
#hidden-view{
  overflow: visible !important;
}

/* Grid should flow naturally and make the page scroll */
.results-grid{
  overflow: visible !important;
  height: auto !important;
  max-height: none !important;
  padding-bottom: 24px;
}

/* Make sure cards never look "compressed" */
.item-card{
  min-height: 150px; /* adjust to taste (150–180 is a good range) */
}

/* Keep: prevent flex children from forcing horizontal overflow */
.item-details,
.item-details > *{
  min-width: 0;
}

/* Keep: break long usernames/IDs/strings instead of overflowing */
.item-card,
.item-details,
.item-meta,
.item-submeta,
.item-footer,
.source-pill,
.seller-info{
  overflow-wrap: anywhere;
}

/* Status bar: wrapping prevents it pushing layout wider */
.status-bar{
  white-space: normal !important;
  flex-wrap: wrap !important;
  max-width: 100%;
}

/* Dual Price Styling */
.price-row {
    display: flex;
    gap: 10px;
    font-weight: bold;
    margin: 4px 0;
    font-size: 0.95em;
}

.price-bid {
    color: #ffc107; /* Yellow/Orange for Bids */
}

.price-bin {
    color: #28a745; /* Green for Buy It Now */
    border-left: 1px solid #555;
    padding-left: 10px;
}

.price-main {
    font-size: 1.2em;
    font-weight: bold;
    color: #28a745;
    margin: 4px 0;
}

/* Hide Button on Live Results - Top Right */
.btn-hide {
    position: absolute;
    top: 50px;
    right: 6px;           /* Change from left to right */
    background: rgba(0, 0, 0, 0.308);
    border: 1px solid #dc3545;
    border-radius: 4px;
    color: white;
    width: auto;
    min-width: 28px;
    padding: 2px 5px;
    font-size: 0.85rem;
    line-height: 1.2;
    cursor: pointer;
    z-index: 10;
    transition: background 0.2s;
    text-align: center;
}

.btn-hide:hover {
    background: #dc3545;
}

/* History / hidden sorting controls */
#sort-type option[value="recently_added"] {
    font-weight: bold;
}

/* Monitored Items: keep the 3 action icons locked on one row */
.mon-item {
    gap: 8px;
}

.mon-item > span:first-child {
    flex: 1 1 auto !important;
    min-width: 0;
    overflow-wrap: anywhere;
}

.mon-btns {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    flex-wrap: nowrap;
    white-space: nowrap;
}

.mon-btns button {
    flex: 0 0 auto;
    width: 34px;
    min-width: 34px;
    height: 28px;
    padding: 4px 8px;
    margin: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.mon-title {
    flex: 1 1 auto !important;
    min-width: 0;
}
