:root {
    --bg: #EEF1F4;
    --panel: #FFFFFF;
    --ink: #14202B;
    --muted: #5B6874;
    --line: #D5DCE3;
    --grid: #E3E8ED;
    --gold: #B07A12;
    --gold-soft: #F6EAD1;
    --win: #1A7F52;
    --win-soft: #DDF1E7;
    --loss: #BC3B33;
    --loss-soft: #F8E0DE;
    --be: #6B7480;
    --be-soft: #E7EAEE;
    --f-body: "Vazirmatn", Tahoma, "Segoe UI", sans-serif;
    --f-num: "Vazirmatn", Consolas, ui-monospace, monospace;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0F161D;
        --panel: #16202A;
        --ink: #E4EAF0;
        --muted: #93A1AE;
        --line: #283541;
        --grid: #1E2934;
        --gold: #E0AE4A;
        --gold-soft: #3A2E16;
        --win: #3CC488;
        --win-soft: #123326;
        --loss: #F06A60;
        --loss-soft: #3B1C1A;
        --be: #9AA4AE;
        --be-soft: #232D37;
        color-scheme: dark;
    }
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
}

body {
    font-family: var(--f-body);
    font-size: 15px;
    line-height: 1.7;
}

a {
    color: var(--gold);
    text-decoration: none;
}

    a:hover {
        text-decoration: underline;
    }

.wrap {
    max-width: 1240px;
    margin: 0 auto;
    padding: 24px 16px 64px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.muted {
    color: var(--muted);
}

.num {
    font-family: var(--f-num);
    font-variant-numeric: tabular-nums;
    direction: ltr;
    unicode-bidi: isolate;
}

.pos {
    color: var(--win);
}

.neg {
    color: var(--loss);
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
}

.topbar-in {
    max-width: 1240px;
    margin: 0 auto;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
    font-size: 1.2rem;
    color: var(--ink);
    text-decoration: none !important;
}

    .brand.big {
        font-size: 1.6rem;
    }

.brand-mark {
    width: 22px;
    height: 22px;
    border-radius: 6px;
    background: linear-gradient(var(--panel), var(--panel)) 5px 9px / 2px 9px no-repeat, linear-gradient(var(--panel), var(--panel)) 10px 4px / 2px 13px no-repeat, linear-gradient(var(--panel), var(--panel)) 15px 7px / 2px 7px no-repeat, var(--gold);
}

.nav-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

form.inline {
    display: inline;
    margin: 0;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: inherit;
    font-size: .9rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--ink);
    padding: 8px 14px;
    line-height: 1.4;
    text-decoration: none !important;
}

    .btn:hover {
        border-color: var(--muted);
    }

    .btn.primary {
        background: var(--gold);
        border-color: var(--gold);
        color: #fff;
        font-weight: 700;
    }

        .btn.primary:hover {
            filter: brightness(1.07);
        }

    .btn.ghost {
        background: transparent;
        border-color: transparent;
        color: var(--muted);
    }

        .btn.ghost:hover {
            color: var(--ink);
        }

    .btn.danger {
        color: var(--loss);
        border-color: var(--loss);
        background: transparent;
    }

    .btn.block {
        width: 100%;
    }

    .btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .row-link:focus-visible {
        outline: 2px solid var(--gold);
        outline-offset: 2px;
    }

input, select, textarea {
    font-family: inherit;
    font-size: .92rem;
    color: var(--ink);
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 10px;
    width: 100%;
    min-width: 0;
}

textarea {
    resize: vertical;
}

input.input-validation-error, select.input-validation-error {
    border-color: var(--loss);
}

.page-head {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: flex-end;
    gap: 12px;
}

.page-title {
    margin: 0;
    font-size: 1.6rem;
    font-weight: 800;
    text-wrap: balance;
}

.page-head p {
    margin: 2px 0 0;
    font-size: .9rem;
}

.stats {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel);
    overflow: hidden;
}

.stat {
    padding: 14px 16px;
    border-inline-start: 1px solid var(--line);
    min-width: 0;
}

    .stat:first-child {
        border-inline-start: 0;
    }

    .stat .lbl {
        font-size: .78rem;
        color: var(--muted);
    }

    .stat .val {
        font-size: 1.4rem;
        font-weight: 700;
        margin-top: 2px;
    }

    .stat .sub {
        font-size: .75rem;
        color: var(--muted);
    }

.grid2 {
    display: grid;
    grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
    gap: 20px;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 16px;
    min-width: 0;
}

    .panel h2 {
        margin: 0 0 10px;
        font-size: 1rem;
        font-weight: 700;
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 8px;
        flex-wrap: wrap;
    }

        .panel h2 small {
            font-weight: 400;
            color: var(--muted);
            font-size: .78rem;
        }

