/* ==========================================================================
   Tropical Aquarium Care - v2 additions
   Admin shell, modals, order history, profit & loss charts.
   Loaded after style.css; relies on its CSS variables.
   ========================================================================== */

/* ---------- shared modal ---------- */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(15,23,42,.55); z-index: 300; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; }
.modal-overlay.open { display: flex; }
.modal { background: #fff; border-radius: 16px; width: 100%; max-width: 720px; padding: 32px; position: relative; box-shadow: 0 24px 60px rgba(0,0,0,.24); }
.modal.wide { max-width: 920px; }
.modal h2 { font-size: 20px; font-weight: 700; margin-bottom: 20px; padding-right: 32px; }
.modal .close-modal { position: absolute; top: 16px; right: 16px; background: none; border: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--gray-400); padding: 4px 8px; border-radius: 6px; }
.modal .close-modal:hover { color: var(--gray-800); background: var(--gray-100); }
.section-label { font-size: 13px; font-weight: 700; color: var(--gray-500); text-transform: uppercase; letter-spacing: .5px; margin: 22px 0 10px; }
.section-label.first { margin-top: 0; }

/* ---------- admin page furniture ---------- */
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.page-head h1 { margin: 0; }
.admin-toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 18px; }
.admin-toolbar .input { width: auto; min-width: 150px; padding: 9px 12px; }
.admin-toolbar .spacer { flex: 1; }
.admin-content table td, .admin-content table th { vertical-align: middle; }

