:root {
    --bg: #0f1117;
    --bg-card: #1a1b23;
    --bg-card-hover: #22232d;
    --bg-input: #13141b;
    --border: #2a2b35;
    --text: #e4e4e7;
    --text-muted: #71717a;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --green: #22c55e;
    --red: #ef4444;
    --yellow: #eab308;
    --orange: #f59e0b;
    --purple: #a855f7;
    --radius: 12px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    font-size: 15px;
    line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85em;
       background: var(--bg-input); padding: 1px 6px; border-radius: 4px; border: 1px solid var(--border); }
h1 { font-size: 1.5rem; font-weight: 650; }
h3 { font-size: 1rem; font-weight: 600; margin-bottom: 10px; }
h4 { font-size: .9rem; font-weight: 600; margin: 16px 0 6px; }
.muted { color: var(--text-muted); }
.small { font-size: .82rem; }
.prewrap { white-space: pre-wrap; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.right { text-align: right; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.neutral { color: var(--text-muted); }
[hidden] { display: none !important; }

/* ---- Login ---- */
.login-page { display: flex; align-items: center; justify-content: center; }
.login-container { width: 100%; max-width: 400px; padding: 20px; }
.login-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 16px; padding: 40px 32px; }
.login-header { text-align: center; margin-bottom: 32px; }
.login-header h1 { font-size: 1.8rem; margin-bottom: 8px; }
.login-header p { color: var(--text-muted); font-size: .9rem; }

/* ---- Layout ---- */
.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: 20px;
    padding: 0 24px; height: 58px;
    background: rgba(19, 20, 27, .92); backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
}
.brand { color: var(--text); font-weight: 700; font-size: 1.1rem; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand:hover { color: var(--text); }
.nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { color: var(--text-muted); padding: 6px 11px; border-radius: 8px; font-size: .9rem; white-space: nowrap; }
.nav a:hover { color: var(--text); background: var(--bg-card); }
.nav a.active { color: var(--text); background: var(--bg-card); }
.logout { color: var(--text-muted); font-size: .9rem; }
.logout:hover { color: var(--red); }
.container { max-width: 1280px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--text-muted); font-size: .9rem; }

/* ---- Forms & buttons ---- */
input, select, textarea {
    width: 100%; background: var(--bg-input); color: var(--text);
    border: 1px solid var(--border); border-radius: 8px;
    padding: 9px 12px; font: inherit; font-size: .92rem; outline: none;
    transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input[type=month], input[type=date], input[type=time] { color-scheme: dark; }
textarea { resize: vertical; }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
input[type=color] { padding: 2px; height: 38px; }
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: .82rem; color: var(--text-muted); margin-bottom: 6px; }
.form-group .help { font-size: .76rem; color: var(--text-muted); margin-top: 4px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.span-2 { grid-column: span 2; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 9px 16px; border-radius: 8px; border: 1px solid var(--border);
    background: var(--bg-card); color: var(--text); font: inherit; font-size: .9rem; font-weight: 500;
    cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--bg-card-hover); color: var(--text); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); color: #fff; }
