:root {
  --bg: #f4f1eb;
  --surface: #fffdf9;
  --surface-strong: #ffffff;
  --ink: #241f18;
  --muted: #7a7165;
  --line: #e6dfd3;
  --gold: #a77b25;
  --gold-soft: #f5ead2;
  --green: #24745a;
  --green-soft: #e4f2ec;
  --orange: #b85d21;
  --orange-soft: #fae9dd;
  --red: #ad3f45;
  --red-soft: #f8e4e5;
  --shadow: 0 18px 50px rgba(44, 34, 21, 0.08);
}

* { box-sizing: border-box; }
html { scrollbar-gutter: stable; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; }
body.drawer-open { overflow: hidden; overscroll-behavior: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.role-hidden { display: none !important; }
.muted { color: var(--muted); }
.eyebrow { margin: 0 0 5px; color: var(--gold); font-size: 11px; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at top left, #fff7e7, transparent 45%), var(--bg); }
.login-card { width: min(420px, 100%); padding: 36px; border: 1px solid var(--line); border-radius: 22px; background: rgba(255,253,249,.95); box-shadow: var(--shadow); }
.brand-mark { display: inline-flex; padding: 8px 12px; margin-bottom: 24px; border-radius: 10px; background: var(--ink); color: white; font-weight: 800; }
.login-card h1 { margin: 0 0 10px; font-size: 30px; }
.login-card label { display: grid; gap: 8px; margin: 28px 0 16px; font-weight: 700; }
.login-card label + label { margin-top: 14px; }
.login-card label small { color: var(--muted); font-weight: 500; }

input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-strong); color: var(--ink); outline: none; transition: .2s; }
input, select { height: 42px; padding: 0 12px; }
textarea { padding: 12px; resize: vertical; line-height: 1.65; }
input:focus, select:focus, textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(167,123,37,.12); }