/* ---------- product images ---------- */
.cell-product { display: flex; align-items: center; gap: 12px; }
.cell-product .meta { min-width: 0; }
.cell-product .meta strong { display: block; font-size: 13px; }
.img-preview { width: 76px; height: 76px; border-radius: 10px; object-fit: cover; border: 1px solid var(--gray-200); background: var(--gray-50); }
.gallery-strip { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.gallery-strip .g-item { position: relative; }
.gallery-strip .g-item button { position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%; border: none; background: var(--red); color: #fff; font-size: 12px; line-height: 1; cursor: pointer; }
.upload-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.upload-row input[type=file] { font-size: 12px; max-width: 240px; }
.hint { font-size: 12px; color: var(--gray-500); margin-top: 4px; }

/* ---------- status pills ---------- */
.profit-pos { color: #0E8F86; font-weight: 700; }
.profit-neg { color: var(--red); font-weight: 700; }
.pill { display: inline-block; font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 6px; background: var(--gray-100); color: var(--gray-600); }
.pill-paid { background: #dcfce7; color: #166534; }
.pill-unpaid { background: #fef3c7; color: #92400e; }
.pill-refunded { background: #e0e7ff; color: #3730a3; }
.pill-failed { background: #fef2f2; color: #991b1b; }
.badge-out { background: #fef2f2; color: #991b1b; }
.badge-low { background: #fef3c7; color: #92400e; }
.badge-ok { background: #dcfce7; color: #166534; }

/* ---------- order timeline ---------- */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { position: relative; padding: 0 0 18px 26px; border-left: 2px solid var(--gray-200); margin-left: 5px; }
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: 2px; width: 12px; height: 12px; border-radius: 50%; background: var(--gray-300); border: 2px solid #fff; }
.timeline li.current::before { background: var(--brand); }
.timeline .what { font-size: 13px; font-weight: 600; }
.timeline .when, .timeline .who { font-size: 12px; color: var(--gray-500); }

/* ---------- order detail ---------- */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.detail-box { background: var(--gray-50); border-radius: 10px; padding: 14px 16px; }
.detail-box h4 { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--gray-500); margin-bottom: 8px; }
.detail-box p { font-size: 13px; line-height: 1.6; margin: 0; }
.line-item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--gray-100); }
.line-item:last-child { border-bottom: none; }
.line-item .li-name { flex: 1; min-width: 0; font-size: 13px; font-weight: 600; }
.line-item .li-sub { font-size: 12px; color: var(--gray-500); font-weight: 400; }
.line-item .li-amt { text-align: right; font-size: 13px; font-weight: 700; white-space: nowrap; }
.totals-row { display: flex; justify-content: space-between; font-size: 14px; padding: 4px 0; }
.totals-row.grand { font-size: 16px; font-weight: 700; border-top: 1px solid var(--gray-200); margin-top: 8px; padding-top: 10px; }

/* ---------- customer order history ---------- */
.order-history-item { border-bottom: 1px solid var(--gray-100); }
.order-history-item:last-child { border-bottom: none; }
.order-history-head { padding: 16px 24px; display: flex; justify-content: space-between; align-items: center; gap: 16px; cursor: pointer; flex-wrap: wrap; }
.order-history-head:hover { background: var(--gray-50); }
.order-history-body { padding: 0 24px 20px; display: none; }
.order-history-item.open .order-history-body { display: block; }
.order-history-item.open .chev { transform: rotate(90deg); }
.chev { transition: transform .2s; color: var(--gray-400); display: inline-block; }

/* ==========================================================================
   CHARTS
   Palette validated with the six-check validator against the #ffffff card
   surface: profit #0E8F86 (the brand teal, chroma-corrected so it does not
   read gray as a mark), loss #dc2626, expenses #4a3aa7. Worst all-pairs
   CVD dE 13.5, normal-vision dE 25.6, all three >= 3:1 on the surface.
   Light-only on purpose - the rest of the panel has no dark mode.
   ========================================================================== */
.viz { --viz-profit: #0E8F86; --viz-loss: #dc2626; --viz-expense: #4a3aa7;
       --viz-grid: #e5e7eb; --viz-axis: #d1d5db; --viz-muted: #6b7280; --viz-ink: #1f2937; }
.viz-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.viz-title { font-size: 15px; font-weight: 700; color: var(--viz-ink); }
.viz-sub { font-size: 12px; color: var(--viz-muted); }
.viz-legend { display: flex; gap: 16px; flex-wrap: wrap; margin: 10px 0 18px; }
.viz-legend span { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--viz-muted); }
.viz-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.viz-empty { padding: 44px 16px; text-align: center; color: var(--viz-muted); font-size: 13px; }

/* diverging column chart - profit above the zero line, loss below */
.col-chart { display: flex; align-items: stretch; justify-content: center; gap: 3px; height: 240px; }
/* Cap the width so a single month does not stretch into a slab. */
.col-chart .col { flex: 1 1 0; min-width: 0; max-width: 86px; display: flex; flex-direction: column; position: relative; cursor: default; }
.col-chart .col:hover .col-pos, .col-chart .col:hover .col-neg { filter: brightness(.88); }
.col-area { flex: 1; display: flex; position: relative; }
.col-area.up { align-items: flex-end; }
.col-area.down { align-items: flex-start; }
.col-pos, .col-neg { width: 100%; }
.col-pos { background: var(--viz-profit); border-radius: 4px 4px 0 0; }
.col-neg { background: var(--viz-loss); border-radius: 0 0 4px 4px; }
.col-zero { height: 1px; background: var(--viz-axis); flex: none; }
.col-lbl { font-size: 10px; color: var(--viz-muted); text-align: center; padding-top: 7px; white-space: nowrap; overflow: hidden; }
/* A downward peak label hangs below its bar - reserve room so it never
   lands on top of the period label. */
.col-chart.has-loss .col-lbl { padding-top: 22px; }
.col-peak { position: absolute; left: 50%; transform: translateX(-50%); font-size: 10px; font-weight: 700; color: var(--viz-ink); white-space: nowrap; pointer-events: none; }
.col-peak.up { bottom: 100%; margin-bottom: 4px; }
.col-peak.down { top: 100%; margin-top: 4px; }

/* hover tooltip - the hit target is the full column, not just the bar */
.viz-tip { position: absolute; left: 50%; bottom: calc(100% + 6px); transform: translateX(-50%);
           background: var(--dark); color: #fff; padding: 8px 11px; border-radius: 8px; font-size: 11px;
           line-height: 1.6; white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity .12s; z-index: 20;
           box-shadow: 0 6px 18px rgba(0,0,0,.25); text-align: left; }
.viz-tip b { font-weight: 700; }
.col-chart .col:hover .viz-tip, .hbar-row:hover .viz-tip { opacity: 1; }
.col-chart .col:first-child .viz-tip { left: 0; transform: none; }
.col-chart .col:last-child .viz-tip { left: auto; right: 0; transform: none; }

/* ranked horizontal bars - one series, so one hue plus a direct label per row */
.hbar-row { display: grid; grid-template-columns: 128px 1fr 92px; gap: 12px; align-items: center; padding: 5px 0; position: relative; }
.hbar-label { font-size: 12px; color: var(--viz-ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { background: var(--gray-100); border-radius: 4px; height: 18px; overflow: hidden; }
.hbar-fill { height: 100%; background: var(--viz-expense); border-radius: 4px; min-width: 3px; }
.hbar-fill.profit { background: var(--viz-profit); }
.hbar-fill.loss { background: var(--viz-loss); }
.hbar-value { font-size: 12px; font-weight: 700; text-align: right; color: var(--viz-ink); font-variant-numeric: tabular-nums; }

/* the P&L statement itself - a table, because that is what a P&L is */
.pnl-table { width: 100%; border-collapse: collapse; }
.pnl-table td { padding: 11px 8px; font-size: 14px; border-bottom: 1px solid var(--gray-100); }
.pnl-table td:last-child { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pnl-table tr.sub td { color: var(--gray-500); font-size: 13px; padding-left: 24px; }
.pnl-table tr.rule td { border-top: 2px solid var(--gray-200); font-weight: 700; }
.pnl-table tr.grand td { border-top: 2px solid var(--gray-800); border-bottom: none; font-size: 17px; font-weight: 700; padding-top: 14px; }
.pnl-table .note { font-size: 11px; color: var(--gray-400); font-weight: 400; display: block; }

/* ---------- KPI tiles ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(185px, 1fr)); gap: 16px; margin-bottom: 24px; }
.kpi { background: #fff; border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.kpi .label { font-size: 11px; color: var(--gray-500); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px; }
.kpi .value { font-size: 25px; font-weight: 700; line-height: 1.2; }
.kpi .foot { font-size: 12px; color: var(--gray-500); margin-top: 5px; }

/* align-items:start so a short card next to a tall one is not padded out
   with dead space. */
.chart-grid { display: grid; grid-template-columns: 1.45fr 1fr; gap: 20px; margin-bottom: 24px; align-items: start; }
.chart-card { background: #fff; border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow); }
.table-scroll { overflow-x: auto; }

@media (max-width: 900px) {
    .chart-grid { grid-template-columns: 1fr; }
    .detail-grid { grid-template-columns: 1fr; }
    .hbar-row { grid-template-columns: 96px 1fr 82px; }
    .modal { padding: 24px 18px; }
}

/* ---------- printable invoice ---------- */
@media print {
    .header, .admin-sidebar, .topbar, .footer, .no-print { display: none !important; }
    .modal-overlay { position: static; padding: 0; background: none; display: block !important; overflow: visible; }
    .modal { box-shadow: none; max-width: 100%; padding: 0; }
    .admin-layout { display: block; }
    .admin-content { padding: 0; background: #fff; }
    body { background: #fff; }
}
