/* ─────────────────────────────────────────────────────────────────
   GOLDEN MUKS · Design System
   Mobile-first, clean, professional
───────────────────────────────────────────────────────────────── */

/* ── Tokens ── */
:root {
    --gold: #F5A623;
    --gold-dim: rgba(245, 166, 35, 0.12);
    --gold-glow: rgba(245, 166, 35, 0.25);
    --green: #34D399;
    --red: #F87171;
    --blue: #60A5FA;

    --bg: #0C0C10;
    --surface: #14141A;
    --surface-2: #1C1C25;
    --surface-3: #242430;
    --border: rgba(255,255,255,0.07);
    --border-strong: rgba(255,255,255,0.12);

    --text: #F0F0F5;
    --text-2: #9090A8;
    --text-3: #5A5A70;

    --radius: 16px;
    --radius-sm: 10px;
    --radius-xs: 6px;

    --nav-h: 72px;
    --header-h: 60px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}
input, button, textarea { font-family: inherit; }
button { cursor: pointer; border: none; background: none; }

/* ── App Shell ── */
.app { display: flex; flex-direction: column; min-height: 100dvh; }

/* ── Header ── */
.app-header {
    position: sticky;
    top: 0;
    z-index: 200;
    height: var(--header-h);
    background: rgba(12, 12, 16, 0.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
}

.header-brand { display: flex; align-items: center; gap: 12px; }

.brand-icon {
    width: 36px; height: 36px;
    background: linear-gradient(135deg, #F5A623, #E8890A);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 900; font-size: 13px; color: #000;
    letter-spacing: -0.5px;
    box-shadow: 0 4px 12px rgba(245, 166, 35, 0.35);
    flex-shrink: 0;
}

.brand-info { display: flex; flex-direction: column; gap: 1px; }
.brand-name { font-size: 15px; font-weight: 700; letter-spacing: -0.3px; }

.cloud-badge {
    font-size: 10px;
    font-weight: 500;
    color: var(--text-3);
    letter-spacing: 0.2px;
    transition: color 0.3s;
}
.cloud-badge.synced { color: var(--green); }
.cloud-badge.error { color: var(--red); }

.user-chip {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-2);
    background: var(--surface-2);
    border: 1px solid var(--border);
    padding: 5px 12px;
    border-radius: 20px;
}

/* ── Bottom Navigation ── */
.bottom-nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 300;
    height: calc(var(--nav-h) + var(--safe-bottom));
    background: rgba(12, 12, 16, 0.96);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: flex-start;
    padding-top: 8px;
    padding-bottom: var(--safe-bottom);
}

.bnav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 4px;
    color: var(--text-3);
    transition: color 0.2s;
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.2px;
}

.bnav-item svg { width: 22px; height: 22px; transition: transform 0.2s; }

.bnav-item.active {
    color: var(--gold);
}

.bnav-item.active svg {
    transform: translateY(-1px);
}

/* ── Main Content ── */
.main-content {
    flex: 1;
    padding: 16px 16px calc(var(--nav-h) + var(--safe-bottom) + 16px);
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
}

/* ── Tabs ── */
.tab { display: none; }
.tab.active { display: block; }

/* ── Cards ── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 12px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.card-title { font-size: 15px; font-weight: 700; letter-spacing: -0.2px; }
.card-sub { font-size: 12px; color: var(--text-2); margin-top: 2px; }

.card-actions { display: flex; align-items: center; gap: 10px; }

/* ── Selection Bar ── */
.selection-bar {
    display: flex;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    margin-bottom: 12px;
    gap: 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.sel-stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex-shrink: 0;
}

.sel-label { font-size: 10px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.5px; }
.sel-value { font-size: 16px; font-weight: 700; color: var(--text); white-space: nowrap; }
.profit-val { color: var(--green); }

.sel-divider { width: 1px; height: 36px; background: var(--border); flex-shrink: 0; }

.sel-stat.profit-stat { margin-left: auto; }

/* ── Buttons ── */
.btn-primary {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--gold);
    color: #000;
    font-size: 13px;
    font-weight: 700;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    transition: opacity 0.2s, transform 0.15s;
    white-space: nowrap;
}
.btn-primary svg { width: 14px; height: 14px; }
.btn-primary:active { opacity: 0.85; transform: scale(0.97); }