select.compact {
    width: auto;
    padding: 4px 8px;
    font-size: .85rem;
}

.chart {
    width: 100%;
    height: auto;
    display: block;
}

    .chart text {
        font-family: var(--f-num);
    }

.ch-grid {
    stroke: var(--grid);
    stroke-width: 1;
}

.ch-axis {
    fill: var(--muted);
    font-size: 11px;
}

.ch-zero {
    stroke: var(--muted);
    stroke-width: 1;
    stroke-dasharray: 3 3;
}

.ch-empty {
    fill: var(--muted);
    font-size: 14px;
    font-family: var(--f-body) !important;
}

.ch-line {
    fill: none;
    stroke-width: 2.2;
    stroke-linejoin: round;
}

    .ch-line.win {
        stroke: var(--win);
    }

    .ch-line.loss {
        stroke: var(--loss);
    }

.ch-area {
    fill-opacity: .1;
    stroke: none;
}

    .ch-area.win {
        fill: var(--win);
    }

    .ch-area.loss {
        fill: var(--loss);
    }

.ch-dot.win {
    fill: var(--win);
}

.ch-dot.loss {
    fill: var(--loss);
}

.ch-end {
    stroke: var(--panel);
    stroke-width: 2;
}

    .ch-end.win {
        fill: var(--win);
    }

    .ch-end.loss {
        fill: var(--loss);
    }

.bars {
    display: flex;
    flex-direction: column;
    gap: 9px;
}

.bar-row {
    display: grid;
    grid-template-columns: 96px minmax(0, 1fr) 110px;
    align-items: center;
    gap: 10px;
    font-size: .85rem;
}

.bar-key {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bar-track {
    height: 10px;
    background: var(--grid);
    border-radius: 5px;
    position: relative;
    overflow: hidden;
}

.bar-mid {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 1px;
    background: var(--line);
}

.bar-fill {
    position: absolute;
    top: 0;
    bottom: 0;
    border-radius: 5px;
}

    .bar-fill.win {
        background: var(--win);
    }

    .bar-fill.loss {
        background: var(--loss);
    }

.bar-val {
    text-align: left;
    font-size: .82rem;
}

    .bar-val small {
        color: var(--muted);
        font-size: .72rem;
    }

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    padding: 12px 16px;
}

    .filters select {
        width: auto;
    }

    .filters .grow {
        flex: 1;
        min-width: 180px;
        width: auto;
    }

.tbl-wrap {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: .88rem;
    min-width: 1100px;
}

th {
    font-weight: 500;
    color: var(--muted);
    font-size: .78rem;
    text-align: right;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}

td {
    padding: 9px 12px;
    border-bottom: 1px solid var(--grid);
    vertical-align: middle;
    white-space: nowrap;
}

    td small {
        font-size: .72rem;
    }

tbody tr:last-child td {
    border-bottom: 0;
}

.row-link {
    cursor: pointer;
}

    .row-link:hover td {
        background: var(--bg);
    }

th.side, td.side {
    width: 4px;
    padding: 0;
}

.r-win td.side {
    background: var(--win);
}

.r-loss td.side {
    background: var(--loss);
}

.r-be td.side {
    background: var(--be);
}

.r-win .res {
    color: var(--win);
}

.r-loss .res {
    color: var(--loss);
}

.r-be .res {
    color: var(--be);
}

.res {
    font-weight: 700;
}

.chip {
    display: inline-block;
    padding: 1px 9px;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 700;
}

    .chip.buy {
        background: var(--win-soft);
        color: var(--win);
    }

    .chip.sell {
        background: var(--loss-soft);
        color: var(--loss);
    }

    .chip.tag {
        background: var(--be-soft);
        color: var(--be);
        font-weight: 500;
    }

.notes-cell {
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--muted);
}

.shot-link {
    font-weight: 700;
    margin-inline-end: 6px;
}

.empty {
    padding: 40px 16px;
    text-align: center;
    color: var(--muted);
}

    .empty p {
        margin: 0 0 12px;
    }

.empty-sm {
    margin: 8px 0;
}

.trade-form {
    padding: 20px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
}

