/* ============================================================
   FJR Keuangan - mobile first
   ============================================================ */

:root {
    --bg: #f4f6f8;
    --panel: #ffffff;
    --text: #14181f;
    --muted: #6b7280;
    --border: #e3e8ef;
    --green: #047857;
    --green-soft: #e7f6ef;
    --red: #b91c1c;
    --red-soft: #fdeaea;
    --blue: #1d4ed8;
    --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px -12px rgba(16, 24, 40, .18);
    --radius: 16px;
    --radius-sm: 10px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

[hidden] { display: none !important; }

a { color: var(--green); }

h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 1.05rem; letter-spacing: -.01em; }

.wrap {
    width: 100%;
    max-width: 1080px;
    margin: 0 auto;
    padding: 0 14px;
}

/* ------------------------------------------------------------ topbar */
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(255, 255, 255, .92);
    backdrop-filter: saturate(180%) blur(8px);
    border-bottom: 1px solid var(--border);
}

.topbar-inner {
    max-width: 1080px;
    margin: 0 auto;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    color: var(--text);
    text-decoration: none;
    letter-spacing: -.02em;
}

.brand-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: linear-gradient(135deg, #10b981, #047857);
    box-shadow: 0 0 0 4px rgba(16, 185, 129, .16);
}

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

.nav-form { display: inline-flex; margin: 0; }

.nav-link {
    display: inline-block;
    padding: 7px 11px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: .875rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
}

.nav-link:hover { background: #eef2f6; color: var(--text); }
.nav-link.is-active { background: var(--green-soft); color: var(--green); }
.nav-logout:hover { background: var(--red-soft); color: var(--red); }

/* ------------------------------------------------------------ layout */
main.wrap { flex: 1 0 auto; padding-top: 16px; padding-bottom: 32px; }

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 16px;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.foot {
    padding: 18px 14px 28px;
    text-align: center;
    color: var(--muted);
    font-size: .78rem;
}

.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: .78rem; font-style: normal; font-weight: 400; }
.nowrap { white-space: nowrap; }

.sr-only {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0);
    white-space: nowrap; border: 0;
}

/* ------------------------------------------------------------ saldo */
.balances {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    margin-bottom: 16px;
}

.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.card-label {
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .09em;
    text-transform: uppercase;
    color: var(--muted);
}

.card-value {
    font-size: 1.6rem;
    font-weight: 800;
    letter-spacing: -.03em;
    font-variant-numeric: tabular-nums;
}

.card-sub { font-size: .78rem; color: var(--muted); }