button { border: 0; border-radius: 10px; padding: 10px 14px; font-weight: 750; }
.primary { background: var(--ink); color: white; }
.primary:hover { background: #44392d; }
.ghost { border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.ghost:hover { border-color: #cbbda8; }
.danger { color: var(--red); }
.full { width: 100%; }
.small { padding: 8px 12px; font-size: 13px; }
.message { min-height: 22px; margin: 12px 0 0; color: var(--red); font-size: 13px; }

.topbar { position: sticky; top: 0; z-index: 20; display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 18px 28px; border-bottom: 1px solid var(--line); background: rgba(244,241,235,.92); backdrop-filter: blur(16px); }
.topbar h1 { margin: 0; font-size: 23px; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.user-chip { display: inline-flex; align-items: center; min-height: 34px; padding: 7px 11px; border-radius: 9px; background: var(--gold-soft); color: #77581b; font-size: 12px; font-weight: 800; }
main { width: min(1480px, calc(100% - 40px)); margin: 24px auto 70px; }

.slot-panel { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 14px; padding: 18px 20px; border: 1px solid #d9c08c; border-radius: 14px; background: #fff8e9; }
.slot-panel h2 { margin: 0 0 5px; font-size: 18px; }
.slot-panel p { margin: 0; }
.slot-form { display: grid; grid-template-columns: minmax(180px, 260px) auto; gap: 9px; }

.stats-grid { display: grid; grid-template-columns: repeat(6, minmax(130px, 1fr)); gap: 12px; }
.stat-card { min-height: 108px; padding: 18px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: 0 8px 25px rgba(44,34,21,.04); }
.stat-card span { color: var(--muted); font-size: 13px; }
.stat-card strong { display: block; margin-top: 8px; font-size: 29px; }
.stat-card.attention { background: var(--orange-soft); border-color: #edc9ae; }
.stat-card.success { background: var(--green-soft); border-color: #bcded0; }

.tabs { display: flex; gap: 7px; margin: 24px 0 12px; padding: 5px; overflow-x: auto; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); }
.tab { flex: 0 0 auto; background: transparent; color: var(--muted); }
.tab.active { background: var(--ink); color: white; }
.toolbar { display: grid; grid-template-columns: minmax(240px, 1fr) 190px 180px 180px; gap: 10px; margin-bottom: 12px; }
.bulk-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; padding: 12px 15px; border-radius: 12px; background: var(--gold-soft); }
.bulk-bar select { width: 220px; }

.panel { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: 0 8px 25px rgba(44,34,21,.035); overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0; font-size: 18px; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; min-width: 1050px; }
th { position: sticky; top: 0; z-index: 1; padding: 11px 12px; background: #f8f4ed; color: var(--muted); font-size: 12px; text-align: left; white-space: nowrap; }
td { padding: 12px; border-top: 1px solid var(--line); font-size: 13px; vertical-align: middle; }
tr:hover td { background: #fffaf1; }
.student-name { font-weight: 800; }
.student-meta { margin-top: 3px; color: var(--muted); font-size: 11px; }
.student-row { cursor: pointer; }
.student-open { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; column-gap: 12px; width: 100%; min-width: 185px; padding: 7px 9px; border: 1px solid #decda9; border-radius: 8px; background: #fffaf1; color: var(--ink); text-align: left; }
.student-open .student-name, .student-open .student-meta { grid-column: 1; }
.student-open span { grid-column: 2; grid-row: 1 / span 2; color: var(--gold); font-size: 12px; font-weight: 800; white-space: nowrap; }
.student-open:hover, .student-open:focus-visible { border-color: var(--gold); background: var(--gold-soft); outline: none; box-shadow: 0 0 0 3px rgba(185,132,35,.16); }
.row-actions { display: flex; gap: 7px; }
.row-check { width: 18px; height: 18px; }
.rank-number { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--gold-soft); font-weight: 850; }
.rank-number.top { background: var(--gold); color: white; }

.tag { display: inline-flex; align-items: center; gap: 5px; padding: 5px 9px; border-radius: 999px; background: #eee9e0; color: #655c50; font-size: 11px; font-weight: 800; white-space: nowrap; }
.tag.green { background: var(--green-soft); color: var(--green); }
.tag.orange { background: var(--orange-soft); color: var(--orange); }
.tag.red { background: var(--red-soft); color: var(--red); }
.progress-mini { width: 110px; height: 7px; overflow: hidden; border-radius: 999px; background: #e9e3d9; }
.progress-mini i { display: block; height: 100%; border-radius: inherit; background: var(--gold); }

.assignment-layout { display: grid; grid-template-columns: 340px minmax(0,1fr); gap: 14px; }
.member-form { display: grid; gap: 9px; padding: 16px; }
.quota-field { display: grid; gap: 6px; color: var(--muted); font-size: 12px; }
.member-form-actions { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.member-cards { display: grid; gap: 9px; padding: 0 16px 16px; }
.member-card { padding: 13px; border: 1px solid var(--line); border-radius: 12px; background: white; }
.member-card-head { display: flex; justify-content: space-between; gap: 10px; }
.member-card p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.member-card-actions { display: flex; align-items: center; gap: 7px; }
.role-label { display: inline-flex; margin-top: 8px; padding: 4px 8px; border-radius: 7px; background: #f3eee5; color: #695f52; font-size: 11px; font-weight: 800; }

.drawer-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(32,25,17,.32); }
.drawer { position: fixed; top: 0; right: 0; z-index: 50; width: min(760px, 96vw); height: 100vh; display: flex; flex-direction: column; background: var(--surface); box-shadow: -24px 0 70px rgba(32,25,17,.2); transform: translateX(102%); transition: transform .25s ease; }
.drawer.open { transform: translateX(0); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 20px 22px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: 0; }
.icon-button { width: 40px; height: 40px; display: grid; place-items: center; padding: 0; border-radius: 50%; background: #eee8df; font-size: 25px; }
.drawer-content { flex: 1; min-height: 0; padding: 20px 22px 60px; overflow-y: auto; overscroll-behavior: contain; scroll-behavior: auto; -webkit-overflow-scrolling: touch; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.detail-card { padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: white; }
.detail-card.wide { grid-column: 1 / -1; }
.detail-card h3 { margin: 0 0 10px; font-size: 15px; }
.profile-list { display: grid; gap: 0; }
.profile-row { display: grid; grid-template-columns: 128px 1fr; gap: 12px; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.profile-row:last-child { border-bottom: 0; }
.profile-row dt { color: var(--muted); font-size: 12px; }
.profile-row dd { margin: 0; white-space: pre-wrap; line-height: 1.65; }
.content-block { margin: 9px 0; padding: 12px; border-radius: 10px; background: #f8f4ed; white-space: pre-wrap; line-height: 1.65; max-height: 360px; overflow: auto; }
.content-block.large { max-height: 640px; }
#drawerScript { max-height: none; overflow: visible; }
.script-tabs { position: sticky; top: 0; z-index: 3; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 4px -6px 10px; padding: 8px 6px; border-radius: 10px; background: rgba(255,255,255,.96); box-shadow: 0 8px 18px rgba(44,34,21,.08); backdrop-filter: blur(8px); }
.script-tab { display: flex; align-items: center; justify-content: center; gap: 7px; padding: 10px 12px; border: 1px solid var(--line); background: #f8f4ed; color: var(--ink); }
.script-tab small { color: var(--muted); font-size: 11px; }
.script-tab:hover { border-color: var(--gold); background: #f1e7d6; }
.script-tab.active { border-color: var(--gold); background: var(--gold-soft); color: var(--ink); }
.script-section { scroll-margin-top: 18px; }
.script-section + .script-section { margin-top: 28px; padding-top: 28px; border-top: 2px solid var(--line); }
.detail-actions { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 10px; }
.manual-editor { margin: 12px 0 0; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: #fffaf1; }
.manual-editor summary { cursor: pointer; font-weight: 800; }
.manual-editor textarea { min-height: 420px; margin-top: 12px; font-family: inherit; }
.manual-editor .detail-actions { justify-content: flex-end; }
.permission-note { margin: 10px 0 0; padding: 10px 12px; border-radius: 9px; background: var(--gold-soft); color: #72551e; font-size: 12px; line-height: 1.6; }
.detail-assignment { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.empty { padding: 40px 20px; color: var(--muted); text-align: center; }

.toast { position: fixed; right: 22px; bottom: 22px; z-index: 100; max-width: 360px; padding: 13px 16px; border-radius: 12px; background: var(--ink); color: white; box-shadow: var(--shadow); }

@media (max-width: 1050px) {
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
  .toolbar { grid-template-columns: 1fr 1fr; }
  .assignment-layout { grid-template-columns: 1fr; }
  .slot-panel { align-items: stretch; flex-direction: column; }
}
@media (max-width: 680px) {
  .topbar { align-items: flex-start; padding: 14px 16px; }
  .top-actions { flex-wrap: wrap; justify-content: flex-end; }
  #lastUpdated { display: none; }
  main { width: min(100% - 20px, 1480px); margin-top: 14px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .toolbar { grid-template-columns: 1fr; }
  .bulk-bar { align-items: stretch; flex-direction: column; }
  .bulk-bar select { width: 100%; }
  .slot-form { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .detail-card.wide { grid-column: auto; }
  .profile-row { grid-template-columns: 1fr; gap: 5px; }
  .detail-assignment { grid-template-columns: 1fr; }
  .manual-editor textarea { min-height: 55vh; }
}
