/*
      Reusing the aesthetic from "CPMH IRR Calculator"
      Dark mode, glassmorphism, gradients.
    */
:root {
    --bg-gradient: radial-gradient(circle at top, #0f172a, #020617);
    --card-bg: linear-gradient(135deg, rgba(15, 23, 42, 0.96), rgba(15, 23, 42, 0.9));
    --card-border: rgba(148, 163, 184, 0.35);
    --text-main: #f7fafc;
    --text-muted: #a0aec0;
    --accent-color: #4fd1c5;
    /* Teal-ish */
    --accent-gradient: linear-gradient(135deg, #4fd1c5, #63b3ed);
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text", sans-serif;
    color: var(--text-main);
    background: var(--bg-gradient);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 32px 16px;
    width: 100%;
    box-sizing: border-box;
}

/* HEADER */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.header h1 {
    font-size: 24px;
    margin: 0;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
    /* Pushes controls to far right */
}

.header p {
    margin: 4px 0 0;
    font-size: 14px;
    color: var(--text-muted);
}

.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    background: rgba(72, 187, 120, 0.12);
    color: #9ae6b4;
    border: 1px solid rgba(72, 187, 120, 0.35);
}

/* CARDS */
.card {
    background:
        radial-gradient(circle at top left, rgba(255, 255, 255, 0.08), transparent),
        var(--card-bg);
    border-radius: 18px;
    border: 1px solid var(--card-border);
    padding: 20px;
    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(18px);
    margin-bottom: 24px;
}

/* SUMMARY ROW */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.summary-item h3 {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-muted);
    margin: 0 0 6px;
}

.summary-item .value {
    font-size: 28px;
    font-weight: 600;
    margin: 0;
}

.summary-item .caption {
    font-size: 12px;
    color: #718096;
    margin: 4px 0 0;
}

/* SEARCH BAR */
.search-container {
    margin-bottom: 16px;
    display: flex;
    flex-wrap: wrap;
    width: 100%;
    gap: 12px;
    align-items: center;
}

.search-input-wrapper {
    flex: 1;
    position: relative;
}

.search-input {
    width: 100%;
    box-sizing: border-box;
    padding: 12px 16px;
    border-radius: 12px;
    border: 1px solid var(--card-border);
    background: rgba(15, 23, 42, 0.8);
    color: #fff;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.search-input:focus {
    border-color: var(--accent-color);
}

.search-btn {
    padding: 0 24px;
    height: 42px;
    border-radius: 999px;
    border: none;
    background: var(--accent-gradient);
    color: #0b1120;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(79, 209, 197, 0.3);
    transition: transform 0.1s;
}

.search-btn:active {
    transform: translateY(1px);
}

/* DASHBOARD LAYOUT (Charts + Table) */
.dashboard-grid {
    display: grid;
    grid-template-columns: 350px 1fr;
    gap: 24px;
    align-items: start;
}

@media (max-width: 900px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
}

/* CHART SECTION */
.chart-container {
    position: relative;
    height: 300px;
    width: 100%;
}

/* TABLE SECTION */
.table-wrapper {
    width: 100%;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    table-layout: auto;
}

th,
td {
    padding: 10px 8px;
    border-bottom: 1px solid rgba(45, 55, 72, 0.5);
    text-align: left;
    vertical-align: top;
    white-space: normal;
    word-wrap: break-word;
}

th {
    font-weight: 500;
    color: var(--text-muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

td {
    color: #e2e8f0;
}

tr:last-child td {
    border-bottom: none;
}

/* Specific Column Styles */
.col-right {
    text-align: right;
}

.col-center {
    text-align: center;
}

.col-artist {
    width: 22%;
    font-weight: 600;
    color: #fff;
}

.col-title {
    width: 33%;
}

.col-format {
    width: 15%;
}

.col-upc {
    width: 12%;
    font-family: monospace;
    font-size: 11px;
    opacity: 0.6;
}

.col-whse {
    width: 10%;
    font-size: 11px;
    color: #a0aec0;
}

.col-onhand {
    width: 8%;
}


/* WIDE LAYOUT TWEAKS */
@media (min-width: 900px) {
    .app-container {
        padding: 28px 24px;
    }
}

.charts-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(280px, 1fr));
    gap: 24px;
    align-items: start;
}

