:root {
    --bg: #0f1115;
    --panel: #181c23;
    --panel-2: #1f242d;
    --border: #2a303b;
    --text: #e6e9ef;
    --muted: #8a93a4;
    --primary: #5b8cff;
    --primary-hover: #7aa0ff;
    --danger: #ef6b6b;
    --warn: #f7b955;
    --ok: #56d68a;
    --shadow: 0 8px 24px rgba(0,0,0,.25);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }

a { color: inherit; text-decoration: none; }
code { background: var(--panel-2); padding: 1px 6px; border-radius: 3px; font-size: 12px; }
.muted { color: var(--muted); }
.tiny { font-size: 11.5px; }
.err { color: var(--danger); min-height: 18px; margin-top: 8px; }

/* Login */
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.login-card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 32px; width: 100%; max-width: 380px; box-shadow: var(--shadow); }
.login-card h1 { margin: 0 0 4px 0; font-size: 22px; }
.login-card .field { margin: 18px 0; }
.login-card label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 12.5px; }

input, select, textarea {
    width: 100%; padding: 9px 12px; border: 1px solid var(--border);
    background: var(--panel-2); color: var(--text); border-radius: 6px; font: inherit; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
textarea { min-height: 90px; resize: vertical; }

.btn { cursor: pointer; padding: 9px 16px; border-radius: 6px; border: 1px solid var(--border); background: var(--panel-2); color: var(--text); font: inherit; }
.btn:hover { background: #242a34; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; width: 100%; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { filter: brightness(1.1); }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn:disabled:hover { filter: none; }

/* App layout */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 220px; background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; position: fixed; top: 0; bottom: 0; }
.brand { padding: 20px; border-bottom: 1px solid var(--border); }
.brand-title { font-size: 20px; font-weight: 600; }
.brand-sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.sidebar nav { flex: 1; padding: 10px 0; overflow-y: auto; }
.sidebar nav a { display: block; padding: 10px 20px; color: var(--muted); border-left: 3px solid transparent; }
.sidebar nav a:hover { color: var(--text); background: #1d222b; }
.sidebar nav a.active { color: var(--text); border-left-color: var(--primary); background: #1d222b; }
.sidebar-bottom { padding: 14px 18px; border-top: 1px solid var(--border); }

.main { flex: 1; margin-left: 220px; padding: 24px 32px; max-width: 1400px; }

/* View */
.page-title { font-size: 22px; font-weight: 600; margin: 0 0 6px 0; }
.page-sub { color: var(--muted); margin: 0 0 20px 0; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 18px; margin-bottom: 18px; }
.card h3 { margin: 0 0 12px 0; font-size: 15px; }
.card .field { margin: 12px 0; }
.card .field label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 12.5px; }

.grid { display: grid; gap: 14px; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }

.stat { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 16px; }
.stat .label { color: var(--muted); font-size: 12.5px; margin-bottom: 6px; }
.stat .value { font-size: 22px; font-weight: 600; }
.stat .value small { font-size: 12px; font-weight: normal; color: var(--muted); }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input, .toolbar select { width: auto; flex: 0 0 auto; }
.toolbar .grow { flex: 1; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
table th, table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); }
table th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .3px; }
table tr:hover td { background: #1d222b; }
table th.num, table td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.cost-table { table-layout: fixed; }
table.cost-table th:nth-child(1), table.cost-table td:nth-child(1) { width: auto; }
table.cost-table th:nth-child(2), table.cost-table td:nth-child(2) { width: 120px; }
table.cost-table th:nth-child(3), table.cost-table td:nth-child(3) { width: 150px; }
table.cost-table th:nth-child(4), table.cost-table td:nth-child(4) { width: 130px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11.5px; background: var(--panel-2); border: 1px solid var(--border); }
.badge.ok { background: rgba(86,214,138,.15); color: var(--ok); border-color: rgba(86,214,138,.3); }
.badge.warn { background: rgba(247,185,85,.15); color: var(--warn); border-color: rgba(247,185,85,.3); }
.badge.danger { background: rgba(239,107,107,.15); color: var(--danger); border-color: rgba(239,107,107,.3); }
.badge.blue { background: rgba(91,140,255,.15); color: var(--primary); border-color: rgba(91,140,255,.3); }
.badge.muted { color: var(--muted); }

.field-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.field-row label { min-width: 92px; color: var(--muted); font-size: 13px; }
.field-row input { flex: 1; padding: 7px 10px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; color: var(--text); }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; margin: 12px 0 14px; }
.kv > div { background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; min-width: 0; }
.kv b { display: block; margin-bottom: 4px; color: var(--muted); font-size: 12px; font-weight: 500; }
.kv span, .kv code { word-break: break-all; }

