:root {
  --bg: #f5f6fa; --panel: #fff; --text: #1d2130; --muted: #6b7185; --line: #e4e6ee;
  --accent: #4f46e5; --accent-soft: #eef0ff; --good: #0f9d58; --good-soft: #e6f6ee;
  --bad: #d93025; --bad-soft: #fdecea; --warn: #b26a00; --warn-soft: #fff4e0; --info: #1967d2; --info-soft: #e8f0fe;
  --radius: 10px; --shadow: 0 1px 2px rgba(20,24,40,.06), 0 4px 16px rgba(20,24,40,.05);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 12px; }
.error { color: var(--bad); min-height: 18px; font-size: 13px; }
a { color: var(--accent); }

/* Buttons & inputs */
.btn { border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 8px 14px; border-radius: 8px; cursor: pointer; font: inherit; font-weight: 500; white-space: nowrap; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { border-color: #c9cddb; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.block { width: 100%; justify-content: center; }
.btn.icon { padding: 6px 10px; }
input, select, textarea { font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { resize: vertical; min-height: 90px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 500; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; }
label.check input { width: auto; }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; background: linear-gradient(135deg, #eef0ff, #f5f6fa 60%); }
.login-card { background: var(--panel); padding: 32px; border-radius: 16px; box-shadow: var(--shadow); width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { margin: 4px 0 0; font-size: 22px; } .login-card p { margin: 0 0 6px; }
.brand-mark { width: 44px; height: 44px; border-radius: 12px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 22px; }
.brand-mark.sm { width: 30px; height: 30px; font-size: 16px; border-radius: 8px; }

/* Layout */
.app { display: flex; min-height: 100%; }
.sidebar { width: 230px; background: #151827; color: #cfd3e3; display: flex; flex-direction: column; padding: 16px 12px; position: sticky; top: 0; height: 100vh; flex-shrink: 0; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 16px; padding: 4px 8px 20px; }
nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
nav a { color: #cfd3e3; text-decoration: none; padding: 9px 12px; border-radius: 8px; display: flex; gap: 10px; align-items: center; }
nav a:hover { background: #22263a; }
nav a.active { background: var(--accent); color: #fff; }
.me { border-top: 1px solid #2a2e44; padding: 14px 8px 0; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.me strong { color: #fff; } .me .btn { color: #cfd3e3; }
main { flex: 1; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 16px 24px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar h2 { margin: 0; font-size: 18px; flex: 1; }
.menu-btn { display: none; font-size: 18px; }
.view { padding: 24px; max-width: 1400px; }

/* Cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 20px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.stat .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.stat.good .value { color: var(--good); } .stat.bad .value { color: var(--bad); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.card h3 { margin: 0 0 12px; font-size: 15px; }

/* Tables */
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #fafbfd; position: sticky; top: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: #fafbff; }
tbody tr.clickable { cursor: pointer; }
tfoot td { font-weight: 700; background: #fafbfd; }
.pos { color: var(--good); } .neg { color: var(--bad); }
.empty { padding: 40px; text-align: center; color: var(--muted); }
.truncate { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #eef0f4; color: var(--muted); }
.badge.Pending { background: var(--warn-soft); color: var(--warn); }
.badge.Article-Received { background: var(--info-soft); color: var(--info); }
.badge.Sent-to-Site { background: var(--accent-soft); color: var(--accent); }
.badge.Published, .badge.Paid { background: var(--good-soft); color: var(--good); }
.badge.Cancelled, .badge.Unpaid { background: var(--bad-soft); color: var(--bad); }
.badge.Partially-Paid { background: var(--warn-soft); color: var(--warn); }

/* Filters */
.filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; align-items: flex-end; }
.filters > * { width: auto; }
.filters input[type=search] { min-width: 220px; flex: 1; }
.filters label { min-width: 130px; }

/* Bars */
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 90px 1fr 90px; gap: 10px; align-items: center; font-size: 13px; }
.bar-track { background: #eef0f4; border-radius: 4px; height: 10px; overflow: hidden; }
.bar-fill { background: var(--accent); height: 100%; border-radius: 4px; }
.bar-row .v { text-align: right; font-variant-numeric: tabular-nums; }

/* Modal */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 32px); box-shadow: 0 20px 60px rgba(0,0,0,.25); color: var(--text); }
dialog::backdrop { background: rgba(15,18,32,.45); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 1; }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-body { padding: 20px; }
.modal-foot { display: flex; justify-content: space-between; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); background: #fafbfd; position: sticky; bottom: 0; }
.modal-foot .right { display: flex; gap: 10px; margin-left: auto; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.section-title { grid-column: 1 / -1; font-weight: 700; font-size: 13px; margin-top: 6px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.calc { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; background: var(--accent-soft); border-radius: 10px; padding: 12px; }
.calc div { display: flex; flex-direction: column; } .calc span { font-size: 12px; color: var(--muted); }
.calc strong { font-size: 17px; font-variant-numeric: tabular-nums; }
.file-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.article-view { white-space: pre-wrap; background: #fafbfd; border: 1px solid var(--line); border-radius: 8px; padding: 12px; max-height: 260px; overflow: auto; font-size: 13px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); background: #1d2130; color: #fff; padding: 10px 18px; border-radius: 8px; opacity: 0; transition: .2s; pointer-events: none; z-index: 100; }
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.err { background: var(--bad); }
.row-actions { display: flex; gap: 6px; }
.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 10px; flex-wrap: wrap; }

@media (max-width: 900px) {
  .grid2 { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 20; transform: translateX(-100%); transition: transform .2s; }
  .app.nav-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .menu-btn { display: inline-flex; }
  .view { padding: 16px; } .topbar { padding: 12px 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .calc { grid-template-columns: repeat(2, 1fr); }
  .filters input[type=search] { min-width: 100%; }
}