.btn-finalize {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    justify-content: center;
    background: linear-gradient(135deg, var(--gold), #E8890A);
    color: #000;
    font-size: 14px;
    font-weight: 800;
    padding: 14px;
    border-radius: var(--radius-sm);
    margin-top: 14px;
    letter-spacing: -0.2px;
    box-shadow: 0 4px 20px rgba(245, 166, 35, 0.3);
    transition: opacity 0.2s, transform 0.15s;
}
.btn-finalize svg { width: 18px; height: 18px; }
.btn-finalize:active { opacity: 0.85; transform: scale(0.98); }

.icon-btn {
    width: 28px; height: 28px;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-3);
    border-radius: 6px;
    transition: background 0.2s, color 0.2s;
    flex-shrink: 0;
}
.icon-btn svg { width: 14px; height: 14px; }
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn:active { transform: scale(0.9); }

.paste-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: var(--gold-dim);
    color: var(--gold);
    border: 1px solid rgba(245, 166, 35, 0.25);
    font-size: 11px;
    font-weight: 600;
    padding: 5px 10px;
    border-radius: 20px;
    white-space: nowrap;
    transition: background 0.2s;
    letter-spacing: 0.1px;
}
.paste-chip svg { width: 12px; height: 12px; }
.paste-chip:active { background: rgba(245, 166, 35, 0.2); }
.paste-chip.small { font-size: 10px; padding: 4px 8px; }

/* ── Table ── */
.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    /* Show 5 rows: ~42px/row + 37px header */
    max-height: calc(37px + 5 * 42px);
    overflow-y: auto;
    position: relative;
}

/* Fade hint at bottom to signal more rows */
.table-card .table-scroll {
    background: linear-gradient(to bottom,
        transparent calc(100% - 40px),
        rgba(20, 20, 26, 0.85) 100%) no-repeat bottom;
    background-attachment: local;
}

.archive-scroll {
    max-height: calc(37px + 5 * 40px);
    overflow-y: auto;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.archive-card .archive-scroll {
    background: linear-gradient(to bottom,
        transparent calc(100% - 36px),
        rgba(20, 20, 26, 0.85) 100%) no-repeat bottom;
    background-attachment: local;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table thead th {
    padding: 10px 12px;
    text-align: left;
    font-size: 10px;
    font-weight: 600;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    position: sticky;
    top: 0;
    z-index: 10;
}

.data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.data-table tbody tr:last-child td { border-bottom: none; }

.data-table tbody tr:hover td { background: rgba(255,255,255,0.02); }
.data-table tbody tr.selected-row td { background: rgba(245, 166, 35, 0.05); }
.data-table tbody tr.locked-row td { opacity: 0.6; }

.col-check { width: 36px; }
.col-icon { width: 36px; }
.col-num { text-align: right; }
.col-num .data-table td { text-align: right; }

/* Table Inputs */
.tbl-input {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text);
    font-size: 13px;
    padding: 4px 6px;
    border-radius: var(--radius-xs);
    width: 100%;
    min-width: 0;
    transition: border-color 0.2s, background 0.2s;
}
.tbl-input:focus {
    outline: none;
    border-color: var(--gold);
    background: var(--surface-2);
}
.tbl-input.narrow { max-width: 80px; }
.tbl-input.wide { max-width: 120px; }

.tbl-cell-right { text-align: right; }
.tbl-val-usd { color: var(--text-2); font-variant-numeric: tabular-nums; }
.tbl-val-zmw { color: var(--text); font-variant-numeric: tabular-nums; }

.lock-btn {
    width: 28px; height: 28px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 6px;
    font-size: 14px;
    transition: background 0.2s;
}
.lock-btn:hover { background: var(--surface-3); }

.del-btn {
    width: 28px; height: 28px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 6px;
    color: var(--text-3);
    transition: background 0.2s, color 0.2s;
}
.del-btn svg { width: 14px; height: 14px; }
.del-btn:hover { background: rgba(248, 113, 113, 0.1); color: var(--red); }

/* Checkbox */
input[type="checkbox"] {
    width: 16px; height: 16px;
    accent-color: var(--gold);
    cursor: pointer;
}

/* ── Profit Panel ── */
.profit-panel { padding: 0; }

.profit-panel-grid {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0;
}

.profit-inputs {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    border-right: 1px solid var(--border);
}

.profit-result {
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 160px;
    text-align: center;
}

.profit-label { font-size: 11px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.5px; }
.profit-amount { font-size: 20px; font-weight: 800; color: var(--green); margin: 6px 0 0; letter-spacing: -0.5px; }

/* ── Form Fields ── */
.field-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-2);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}
.field-unit { color: var(--text-3); font-weight: 400; }

