/* ==========================================
   Flower Shop dashboard — Apple-style design
   ========================================== */

:root {
    --bg: #f5f5f7;
    --card: #ffffff;
    --text: #1d1d1f;
    --muted: #6e6e73;
    --line: #e5e5ea;
    --soft: #f2f2f7;
    --green: #248a3d;
    --red: #d70015;
    --bar-bg: rgba(0, 0, 0, 0.12);
    --shadow: 0 1px 2px rgba(0,0,0,0.04), 0 8px 24px rgba(0,0,0,0.05);
    --radius: 20px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #000000;
        --card: #1c1c1e;
        --text: #f5f5f7;
        --muted: #98989d;
        --line: #38383a;
        --soft: #2c2c2e;
        --green: #30d158;
        --red: #ff453a;
        --bar-bg: rgba(255, 255, 255, 0.16);
        --shadow: none;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", "Segoe UI", Roboto, Tahoma, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    font-size: 17px;
    line-height: 1.47;
    letter-spacing: -0.01em;
}

h1, h2, h3, p { margin: 0; }

/* ---------- Top bar (frosted glass) ---------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    background: color-mix(in srgb, var(--bg) 78%, transparent);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 1px solid var(--line);
    padding: 10px 16px 12px;
}
.topbar-inner {
    max-width: 1080px;
    margin: 0 auto 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.brand { font-weight: 600; font-size: 21px; letter-spacing: -0.02em; }

.pill-select {
    appearance: none;
    -webkit-appearance: none;
    background: var(--card) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2386868b' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 14px center / 11px;
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 8px 36px 8px 16px;
    font: inherit;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
}

/* Branch switcher — looks like an iOS segmented control */
.segmented {
    max-width: 1080px;
    margin: 0 auto;
    display: flex;
    gap: 2px;
    background: var(--bar-bg);
    background: color-mix(in srgb, var(--text) 8%, transparent);
    padding: 3px;
    border-radius: 10px;
    overflow-x: auto;
    scrollbar-width: none;
}
.segmented::-webkit-scrollbar { display: none; }
.segmented a {
    flex: 1 0 auto;
    text-align: center;
    padding: 7px 14px;
    border-radius: 8px;
    color: var(--text);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    transition: background 0.2s;
}
.segmented a:hover { background: color-mix(in srgb, var(--card) 50%, transparent); }
.segmented a.active {
    background: var(--card);
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 1px rgba(0,0,0,0.04);
}

/* ---------- Layout ---------- */
main {
    max-width: 1080px;
    margin: 0 auto;
    padding: 0 16px 60px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    min-width: 0;
}
.card h2 { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; }
.muted { color: var(--muted); font-size: 15px; margin-top: 2px; }
.small { font-size: 13px; }
.empty { text-align: center; color: var(--muted); padding: 60px 24px; }

.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }

/* ---------- Hero ---------- */
.hero { text-align: center; padding: 48px 0 12px; }
.eyebrow { color: var(--accent); font-weight: 600; font-size: 17px; }
.hero h1 { font-size: clamp(40px, 7vw, 64px); font-weight: 700; letter-spacing: -0.035em; line-height: 1.08; margin: 4px 0 8px; }
.hero-sub { color: var(--muted); font-size: 19px; }

/* ---------- Key numbers ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 20px; }
.kpi-title { color: var(--muted); font-size: 14px; font-weight: 500; }
.kpi-value { font-size: 40px; font-weight: 700; letter-spacing: -0.03em; line-height: 1.15; margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.kpi-small { color: var(--muted); font-size: 13px; }
.delta { display: inline-block; margin-top: 12px; font-size: 13px; font-weight: 600; padding: 3px 10px; border-radius: 999px; }
.delta span { font-weight: 400; opacity: 0.8; }
.delta.up { color: var(--green); background: color-mix(in srgb, var(--green) 12%, transparent); }
.delta.down { color: var(--red); background: color-mix(in srgb, var(--red) 12%, transparent); }

/* ---------- Highlights ---------- */
.highlights { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 20px; }
.highlight { min-width: 0; }
.highlight > div:last-child { min-width: 0; }
.highlight { display: flex; gap: 16px; align-items: flex-start; }
.icon { flex: none; width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; }
.icon svg { width: 22px; height: 22px; fill: #fff; }
.hl-title { color: var(--muted); font-size: 14px; }
.hl-value { font-size: 20px; font-weight: 600; letter-spacing: -0.02em; margin: 2px 0; }
.hl-sub { color: var(--muted); font-size: 14px; }

/* ---------- Chart ---------- */
.chart-box { position: relative; height: 320px; }
.mini-segmented { display: flex; background: color-mix(in srgb, var(--text) 8%, transparent); padding: 2px; border-radius: 9px; }
.mini-segmented button {
    border: 0; background: transparent; color: var(--text); font: inherit; font-size: 13px; font-weight: 500;
    padding: 5px 16px; border-radius: 7px; cursor: pointer;
}
.mini-segmented button.active { background: var(--card); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,0.12); }

