/* Net Worth Tracker.
 *
 * Was an inline <style> in dashboard.html. Moved out so the service worker can
 * cache it and so the login screen shares it. The rules up to "Mobile" are the
 * originals; everything below is the phone treatment the page never had. */

:root {
    --ink: #1a1a2e;
    --muted: #6b7280;
    --page: #f0f2f5;
    --surface: #fff;
    --line: #e5e7eb;
    --line-soft: #f3f4f6;
    --up: #059669;
    --down: #dc2626;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    /* Height of the bottom tab bar, plus the phone's home-indicator inset. */
    --tabbar: calc(56px + env(safe-area-inset-bottom));
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--page);
    color: var(--ink);
    line-height: 1.6;
    /* Never let a wide chart or table scroll the whole page sideways. */
    overflow-x: hidden;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px 16px;
    /* Clear the fixed tab bar so the last card is never trapped under it. */
    padding-bottom: calc(var(--tabbar) + 24px);
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
}

.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 24px;
    gap: 16px;
}

h1 { font-size: clamp(22px, 5vw, 28px); font-weight: 700; color: var(--ink); }
h2 { font-size: 18px; font-weight: 600; margin-bottom: 16px; color: var(--ink); }

.last-updated { font-size: 14px; color: var(--muted); white-space: nowrap; }
.last-updated span { color: var(--ink); font-weight: 600; }

.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}

.card-label {
    font-size: 13px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.card-value { font-size: clamp(22px, 5.5vw, 26px); font-weight: 700; }
.card-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

.text-green { color: var(--up); }
.text-red { color: var(--down); }

.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--line);
    border-radius: 4px;
    overflow: hidden;
    margin-top: 12px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--up), #10b981);
    border-radius: 4px;
    transition: width 0.5s ease;
}

.chart-section {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: var(--shadow);
}

/* A chart that cannot shrink further scrolls inside its own box rather than
 * widening the page. */
.chart-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.notes-table { width: 100%; border-collapse: collapse; }

.notes-table th {
    text-align: left;
    padding: 12px;
    border-bottom: 2px solid var(--line);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--muted);
}

.notes-table td {
    padding: 12px;
    border-bottom: 1px solid var(--line-soft);
    vertical-align: top;
}

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

.empty-state { text-align: center; padding: 80px 20px; color: var(--muted); }
.empty-state h2 { color: var(--muted); }

/* ---------------------------------------------------------------- tab bar */

.tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    background: var(--ink);
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 20;
}

.tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 56px;
    padding: 6px 4px;
    color: rgba(255, 255, 255, 0.62);
    text-decoration: none;
    font-size: 11px;
    letter-spacing: 0.3px;
    background: none;
    border: 0;
    cursor: pointer;
    font-family: inherit;
}