.card-total {
    background: linear-gradient(160deg, #0b3d2e 0%, #071f19 100%);
    border-color: transparent;
    color: #eafff5;
}

.card-total .card-label { color: rgba(234, 255, 245, .68); }
.card-total .card-sub { color: rgba(234, 255, 245, .6); }

.card-total .card-value { color: #ffffff; }
.card-total .card-value.neg { color: #fca5a5; }

/* ------------------------------------------------------------ form */
.trx-form { display: flex; flex-direction: column; gap: 13px; }

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

.field { display: flex; flex-direction: column; gap: 5px; }

.field > span {
    font-size: .78rem;
    font-weight: 600;
    color: #374151;
}

input[type="text"],
input[type="date"],
input[type="search"],
input[type="password"],
select {
    width: 100%;
    min-height: 44px;
    padding: 9px 11px;
    border: 1px solid #d5dbe3;
    border-radius: var(--radius-sm);
    background: #fff;
    color: var(--text);
    font: inherit;
    font-size: 1rem;
    transition: border-color .15s, box-shadow .15s;
    appearance: none;
}

select {
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236b7280' d='M1.4.6 6 5.2 10.6.6 12 2 6 8 0 2z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

input:focus,
select:focus {
    outline: none;
    border-color: #10b981;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, .18);
}

input::placeholder { color: #9aa3af; }

.field-pin input {
    text-align: center;
    font-size: 1.75rem;
    letter-spacing: .5em;
    padding: 14px 10px 14px 22px;
}

.field-error {
    color: var(--red);
    font-size: .78rem;
    font-style: normal;
    font-weight: 600;
    margin: 0;
}

/* segmented control */
.segmented {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    background: #eef2f6;
    border-radius: 12px;
    padding: 4px;
}

.seg { position: relative; display: block; }

.seg input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
}

.seg span {
    display: block;
    text-align: center;
    padding: 9px 6px;
    border-radius: 9px;
    font-size: .84rem;
    font-weight: 700;
    color: var(--muted);
    cursor: pointer;
    transition: background .15s, color .15s;
    user-select: none;
}

.seg input:checked + span {
    background: #fff;
    color: var(--text);
    box-shadow: 0 1px 3px rgba(16, 24, 40, .12);
}

.seg input[value="income"]:checked + span { color: var(--green); }
.seg input[value="expense"]:checked + span { color: var(--red); }
.seg input[value="transfer"]:checked + span { color: var(--blue); }

.seg input:focus-visible + span {
    box-shadow: 0 0 0 2px rgba(16, 185, 129, .55);
}

/* ------------------------------------------------------------ buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 44px;
    padding: 10px 18px;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: #fff;
    color: var(--text);
    font: inherit;
    font-weight: 700;
    font-size: .9rem;
    text-decoration: none;
    cursor: pointer;
    transition: transform .06s, background .15s, border-color .15s;
}

.btn:hover { background: #f6f8fa; }
.btn:active { transform: translateY(1px); }

.btn.primary {
    background: linear-gradient(180deg, #059669, #047857);
    border-color: #047857;
    color: #fff;
    box-shadow: 0 1px 2px rgba(4, 120, 87, .35);
}

.btn.primary:hover { background: linear-gradient(180deg, #047857, #036249); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: #eef2f6; }
.btn.small { min-height: 34px; padding: 6px 12px; font-size: .8rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .6; cursor: not-allowed; }

.form-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 2px;
}

/* ------------------------------------------------------------ filter & rekap */
.filters {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    align-items: end;
    margin-bottom: 16px;
}

.filters .btn { grid-column: 1 / -1; }

.stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 6px;
}

.stat {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.stat > span {
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--muted);
}

.stat strong {
    font-size: 1rem;
    font-variant-numeric: tabular-nums;
    letter-spacing: -.02em;
}

.stats-compact { margin-top: 16px; }

.pos { color: var(--green); }
.neg { color: var(--red); }

.bycat { margin-top: 16px; }
.bycat h3 {
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--muted);
    margin-bottom: 8px;
}
.bycat ul { list-style: none; margin: 0; padding: 0; }
.bycat li {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 7px 0;
    border-bottom: 1px dashed var(--border);
    font-size: .9rem;
}
.bycat li:last-child { border-bottom: 0; }
.bycat strong { font-variant-numeric: tabular-nums; color: var(--red); }

/* ------------------------------------------------------------ tabel */
.table-wrap {
    overflow-x: auto;
    margin: 0 -4px;
    padding: 0 4px;
    -webkit-overflow-scrolling: touch;
}

table.trx {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
    min-width: 520px;
}

table.trx th {
    text-align: left;
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--muted);
    font-weight: 700;
    padding: 8px 8px;
    border-bottom: 1px solid var(--border);
}

table.trx td {
    padding: 10px 8px;
    border-bottom: 1px solid #f1f4f8;
    vertical-align: top;
}

table.trx tbody tr:hover { background: #fafbfc; }
table.trx tbody tr:last-child td { border-bottom: 0; }

table.trx .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    white-space: nowrap;
}

.wallet { color: var(--muted); font-size: .8rem; }

.badge {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 999px;
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .02em;
    white-space: nowrap;
}

.badge-income { background: var(--green-soft); color: var(--green); }
.badge-expense { background: var(--red-soft); color: var(--red); }
.badge-transfer { background: #e8eefc; color: var(--blue); }

.cat {
    margin-left: 4px;
    font-size: .76rem;
    color: var(--muted);
}

.cat::before { content: "· "; }

.desc {
    font-size: .8rem;
    color: var(--muted);
    margin-top: 2px;
    word-break: break-word;
}

.actions-col { width: 74px; }
.actions { display: flex; gap: 2px; justify-content: flex-end; align-items: center; }
.actions form { margin: 0; display: inline-flex; }

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    font-size: .95rem;
    line-height: 1;
    cursor: pointer;
    text-decoration: none;
}

.icon-btn:hover { background: #eef2f6; color: var(--text); }
.icon-btn.danger:hover { background: var(--red-soft); color: var(--red); }

.empty {
    text-align: center;
    color: var(--muted);
    padding: 26px 10px;
    margin: 0;
    font-size: .9rem;
}

/* ------------------------------------------------------------ flash */
.flash {
    border-radius: 12px;
    padding: 11px 14px;
    margin: 14px 0 0;
    font-size: .875rem;
    font-weight: 600;
    border: 1px solid transparent;
}

.flash-success { background: var(--green-soft); border-color: #bfe7d6; color: #065f46; }
.flash-error { background: var(--red-soft); border-color: #f5c7c7; color: #991b1b; }
.panel .flash { margin: 0 0 14px; }

/* ------------------------------------------------------------ login */
.login {
    min-height: 62vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 0;
}

.login-card {
    width: 100%;
    max-width: 340px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 20px;
    box-shadow: var(--shadow);
    padding: 26px 22px 20px;
    text-align: center;
}

.login-icon {
    font-size: 1.6rem;
    width: 52px;
    height: 52px;
    margin: 0 auto 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--green-soft);
    border-radius: 50%;
}

.login-card h1 { font-size: 1.3rem; letter-spacing: -.02em; }
.login-sub { color: var(--muted); font-size: .86rem; margin: 6px 0 16px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; }
.login-note { color: var(--muted); font-size: .76rem; margin: 14px 0 0; }

/* ------------------------------------------------------------ misc */
.notes { margin: 0; padding-left: 18px; color: #374151; font-size: .9rem; }
.notes li { margin-bottom: 7px; }
.notes li:last-child { margin-bottom: 0; }

.code {
    background: #0f172a;
    color: #d7f2e4;
    border-radius: 10px;
    padding: 12px 14px;
    font-size: .8rem;
    overflow-x: auto;
    margin: 8px 0 14px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ------------------------------------------------------------ responsive */
@media (min-width: 560px) {
    .balances { grid-template-columns: repeat(3, 1fr); }
    .row { grid-template-columns: 1fr 1fr; }
    .filters { grid-template-columns: 1fr 1fr 1fr auto; }
    .filters .btn { grid-column: auto; }
    .stats { grid-template-columns: repeat(4, 1fr); }
    .card-value { font-size: 1.45rem; }
}

@media (min-width: 860px) {
    .panel { padding: 20px 22px; }
    .card { padding: 18px 20px; }
    .card-value { font-size: 1.7rem; }
    table.trx { min-width: 0; }
}