.field-label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}
.field-label-row .field-label { margin-bottom: 0; }

.field-input {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
    padding: 10px 12px;
    transition: border-color 0.2s, box-shadow 0.2s;
    -webkit-appearance: none;
    appearance: none;
}
.field-input:focus {
    outline: none;
    border-color: var(--gold);
    box-shadow: 0 0 0 3px var(--gold-glow);
}
.field-input--lg {
    font-size: 22px;
    font-weight: 700;
    padding: 12px;
    letter-spacing: -0.5px;
}

.input-row { display: flex; flex-direction: column; }

.input-with-action {
    display: flex;
    align-items: center;
    gap: 8px;
}
.input-with-action .field-input { flex: 1; }

/* ── Select All ── */
.select-all-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-2);
    cursor: pointer;
}

/* ── Rates Bar ── */
.rates-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    margin-bottom: 12px;
}

.rate-pill {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}
.rate-label { font-size: 10px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.5px; }
.rate-value { font-size: 16px; font-weight: 700; color: var(--text); }
.rate-unit { font-size: 11px; font-weight: 400; color: var(--text-2); }

.live-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 8px var(--green);
    animation: pulse-dot 2s infinite;
    flex-shrink: 0;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.8); }
}

/* ── Settings Card ── */
.settings-card { padding: 20px; }
.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

/* ── Calculator Cards ── */
.calc-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.calc-card { overflow: visible; }

.calc-tag {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    padding: 10px 20px;
    border-bottom: 1px solid var(--border);
}

.acq-tag { color: var(--blue); }
.ref-tag { color: var(--gold); }

.calc-body { padding: 20px; display: flex; flex-direction: column; gap: 18px; }

.calc-info-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    padding: 12px;
}

.info-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
}
.info-label { color: var(--text-2); }
.info-val { font-weight: 600; font-variant-numeric: tabular-nums; }
.info-val.accent { color: var(--gold); }

.calc-result-block {
    background: linear-gradient(135deg, var(--surface-2), var(--surface-3));
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 16px;
}

.calc-result-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.calc-result-usd {
    font-size: 26px;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -1px;
    line-height: 1;
}

.calc-result-zmw {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-2);
    margin-top: 4px;
}

.calc-result-zmw-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 4px;
}

.copy-yield-btn { margin-left: auto; }

.two-col-inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── Breakdown ── */
.breakdown {
    font-size: 11px;
    color: var(--text-3);
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.breakdown-step {
    display: flex;
    justify-content: space-between;
    padding: 5px 8px;
    background: var(--surface-2);
    border-radius: 4px;
}

.step-result {
    font-weight: 600;
    color: var(--text-2);
    font-variant-numeric: tabular-nums;
}

/* ── Empty State ── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 40px 20px;
    color: var(--text-3);
}
.empty-state svg { width: 32px; height: 32px; }
.empty-state p { font-size: 13px; font-weight: 500; }

/* ── Archive Table specific ── */
.archive-table { font-size: 12px; }
.archive-table td { padding: 8px 12px; }
.loss-pct { color: var(--red); font-weight: 700; }
.profit-pos { color: var(--green); font-weight: 700; }
.profit-neg { color: var(--red); font-weight: 700; }

/* ── Toast ── */
.toast {
    position: fixed;
    bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px);
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--surface-3);
    border: 1px solid var(--border-strong);
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    padding: 10px 20px;
    border-radius: 40px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    white-space: nowrap;
    pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ═══════════════════════════════════════════
   RESPONSIVE
═══════════════════════════════════════════ */

@media (max-width: 640px) {
    .main-content { padding: 12px 12px calc(var(--nav-h) + var(--safe-bottom) + 12px); }

    .card-header { padding: 14px 16px; }
    .card-title { font-size: 14px; }

    /* Settings: single column */
    .settings-grid { grid-template-columns: 1fr; gap: 12px; }

    /* Calculators: single column */
    .calc-grid { grid-template-columns: 1fr; }

    /* Profit panel: stack vertically */
    .profit-panel-grid { grid-template-columns: 1fr; }
    .profit-inputs { border-right: none; border-bottom: 1px solid var(--border); }
    .profit-result { padding: 16px; align-items: flex-start; text-align: left; }
    .profit-amount { font-size: 24px; }

    /* Two-col inputs */
    .two-col-inputs { grid-template-columns: 1fr; }

    /* Selection bar */
    .selection-bar { padding: 10px 12px; }
    .sel-value { font-size: 14px; }

    /* Table font */
    .data-table { font-size: 12px; }
    .data-table thead th { font-size: 9px; padding: 8px 10px; }
    .data-table td { padding: 8px 10px; }

    .calc-result-usd { font-size: 22px; }
}

