:root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --border: #e2e5ea;
    --text: #1d2129;
    --muted: #6b7280;
    --primary: #1f5f9e;
    --send: #1d7a4c;
    --send-bg: #e8f5ee;
    --cancel: #b02a2a;
    --cancel-bg: #fbecec;
    --disabled: #b3b8c0;
    --warning: #8a5a05;
    --warning-bg: #fdf3e0;
    --radius: 8px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

a { color: var(--primary); }

.topbar {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 0 24px;
    height: 56px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.brand { font-weight: 600; text-decoration: none; color: var(--text); }
.brand span { color: var(--muted); font-weight: 400; margin-left: 4px; }

.topbar nav { display: flex; gap: 18px; flex: 1; }
.topbar nav a { text-decoration: none; color: var(--muted); padding: 4px 0; }
.topbar nav a:hover { color: var(--text); }
.topbar nav a.active { color: var(--text); box-shadow: inset 0 -2px 0 var(--primary); }

.topbar-right { display: flex; align-items: center; gap: 14px; font-size: 13px; color: var(--muted); }

.env { padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; }
.env-stage { background: var(--warning-bg); color: var(--warning); }
.env-prod { background: var(--cancel-bg); color: var(--cancel); }

.wrap { max-width: 1200px; margin: 0 auto; padding: 24px; }
.wrap-narrow { max-width: 420px; margin: 60px auto; padding: 0 20px; }

.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 22px 0 10px; }
h2:first-child { margin-top: 0; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 18px;
}

.card-head { margin-bottom: 14px; }
.card-head h2 { margin: 0 0 4px; }
.card-head p { margin: 0; font-size: 13px; }

.login-card h1 { margin-bottom: 6px; }

.muted, .hint { color: var(--muted); font-size: 13px; }
.hint { display: block; margin-top: 4px; }
.sub { display: block; font-size: 12px; color: var(--muted); }
.sub-error { color: var(--cancel); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.block { display: block; }
.req { color: var(--cancel); }

.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; font-size: 14px; }
.flash-success { background: var(--send-bg); color: var(--send); }
.flash-error { background: var(--cancel-bg); color: var(--cancel); }
.flash-warning { background: var(--warning-bg); color: var(--warning); }

.filters { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }

.legend { display: flex; gap: 20px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-item svg { width: 16px; height: 16px; }

table.grid { width: 100%; border-collapse: collapse; background: var(--surface); }
table.grid thead th {
    text-align: left;
    font-size: 12px;
    font-weight: 500;
    color: var(--muted);
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}
table.grid tbody td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.grid tbody tr:hover { background: #fafbfc; }
.row-muted { opacity: 0.55; }
.col-actions { text-align: right; white-space: nowrap; }
.col-qty { width: 90px; text-align: right; }

.chip {
    display: inline-block;
    padding: 1px 8px;
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 12px;
    color: var(--muted);
}

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; }
.badge-success { background: var(--send-bg); color: var(--send); }
.badge-info { background: #e8f0f9; color: var(--primary); }
.badge-progress { background: #e9eefb; color: #33449b; }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--cancel-bg); color: var(--cancel); }
.badge-muted, .badge-neutral { background: #eef0f3; color: var(--muted); }

.btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    text-decoration: none;
    cursor: pointer;
}
.btn:hover { border-color: #c9ced6; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: #1a5288; }
.btn-send { color: var(--send); border-color: #bcdccb; }
.btn-cancel { color: var(--cancel); border-color: #e6c3c3; }
.btn-disabled { color: var(--disabled); background: #f4f5f7; cursor: not-allowed; }
.btn-disabled svg { color: var(--disabled); }

.btn-link {
    background: none;
    border: none;
    padding: 0;
    color: var(--primary);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
    text-decoration: none;
}
.btn-link.danger { color: var(--cancel); }

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 30px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: none;
    cursor: pointer;
}
.icon-btn + .icon-btn, form.inline + form.inline .icon-btn, form.inline + .icon-btn { margin-left: 2px; }
.icon-send { color: var(--send); }
.icon-send:hover { background: var(--send-bg); }
.icon-cancel { color: var(--cancel); }
.icon-cancel:hover { background: var(--cancel-bg); }
.icon-disabled { color: var(--disabled); cursor: not-allowed; }

form.inline { display: inline-flex; }
.detail-actions { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }

label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 4px; }
label.check { font-weight: 400; display: flex; align-items: center; gap: 8px; }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=search], select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    font: inherit;
    font-size: 14px;
}
input:focus, select:focus { outline: 2px solid #cddff2; outline-offset: -1px; border-color: var(--primary); }
input[type=checkbox] { width: auto; }

.filters input[type=search] { width: 240px; }
.filters select { width: auto; min-width: 150px; }

.field { margin-bottom: 14px; }
.field-checks { display: flex; flex-direction: column; gap: 6px; justify-content: flex-end; }
.row { display: flex; gap: 14px; }
.row > .field { flex: 1; }
.field-narrow { max-width: 130px; }
.field-wide { flex: 2; }

table.items { width: 100%; border-collapse: collapse; }
table.items th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 500; padding: 0 8px 6px 0; }
table.items td { padding: 0 8px 8px 0; }

.actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.actions.sticky {
    position: sticky;
    bottom: 0;
    background: linear-gradient(180deg, rgba(246,247,249,0), var(--bg) 40%);
    padding: 14px 0;
    margin-top: 0;
}

.columns { display: flex; gap: 18px; align-items: flex-start; }
.columns > .card { flex: 1; }

dl { margin: 0; display: grid; grid-template-columns: 150px 1fr; gap: 8px 14px; font-size: 14px; }
dt { color: var(--muted); font-size: 13px; }
dd { margin: 0; }

address { font-style: normal; font-size: 14px; }
code.block { display: block; padding: 8px 10px; background: #f4f5f7; border-radius: var(--radius); font-size: 13px;
    word-break: break-all; }

.empty { text-align: center; }
.inline-details { display: inline-block; }
.inline-details summary { cursor: pointer; }
.inline-form { display: flex; gap: 6px; margin-top: 8px; align-items: center; }
.inline-form input { width: 170px; }
.name-form { margin-top: 0; }
.name-form input { width: 180px; }

@media (max-width: 900px) {
    .columns, .row { flex-direction: column; }
    .field-narrow, .filters input[type=search] { max-width: none; width: 100%; }
    .topbar { flex-wrap: wrap; height: auto; padding: 10px 16px; gap: 12px; }
}
