:root {
  --bg: #f3f4f6;
  --panel: #fff;
  --ink: #151515;
  --muted: #6f737a;
  --line: #e6e7ea;
  --red: #d31820;
  --red-dark: #a90d14;
  --red-soft: #fff0f1;
  --green: #147a4b;
  --green-soft: #eaf8f1;
  --orange: #a55b00;
  --orange-soft: #fff5e6;
  --blue: #175a9f;
  --blue-soft: #edf5ff;
  --shadow: 0 12px 30px rgba(0,0,0,.06);
  --radius: 16px;
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body { margin: 0; font: 15px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--ink); background: var(--bg); }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }
button { cursor: pointer; }

.sidebar { position: fixed; inset: 0 auto 0 0; width: 248px; padding: 24px 18px; color: #fff; background: #111; display: flex; flex-direction: column; z-index: 20; }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 26px; border-bottom: 1px solid #292929; }
.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; color: #fff; background: var(--red); border-radius: 10px; font-size: 17px; font-weight: 900; letter-spacing: -.04em; transform: skew(-4deg); }
.brand strong, .brand small { display: block; }
.brand strong { letter-spacing: .08em; }
.brand small { color: #aaa; margin-top: 1px; }
.sidebar nav { display: grid; gap: 5px; margin-top: 24px; }
.sidebar nav a { min-height: 44px; padding: 11px 12px; border-radius: 9px; color: #bebebe; display: flex; align-items: center; justify-content: space-between; transition: .16s ease; }
.sidebar nav a:hover { color: #fff; background: #202020; }
.sidebar nav a.active { color: #fff; background: #2a2a2a; box-shadow: inset 3px 0 0 var(--red); }
.sidebar nav a span { min-width: 24px; padding: 1px 7px; border-radius: 999px; background: #303030; font-size: 12px; text-align: center; }
.sidebar nav .danger-link { color: #ff9b9f; }
.sidebar nav .danger-link span { background: #4d181b; }
.sidebar-footer { margin-top: auto; padding: 18px 10px 4px; border-top: 1px solid #292929; display: flex; justify-content: space-between; color: #aaa; }
.sidebar-footer a { color: #fff; }

.main { margin-left: 248px; min-height: 100vh; padding: 30px 34px 60px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 26px; }
.topbar h1 { margin: 1px 0 0; font-size: clamp(25px, 3vw, 36px); line-height: 1.1; letter-spacing: -.035em; }
.eyebrow { margin: 0; color: var(--red); font-size: 11px; font-weight: 850; letter-spacing: .13em; }
.muted { color: var(--muted); }
.mobile-menu { display: none; border: 0; background: transparent; font-size: 25px; }

.button { min-height: 40px; padding: 9px 15px; border: 1px solid transparent; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; font-weight: 750; line-height: 1.1; white-space: nowrap; transition: .15s ease; }
.button:hover { transform: translateY(-1px); }
.button.primary { color: #fff; background: var(--red); box-shadow: 0 6px 16px rgba(211,24,32,.18); }
.button.primary:hover { background: var(--red-dark); }
.button.ghost { color: #333; background: #fff; border-color: #d8dade; }
.button.success { color: #fff; background: var(--green); }
.button.danger { color: #fff; background: #b9161c; }
.button.small { min-height: 32px; padding: 7px 10px; font-size: 12px; }
.text-link, .member-link { color: var(--red-dark); font-weight: 750; }
.back-link { display: inline-flex; margin-bottom: 16px; color: var(--muted); font-weight: 700; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 16px; margin-bottom: 18px; }
.stat-card { min-height: 142px; padding: 22px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; }
.stat-card span { color: var(--muted); font-weight: 650; }
.stat-card strong { margin: auto 0 3px; font-size: 29px; letter-spacing: -.04em; }
.stat-card small { color: #96999e; }
.red-text { color: var(--red); }

.split-grid, .detail-grid { display: grid; grid-template-columns: 1.2fr .8fr; gap: 18px; margin-bottom: 18px; }
.panel { margin-bottom: 18px; padding: 22px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel h2 { margin: 3px 0 0; font-size: 20px; letter-spacing: -.02em; }
.panel p { color: var(--muted); }
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.upload-panel { color: #fff; background: linear-gradient(135deg,#171717,#2a1112); border: 0; }
.upload-panel p:not(.eyebrow) { color: #c8c8c8; max-width: 600px; }
.attention-panel { display: grid; align-content: start; }
.attention-row { display: flex; align-items: center; justify-content: space-between; padding: 15px 0; border-bottom: 1px solid var(--line); }
.attention-row:last-child { border: 0; }
.attention-row a { min-width: 34px; min-height: 30px; display: grid; place-items: center; border-radius: 99px; background: #111; color: #fff; font-weight: 800; }
.panel-note { margin: -4px 0 18px; padding: 13px 15px; border: 1px solid #dbe7f4; border-radius: 10px; background: #f4f8fd; color: #35526e; }
.panel-note.danger { color: #7f171b; background: var(--red-soft); border-color: #f2c4c6; }

.alert { margin: 0 0 18px; padding: 13px 15px; border: 1px solid; border-radius: 10px; }
.alert.success, .message.success { color: var(--green); background: var(--green-soft); border-color: #bce6d1; }
.alert.warning, .message.warning { color: #85500d; background: var(--orange-soft); border-color: #f0d29f; }
.alert.danger { color: #8e1419; background: var(--red-soft); border-color: #efbfc2; }
.alert .inline-form { margin-left: 10px; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 10px 12px; color: #81848a; border-bottom: 1px solid var(--line); font-size: 11px; text-align: left; text-transform: uppercase; letter-spacing: .08em; white-space: nowrap; }
td { padding: 14px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafafb; }
td strong, td small { display: block; }
td small { margin-top: 3px; color: var(--muted); max-width: 360px; }
td.actions { text-align: right; white-space: nowrap; }
.actions .inline-form { margin-left: 5px; }
.check { width: 30px; }
.empty-cell { padding: 35px; text-align: center; color: var(--muted); }
.status-row-red { background: #fffafa; }
.status-row-review { background: #fffdf8; }

.badge { display: inline-flex; align-items: center; min-height: 24px; padding: 3px 8px; border-radius: 999px; font-size: 11px; font-weight: 800; white-space: nowrap; }
.badge.success { color: var(--green); background: var(--green-soft); }
.badge.danger { color: #9b1419; background: var(--red-soft); }
.badge.warning { color: var(--orange); background: var(--orange-soft); }
.badge.info { color: var(--blue); background: var(--blue-soft); }
.badge.muted { color: #666; background: #eceef0; }
.error-text { color: var(--red); }
.level-dots { display: flex; gap: 5px; }
.level-dots i { width: 11px; height: 11px; border: 2px solid #c9cbd0; border-radius: 50%; }
.level-dots i.on { border-color: var(--orange); background: var(--orange); }
.level-dots i.danger { border-color: var(--red); background: var(--red); }

.batch-bar { margin: -7px -7px 18px; padding: 12px; border-radius: 11px; background: #f1f2f4; display: flex; align-items: center; gap: 14px; }
.batch-bar span { margin-right: auto; }
.batch-bar label { display: flex; align-items: center; gap: 8px; }
label { color: #4f5359; font-size: 13px; font-weight: 700; }
input, select { width: 100%; min-height: 41px; margin-top: 6px; padding: 9px 11px; color: var(--ink); background: #fff; border: 1px solid #d5d7dc; border-radius: 8px; outline: 0; }
input:focus, select:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(211,24,32,.10); }
.batch-bar input { width: 150px; margin: 0; }
.inline-form { display: inline-flex; }
.manual-allocation { min-width: 520px; display: grid; grid-template-columns: minmax(240px,1fr) 100px auto; gap: 7px; align-items: center; }
.manual-allocation input, .manual-allocation select { margin: 0; }

.review-list { display: grid; gap: 13px; }
.review-card { padding: 18px; border: 1px solid var(--line); border-radius: 12px; display: grid; grid-template-columns: 1fr 340px; gap: 24px; }
.review-card h3 { margin: 8px 0 5px; }
.review-card p { margin: 0 0 7px; word-break: break-word; }
.message { margin-top: 10px; padding: 9px 11px; border: 1px solid; border-radius: 8px; font-size: 13px; }
.member-match { position: relative; display: grid; align-content: start; gap: 8px; }
.member-results { position: absolute; top: 66px; inset-inline: 0; max-height: 230px; overflow: auto; z-index: 10; background: #fff; border: 1px solid var(--line); border-radius: 9px; box-shadow: 0 14px 28px rgba(0,0,0,.14); display: none; }
.member-results.open { display: block; }
.member-result { width: 100%; padding: 10px 12px; border: 0; border-bottom: 1px solid var(--line); background: #fff; text-align: left; }
.member-result:hover { background: #f7f7f8; }
.member-result strong, .member-result small { display: block; }
.member-result small { color: var(--muted); }

.score { display: inline-block; padding: 4px 8px; border-radius: 8px; font-weight: 850; }
.score-high { color: var(--green); background: var(--green-soft); }
.score-medium { color: var(--orange); background: var(--orange-soft); }

.case-head { margin-bottom: 18px; padding: 24px; color: #fff; background: linear-gradient(125deg,#141414,#2b2b2b); border-radius: var(--radius); display: flex; justify-content: space-between; align-items: flex-end; box-shadow: var(--shadow); }
.case-head h2 { margin: 10px 0 3px; font-size: 29px; }
.case-head p { margin: 0; color: #aaa; }
.case-total { text-align: right; }
.case-total span, .case-total small, .case-total strong { display: block; }
.case-total span, .case-total small { color: #aaa; }
.case-total strong { font-size: 30px; }
.action-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 16px; margin-bottom: 18px; }
.action-card { padding: 18px; background: #fff; border: 1px solid var(--line); border-radius: 13px; box-shadow: var(--shadow); display: grid; align-content: start; gap: 10px; }
.action-card > strong { font-size: 17px; }
.action-card p { margin: 0; color: var(--muted); }
.danger-card { border-color: #efc6c8; background: #fffafa; }

.timeline { margin: 0; padding: 0; list-style: none; }
.timeline li { position: relative; padding: 0 0 18px 25px; }
.timeline li:not(:last-child)::before { content: ""; position: absolute; left: 5px; top: 14px; bottom: 0; width: 1px; background: var(--line); }
.timeline-dot { position: absolute; left: 0; top: 5px; width: 11px; height: 11px; border-radius: 50%; background: #aaa; }
.timeline-dot.success { background: var(--green); }
.timeline-dot.danger { background: var(--red); }
.timeline-dot.warning { background: var(--orange); }
.timeline-dot.info { background: var(--blue); }
.timeline p, .timeline small { margin: 2px 0 0; color: var(--muted); }

.empty-state { padding: 45px 20px; text-align: center; color: var(--muted); }
.empty-state strong { color: var(--ink); font-size: 17px; }
.empty-state p { margin: 5px 0 0; }
.empty-state.compact { padding: 22px 10px; }

dialog { width: min(520px,calc(100vw - 28px)); padding: 0; border: 0; border-radius: 17px; box-shadow: 0 30px 90px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(0,0,0,.58); backdrop-filter: blur(3px); }
.dialog-card { position: relative; padding: 27px; display: grid; gap: 16px; }
.dialog-card h2, .dialog-card p { margin: 0; }
.dialog-card p { color: var(--muted); }
.dialog-close { position: absolute; top: 12px; right: 13px; width: 34px; height: 34px; border: 0; border-radius: 50%; background: #f0f1f3; font-size: 22px; }
.file-drop { min-height: 140px; padding: 23px; border: 2px dashed #d3d5da; border-radius: 12px; display: grid; place-items: center; text-align: center; background: #fafafb; }
.file-drop input { width: 100%; margin: 0 0 8px; border: 0; }
.file-drop span, .file-drop small { display: block; }

.login-body { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(circle at top right,#421113 0,#151515 45%,#090909 100%); }
.login-card { width: min(430px,100%); padding: 34px; background: #fff; border-radius: 18px; box-shadow: 0 30px 90px rgba(0,0,0,.4); }
.login-card h1 { margin: 12px 0 4px; letter-spacing: -.04em; }
.login-card .brand-mark { margin-bottom: 22px; }
.stack { display: grid; gap: 14px; margin-top: 24px; }

@media (max-width: 1120px) {
  .stats-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .action-grid { grid-template-columns: 1fr 1fr; }
  .review-card { grid-template-columns: 1fr; }
}

@media (max-width: 780px) {
  .sidebar { transform: translateX(-100%); transition: .2s ease; box-shadow: 18px 0 40px rgba(0,0,0,.25); }
  body.menu-open .sidebar { transform: translateX(0); }
  .main { margin-left: 0; padding: 22px 15px 45px; }
  .mobile-menu { display: block; }
  .topbar { align-items: flex-start; }
  .topbar > .button { padding-inline: 10px; font-size: 12px; }
  .stats-grid, .split-grid, .detail-grid, .action-grid { grid-template-columns: 1fr; }
  .panel { padding: 16px; }
  .batch-bar { align-items: stretch; flex-direction: column; }
  .batch-bar input { width: 100%; }
  .case-head { align-items: flex-start; flex-direction: column; gap: 20px; }
  .case-total { text-align: left; }
  td { padding: 12px 9px; }
}
