:root {
    --navy: #0e2744;
    --navy-2: #16375f;
    --bg: #f3f6fb;
    --card: #ffffff;
    --text: #142033;
    --muted: #6b7c93;
    --line: #e6edf5;
    --green: #16a34a;
    --blue: #2563eb;
    --orange: #e8892c;
    --purple: #7c5cbf;
    --red: #dc2626;
    --shadow: 0 10px 30px rgba(15, 39, 68, 0.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    font-family: "Segoe UI", Tahoma, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }

.app { display: flex; min-height: 100vh; }
.sidebar {
    width: 272px;
    background: var(--navy);
    color: #fff;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    flex: none;
}
.brand, .side-user { display: flex; align-items: center; gap: 12px; padding: 22px 18px; }
.brand { position: relative; }
.brand strong, .side-user strong { display: block; font-size: 16px; }
.brand small, .side-user small { display: block; color: rgba(255,255,255,.62); margin-top: 2px; }
.nav-close,
.mobile-bar,
.sidebar-backdrop { display: none; }
.brand-logo, .avatar {
    width: 58px; height: 58px; border-radius: 50%;
    object-fit: cover; background: #fff;
    box-shadow: 0 0 0 2px rgba(214, 176, 96, .85);
    flex: none;
}
.avatar { width: 42px; height: 42px; }
.side-label { color: rgba(255,255,255,.45); font-size: 13px; padding: 4px 22px 8px; }
.side-nav { display: flex; flex-direction: column; gap: 4px; padding: 0 12px; overflow: auto; flex: 1; }
.nav-link {
    display: flex; align-items: center; gap: 10px;
    text-decoration: none; color: rgba(255,255,255,.82);
    padding: 11px 12px; border-radius: 12px;
}
.nav-link svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.nav-link:hover { background: rgba(255,255,255,.06); }
.nav-link.active { background: var(--navy-2); color: #fff; }
.side-user { border-top: 1px solid rgba(255,255,255,.08); }

.main { flex: 1; min-width: 0; max-width: 100%; padding: 28px; }
.top { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 18px; }
.top-title { display: flex; align-items: center; gap: 14px; }
.top-logo {
    width: 64px; height: 64px; border-radius: 50%; object-fit: cover; flex: none;
    box-shadow: 0 0 0 2px rgba(214, 176, 96, .9), 0 8px 18px rgba(15, 39, 68, .12);
}
.top h1 { margin: 0 0 6px; font-size: 28px; }
.top p, .card-head p { margin: 0; color: var(--muted); line-height: 1.7; }
.top time { color: var(--muted); white-space: nowrap; padding-top: 8px; }

.card, .stat {
    background: var(--card);
    border-radius: 18px;
    box-shadow: var(--shadow);
    padding: 18px 18px 16px;
}
.card { margin-bottom: 16px; min-width: 0; max-width: 100%; }
.card-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; margin-bottom: 14px; }
.head-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.item-quick { border-style: dashed; }
.card-head h2, .stat h3 { margin: 0; font-size: 16px; font-weight: 700; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; min-width: 0; }
.stat { min-height: 168px; display: flex; flex-direction: column; }
.stat-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.stat strong { font-size: 26px; margin: 18px 0 14px; letter-spacing: -0.3px; }
.stat small { color: var(--muted); margin-top: 8px; }
.pill { background: #f3f6fb; color: var(--muted); border-radius: 999px; padding: 3px 8px; font-size: 12px; }
.bar { height: 7px; background: #eef2f7; border-radius: 999px; overflow: hidden; margin-top: auto; }
.bar span { display: block; height: 100%; border-radius: inherit; background: var(--green); }
.stat.blue .bar span, .bar.blue span { background: var(--blue); }
.stat.orange .bar span, .bar.orange span { background: var(--orange); }
.stat.purple .bar span { background: var(--purple); }
.stat.green small { color: var(--green); }
.stat.blue small { color: var(--blue); }
.stat.orange small { color: var(--orange); }
.stat.purple small { color: var(--purple); }

.split { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, .8fr); gap: 16px; min-width: 0; }
.compare { display: grid; gap: 14px; margin: 8px 0 18px; }
.compare span { display: block; margin-bottom: 6px; color: var(--muted); }
.bar.tall { height: 12px; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; margin: 0; }
.facts div { background: #f8fafc; border-radius: 12px; padding: 10px 12px; }
.facts dt { color: var(--muted); font-size: 13px; }
.facts dd { margin: 4px 0 0; font-weight: 700; }
.facts.plain { grid-template-columns: 1fr; }
.facts.plain div { background: transparent; border-bottom: 1px solid var(--line); border-radius: 0; padding: 8px 0; display: flex; justify-content: space-between; gap: 12px; }
.facts.plain dd { margin: 0; }

.table-wrap { overflow-x: auto; max-width: 100%; min-width: 0; border: 1px solid var(--line); border-radius: 14px; }
table { width: max-content; min-width: 100%; border-collapse: collapse; }
th, td { padding: 12px 14px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line); }
th { background: #f8fafc; color: var(--muted); font-weight: 600; font-size: 13px; }
tr:last-child td { border-bottom: 0; }
tr:hover td { background: #fbfcfe; }
td.wrap { white-space: normal; min-width: 180px; }
td.empty { text-align: center; color: var(--muted); padding: 28px; }
td.neg, .neg { color: var(--red); }
.actions { display: flex; gap: 6px; align-items: center; }
.actions form { margin: 0; }

.btn {
    background: var(--navy); color: #fff; border: 0; border-radius: 12px;
    padding: 10px 16px; text-decoration: none; display: inline-flex; align-items: center;
    cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--navy-2); }
.btn.ghost { background: #fff; color: var(--navy); border: 1px solid #d7e0ea; }
.btn.ghost:hover { background: #f8fafc; }
.btn.danger { background: #fff; color: var(--red); border: 1px solid #fecaca; }
.btn.tiny { padding: 6px 10px; border-radius: 10px; font-size: 13px; }

.entry-form { background: #f8fafc; border: 1px solid var(--line); border-radius: 16px; padding: 16px; margin-bottom: 16px; }
.form-title { font-weight: 700; margin-bottom: 12px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.wide { grid-column: 1 / -1; }
.field span { color: var(--muted); font-size: 13px; }
.field em { color: var(--red); font-style: normal; }
input, select, textarea {
    width: 100%; background: #fff; border: 1px solid #d7e0ea; border-radius: 12px; padding: 10px 12px;
    font-size: 16px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(37, 99, 235, .18); border-color: #93c5fd; }
.form-actions { display: flex; gap: 8px; margin-top: 14px; }

.alert { border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; }
.alert.ok { background: #ecfdf3; color: #166534; }
.alert.bad { background: #fef2f2; color: #991b1b; }
.badge { border-radius: 999px; padding: 4px 10px; font-size: 13px; background: #f1f5f9; }
.badge.ok { background: #dcfce7; color: #166534; }
.badge.wait { background: #ffedd5; color: #9a3412; }
.badge.off { background: #f1f5f9; color: #64748b; }
.pager { display: flex; gap: 6px; justify-content: center; align-items: center; padding-top: 14px; }
.pager a, .pager span {
    min-width: 36px; height: 36px; padding: 0 10px; border-radius: 10px;
    display: inline-flex; align-items: center; justify-content: center; text-decoration: none;
    background: #fff; border: 1px solid var(--line);
}
.pager .current { background: var(--navy); color: #fff; border-color: var(--navy); }

.stock-value-hero {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 4px 4px;
}
.stock-value-hero span {
    color: var(--muted);
    font-size: 15px;
}
.stock-value-hero strong {
    font-size: 42px;
    line-height: 1.1;
    letter-spacing: -0.6px;
    color: var(--navy);
    font-weight: 800;
}
.empty-box {
    border: 1px dashed var(--line); border-radius: 14px; padding: 28px;
    text-align: center; color: var(--muted);
}
.modal-backdrop {
    position: fixed; inset: 0; z-index: 40;
    background: rgba(15, 39, 68, .45);
    display: grid; place-items: center; padding: 20px;
}
.modal-card {
    width: min(720px, 100%);
    max-height: calc(100vh - 40px);
    overflow: auto;
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 24px 60px rgba(15, 39, 68, .22);
    padding: 18px;
}

@media (max-width: 1100px) {
    .stats, .split, .form-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 900px) {
    .app { display: block; min-height: 100vh; }
    .main {
        padding: 12px 14px 28px;
        width: 100%;
    }

    .mobile-bar {
        display: grid;
        grid-template-columns: 42px 1fr 42px;
        align-items: center;
        gap: 10px;
        position: sticky;
        top: 0;
        z-index: 30;
        background: rgba(243, 246, 251, .94);
        backdrop-filter: blur(8px);
        margin: -12px -14px 14px;
        padding: 12px 14px;
        border-bottom: 1px solid var(--line);
    }
    .mobile-brand {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        min-width: 0;
        justify-self: center;
        max-width: 100%;
    }
    .mobile-brand img {
        width: 36px; height: 36px; border-radius: 50%; object-fit: cover;
        box-shadow: 0 0 0 2px rgba(214, 176, 96, .85);
        flex: none;
    }
    .mobile-brand strong {
        font-size: 15px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .menu-toggle,
    .notify-btn {
        width: 42px; height: 42px;
        border: 1px solid #d7e0ea;
        border-radius: 12px;
        background: #fff;
        display: inline-flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 5px;
        padding: 0;
        cursor: pointer;
        flex: none;
    }
    .menu-toggle span {
        display: block;
        width: 18px; height: 2px;
        background: var(--navy);
        border-radius: 2px;
    }
    .notify-btn svg {
        width: 20px;
        height: 20px;
        fill: none;
        stroke: var(--navy);
        stroke-width: 1.8;
        stroke-linecap: round;
        stroke-linejoin: round;
    }

    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(15, 39, 68, .45);
        z-index: 45;
        opacity: 0;
        pointer-events: none;
        transition: opacity .2s ease;
    }
    body.nav-open .sidebar-backdrop {
        opacity: 1;
        pointer-events: auto;
    }
    body.nav-open { overflow: hidden; }

    .sidebar {
        position: fixed;
        top: 0;
        right: 0;
        width: min(300px, 88vw);
        height: 100vh;
        height: 100dvh;
        z-index: 50;
        transform: translateX(105%);
        transition: transform .25s ease;
        box-shadow: -12px 0 40px rgba(15, 39, 68, .2);
    }
    body.nav-open .sidebar { transform: translateX(0); }
    .side-nav {
        flex-direction: column;
        flex-wrap: nowrap;
        padding-bottom: 12px;
    }
    .nav-link { padding: 12px; font-size: 15px; }
    .nav-close {
        display: grid;
        place-items: center;
        margin-right: auto;
        width: 36px; height: 36px;
        border: 0;
        border-radius: 10px;
        background: rgba(255,255,255,.1);
        color: #fff;
        font-size: 24px;
        line-height: 1;
        cursor: pointer;
        flex: none;
    }

    .top {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        gap: 10px;
        margin-bottom: 14px;
    }
    .top-logo { display: none; }
    .top-title { flex: 1; min-width: 0; }
    .top h1 {
        font-size: 22px;
        margin: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .top time {
        padding-top: 0;
        font-size: 12px;
        white-space: nowrap;
        flex: none;
        color: var(--muted);
        text-align: left;
    }

    .stats,
    .split,
    .form-grid,
    .facts { grid-template-columns: 1fr; }
    .stats { gap: 10px; }
    .stat { min-height: 0; padding: 14px; }
    .stat strong { font-size: 22px; margin: 10px 0 8px; }

    .card { padding: 14px; border-radius: 14px; }
    .card-head {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    .head-actions {
        width: 100%;
        justify-content: stretch;
    }
    .head-actions .btn {
        flex: 1;
        justify-content: center;
        text-align: center;
    }

    .form-actions {
        flex-wrap: wrap;
    }
    .form-actions .btn {
        flex: 1 1 auto;
        justify-content: center;
        min-height: 44px;
    }

    .table-wrap {
        margin: 0 -2px;
        -webkit-overflow-scrolling: touch;
    }
    th, td { padding: 10px 12px; font-size: 13px; }
    .actions {
        flex-wrap: wrap;
    }

    .pager {
        flex-wrap: wrap;
        gap: 6px;
    }

    .stock-value-hero strong { font-size: 32px; }

    .modal-backdrop {
        padding: 12px;
        align-items: flex-end;
    }
    .modal-card {
        width: 100%;
        max-height: min(92vh, 92dvh);
        border-radius: 16px 16px 12px 12px;
        padding: 14px;
    }
}

@media (max-width: 420px) {
    .btn { padding: 10px 12px; }
    .stock-value-hero strong { font-size: 28px; }
}
