:root {
    color-scheme: dark;
    --bg: #080b10;
    --surface: #10161f;
    --surface-2: #151d28;
    --line: #253040;
    --text: #f2f5f7;
    --muted: #8e9bad;
    --accent: #c8ff39;
    --accent-2: #95d700;
    --danger: #ff5f6d;
    --warning: #ffbf47;
    --radius: 18px;
    --shadow: 0 18px 55px rgb(0 0 0 / 28%);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; background: radial-gradient(circle at 75% -10%, #1d2b26 0, transparent 30rem), var(--bg); color: var(--text); font: 15px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
svg { width: 1.25rem; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.4rem, 3vw, 2rem); letter-spacing: -.04em; }
h2 { margin-bottom: 0; font-size: 1.2rem; letter-spacing: -.025em; }
h3 { margin-bottom: .25rem; font-size: 1.15rem; }
small { color: var(--muted); }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 250px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 28px 18px; border-right: 1px solid var(--line); background: rgb(8 11 16 / 88%); backdrop-filter: blur(18px); display: flex; flex-direction: column; z-index: 20; }
.brand { display: flex; gap: 12px; align-items: center; padding: 0 10px 32px; }
.brand-mark { width: 43px; height: 43px; border-radius: 13px; display: grid; place-items: center; color: #111; background: var(--accent); font-weight: 900; letter-spacing: -.08em; box-shadow: 0 0 35px rgb(200 255 57 / 20%); }
.brand strong, .brand small { display: block; }
.brand small { margin-top: 1px; font-size: .72rem; }
.sidebar nav { display: grid; gap: 6px; }
.nav-link { color: var(--muted); padding: 11px 13px; border-radius: 11px; transition: .2s ease; }
.nav-link span { color: var(--accent); display: inline-block; width: 24px; }
.nav-link:hover { color: var(--text); background: var(--surface-2); transform: translateX(2px); }
.sidebar-note { margin-top: auto; color: var(--muted); font-size: .8rem; padding: 12px; border: 1px solid var(--line); border-radius: 11px; }
.pulse { display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.main { min-width: 0; padding: 0 34px 50px; }
.topbar { min-height: 112px; display: flex; align-items: center; gap: 18px; }
.top-action { margin-left: auto; }
.menu-button { display: none; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; width: 42px; height: 42px; }
.eyebrow, .section-kicker { margin-bottom: 2px; color: var(--accent); text-transform: uppercase; font-weight: 800; letter-spacing: .13em; font-size: .67rem; }

.panel, .metric, .detail-hero { border: 1px solid var(--line); background: linear-gradient(145deg, rgb(21 29 40 / 92%), rgb(14 20 28 / 92%)); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel { padding: 22px; margin-bottom: 22px; }
.panel-head, .toolbar, .detail-hero { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.panel-head { margin-bottom: 20px; }
.toolbar { margin-bottom: 20px; }
.badge, .status { display: inline-flex; align-items: center; width: fit-content; white-space: nowrap; border: 1px solid var(--line); border-radius: 999px; padding: 4px 9px; color: var(--muted); font-size: .73rem; font-weight: 700; }
.status-active { color: var(--accent); border-color: rgb(200 255 57 / 30%); background: rgb(200 255 57 / 7%); }
.status-inactive { color: var(--muted); }
.positive { color: var(--accent) !important; }
.negative { color: var(--danger) !important; }

.button, .icon-button { cursor: pointer; border: 1px solid var(--line); color: var(--text); background: var(--surface-2); transition: .18s ease; }
.button { min-height: 40px; padding: 9px 14px; display: inline-flex; justify-content: center; align-items: center; border-radius: 10px; font-weight: 750; }
.button:hover, .icon-button:hover { border-color: #4b5b70; transform: translateY(-1px); }
.button-primary { color: #101508; border-color: var(--accent); background: var(--accent); }
.button-primary:hover { border-color: #ddff83; background: #d4ff63; }
.button-danger { color: #ff8993; background: rgb(255 95 109 / 8%); border-color: rgb(255 95 109 / 22%); }
.icon-button { width: 36px; height: 36px; border-radius: 9px; }
.icon-button.danger { color: var(--danger); }

input, select { width: 100%; color: var(--text); background: #0b1017; border: 1px solid var(--line); border-radius: 10px; padding: 10px 11px; outline: none; }
input:focus, select:focus { border-color: var(--accent-2); box-shadow: 0 0 0 3px rgb(200 255 57 / 8%); }
label { display: grid; gap: 6px; color: var(--muted); font-size: .77rem; font-weight: 700; }
.item-form { display: grid; grid-template-columns: 1.1fr 2fr 1fr .8fr auto; align-items: end; gap: 12px; }
.inline-form, .filter-form, .period-form, .edit-form, .version-form { display: flex; align-items: end; gap: 10px; }
.filter-form input { min-width: 210px; }
.custom-period { display: flex; gap: 6px; }
.custom-period.is-hidden { display: none; }

.metric-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 14px; margin-bottom: 22px; }
.metric { padding: 20px; min-height: 144px; display: flex; flex-direction: column; justify-content: center; overflow: hidden; position: relative; }
.metric::after { content: ""; position: absolute; width: 100px; height: 100px; right: -55px; top: -55px; background: var(--accent); border-radius: 50%; filter: blur(35px); opacity: .12; }
.metric-featured { border-color: rgb(200 255 57 / 34%); }
.metric-label { color: var(--muted); font-size: .78rem; }
.metric strong { display: block; margin: 8px 0 4px; font-size: clamp(1.05rem, 1.6vw, 1.55rem); letter-spacing: -.045em; }
.split-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(300px, .7fr); gap: 22px; }
.split-grid .panel { margin-bottom: 0; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { color: var(--muted); text-align: left; font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; }
th, td { padding: 13px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
.item-link { display: flex; gap: 10px; align-items: center; }
.item-link strong, .item-link small { display: block; }
.category-icon { flex: 0 0 auto; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 10px; color: var(--accent); background: rgb(200 255 57 / 7%); border: 1px solid rgb(200 255 57 / 15%); }
.category-icon.large { width: 44px; height: 44px; }
.category-icon.hero-icon { width: 62px; height: 62px; border-radius: 16px; }
.category-icon.hero-icon svg { width: 30px; }
.category-stats { display: grid; gap: 8px; }
.category-stat { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; padding: 13px 0; border-bottom: 1px solid var(--line); }
.category-stat:last-child { border: 0; }
.category-stat strong, .category-stat small { display: block; }

.item-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.item-card { min-width: 0; padding: 18px; border: 1px solid var(--line); border-radius: 15px; background: rgb(8 13 19 / 54%); display: grid; gap: 18px; }
.item-card.is-inactive { opacity: .68; }
.item-card-head, .card-actions { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.item-card p { margin-bottom: 0; color: var(--muted); }
.item-numbers { display: grid; grid-template-columns: .55fr 1.15fr 1fr; gap: 7px; }
.item-numbers span { min-width: 0; padding: 9px; border-radius: 9px; background: var(--surface); }
.item-numbers small, .item-numbers strong { display: block; overflow: hidden; text-overflow: ellipsis; }
.item-numbers strong { margin-top: 2px; font-size: .84rem; }
.card-actions .button, .card-actions form { flex: 1; }
.card-actions form .button { width: 100%; }

.detail-hero { margin-bottom: 22px; padding: 24px; }
.detail-title { display: flex; align-items: center; gap: 16px; }
.detail-title p:last-child { color: var(--muted); margin: 3px 0 0; }
.quick-entry { display: flex; justify-content: space-between; align-items: end; gap: 20px; }
.quick-entry p:last-child { margin-bottom: 0; color: var(--muted); }
.trade-list { display: grid; gap: 10px; }
.trade-row { display: grid; grid-template-columns: 80px minmax(150px, .7fr) 28px minmax(250px, 1.1fr) auto auto; gap: 12px; align-items: center; padding: 14px; border: 1px solid var(--line); border-radius: 13px; background: rgb(8 13 19 / 45%); }
.trade-status { color: var(--warning); text-transform: uppercase; font-size: .68rem; letter-spacing: .08em; font-weight: 850; }
.trade-status span { display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; background: var(--warning); }
.trade-row.is-sold .trade-status { color: var(--accent); }
.trade-row.is-sold .trade-status span { background: var(--accent); }
.trade-block small { display: block; margin-bottom: 5px; }
.edit-form input { max-width: 150px; }
.sale-form { display: grid; grid-template-columns: minmax(120px, .7fr) minmax(180px, 1fr) auto; gap: 10px; align-items: end; }
.sale-preview { align-self: center; color: var(--muted); font-size: .75rem; }
.trade-arrow { color: var(--muted); font-size: 1.25rem; }
.trade-meta { color: var(--muted); font-size: .73rem; }
.trade-profit { white-space: nowrap; }

.version-list { display: grid; gap: 9px; }
.version-row { display: grid; grid-template-columns: 80px 1fr auto; gap: 14px; align-items: end; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: rgb(8 13 19 / 45%); }
.version-row.is-inactive { opacity: .62; }
.version-form { display: grid; grid-template-columns: 1fr 130px auto; }
.empty-state, .error-page { padding: 45px 20px; text-align: center; color: var(--muted); }
.empty-state strong, .error-page h2 { color: var(--text); }
.empty-state p { margin: 5px auto 18px; }
.empty-state.compact { padding: 22px 10px; }
.error-page { padding-block: 90px; }
.error-page > span { color: var(--accent); font-size: 4rem; font-weight: 900; }
.error-page pre { text-align: left; white-space: pre-wrap; color: #ffb0b7; background: #090d12; padding: 15px; border-radius: 10px; }
.flash-stack { display: grid; gap: 8px; margin-bottom: 18px; }
.flash { padding: 12px 15px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); }
.flash-success { border-color: rgb(200 255 57 / 25%); color: var(--accent); }
.flash-error { border-color: rgb(255 95 109 / 30%); color: #ff9ba4; }
.flash-info { color: #91cfff; border-color: rgb(77 167 255 / 28%); }

@media (max-width: 1180px) {
    .metric-grid { grid-template-columns: repeat(3, 1fr); }
    .item-grid { grid-template-columns: repeat(2, 1fr); }
    .item-form { grid-template-columns: repeat(2, 1fr); }
    .trade-row { grid-template-columns: 70px 1fr 25px 1.5fr auto; }
    .trade-row > .delete-form { grid-column: 5; }
    .trade-profit { grid-column: 5; grid-row: 1; }
}

@media (max-width: 900px) {
    .app-shell { display: block; }
    .sidebar { position: fixed; left: 0; transform: translateX(-105%); width: 260px; transition: transform .2s ease; box-shadow: var(--shadow); }
    .menu-open .sidebar { transform: translateX(0); }
    .main { padding-inline: 20px; }
    .menu-button { display: block; }
    .split-grid { grid-template-columns: 1fr; }
    .quick-entry { align-items: stretch; flex-direction: column; }
}

@media (max-width: 680px) {
    .main { padding-inline: 14px; }
    .topbar { min-height: 92px; }
    .top-action { display: none; }
    .metric-grid { grid-template-columns: repeat(2, 1fr); }
    .metric:first-child { grid-column: 1 / -1; }
    .item-grid { grid-template-columns: 1fr; }
    .item-form, .version-form { grid-template-columns: 1fr; }
    .stack-mobile, .toolbar { align-items: stretch; flex-direction: column; }
    .filter-form, .period-form, .inline-form { align-items: stretch; flex-direction: column; }
    .filter-form input { min-width: 0; }
    .custom-period { display: grid; grid-template-columns: 1fr 1fr; }
    .trade-row { grid-template-columns: 1fr auto; }
    .trade-status, .trade-block, .sale-form { grid-column: 1 / -1; }
    .trade-arrow { display: none; }
    .sale-form { grid-template-columns: 1fr; }
    .trade-profit { grid-column: 1; grid-row: auto; }
    .trade-row > .delete-form { grid-column: 2; grid-row: auto; }
    .version-row { grid-template-columns: 1fr; align-items: stretch; }
    .detail-hero { align-items: flex-start; }
}
