:root {
    --bg: #0b1018;
    --panel: #131a26;
    --panel-2: #1a2333;
    --line: #25304a;
    --text: #e6e9f0;
    --muted: #8b95a8;
    --accent: #4c8dff;
    --accent-strong: #3b76e0;
    --danger: #ff8989;
    --danger-strong: #e26464;
    --pos: #74e08c;
    --neg: #ff8989;
    --warn: #f0c674;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
html { min-height: 100%; }
body {
    min-height: 100dvh;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: 100%;
}
@supports not (height: 100dvh) { body { min-height: 100vh; } }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-strong); text-decoration: underline; }
.muted { color: var(--muted); }
.sr-only { position: absolute; left: -9999px; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--panel-2); padding: .1em .35em; border-radius: 3px; font-size: .9em; }

/* --- login --- */
body.login {
    display: flex; align-items: center; justify-content: center;
    padding: 1rem;
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
    padding-top: max(1rem, env(safe-area-inset-top));
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
}
body.login main {
    width: 100%; max-width: 360px;
    padding: 1.75rem;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: 0 8px 30px rgba(0,0,0,.4);
}
body.login form { display: flex; flex-direction: column; gap: 1rem; }
body.login label { display: flex; flex-direction: column; gap: .3rem; }
body.login label span {
    font-size: .75rem; color: var(--muted);
    letter-spacing: .08em; text-transform: uppercase;
}
body.login input {
    padding: .75rem .85rem;
    background: #0e1421;
    border: 1px solid var(--line);
    color: var(--text);
    border-radius: 6px;
    font-size: 16px;
    font-family: inherit;
    line-height: 1.2;
    appearance: none; -webkit-appearance: none;
    min-height: 44px;
}
body.login input:focus { outline: none; border-color: var(--accent); }
body.login button {
    padding: .85rem 1rem;
    background: var(--accent); color: #fff; border: 0;
    border-radius: 6px;
    font-size: 16px; font-family: inherit; font-weight: 500;
    cursor: pointer; min-height: 44px;
    appearance: none; -webkit-appearance: none;
}
body.login button:hover, body.login button:active { background: var(--accent-strong); }
body.login .err {
    color: var(--danger); font-size: .9rem;
    text-align: center; padding: .25rem;
}

/* --- authenticated app --- */
body.app { display: flex; flex-direction: column; }
header.appbar {
    display: flex; align-items: center; gap: 1.25rem;
    padding: .9rem 1.25rem;
    padding-top: max(.9rem, env(safe-area-inset-top));
    padding-left: max(1.25rem, env(safe-area-inset-left));
    padding-right: max(1.25rem, env(safe-area-inset-right));
    border-bottom: 1px solid var(--line);
    background: var(--panel);
}
header.appbar .brand {
    color: var(--text);
    font-weight: 600; letter-spacing: .08em;
    text-decoration: none; font-size: 1rem;
}
header.appbar .topnav { display: flex; gap: 1rem; flex: 1; }
header.appbar .topnav a {
    color: var(--muted); padding: .25rem 0;
    border-bottom: 2px solid transparent;
    font-size: .9rem;
}
header.appbar .topnav a:hover { color: var(--text); text-decoration: none; }
header.appbar .logout { margin: 0; }
header.appbar .logout button {
    background: transparent; color: var(--muted);
    border: 1px solid var(--line);
    padding: .45rem .9rem; border-radius: 6px;
    cursor: pointer; font-family: inherit; font-size: .85rem;
    min-height: 36px;
    appearance: none; -webkit-appearance: none;
}
header.appbar .logout button:hover { color: var(--text); border-color: var(--muted); }

body.app main {
    padding: 1.25rem;
    padding-left: max(1.25rem, env(safe-area-inset-left));
    padding-right: max(1.25rem, env(safe-area-inset-right));
    padding-bottom: max(2rem, env(safe-area-inset-bottom));
    max-width: 1280px; width: 100%; margin: 0 auto;
}

.page-head {
    display: flex; justify-content: space-between; align-items: center;
    gap: 1rem; margin-bottom: 1.25rem;
}
.page-head h1 { font-weight: 500; margin: 0; font-size: 1.35rem; }
.link-muted { color: var(--muted); font-size: .9rem; }

/* --- buttons --- */
.btn-primary, .btn-secondary, .btn-danger {
    display: inline-block; min-height: 44px;
    padding: .65rem 1.1rem; border-radius: 6px;
    font-size: 16px; font-family: inherit; font-weight: 500;
    text-decoration: none; cursor: pointer;
    border: 1px solid transparent;
    appearance: none; -webkit-appearance: none;
    line-height: 1.3;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); color: #fff; text-decoration: none; }
.btn-secondary { background: transparent; color: var(--muted); border-color: var(--line); }
.btn-secondary:hover { color: var(--text); border-color: var(--muted); text-decoration: none; }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: var(--bg); text-decoration: none; }

/* --- holdings table --- */
.holdings { width: 100%; border-collapse: separate; border-spacing: 0; }
.holdings th, .holdings td {
    text-align: left; padding: .65rem .75rem;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}