@media (max-width: 900px) {
    .charts-grid {
        grid-template-columns: 1fr;
    }
}

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(2, 6, 23, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    flex-direction: column;
    gap: 16px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(79, 209, 197, 0.3);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Modal */

/* INLINE TITLE REPORT */
.report-inline-grid {
    display: grid;
    grid-template-columns: minmax(280px, 420px) 1fr;
    gap: 16px;
    align-items: start;
}

@media (max-width: 980px) {
    .report-inline-grid {
        grid-template-columns: 1fr;
    }
}

.inline-report-card {
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 14px;
    background: rgba(2, 6, 23, 0.25);
}

.inline-report-header {
    display: flex;
    gap: 12px;
    justify-content: space-between;
    align-items: flex-start;
    border-bottom: 1px solid rgba(148, 163, 184, 0.22);
    padding-bottom: 12px;
    margin-bottom: 12px;
}

.inline-report-title {
    font-size: 16px;
    font-weight: 600;
    margin: 0 0 4px;
}

.inline-report-subtitle {
    font-size: 12px;
    color: var(--text-muted);
    margin: 0;
    line-height: 1.4;
}

.inline-kpis {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.inline-kpi {
    text-align: right;
    min-width: 86px;
}

.inline-kpi .k {
    font-size: 10px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.inline-kpi .v {
    font-size: 18px;
    font-weight: 600;
    margin-top: 2px;
}

.inline-report-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    align-items: start;
}

@media (max-width: 980px) {
    .inline-report-body {
        grid-template-columns: 1fr;
    }
}

.inline-report-list {
    max-height: none;
    overflow: visible;
    padding-right: 0;
}

.report-row {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 8px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.12);
}

.report-row:last-child {
    border-bottom: none;
}

.report-row .title {
    font-size: 13px;
    font-weight: 600;
    margin: 0 0 4px;
}

.report-row .meta {
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.35;
}

.report-row .qty {
    font-size: 14px;
    font-weight: 600;
    color: var(--accent-color);
    white-space: nowrap;
}

.report-row {
    cursor: pointer;
    border-radius: 10px;
    transition: background 140ms ease, opacity 140ms ease;
}

.report-row:hover {
    background: rgba(148, 163, 184, 0.10);
}

.report-row.is-active {
    background: rgba(56, 189, 248, 0.14);
    outline: 1px solid rgba(56, 189, 248, 0.35);
}

.report-row.is-faded {
    opacity: 0.45;
}

.format-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 14px;
    align-items: center;
}

.format-filters .ff-label {
    display: flex;
    gap: 8px;
    align-items: center;
    font-size: 12px;
    color: var(--text-muted);
    user-select: none;
}

.format-filters input[type="checkbox"] {
    accent-color: var(--accent-color);
    transform: translateY(1px);
}

.format-filters .ff-hint {
    width: 100%;
    font-size: 11px;
    color: var(--text-muted);
    opacity: 0.85;
}


.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 9999;
}

.modal-card {
    width: min(1100px, 96vw);
    max-height: 90vh;
    overflow: hidden;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    box-shadow: 0 12px 50px rgba(0, 0, 0, 0.45);
}

.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--card-border);
}

.modal-body {
    padding: 14px 16px 16px;
}

.kpi-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.kpi {
    flex: 1 1 160px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 12px;
    padding: 10px 12px;
}

.kpi-label {
    font-size: 11px;
    opacity: 0.75;
}

.kpi-value {
    font-size: 18px;
    font-weight: 700;
    margin-top: 4px;
    color: var(--accent-color);
}

.modal-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

@media (max-width: 900px) {
    .modal-grid {
        grid-template-columns: 1fr;
    }
}

.report-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.report-row:last-child {
    border-bottom: 0;
}

.report-row .title {
    font-size: 12px;
}

.report-row .meta {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 2px;
}

.report-row .qty {
    font-weight: 700;
    color: var(--accent-color);
}

/* Guide Modal Specifics */
.guide-section {
    margin-bottom: 24px;
}

.guide-section h4 {
    margin: 0 0 8px;
    font-size: 14px;
    color: #fff;
}

.guide-section p,
.guide-section li {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.6;
    margin-bottom: 8px;
}

.guide-section ul {
    padding-left: 20px;
    margin: 8px 0;
}

.guide-badge-example {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 4px 0 12px;
}


/* Interactivity cues */
th.sortable {
    cursor: pointer;
    user-select: none;
}

th.sortable:hover {
    color: var(--accent-color);
}

#stock-table tbody tr {
    cursor: pointer;
}

#stock-table tbody tr:hover {
    background: rgba(79, 209, 197, 0.07);
}


/* Inventory Intelligence / Watchlist styling (match "Matching Titles" aesthetic) */
.report-item {
    border: 1px solid var(--card-border);
    border-radius: 18px;
    padding: 14px 16px;
    background: rgba(255, 255, 255, 0.03);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.report-item-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
}

.report-item-name {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.01em;
    color: var(--text-main);
}

.report-item-sub {
    margin-top: 6px;
}

.report-item-qty {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: 0.02em;
    color: var(--text-main);
    white-space: nowrap;
    padding-left: 10px;
}

.report-item-meta {
    margin-top: 8px;
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.35;
}

.badge-warn {
    background: rgba(246, 224, 94, 0.16);
    color: #f6e05e;
    border: 1px solid rgba(246, 224, 94, 0.35);
    font-size: 10px;
}

.badge-danger {
    background: rgba(254, 178, 178, 0.16);
    color: #f56565;
    border: 1px solid rgba(254, 178, 178, 0.35);
    font-size: 10px;
}

/* PDF button disabled state */
#download-pdf-btn[disabled] {
    opacity: 0.45;
    cursor: not-allowed;
    box-shadow: none;
    filter: grayscale(0.3);
}
