:root {
    --bg: #ffffff;
    --fg: #101827;
    --muted: #5a667a;
    --line: #e1e8f0;
    --line-strong: #c9d6e4;
    --primary: #0f2616;
    --primary-soft: #e9f1ec;
    --surface: #ffffff;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--fg);
}

.topbar {
    border-bottom: 1px solid var(--line-strong);
    background: var(--surface);
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar-inner {
    width: 100%;
    padding: 0.9rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    cursor: pointer;
    user-select: none;
}

.nav {
    display: flex;
    gap: 1.2rem;
}

.nav-item {
    color: var(--fg);
    text-decoration: none;
    display: inline-flex;
    gap: 0.45rem;
    align-items: center;
    padding: 0.25rem 0;
    border-bottom: 2px solid transparent;
    font-weight: 500;
}

.nav-item:hover,
.nav-item.is-active {
    border-bottom-color: var(--primary);
    color: var(--primary);
}

.nav-item-hidden {
    display: none;
}

.container {
    width: 100%;
    margin: 1.1rem 0 2rem;
    padding: 0 1rem;
}

.tab {
    display: none;
}

.tab.is-active {
    display: block;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1rem;
}

h1 {
    margin: 0;
    font-size: 1.5rem;
}

p {
    margin: 0.4rem 0 0;
    color: var(--muted);
}

.actions {
    display: inline-flex;
    gap: 0.6rem;
}

.btn {
    border: 1px solid #b8c9bd;
    background: #f3f8f5;
    color: #143423;
    border-radius: 10px;
    padding: 0.55rem 0.85rem;
    font-size: 0.9rem;
    cursor: pointer;
}

.btn:hover {
    border-color: #7c9b88;
    background: #e9f2ec;
}

.btn:disabled {
    opacity: 0.65;
    cursor: not-allowed;
}

.btn-ghost {
    border-color: var(--line);
    background: #fff;
    color: var(--fg);
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start;
    gap: 1rem;
    padding: 0.85rem 0;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    margin-bottom: 0.7rem;
}

.toolbar label {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    color: var(--muted);
    font-size: 0.9rem;
    background: #fbfcfb;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0.45rem 0.6rem;
}

.toolbar-right {
    margin-left: auto;
}

select {
    min-width: 190px;
    padding: 0.48rem 0.55rem;
    border: 1px solid #b9cabb;
    border-radius: 8px;
    font-size: 0.9rem;
    background: #fff;
}

.stock-select {
    min-width: 250px;
}

input[type="number"] {
    width: 110px;
    padding: 0.48rem 0.55rem;
    border: 1px solid #b9cabb;
    border-radius: 8px;
    font-size: 0.9rem;
    background: #fff;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

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

th,
td {
    padding: 0.78rem 0.5rem;
    border-bottom: 1px solid var(--line);
    font-size: 0.92rem;
}

th {
    text-align: left;
    color: #1f382a;
    font-weight: 600;
    white-space: nowrap;
}

th.right,
td.right {
    text-align: right;
}

.empty-row {
    text-align: center;
    color: var(--muted);
    padding: 1.8rem 0.5rem;
}

.status-text {
    margin-top: 0.8rem;
    color: var(--muted);
    font-size: 0.9rem;
}

.preview-panel {
    margin-top: 0.8rem;
    background: #fff;
    border-radius: 12px;
    border: 1px solid #ccd9cf;
    padding: 0.3rem 0.75rem;
}

.dir {
    display: inline-flex;
    width: 22px;
    height: 22px;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    font-weight: 700;
}

.dir-plus {
    background: #e4f3e9;
    color: #185735;
}

.dir-minus {
    background: #fdeaea;
    color: #872626;
}

.shortage-row {
    background: rgba(220, 38, 38, 0.07);
}

.shortage-text {
    color: #9f1239;
    font-weight: 600;
}

.shortage-cell {
    background: rgba(220, 38, 38, 0.12);
    color: #9f1239;
}

.toast-container {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 50;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}

.toast {
    min-width: 230px;
    max-width: 360px;
    border-radius: 10px;
    padding: 0.65rem 0.8rem;
    border: 1px solid #c8d5cc;
    background: #ffffff;
    color: #163124;
    box-shadow: 0 10px 24px rgba(16, 24, 39, 0.18);
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.toast-success {
    border-color: #a8c9b1;
    background: #f3faf5;
}

.toast-error {
    border-color: #efc5c9;
    background: #fff5f6;
    color: #7f1d1d;
}

.toast-hide {
    opacity: 0;
    transform: translateY(8px);
}

#health-output {
    margin-top: 1rem;
    background: #f5faf7;
    border: 1px solid #cde1d2;
    color: #1b3e2c;
    padding: 0.75rem;
    border-radius: 8px;
    overflow: auto;
    min-height: 66px;
    white-space: pre-wrap;
}

@media (max-width: 860px) {
    .topbar-inner {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.55rem;
        padding: 0.8rem 0.75rem;
    }

    .page-header {
        flex-direction: column;
    }

    .toolbar {
        flex-direction: column;
        align-items: flex-start;
    }

    .container {
        padding: 0 0.75rem;
    }
}