.holdings th {
    color: var(--muted); font-weight: 500; font-size: .75rem;
    letter-spacing: .08em; text-transform: uppercase;
    background: var(--panel-2);
}
.holdings .num { text-align: right; font-variant-numeric: tabular-nums; }
.holdings .num small { display: block; color: var(--muted); font-size: .8em; }
.holdings .pos { color: var(--pos); }
.holdings .neg { color: var(--neg); }
.holdings .asset strong { display: block; }
.holdings .asset .ticker { color: var(--muted); font-size: .85em; font-variant-numeric: tabular-nums; }
.holdings .actions { text-align: right; white-space: nowrap; }
.holdings tbody tr:hover { background: var(--panel-2); }

.badge {
    display: inline-block; padding: .15rem .55rem;
    border-radius: 99px; font-size: .75rem;
    background: var(--panel-2); color: var(--muted);
    border: 1px solid var(--line); text-transform: lowercase;
}
.badge.warn { background: transparent; color: var(--warn); border-color: var(--warn); }
.account-pill {
    display: inline-block; padding: .15rem .55rem;
    border-radius: 4px; background: var(--panel-2);
    color: var(--text); font-size: .8rem;
}

.empty {
    padding: 2rem; border: 1px dashed var(--line); border-radius: 8px;
    background: var(--panel); text-align: center;
}

/* --- form --- */
.holding-form { display: flex; flex-direction: column; gap: 1.25rem; max-width: 720px; }
.holding-form fieldset {
    border: 1px solid var(--line); border-radius: 8px;
    padding: 1rem 1.25rem 1.25rem; margin: 0;
    background: var(--panel);
    display: flex; flex-direction: column; gap: .85rem;
}
.holding-form legend {
    padding: 0 .5rem; color: var(--muted);
    font-size: .75rem; letter-spacing: .08em; text-transform: uppercase;
}
.holding-form label {
    display: flex; flex-direction: column; gap: .3rem;
}
.holding-form label > span {
    font-size: .8rem; color: var(--muted);
}
.holding-form label small { color: var(--muted); font-weight: normal; }
.holding-form input[type="text"],
.holding-form select,
.holding-form textarea {
    padding: .65rem .8rem;
    background: #0e1421;
    border: 1px solid var(--line);
    color: var(--text);
    border-radius: 6px;
    font-size: 16px;
    font-family: inherit;
    line-height: 1.3;
    appearance: none; -webkit-appearance: none;
    min-height: 44px;
}
.holding-form select {
    /* tiny chevron via background SVG so we don't need an external asset */
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path d='M1 1l5 5 5-5' fill='none' stroke='%238b95a8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/></svg>");
    background-repeat: no-repeat; background-position: right .9rem center;
    padding-right: 2.25rem;
}
.holding-form textarea { min-height: 5rem; resize: vertical; line-height: 1.4; }
.holding-form input:focus, .holding-form select:focus, .holding-form textarea:focus {
    outline: none; border-color: var(--accent);
}
.holding-form label.checkbox {
    flex-direction: row; align-items: center; gap: .65rem;
}
.holding-form label.checkbox input { width: 22px; height: 22px; min-height: auto; accent-color: var(--accent); }
.holding-form label.checkbox span { color: var(--text); font-size: .95rem; }
.field-err {
    color: var(--danger); font-size: .8rem;
}
.form-actions {
    display: flex; gap: .75rem; align-items: center; flex-wrap: wrap;
}

.danger-zone {
    margin-top: 2rem; padding: 1.25rem;
    border: 1px solid var(--danger); border-radius: 8px;
    background: rgba(255, 137, 137, .05);
    max-width: 720px;
}
.danger-zone h2 {
    margin: 0 0 .5rem; font-size: 1rem; color: var(--danger);
}

.confirm {
    padding: 1.25rem; border: 1px solid var(--line);
    border-radius: 8px; background: var(--panel);
    max-width: 520px;
}
.confirm form { margin-top: 1rem; display: flex; gap: .75rem; flex-wrap: wrap; }

/* --- responsive: stack table as cards on narrow screens --- */
@media (max-width: 719px) {
    .holdings, .holdings thead, .holdings tbody, .holdings tr, .holdings td {
        display: block; width: 100%;
    }
    .holdings thead { display: none; }
    .holdings tr {
        background: var(--panel); border: 1px solid var(--line);
        border-radius: 8px; padding: .75rem 1rem;
        margin-bottom: .9rem;
    }
    .holdings td {
        display: flex; justify-content: space-between; align-items: baseline;
        gap: 1rem; padding: .35rem 0; border-bottom: 0;
        text-align: right;
    }
    .holdings td::before {
        content: attr(data-label);
        color: var(--muted); font-size: .75rem;
        letter-spacing: .04em; text-transform: uppercase;
        font-weight: 500;
    }
    .holdings td.asset {
        border-bottom: 1px solid var(--line); padding-bottom: .65rem; margin-bottom: .35rem;
        display: block; text-align: left;
    }
    .holdings td.asset::before { display: none; }
    .holdings .actions { justify-content: flex-end; padding-top: .5rem; }
    .holdings .num small { display: inline; margin-left: .35rem; }
}

@media (min-width: 720px) {
    header.appbar { padding-left: max(2rem, env(safe-area-inset-left)); padding-right: max(2rem, env(safe-area-inset-right)); }
    body.app main { padding: 2rem; padding-left: max(2rem, env(safe-area-inset-left)); padding-right: max(2rem, env(safe-area-inset-right)); }
    .page-head h1 { font-size: 1.6rem; }
}