.f {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

    .f label, .f .lbl {
        font-size: .8rem;
        color: var(--muted);
    }

    .f.s2 {
        grid-column: span 2;
    }

    .f.s4 {
        grid-column: span 4;
    }

.seg {
    display: flex;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}

.seg-opt {
    flex: 1;
    position: relative;
    cursor: pointer;
}

    .seg-opt input {
        position: absolute;
        opacity: 0;
        inset: 0;
        cursor: pointer;
    }

    .seg-opt span {
        display: block;
        text-align: center;
        padding: 8px;
        background: var(--bg);
        font-weight: 500;
        color: var(--muted) !important;
    }

    .seg-opt.buy input:checked + span {
        background: var(--win);
        color: #fff !important;
        font-weight: 700;
    }

    .seg-opt.sell input:checked + span {
        background: var(--loss);
        color: #fff !important;
        font-weight: 700;
    }

    .seg-opt input:focus-visible + span {
        outline: 2px solid var(--gold);
        outline-offset: -2px;
    }

.calc {
    grid-column: span 4;
    display: flex;
    flex-wrap: wrap;
    gap: 18px;
    font-size: .84rem;
    color: var(--muted);
    background: var(--bg);
    border-radius: 8px;
    padding: 9px 12px;
}

    .calc b {
        color: var(--ink);
    }

.shot-box {
    display: flex;
    flex-direction: column;
    gap: 12px;
    border: 1px dashed var(--line);
    border-radius: 8px;
    padding: 12px;
    transition: border-color .15s, background .15s;
}

    .shot-box.drag {
        border-color: var(--gold);
        background: var(--gold-soft);
    }

.shots {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
}

    .shots:empty {
        display: none;
    }

.shot {
    position: relative;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg);
}

    .shot img {
        display: block;
        width: 100%;
        aspect-ratio: 16 / 10;
        object-fit: cover;
    }

    .shot.new {
        border-color: var(--gold);
    }

.shot-badge {
    position: absolute;
    top: 6px;
    right: 6px;
    background: var(--gold);
    color: #fff;
    font-size: .7rem;
    font-weight: 700;
    padding: 0 7px;
    border-radius: 999px;
}

.shot-remove {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 5px 8px;
    font-family: inherit;
    font-size: .8rem;
    color: var(--loss);
    background: var(--panel);
    border: 0;
    border-top: 1px solid var(--line);
    cursor: pointer;
}

    .shot-remove input {
        width: auto;
        margin: 0;
    }

.shot.existing:has(.rm-existing:checked) img {
    opacity: .3;
    filter: grayscale(1);
}

.shot.existing:has(.rm-existing:checked) {
    border-color: var(--loss);
}

.shot-drop {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    font-size: .82rem;
}

.shot-box input[type=file] {
    width: auto;
    flex: 0 1 auto;
    min-width: 0;
    max-width: 100%;
    background: transparent;
    border: 0;
    padding: 0;
}

.shot-count {
    font-size: .8rem;
}

    .shot-count.over {
        color: var(--loss);
        font-weight: 700;
    }

.check {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: .85rem;
    color: var(--ink);
    cursor: pointer;
}

    .check input {
        width: auto;
    }

.form-foot {
    display: flex;
    gap: 8px;
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
}

.danger-zone {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 12px 16px;
    border: 1px solid var(--loss-soft);
    border-radius: 12px;
    font-size: .85rem;
}

.alert {
    background: var(--loss-soft);
    color: var(--loss);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: .88rem;
    margin-bottom: 14px;
}

    .alert.validation-summary-valid {
        display: none;
    }

    .alert ul {
        margin: 0;
        padding-inline-start: 18px;
    }

.err {
    color: var(--loss);
    font-size: .78rem;
}

.login {
    min-height: 70vh;
    display: grid;
    place-items: center;
}

.login-card {
    width: min(400px, 100%);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 28px 24px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

    .login-card p {
        margin: 0;
    }

.stack {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--ink);
    color: var(--bg);
    padding: 9px 18px;
    border-radius: 8px;
    font-size: .9rem;
    z-index: 50;
    transition: opacity .3s;
}

    .toast.hide {
        opacity: 0;
        pointer-events: none;
    }

@media (max-width: 960px) {
    .stats {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .stat:nth-child(4) {
        border-inline-start: 0;
    }

    .stat:nth-child(n+4) {
        border-top: 1px solid var(--line);
    }

    .grid2 {
        grid-template-columns: minmax(0, 1fr);
    }
}

@media (max-width: 600px) {
    .stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .stat {
        border-inline-start: 0 !important;
        border-top: 1px solid var(--line);
    }

        .stat:nth-child(even) {
            border-inline-start: 1px solid var(--line) !important;
        }

        .stat:nth-child(-n+2) {
            border-top: 0;
        }

    .form-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .f.s2, .f.s4, .calc {
        grid-column: span 2;
    }

    .page-title {
        font-size: 1.35rem;
    }

    .bar-row {
        grid-template-columns: 74px minmax(0, 1fr) 96px;
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
    }
}