@media (min-width: 641px) {
    /* On larger screens, show nav at top */
    .bottom-nav {
        position: static;
        height: auto;
        background: transparent;
        border: none;
        padding: 0 0 16px 0;
        gap: 8px;
        border-bottom: 1px solid var(--border);
        margin-bottom: 0;
        display: flex;
        flex-direction: row;
        align-items: stretch;
        justify-content: flex-start;
        max-width: 900px;
        margin: 0 auto;
    }

    .bnav-item {
        flex-direction: row;
        flex: 0;
        gap: 8px;
        padding: 10px 20px;
        border-radius: var(--radius-sm);
        font-size: 13px;
        font-weight: 600;
        border: 1px solid transparent;
        letter-spacing: 0;
        color: var(--text-2);
    }

    .bnav-item svg { width: 18px; height: 18px; }

    .bnav-item.active {
        color: var(--gold);
        background: var(--gold-dim);
        border-color: rgba(245, 166, 35, 0.2);
    }
    .bnav-item.active svg { transform: none; }

    .main-content {
        padding: 20px;
        max-width: 960px;
    }

    /* Wrap nav inside main */
    .app-header { padding: 0 20px; }
}

@media (min-width: 641px) and (max-width: 900px) {
    .profit-panel-grid { grid-template-columns: 1fr; }
    .profit-inputs { border-right: none; border-bottom: 1px solid var(--border); }
    .profit-result { align-items: flex-start; text-align: left; }
}

/* Deal count badge */
.deal-count {
    display: inline-flex;
    align-items: center;
    background: var(--gold-dim);
    color: var(--gold);
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 20px;
    margin-left: 8px;
    vertical-align: middle;
    letter-spacing: 0;
}

/* Gold purity cell */
.au-pct {
    color: var(--gold);
    font-weight: 700;
}
.au-pct-good { color: var(--green); font-weight: 700; }
.au-pct-low  { color: var(--red);   font-weight: 700; }

/* ══════════════════════════════════════════
   BALANCE TAB
══════════════════════════════════════════ */

/* Summary cards row */
.bal-summary {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 12px;
}

.bal-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.bal-card-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.bal-card-value {
    font-size: 18px;
    font-weight: 800;
    letter-spacing: -0.5px;
    font-variant-numeric: tabular-nums;
}

.bal-start  { border-color: rgba(96,165,250,0.2); }
.bal-start .bal-card-value  { color: var(--blue); }

.bal-deals  { border-color: rgba(52,211,153,0.2); }
.bal-deals .bal-card-value  { color: var(--green); }

.bal-expenses { border-color: rgba(248,113,113,0.2); }
.bal-expenses .bal-card-value { color: var(--red); }

.bal-net {
    grid-column: span 2;
    border-color: rgba(245,166,35,0.3);
    background: var(--gold-dim);
}
.bal-net .bal-card-label { color: var(--gold); }
.bal-net .bal-card-value { color: var(--gold); font-size: 24px; }

/* Starting capital setup row */
.bal-setup {
    display: flex;
    gap: 14px;
    align-items: flex-start;
    padding: 20px;
    flex-wrap: wrap;
}

/* Category chip select */
.cat-select {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    padding: 10px 12px;
    -webkit-appearance: none;
    appearance: none;
}
.cat-select:focus {
    outline: none;
    border-color: var(--gold);
}

@media (max-width: 640px) {
    .bal-summary { grid-template-columns: 1fr 1fr; }
    .bal-setup { flex-direction: column; }
    .bal-net { grid-column: span 2; }
    .bal-net .bal-card-value { font-size: 20px; }
}

/* Danger / Reset button */
.btn-danger {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(248, 113, 113, 0.1);
    color: var(--red);
    border: 1px solid rgba(248, 113, 113, 0.25);
    font-size: 12px;
    font-weight: 700;
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    transition: background 0.2s;
    white-space: nowrap;
}
.btn-danger svg { width: 14px; height: 14px; }
.btn-danger:hover { background: rgba(248, 113, 113, 0.2); }
.btn-danger:active { transform: scale(0.97); }