.btn-danger { color: var(--red); }
.btn-danger:hover { background: rgba(239, 68, 68, .12); border-color: var(--red); color: var(--red); }
.btn-sm { padding: 5px 10px; font-size: .82rem; }
.btn-full { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.icon-btn { background: none; border: none; color: var(--text-muted); font-size: 1.1rem; cursor: pointer; padding: 4px 8px; }
.icon-btn:hover { color: var(--text); }
.link-btn { background: none; border: none; color: var(--accent); cursor: pointer; font: inherit; font-size: .85rem; padding: 0; }
.link-btn:hover { color: var(--accent-hover); }
.link-btn.danger { color: var(--red); }

.alert { padding: 12px 14px; border-radius: 8px; margin-bottom: 18px; font-size: .9rem; }
.alert-error { background: rgba(239, 68, 68, .1); border: 1px solid rgba(239, 68, 68, .35); color: #fca5a5; }
.alert-warn { background: rgba(234, 179, 8, .08); border: 1px solid rgba(234, 179, 8, .3); color: #fde68a; }
.alert-info { background: rgba(59, 130, 246, .08); border: 1px solid rgba(59, 130, 246, .3); color: #bfdbfe; }

/* ---- Month nav ---- */
.month-nav { display: flex; align-items: center; gap: 6px; }
.month-nav input { width: auto; padding: 7px 10px; }
.month-nav .btn { padding: 7px 12px; }

/* ---- Stats ---- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
        padding: 14px 18px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat-value { font-size: 1.45rem; font-weight: 700; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat-label { color: var(--text-muted); font-size: .8rem; }
.stat-sub { color: var(--text-muted); font-size: .76rem; }

/* ---- Panels & grids ---- */
.panel { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; min-width: 0; }
.panel p { margin-bottom: 12px; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.panel-head h3 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
.grid-2 > .panel { margin-bottom: 0; }
.stack { display: flex; flex-direction: column; gap: 16px; margin-bottom: 16px; }
.chart { width: 100%; height: 320px; }
.chart-lg { height: 560px; }
.chart-cal { height: 190px; }
.empty-chart { display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: .9rem; height: 100%; min-height: 120px; }

/* ---- Toolbar ---- */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar .search { flex: 1 1 220px; }
.toolbar select, .toolbar input[type=month], .toolbar input[type=date] { width: auto; flex: 0 1 auto; }
.spacer { flex: 1; }
.result-info { font-size: .82rem; margin-bottom: 10px; min-height: 1.2em; }

/* ---- Chips & badges ---- */
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: .75rem; padding: 2px 9px; border-radius: 999px;
        background: var(--bg-card-hover); border: 1px solid var(--border); color: var(--text-muted); white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.badge { display: inline-block; font-size: .72rem; padding: 1px 8px; border-radius: 6px; background: var(--bg-card-hover); color: var(--text-muted); white-space: nowrap; border: 1px solid transparent; }
.badge-green { color: var(--green); border-color: rgba(34, 197, 94, .35); }
.badge-red { color: var(--red); border-color: rgba(239, 68, 68, .35); }
.badge-yellow { color: var(--yellow); border-color: rgba(234, 179, 8, .35); }
.badge-blue { color: #93c5fd; border-color: rgba(59, 130, 246, .4); }
.badge-purple { color: #d8b4fe; border-color: rgba(168, 85, 247, .4); }
.badge-orange { color: var(--orange); border-color: rgba(245, 158, 11, .4); }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); }
table.tbl { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.tbl th { text-align: left; font-weight: 500; color: var(--text-muted); font-size: .78rem; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.tbl td { padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.tbl tr:last-child td { border-bottom: none; }
table.tbl tbody tr:hover td { background: var(--bg-card-hover); }
table.tbl tr.clickable { cursor: pointer; }
table.tbl a { color: var(--text); font-weight: 500; }
table.tbl a:hover { color: var(--accent); }
table.tbl th.right, table.tbl td.right { text-align: right; }
.tx-title { font-weight: 500; color: var(--text); }
.tx-sub { color: var(--text-muted); font-size: .78rem; max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel .table-wrap { border: none; background: none; border-radius: 0; margin: 0 -8px; }

/* ---- Lists ---- */
.list { list-style: none; }
.list li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: .88rem; }
.list li:last-child { border-bottom: none; }
.list .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- Progress ---- */
.progress { position: relative; height: 8px; background: var(--bg-input); border-radius: 999px; overflow: hidden; border: 1px solid var(--border); }
.progress > span { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 999px; background: var(--accent); }
.progress.ok > span { background: var(--green); }
.progress.warn > span { background: var(--yellow); }
.progress.over > span { background: var(--red); }
.progress .pace { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--text-muted); opacity: .7; }
.budget-row { padding: 9px 0; border-bottom: 1px solid var(--border); }
.budget-row:last-child { border-bottom: none; }
.budget-top { display: flex; justify-content: space-between; gap: 8px; font-size: .86rem; margin-bottom: 5px; }

/* ---- Empty ---- */
.empty { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-icon { font-size: 2.6rem; margin-bottom: 10px; }
.empty h2 { color: var(--text); margin-bottom: 14px; font-size: 1.2rem; }
.empty p { margin-bottom: 6px; }

/* ---- Detail pages ---- */
.back-link { display: inline-block; color: var(--text-muted); margin-bottom: 16px; font-size: .9rem; }
.detail-layout { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.amount-big { font-size: 2rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.info-list { display: grid; grid-template-columns: 130px 1fr; gap: 7px 12px; font-size: .9rem; }
.info-list dt { color: var(--text-muted); }
.info-list dd { overflow-wrap: anywhere; }
.gallery { display: flex; flex-wrap: wrap; gap: 10px; }
.gthumb { position: relative; width: 110px; height: 140px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: #121319; cursor: zoom-in; }
.gthumb img { width: 100%; height: 100%; object-fit: cover; }
.gthumb .mini-btn { position: absolute; top: 4px; right: 4px; display: none; }
.gthumb:hover .mini-btn { display: block; }
.mini-btn { background: rgba(15, 17, 23, .9); color: var(--text); border: 1px solid var(--border); border-radius: 6px;
            width: 26px; height: 26px; cursor: pointer; font-size: .85rem; line-height: 1; }
.mini-btn:hover { border-color: var(--red); color: var(--red); }
.upload-box { border: 1px dashed var(--border); border-radius: 10px; padding: 14px; text-align: center; color: var(--text-muted); font-size: .85rem; }
.items-edit input { padding: 6px 8px; font-size: .85rem; }
.items-edit select { padding: 6px 8px; font-size: .85rem; }
.cand { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; font-size: .86rem; }
.cand-top { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.cand-reasons { color: var(--text-muted); font-size: .76rem; margin-top: 3px; }

/* ---- Log ---- */
.log-list { list-style: none; }
.log-list li { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-bottom: 1px solid var(--border); font-size: .86rem; flex-wrap: wrap; }
.log-list li:last-child { border-bottom: none; }
.card-list { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); }
.log-time { color: var(--text-muted); font-size: .8rem; font-variant-numeric: tabular-nums; min-width: 112px; }
.log-details { color: var(--text-muted); overflow-wrap: anywhere; flex: 1; }

/* ---- Settings ---- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs button { background: none; border: none; color: var(--text-muted); padding: 9px 14px; cursor: pointer; font: inherit; font-size: .9rem; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.cat-tree .cat { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: .88rem; }
.cat-tree .cat.child { padding-left: 28px; }
.cat-tree .cat .grow { flex: 1; }
.swatch { width: 12px; height: 12px; border-radius: 4px; flex: none; }

/* ---- Agent page ---- */
.link-list { list-style: none; font-size: .9rem; }
.link-list li { margin-bottom: 6px; overflow-wrap: anywhere; }
pre.code { background: var(--bg-input); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px;
           font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8rem; overflow-x: auto; line-height: 1.55; }
.tools-table { width: 100%; border-collapse: collapse; font-size: .86rem; }
.tools-table th, .tools-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.tools-table th { white-space: nowrap; font-weight: 500; }
.tools-table td { color: var(--text-muted); }

/* ---- Modal ---- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); }
.modal-card { position: relative; width: 100%; max-width: 640px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 16px; padding: 22px 24px; }
.modal-card.wide { max-width: 900px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.modal-head h2 { font-size: 1.15rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

/* ---- Lightbox / toast ---- */
.lightbox { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, .9); display: flex; align-items: center; justify-content: center; cursor: zoom-out; padding: 20px; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
         background: var(--bg-card-hover); border: 1px solid var(--border); padding: 10px 18px; border-radius: 10px; font-size: .9rem;
         transition: opacity .2s, transform .2s; z-index: 70; max-width: 90vw; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { border-color: var(--red); color: #fca5a5; }

/* ---- Responsive ---- */
@media (max-width: 960px) {
    .grid-2, .detail-layout { grid-template-columns: 1fr; }
    .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
    .container { padding: 14px; }
    .topbar { padding: 0 12px; gap: 10px; }
    .nav a { padding: 6px 8px; font-size: .84rem; }
    .brand-text { display: none; }
    .form-grid { grid-template-columns: 1fr; }
    .span-2 { grid-column: span 1; }
    .toolbar select, .toolbar input[type=month] { flex: 1 1 45%; }
    .stat-value { font-size: 1.2rem; }
    .chart { height: 280px; }
    .chart-lg { height: 640px; }
    .info-list { grid-template-columns: 105px 1fr; }
    .hide-sm { display: none; }
    .panel { padding: 14px; }
}