/* ---------- Branch ranking ---------- */
.ranking { display: flex; flex-direction: column; }
.rank-row {
    display: grid;
    grid-template-columns: 130px 1fr 90px 120px;
    align-items: center;
    gap: 16px;
    padding: 12px 10px;
    margin: 0 -10px;
    border-radius: 12px;
    color: var(--text);
    text-decoration: none;
    transition: background 0.15s;
}
a.rank-row:hover { background: var(--soft); }
.rank-row.current { background: var(--soft); }
.rank-name { font-weight: 600; display: flex; align-items: center; gap: 10px; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.rank-bar { height: 8px; background: var(--soft); border-radius: 999px; overflow: hidden; }
.rank-row.current .rank-bar { background: var(--card); }
.rank-bar span { display: block; height: 100%; border-radius: 999px; }
.rank-sales { font-weight: 600; text-align: end; font-variant-numeric: tabular-nums; }
.rank-profit { color: var(--muted); font-size: 14px; text-align: end; font-variant-numeric: tabular-nums; }
.ranking.compact .rank-row { grid-template-columns: 110px 1fr 90px; padding: 8px 10px; }

/* ---------- Product lists ---------- */
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 20px; }
.list { list-style: none; padding: 0; margin: 14px 0 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
details .list li:first-child { border-top: 1px solid var(--line); }
.num { width: 22px; color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; flex: none; }
.name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.val { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.good-news { margin-top: 18px; color: var(--green); font-weight: 500; }

details summary, .text-btn {
    color: #0071e3;
    cursor: pointer;
    font-size: 15px;
    margin-top: 10px;
    list-style: none;
    background: none;
    border: 0;
    padding: 0;
    font-family: inherit;
}
details summary::-webkit-details-marker { display: none; }
details summary::after { content: " ›"; }
details[open] summary { display: none; }
details .list { max-height: 360px; overflow-y: auto; margin-top: 0; }
@media (prefers-color-scheme: dark) { details summary, .text-btn { color: #2997ff; } }

/* ---------- Bought together ---------- */
.pairs { list-style: none; padding: 0; margin: 14px 0 0; }
.pairs li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.pairs li:first-child { border-top: 0; }
.pair { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; font-weight: 500; }
.plus { color: var(--muted); }
.badge { background: var(--soft); border-radius: 999px; padding: 4px 12px; font-size: 14px; font-weight: 600; white-space: nowrap; }

/* ---------- Product lookup ---------- */
.search-field { position: relative; margin-top: 16px; }
.search-field svg { position: absolute; inset-inline-start: 14px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; fill: var(--muted); }
.search-field input {
    width: 100%;
    font: inherit;
    padding: 12px 16px 12px 42px;
    border-radius: 12px;
    border: 0;
    background: var(--soft);
    color: var(--text);
    outline: none;
    transition: box-shadow 0.2s;
}
.search-field input:focus { box-shadow: 0 0 0 4px color-mix(in srgb, #0071e3 30%, transparent); }
#matchCount { margin: 8px 2px 0; }

.results { list-style: none; padding: 0; margin: 8px 0 0; max-height: 300px; overflow-y: auto; border-radius: 12px; }
.results li {
    display: flex; justify-content: space-between; gap: 12px;
    padding: 11px 14px; border-radius: 10px; cursor: pointer;
}
.results li:hover, .results li.selected { background: var(--soft); }
.results li .val { color: var(--muted); font-weight: 500; font-size: 15px; }

.detail { margin-top: 20px; padding: 20px; border-radius: 16px; background: var(--soft); }
.detail-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }
.detail-head h3 { font-size: 22px; font-weight: 600; }
.detail-head .text-btn { margin: 0; font-weight: 600; }
.detail-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-bottom: 18px; }
.detail-stats > div { background: var(--card); border-radius: 12px; padding: 14px; }
.stat { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
#splitTitle { margin-bottom: 6px; }
.detail .rank-row.current, .detail .rank-row:hover { background: transparent; }
.detail .rank-bar { background: var(--card); }

footer { text-align: center; color: var(--muted); font-size: 13px; padding-top: 10px; }

/* ---------- Phones ---------- */
@media (max-width: 640px) {
    .hero { padding-top: 28px; }
    .card { padding: 20px; border-radius: 18px; }
    .kpis { grid-template-columns: 1fr 1fr; gap: 12px; }
    .kpi-value { font-size: 28px; }
    .two-col { grid-template-columns: 1fr; }
    .rank-row { grid-template-columns: 1fr auto; gap: 6px 12px; }
    .rank-bar { grid-column: 1 / -1; grid-row: 2; }
    .rank-profit { display: none; }
    .ranking.compact .rank-row { grid-template-columns: 1fr auto; }
    .chart-box { height: 240px; }
}

/* ---------- Most sold ---------- */
.unit { color: var(--muted); font-weight: 400; font-size: 14px; }

/* ---------- Association rules ---------- */
.legend-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin: 18px 0 6px; }
.legend-row div { background: var(--soft); border-radius: 12px; padding: 12px 14px; font-size: 14px; }
.legend-row strong { display: block; margin-bottom: 2px; }
.legend-row span { color: var(--muted); }

.rules { list-style: none; padding: 0; margin: 10px 0 0; }
.rules li { display: flex; justify-content: space-between; gap: 24px; padding: 18px 0; border-top: 1px solid var(--line); }
.rules li:first-child { border-top: 0; }
.rule-text { min-width: 0; flex: 1; }
.rule-label { color: var(--muted); font-size: 13px; margin: 4px 0; }
.rule-items { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.chip { background: var(--soft); border-radius: 8px; padding: 5px 10px; font-weight: 500; font-size: 15px; }
.chip.then { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--text); }
.rule-stats { flex: none; width: 170px; text-align: end; }
.rule-conf { font-size: 34px; font-weight: 700; letter-spacing: -0.03em; line-height: 1; font-variant-numeric: tabular-nums; }
.conf-bar { height: 6px; background: var(--soft); border-radius: 999px; overflow: hidden; margin: 8px 0 10px; }
.conf-bar span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.strength { display: inline-block; font-size: 13px; font-weight: 600; padding: 3px 10px; border-radius: 999px; margin-bottom: 4px; }
.s-very-strong { color: #fff; background: #248a3d; }
.s-strong { color: var(--green); background: color-mix(in srgb, var(--green) 14%, transparent); }
.s-moderate { color: #c93400; background: color-mix(in srgb, #ff9500 16%, transparent); }
.s-weak { color: var(--muted); background: var(--soft); }

/* ---------- Product profile ---------- */
.detail-head h3 { margin-bottom: 2px; }
.detail-block { background: var(--card); border-radius: 16px; padding: 18px; margin-top: 14px; }
.detail-block h4 { margin: 0; font-size: 17px; font-weight: 600; }
.detail-block .card-head { margin-bottom: 10px; }
.detail-stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.detail-stats .stat-note { color: var(--muted); font-size: 12px; margin-top: 2px; }
.table-wrap { overflow-x: auto; margin-top: 10px; }
.branch-table { width: 100%; border-collapse: collapse; font-size: 15px; font-variant-numeric: tabular-nums; }
.branch-table th { text-align: end; color: var(--muted); font-weight: 500; font-size: 13px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.branch-table td { text-align: end; padding: 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.branch-table th:first-child, .branch-table td:first-child { text-align: start; }
.branch-table tr:last-child td { border-bottom: 0; }
.branch-table .dot { display: inline-block; margin-inline-end: 8px; vertical-align: middle; }
.badge-best { font-size: 11px; font-weight: 600; color: var(--green); background: color-mix(in srgb, var(--green) 14%, transparent); padding: 2px 7px; border-radius: 999px; margin-inline-start: 6px; }
#productTogether .val { display: flex; align-items: center; gap: 8px; }

@media (max-width: 640px) {
    .rules li { flex-direction: column; gap: 12px; }
    .rule-stats { width: 100%; text-align: start; }
    .detail { padding: 14px; }
    .detail-stats { grid-template-columns: 1fr 1fr; }
    .stat { font-size: 20px; }
}

/* ==========================================
   Product page
   ========================================== */
.back-link { display: flex; align-items: center; gap: 2px; color: #0071e3; text-decoration: none; font-size: 16px; font-weight: 500; white-space: nowrap; }
.back-link svg { width: 20px; height: 20px; fill: currentColor; }
@media (prefers-color-scheme: dark) { .back-link { color: #2997ff; } }

.top-search { position: relative; flex: 1; max-width: 420px; }
.search-field.compact { margin: 0; }
.search-field.compact input { padding: 8px 14px 8px 38px; font-size: 15px; background: var(--card); border: 1px solid var(--line); border-radius: 999px; }
.search-field.compact svg { inset-inline-start: 13px; width: 16px; height: 16px; }
.results.floating {
    position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 20;
    background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 6px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.15); max-height: 360px; margin: 0;
}
.results li.is-current { font-weight: 600; }
.results li.no-match { color: var(--muted); cursor: default; }

.product-title { font-size: clamp(32px, 5.5vw, 54px) !important; }

.kpis-8 { grid-template-columns: repeat(4, 1fr); }
.kpis-8 .kpi-value { font-size: 32px; }
.kpi-value.neg { color: var(--red); }

.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.chart-grid .wide { grid-column: 1 / -1; }
.chart-grid .card .chart-box { margin-top: 14px; height: 280px; }
.chart-grid .card .chart-box.tall { height: 360px; }
.controls { display: flex; flex-wrap: wrap; gap: 8px; }

.branch-table tr.current td { background: var(--soft); }
.branch-table td a { color: var(--text); text-decoration: none; font-weight: 600; }
.branch-table td a:hover { text-decoration: underline; }
.list a.name { color: var(--text); text-decoration: none; }
.list a.name:hover { color: #0071e3; }

@media (max-width: 900px) {
    .kpis-8 { grid-template-columns: 1fr 1fr; }
    .chart-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
    .topbar-inner { flex-wrap: wrap; }
    .top-search { order: 3; flex-basis: 100%; max-width: none; }
    .kpis-8 .kpi-value { font-size: 24px; }
    .chart-grid .card .chart-box { height: 240px; }
    .chart-grid .card .chart-box.tall { height: 280px; }
}
.plain-link { color: inherit; text-decoration: none; } .plain-link:hover { color: #0071e3; }

/* ==========================================
   Shared top bar: By Branch | By Product + search + month
   ========================================== */
a.brand { color: var(--text); text-decoration: none; white-space: nowrap; }
.topbar-inner { gap: 14px; }
.mode-switch { display: flex; background: color-mix(in srgb, var(--text) 8%, transparent); padding: 3px; border-radius: 10px; flex: none; }
.mode-switch a {
    padding: 6px 14px; border-radius: 8px; color: var(--text); text-decoration: none;
    font-size: 14px; font-weight: 500; white-space: nowrap;
}
.mode-switch a.active { background: var(--card); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,0.12); }
.mode-switch a:not(.active):hover { background: color-mix(in srgb, var(--card) 50%, transparent); }
.topbar-inner .top-search { margin-inline-start: auto; }
.results li.list-head { color: var(--muted); font-size: 12px; font-weight: 500; cursor: default; padding: 6px 14px 4px; }
.results li.list-head:hover { background: transparent; }

@media (max-width: 760px) {
    .topbar-inner { flex-wrap: wrap; }
    .topbar-inner .top-search { order: 4; flex-basis: 100%; max-width: none; margin-inline-start: 0; }
    .month-form { margin-inline-start: auto; }
}
@media (max-width: 420px) {
    .brand { display: none; }
}

/* ==========================================
   Language button + Arabic (right-to-left)
   ========================================== */
.lang-btn {
    flex: none; text-decoration: none; color: var(--text); font-size: 14px; font-weight: 600;
    padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--card);
}
.lang-btn:hover { background: var(--soft); }
.lang-btn:lang(ar) { font-family: -apple-system, "SF Arabic", "Geeza Pro", "Segoe UI", Tahoma, "Noto Sans Arabic", sans-serif; }

[dir="rtl"] body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Arabic", "Geeza Pro", "Segoe UI", Tahoma, "Noto Sans Arabic", Arial, sans-serif;
}
/* Arabic letters must join together, so no tight letter spacing in Arabic */
[dir="rtl"] body, [dir="rtl"] h1, [dir="rtl"] h2, [dir="rtl"] h3, [dir="rtl"] .brand,
[dir="rtl"] .kpi-title, [dir="rtl"] .hl-value, [dir="rtl"] .card h2 { letter-spacing: 0; }
[dir="rtl"] .hero h1 { line-height: 1.25; }
[dir="rtl"] .pill-select { padding: 8px 16px 8px 36px; background-position: left 14px center; }
[dir="rtl"] .search-field input { padding: 12px 42px 12px 16px; }
[dir="rtl"] .search-field.compact input { padding: 8px 38px 8px 14px; }
[dir="rtl"] details summary::after { content: " ‹"; }
[dir="rtl"] .num { text-align: start; }
/* Money and percentages stay left-to-right inside Arabic text */
[dir="rtl"] .val, [dir="rtl"] .stat, [dir="rtl"] .rank-sales { unicode-bidi: isolate; }
@media (max-width: 760px) {
    .lang-btn { padding: 6px 10px; }
}

/* ==========================================
   Top bar v2: page tabs + second row (branch, month, search)
   ========================================== */
.page-tabs { overflow-x: auto; scrollbar-width: none; flex: 0 1 auto; min-width: 0; }
.page-tabs::-webkit-scrollbar { display: none; }
.topbar-inner .lang-btn { margin-inline-start: auto; }
.topbar-row2 { max-width: 1080px; margin: 0 auto; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.topbar-row2 .segmented { flex: 1 1 520px; margin: 0; }
.topbar-row2 .top-search { flex: 1 1 220px; max-width: 320px; margin: 0; }
.month-note { color: var(--muted); font-size: 13px; white-space: nowrap; }
@media (max-width: 760px) {
    .topbar-row2 .segmented { flex-basis: 100%; }
    .topbar-row2 .top-search { max-width: none; }
}

/* ---------- Shared bits for analysis pages ---------- */
.kpis-6 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.kpis-6 .kpi-value { font-size: 30px; }
.chart-grid.three { grid-template-columns: repeat(3, 1fr); margin-top: 16px; }
.chart-grid.four { grid-template-columns: repeat(4, 1fr); }
.chart-grid h4, .card h4 { margin: 0 0 6px; font-size: 15px; font-weight: 600; }
.chart-grid .chart-box.small, .chart-box.small { height: 210px; margin-top: 6px; }
.chart-box.doughnut-box { height: 220px; margin-top: 8px; }
.small-h2 { font-size: 17px !important; }
.mini-segmented.centered { display: inline-flex; margin-top: 18px; }
.mini-segmented a { padding: 5px 16px; border-radius: 7px; color: var(--text); text-decoration: none; font-size: 13px; font-weight: 500; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.mini-segmented a.active { background: var(--card); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,0.12); }
.dot.big { width: 12px; height: 12px; display: inline-block; margin-inline-end: 8px; vertical-align: middle; }
.note-line { text-align: center; max-width: 760px; margin: 0 auto; }

/* Callout (warning box) */
.callout { border: 1px solid color-mix(in srgb, #FF9500 45%, transparent); background: color-mix(in srgb, #FF9500 7%, var(--card)); }
.callout h2 { color: #c93400; }
@media (prefers-color-scheme: dark) { .callout h2 { color: #ff9f0a; } }
.soft-callout { border-color: var(--line); background: var(--card); }
.callout-text { margin-top: 10px; line-height: 1.6; }
.callout-text.strong { font-weight: 600; }
.compact-list li { padding: 7px 0; font-size: 14px; }

/* Tags */
.tag { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; white-space: nowrap; margin: 0; }
.tag.good { color: var(--green); background: color-mix(in srgb, var(--green) 14%, transparent); }
.tag.warn { color: #c93400; background: color-mix(in srgb, #FF9500 18%, transparent); }
.tag.bad { color: var(--red); background: color-mix(in srgb, var(--red) 12%, transparent); }
.tag.soft { color: var(--muted); background: var(--soft); }
@media (prefers-color-scheme: dark) { .tag.warn { color: #ff9f0a; } }

/* Filter chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 6px; }
.chips button { border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit; font-size: 13px; font-weight: 500; padding: 6px 12px; border-radius: 999px; cursor: pointer; }
.chips button.active { background: var(--text); color: var(--card); border-color: var(--text); }

/* Expandable product rows (losses, pricing) */
.loss-item { border-top: 1px solid var(--line); }
.loss-item summary { list-style: none; display: flex; align-items: center; gap: 12px; padding: 14px 4px; cursor: pointer; flex-wrap: wrap; }
.loss-item summary::-webkit-details-marker { display: none; }
.loss-item summary::before { content: "›"; color: var(--muted); font-size: 18px; transition: transform 0.2s; display: inline-block; width: 12px; }
[dir="rtl"] .loss-item summary::before { content: "‹"; }
.loss-item[open] summary::before { transform: rotate(90deg); }
[dir="rtl"] .loss-item[open] summary::before { transform: rotate(-90deg); }
.loss-item summary:hover { background: var(--soft); border-radius: 10px; }
.loss-name { flex: 1 1 220px; min-width: 0; font-weight: 600; }
.loss-badges { display: flex; flex-wrap: wrap; gap: 6px; }
.loss-body { padding: 4px 4px 22px 28px; }
[dir="rtl"] .loss-body { padding: 4px 28px 22px 4px; }
.facts { margin: 0 0 8px; padding-inline-start: 18px; line-height: 1.65; font-size: 15px; }
.basket-box { margin: 14px 0 8px; padding: 14px 16px; border-radius: 14px; background: var(--soft); border-inline-start: 4px solid var(--muted); }
.basket-box.good { border-inline-start-color: var(--green); }
.basket-box.warn { border-inline-start-color: #FF9500; }
.basket-box.bad { border-inline-start-color: var(--red); }
.basket-box p { margin-top: 4px; }

/* ABC */
.group-card .kpi-value { font-size: 26px; }
.group-note { color: var(--muted); font-size: 13px; margin-top: 10px; line-height: 1.45; }
.risk-row { display: grid; grid-template-columns: 1fr 1.4fr; gap: 24px; align-items: center; margin-top: 14px; }
.risk-big .kpi-value { color: var(--accent); }
.stack-bar { display: flex; height: 14px; background: var(--soft); border-radius: 999px; overflow: hidden; margin-bottom: 10px; }
.stack-bar span { display: block; height: 100%; }
.group-details summary { cursor: pointer; list-style: none; }
.group-details summary::-webkit-details-marker { display: none; }
.name-cell { max-width: 340px; overflow: hidden; text-overflow: ellipsis; }
.branch-table td.name-cell a { font-weight: 500; }

/* Suppliers */
.supplier-card { text-decoration: none; color: var(--text); transition: transform 0.15s; }
.supplier-card:hover { transform: translateY(-2px); }
.mini-stats { display: grid; grid-template-columns: auto auto; gap: 6px 12px; margin: 14px 0 0; font-size: 14px; }
.mini-stats dt { color: var(--muted); }
.mini-stats dd { margin: 0; text-align: end; font-weight: 600; }

/* Orders: bundles */
.bundles { list-style: none; padding: 0; margin: 14px 0 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.bundles li { background: var(--soft); border-radius: 14px; padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; }
.bundle-pair { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.bundle-pair a { text-decoration: none; color: var(--text); }
.loss-chip { background: color-mix(in srgb, var(--red) 12%, transparent); }
.bundles .tag { align-self: flex-start; }

/* Pricing table */
.price-head, .price-row { display: grid; grid-template-columns: 2.2fr 0.8fr 0.9fr 0.9fr 1.3fr 0.7fr 1fr 1.1fr; gap: 10px; align-items: center; }
.price-head { color: var(--muted); font-size: 12px; font-weight: 500; padding: 10px 4px 8px 28px; }
[dir="rtl"] .price-head { padding: 10px 28px 8px 4px; }
.price-item summary.price-row { display: grid; font-size: 14px; font-variant-numeric: tabular-nums; }
.price-item summary.price-row::before { position: absolute; margin-inline-start: -20px; }
.price-item summary.price-row { position: relative; padding-inline-start: 28px; }
.price-table td { white-space: nowrap; }

@media (max-width: 900px) {
    .chart-grid.three, .chart-grid.four { grid-template-columns: 1fr 1fr; }
    .risk-row { grid-template-columns: 1fr; }
    .price-head { display: none; }
    .price-row { grid-template-columns: 1fr 1fr; }
    .price-row .loss-name { grid-column: 1 / -1; }
}
@media (max-width: 640px) {
    .chart-grid.three, .chart-grid.four { grid-template-columns: 1fr; }
    .loss-body, [dir="rtl"] .loss-body { padding-inline: 4px; }
}

/* ==========================================
   Origin page + product info chips
   ========================================== */
.info-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 4px 0 12px; }
.info-chip { display: inline-flex; align-items: center; gap: 6px; background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; font-size: 14px; font-weight: 500; color: var(--text); text-decoration: none; }
.info-chip small { color: var(--muted); font-weight: 400; }
a.info-chip:hover { background: var(--soft); }
.results .result-type { color: var(--muted); font-size: 12px; white-space: nowrap; }
.loss-name { display: flex; flex-direction: column; gap: 2px; }
.loss-meta { font-weight: 400; font-size: 12px; }

.h2h-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(440px, 1fr)); gap: 16px; margin-top: 16px; }
.h2h-card { background: var(--soft); border-radius: 16px; padding: 16px; min-width: 0; overflow-x: auto; }
.h2h-card .branch-table td, .h2h-card .branch-table th { padding: 7px 8px; font-size: 14px; }
.h2h-card .branch-table tr.current td { background: var(--card); }
.h2h-verdict { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

.m-good { color: var(--green); font-weight: 600; }
.m-ok { color: #30B0C7; font-weight: 600; }
.m-low { color: #c93400; font-weight: 600; }
.m-bad { color: var(--red); font-weight: 600; }
.matrix td.cell { text-align: center; }
.matrix td.cell span { display: block; font-weight: 600; }
.matrix td.cell small { display: block; font-size: 12px; opacity: 0.85; }
.matrix th { text-align: center; }
.m-good-bg { background: color-mix(in srgb, var(--green) 16%, transparent); }
.m-ok-bg { background: color-mix(in srgb, #30B0C7 14%, transparent); }
.m-low-bg { background: color-mix(in srgb, #FFCC00 20%, transparent); }
.m-bad-bg { background: color-mix(in srgb, var(--red) 16%, transparent); }
@media (max-width: 640px) { .h2h-grid { grid-template-columns: 1fr; } }

/* ---------- Opened product in a list: sticky title + close button ---------- */
.loss-item { scroll-margin-top: calc(var(--topbar-h, 110px) + 8px); }
.loss-item[open] > summary {
    position: sticky; top: var(--topbar-h, 110px); z-index: 5;
    background: var(--card); border-bottom: 1px solid var(--line); border-radius: 0;
    box-shadow: 0 6px 12px -10px rgba(0,0,0,0.25);
}
.loss-item[open] > summary:hover { background: var(--soft); }
.detail-footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.detail-footer .text-btn { margin: 0; }
.close-btn {
    border: 1px solid var(--line); background: var(--soft); color: var(--text); font: inherit; font-size: 14px; font-weight: 600;
    padding: 8px 18px; border-radius: 999px; cursor: pointer;
}
.close-btn:hover { background: var(--line); }

/* ---------- Candlestick block ---------- */
.candle-block { margin-top: 16px; }
.card > .candle-block:first-child { margin-top: 0; }
.candle-h { font-size: 17px !important; }
.card.wide > .candle-block .candle-h { font-size: 22px !important; letter-spacing: -0.02em; }
.chart-box.candle-box { height: 380px; }
.candle-msg { padding: 40px 0; text-align: center; }
.candle-switch button { white-space: nowrap; }
@media (max-width: 640px) { .chart-box.candle-box { height: 300px; } }

/* ==========================================
   Price chart v2 (Apple Stocks style)
   ========================================== */
.candle-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.candle-controls { display: flex; flex-wrap: wrap; gap: 8px; }
.candle-controls .mini-segmented button { padding: 5px 12px; }
.candle-stats { display: flex; justify-content: space-between; align-items: flex-end; gap: 18px; flex-wrap: wrap; margin: 16px 0 6px; }
.candle-main { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.cs-price { font-size: 38px; font-weight: 700; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; line-height: 1; }
.cs-change { font-size: 15px; font-weight: 600; padding: 3px 10px; border-radius: 999px; }
.cs-change.up { color: var(--green); background: color-mix(in srgb, var(--green) 13%, transparent); }
.cs-change.down { color: var(--red); background: color-mix(in srgb, var(--red) 12%, transparent); }
.cs-when { font-size: 15px; }
.cs-grid { display: grid; grid-template-columns: repeat(6, auto); gap: 4px 18px; margin: 0; }
.cs-grid div { display: flex; flex-direction: column; }
.cs-grid dt { color: var(--muted); font-size: 12px; }
.cs-grid dd { margin: 0; font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.chart-box.candle-box { height: 360px; margin-top: 4px; cursor: crosshair; }
.cs-hint { text-align: center; margin-top: 2px; }

.candle-help { display: flex; gap: 16px; align-items: center; background: var(--soft); border-radius: 14px; padding: 12px 16px; margin-top: 14px; }
.candle-diagram { width: 54px; height: 54px; flex: none; }
.how-title { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.how-list { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 3px 18px; font-size: 13px; color: var(--muted); }
.how-list li { display: flex; align-items: center; gap: 8px; }
.sw { display: inline-block; flex: none; border-radius: 2px; }
.sw.up { width: 10px; height: 14px; background: #34C759; }
.sw.down { width: 10px; height: 14px; background: #FF3B30; }
.sw.wick { width: 2px; height: 14px; background: var(--muted); margin: 0 4px; }
.sw.body { width: 10px; height: 10px; background: var(--muted); }
.sw.bars { width: 10px; height: 8px; background: rgba(0, 122, 255, 0.5); }
.candle-about { margin-top: 10px; }
.candle-about summary { cursor: pointer; color: #0071e3; font-size: 14px; list-style: none; }
.candle-about summary::-webkit-details-marker { display: none; }
.candle-about[open] summary { margin-bottom: 6px; }
@media (prefers-color-scheme: dark) { .candle-about summary { color: #2997ff; } }

@media (max-width: 760px) {
    .cs-grid { grid-template-columns: repeat(3, auto); }
    .cs-price { font-size: 30px; }
    .chart-box.candle-box { height: 280px; }
}
.candle-main { flex-wrap: wrap; }
.cs-label { flex-basis: 100%; font-size: 13px; margin-bottom: -6px; }
.cs-grid { grid-template-columns: repeat(5, auto); }
@media (max-width: 760px) { .cs-grid { grid-template-columns: repeat(3, auto); } }

/* ---------- Search results: full product names ---------- */
.top-search .results.floating { min-width: 100%; width: max(100%, 460px); max-width: calc(100vw - 32px); max-height: 420px; }
[dir="ltr"] .top-search .results.floating { left: auto; right: 0; }
[dir="rtl"] .top-search .results.floating { right: auto; left: 0; }
.results li { align-items: center; }
.result-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1; }
.result-name { white-space: normal; overflow-wrap: anywhere; line-height: 1.35; font-size: 15px; }
.results .result-type { font-size: 12px; color: var(--muted); }
.results li .val { flex: none; }
@media (max-width: 760px) { .top-search .results.floating { width: 100%; } }
/* name and type line up on the same side (the page's reading direction) */
[dir="ltr"] .result-name, [dir="ltr"] .results .result-type { text-align: left; }
[dir="rtl"] .result-name, [dir="rtl"] .results .result-type { text-align: right; }

/* ---------- Importance section (Origin page) ---------- */
.formula { background: var(--soft); border-radius: 16px; padding: 14px 16px; margin-top: 16px; }
.formula-row { display: flex; align-items: stretch; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.f-part { flex: 1 1 170px; background: var(--card); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.f-part .f-w { font-size: 22px; font-weight: 700; color: var(--accent); letter-spacing: -0.02em; }
.f-part small { color: var(--muted); font-size: 12px; line-height: 1.35; }
.f-plus { align-self: center; color: var(--muted); font-size: 20px; font-weight: 300; }
.chart-box.bubble-box { height: 460px; margin-top: 8px; }
.zone-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-top: 16px; }
.zone-card { background: var(--soft); border-radius: 14px; padding: 12px 14px; border-top: 4px solid; }
.zone-title { font-weight: 600; margin-bottom: 4px; }
.zone-members { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.zone-members .chip { background: var(--card); font-size: 13px; padding: 3px 9px; text-decoration: none; color: var(--text); }
.score-cell { display: flex; align-items: center; gap: 8px; min-width: 120px; }
.score-bar { flex: 1; height: 8px; background: var(--soft); border-radius: 999px; overflow: hidden; }
.score-bar span { display: block; height: 100%; border-radius: 999px; }
.zone-tag { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.imp-table td.pos, .imp-table .pos { color: var(--green); }
@media (max-width: 640px) { .chart-box.bubble-box { height: 360px; } .f-plus { display: none; } }
.imp-table th:nth-child(2), .imp-table td.name-cell { text-align: start; }
.imp-table th:nth-child(3), .imp-table th:nth-child(4), .imp-table td:nth-child(4) { text-align: start; }
.kpis-9 { grid-template-columns: repeat(3, 1fr); }
.kpis-9 .kpi-value { font-size: 32px; }
@media (max-width: 900px) { .kpis-9 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 640px) { .kpis-9 .kpi-value { font-size: 24px; } }
.kpis:has(> .kpi:nth-child(6)):not(:has(> .kpi:nth-child(7))) { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 760px) { .kpis:has(> .kpi:nth-child(6)) { grid-template-columns: 1fr 1fr; } }