.toast { position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%); background: #222; color: #fff; padding: 10px 18px; border-radius: 6px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 999; }
.toast.show { opacity: 1; }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); color: #0b1611; }

/* Modal */
.modal-mask { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 500; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 22px; width: 100%; max-width: 520px; box-shadow: var(--shadow); }
.modal h3 { margin: 0 0 16px 0; }
.modal .field { margin-bottom: 14px; }
.modal label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 12.5px; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }

.progress { width: 100%; height: 10px; background: var(--panel-2); border-radius: 5px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--primary); transition: width .3s; }
.progress-bar.warn { background: var(--warn); }
.progress-bar.danger { background: var(--danger); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; background: var(--panel-2); border-radius: 999px; font-size: 13px; }
.chip-x { background: transparent; border: 0; color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1; padding: 0 0 0 2px; }
.chip-x:hover { color: var(--danger); }

pre.code { background: var(--panel-2); padding: 14px; border-radius: 6px; overflow: auto; font-size: 12px; max-height: 400px; }
pre.code-block { background: var(--panel-2); padding: 12px; border-radius: 6px; overflow: auto; font-size: 12px; max-height: 320px; white-space: pre-wrap; word-break: break-word; }

.modal.large { max-width: 860px; }
.modal-title { font-size: 16px; font-weight: 600; margin-bottom: 12px; }
.modal-body { max-height: 70vh; overflow-y: auto; padding-right: 6px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

.briefing-progress {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 16px;
    margin-bottom: 14px;
}
.briefing-progress-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.briefing-progress-detail { color: var(--muted); font-size: 12.5px; margin-top: 8px; }

.briefing-modal {
    width: calc(100vw - 56px);
    max-width: 1120px;
    max-height: calc(100vh - 56px);
    display: flex;
    flex-direction: column;
}
.briefing-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.briefing-content {
    flex: 1;
    min-height: 0;
    max-height: calc(100vh - 190px);
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 18px 20px;
    line-height: 1.72;
    overflow-wrap: anywhere;
    word-break: break-word;
}
.briefing-content h2,
.briefing-content h3,
.briefing-content h4 { margin: 16px 0 8px; line-height: 1.35; }
.briefing-content h2:first-child,
.briefing-content h3:first-child,
.briefing-content h4:first-child { margin-top: 0; }
.briefing-content p { margin: 5px 0; }
.briefing-content .briefing-bullet { display: grid; grid-template-columns: 18px minmax(0, 1fr); gap: 4px; margin: 5px 0; }
.briefing-content .briefing-blank { height: 8px; }
.briefing-content code { white-space: normal; }

.newapi-card { padding: 14px; }
.newapi-frame {
    width: 100%;
    height: calc(100vh - 250px);
    min-height: 680px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
}

tr.clickable { cursor: pointer; }
tr.clickable:hover { background: var(--panel-2); }

.nowrap { white-space: nowrap; }
.badge.muted { background: #e5e7eb; color: var(--muted); }

.row-actions { display: flex; gap: 6px; }
.message-cell { max-width: 260px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }

@media (max-width: 900px) {
    .sidebar { width: 180px; }
    .main { margin-left: 180px; padding: 18px; }
    .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
    .sidebar { display: none; }
    .main { margin-left: 0; padding: 14px; }
    .grid-3, .grid-4, .grid-2 { grid-template-columns: 1fr; }
}