.tab:hover, .tab:focus-visible { color: #fff; }
.tab--on { color: #fff; }
.tab--on .tab__glyph { transform: translateY(-1px); }
.tab__glyph { font-size: 18px; line-height: 1; }

@media (min-width: 900px) {
    /* Four tabs stretched across a 1440px window read as a toolbar rather than
       navigation. Group them in the middle once there is room. */
    .tabbar { justify-content: center; gap: 8px; }
    .tab { flex: 0 0 140px; }
}

/* ------------------------------------------------------------------ login */

.auth-page {
    min-height: 100svh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px max(20px, env(safe-area-inset-left));
    gap: 24px;
}

.auth-brand { text-align: center; }
.auth-brand img { width: 72px; height: 72px; border-radius: 18px; }
.auth-brand h1 { margin-top: 12px; }
.auth-brand p { color: var(--muted); font-size: 15px; }

.auth {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.auth label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }

.auth input {
    /* 16px keeps iOS Safari from zooming the page when the field is focused. */
    font-size: 16px;
    font-family: inherit;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    color: var(--ink);
    width: 100%;
}

.auth input:focus-visible { outline: 2px solid var(--up); outline-offset: 1px; border-color: var(--up); }

.auth button {
    font-size: 16px;
    font-family: inherit;
    font-weight: 600;
    padding: 13px;
    border: 0;
    border-radius: 10px;
    background: var(--ink);
    color: #fff;
    cursor: pointer;
    min-height: 48px;
}

.auth__error {
    background: #fef2f2;
    color: var(--down);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 14px;
}

/* ----------------------------------------------------------- track values */

/* Replaces form.as_table inside the admin: a stacked list, so 23 assets are a
 * column of large tap targets instead of a table wider than the screen. */
.track-fields { display: flex; flex-direction: column; gap: 14px; max-width: 560px; }

.track-field { display: flex; flex-direction: column; gap: 6px; }
.track-field > label { font-size: 14px; font-weight: 600; }

.track-field input {
    font-size: 16px;
    font-family: inherit;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    width: 100%;
    min-height: 48px;
}

.track-field .helptext, .track-field .errorlist { font-size: 13px; color: var(--down); list-style: none; }

/* ----------------------------------------------------------------- mobile */

@media (max-width: 640px) {
    .container { padding: 16px 12px calc(var(--tabbar) + 16px); }

    /* One card per row: two 150px columns squeeze a €1,137,903 figure into an
     * ellipsis, which is the one thing this screen exists to show. */
    .cards { grid-template-columns: 1fr; gap: 12px; margin-bottom: 16px; }
    .card { padding: 16px; }

    .dashboard-header { flex-direction: column; align-items: flex-start; gap: 4px; margin-bottom: 16px; }
    .last-updated { white-space: normal; }

    .chart-section { padding: 16px 12px; margin-bottom: 16px; border-radius: 10px; }
    .chart-section h2 { font-size: 16px; margin-bottom: 8px; }

    .notes-table th, .notes-table td { padding: 10px 8px; font-size: 14px; }
    .notes-table th:first-child, .notes-table td:first-child { white-space: nowrap; }
}

@media (prefers-reduced-motion: reduce) {
    .progress-fill { transition: none; }
}

/* -------------------------------------------------- asset / note screens */

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.section-head {
    display: flex;
    align-items: baseline;
    gap: 8px;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--muted);
    margin: 24px 0 10px;
}

.count {
    font-size: 12px;
    background: var(--line);
    color: var(--muted);
    border-radius: 999px;
    padding: 1px 8px;
    letter-spacing: 0;
}

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

/* Labelled figures in a grid: three across, two on a phone. */
.section-head--split { justify-content: space-between; }
.section-head__action { text-transform: none; letter-spacing: 0; font-size: 14px; }
.stat-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}
.stat {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 14px 16px;
    box-shadow: var(--shadow);
}
.stat__label {
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.stat__tag {
    text-transform: none;
    letter-spacing: 0;
    font-size: 11px;
    background: var(--line);
    border-radius: 999px;
    padding: 0 6px;
    margin-left: 2px;
    white-space: nowrap;
}
.stat__value { font-size: 20px; font-weight: 700; margin-top: 4px; }
.stat__sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
@media (max-width: 640px) {
    .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .stat { padding: 12px; }
}
.nowrap { white-space: nowrap; }
.hint { font-size: 13px; color: var(--muted); margin-top: 8px; }

.badge {
    display: inline-block;
    background: var(--line);
    color: var(--muted);
    border-radius: 999px;
    padding: 1px 10px;
    font-size: 12px;
}

/* Rows: the list primitive shared by assets, history and notes. */
.rows { list-style: none; display: flex; flex-direction: column; gap: 8px; }

.row {
    background: var(--surface);
    border-radius: 10px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
}

.row--stacked { flex-direction: column; align-items: stretch; gap: 8px; }
.rows--muted .row { opacity: 0.72; }

.row__link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    /* The whole row is the tap target, not just the words. */
    margin: -14px -16px;
    padding: 14px 16px;
    width: calc(100% + 32px);
    text-decoration: none;
    color: inherit;
    min-height: 48px;
}

.row__main { display: flex; flex-direction: column; min-width: 0; }
.row__title { font-weight: 600; overflow-wrap: anywhere; }
.row__sub { font-size: 13px; color: var(--muted); }
.row__value { text-align: right; display: flex; flex-direction: column; white-space: nowrap; }
.row__amount { font-weight: 600; }
.row__actions { display: flex; gap: 8px; flex-shrink: 0; }

.note__content { overflow-wrap: anywhere; }

/* Buttons. */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 10px 16px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    color: var(--ink);
    font: inherit;
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
}

.btn--primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn--danger { color: var(--down); border-color: #fecaca; }
.btn--small { min-height: 36px; padding: 6px 12px; font-size: 13px; font-weight: 500; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 16px; }
.actions form { display: contents; }

/* Forms. */
.card-form {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    max-width: 560px;
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: 14px; font-weight: 600; }

.field input,
.field select,
.field textarea {
    /* 16px keeps iOS Safari from zooming the page when a field is focused. */
    font-size: 16px;
    font-family: inherit;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    color: var(--ink);
    width: 100%;
    min-height: 48px;
}

.field textarea { min-height: 120px; resize: vertical; }
.field input:focus-visible,
.field select:focus-visible,
.field textarea:focus-visible {
    outline: 2px solid var(--up);
    outline-offset: 1px;
    border-color: var(--up);
}

.errorlist {
    list-style: none;
    color: var(--down);
    font-size: 13px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* Messages. */
.messages { list-style: none; display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }

.message {
    border-radius: 10px;
    padding: 12px 14px;
    font-size: 14px;
    background: #ecfdf5;
    color: #065f46;
}

.message--error { background: #fef2f2; color: var(--down); }

@media (max-width: 640px) {
    .row__actions .btn { min-height: 40px; }
    .page-head { gap: 8px; }
}

/* ------------------------------------------------------------- portfolios */

.pill {
    display: inline-block;
    border-radius: 999px;
    padding: 1px 9px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0;
}

.pill--ok, .pill--on_target { background: #ecfdf5; color: #065f46; }
.pill--warn, .pill--over { background: #fef3c7; color: #92400e; }
.pill--under { background: #eff6ff; color: #1e40af; }

.totals-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 20px;
    align-items: baseline;
    background: var(--surface);
    border-radius: 10px;
    box-shadow: var(--shadow);
    padding: 12px 16px;
    margin-bottom: 12px;
    font-size: 14px;
}

.totals-strip--ok { border-left: 4px solid var(--up); }
.totals-strip--warn { border-left: 4px solid #d97706; }

.holding-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
}

/* Current weight as a bar, target as a marker on the same track — the gap
 * between them IS the drift, without reading two numbers and subtracting. */
.weight-track {
    position: relative;
    height: 10px;
    background: var(--line);
    border-radius: 999px;
    overflow: hidden;
    margin-top: 4px;
}

.weight-fill {
    height: 100%;
    border-radius: 999px;
    background: var(--muted);
    max-width: 100%;
}

.weight-fill--on_target { background: var(--up); }
.weight-fill--over { background: #d97706; }
.weight-fill--under { background: #3b82f6; }

.weight-target {
    position: absolute;
    top: -3px;
    bottom: -3px;
    width: 2px;
    background: var(--ink);
    /* The marker sits ON the target, so centre it rather than starting there. */
    transform: translateX(-1px);
}

.weight-legend {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    font-size: 13px;
    margin-top: 8px;
}

/* Holdings editor. */
.holding-rows { display: flex; flex-direction: column; gap: 12px; }

.holding-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-end;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line-soft);
}

.holding-row:last-child { border-bottom: 0; }
.field--grow { flex: 1 1 200px; min-width: 0; }
.field--target { flex: 0 0 110px; }

.field--remove {
    /* margin-left:auto so that when the row wraps, Remove sits at the right
       edge under its own row rather than floating at the left looking orphaned. */
    flex: 0 0 auto;
    margin-left: auto;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--muted);
}

.field--remove input { width: 22px; height: 22px; min-height: 0; }

.inline-form { flex-direction: row; align-items: flex-end; flex-wrap: wrap; gap: 12px; }
.inline-form .field { flex: 1 1 200px; }

@media (max-width: 640px) {
    .field--target { flex: 1 1 100px; }
    .inline-form { flex-direction: column; align-items: stretch; }
    /* Without this the field keeps its flex-grow and stretches down the column,
       leaving a gap between the input and the button. */
    .inline-form .field { flex: 0 0 auto; }
    .inline-form .btn { width: 100%; }
}
