:root {
  --bg: #f5f7f6;
  --surface: #ffffff;
  --surface-2: #eef4f2;
  --ink: #18211f;
  --muted: #66736f;
  --line: #dbe4e1;
  --accent: #0f766e;
  --accent-dark: #0b4f4a;
  --warm: #c97632;
  --danger: #b42318;
  --shadow: 0 18px 42px rgba(21, 37, 33, 0.1);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Noto Sans TC", "Segoe UI", sans-serif;
  letter-spacing: 0;
}
a { color: inherit; text-decoration: none; }
button, input, textarea { font: inherit; }

.app-shell { display: grid; grid-template-columns: 260px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  background: #102522;
  color: #eef7f4;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; font-size: 19px; }
.brand.compact { color: var(--ink); }
.brand-mark {
  width: 34px; height: 34px; display: grid; place-items: center;
  background: #d9f2ea; color: #0e5f57; border-radius: 8px; font-weight: 900;
}
.nav-list { display: grid; gap: 8px; }
.nav-list a {
  padding: 12px 14px; border-radius: 8px; color: #cfe0dc; font-weight: 650;
}
.nav-list a:hover { background: rgba(255,255,255,0.08); color: #fff; }
.sidebar-footer { margin-top: auto; display: grid; gap: 14px; }
.user-chip { border-top: 1px solid rgba(255,255,255,0.14); padding-top: 16px; display: grid; gap: 4px; }
.user-chip span, .ghost-link { color: #a9bdb8; font-size: 14px; }

.main { padding: 26px 34px 44px; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 28px; }
.topbar h1 { margin: 4px 0 0; font-size: 30px; line-height: 1.15; }
.topbar-actions { display: flex; align-items: center; gap: 8px; color: var(--muted); font-weight: 650; }
.status-dot { width: 9px; height: 9px; background: #22a06b; border-radius: 50%; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.panel-label { margin: 0 0 10px; color: var(--accent-dark); text-transform: uppercase; letter-spacing: .08em; font-size: 12px; font-weight: 800; }

.login-page { min-height: 100vh; display: grid; grid-template-columns: 1.1fr .9fr; }
.login-visual {
  background:
    linear-gradient(90deg, rgba(14, 43, 39, .92), rgba(14, 43, 39, .58)),
    url("../img/interviewer.png") center/cover;
  display: flex; align-items: flex-end; padding: 70px;
}
.login-copy { max-width: 680px; color: #fff; }
.login-copy h1 { font-size: clamp(40px, 5vw, 68px); line-height: 1.02; margin: 52px 0 18px; }
.login-copy p { max-width: 560px; color: #d8e8e4; font-size: 18px; line-height: 1.7; }
.login-panel { display: grid; place-items: center; padding: 32px; background: var(--surface); }
.auth-card { width: min(420px, 100%); display: grid; gap: 18px; }
.auth-card h2 { font-size: 32px; margin: 0; }
label { display: grid; gap: 8px; color: #2c3936; font-weight: 700; font-size: 14px; }
input, textarea, select {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; background: #fff;
  padding: 12px 13px; color: var(--ink); outline: none;
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(15, 118, 110, .13); }
.compact-select { font-size: 13px; margin-top: 2px; }
.compact-select select { min-height: 42px; padding: 9px 11px; }

.btn {
  border: 0; border-radius: 8px; padding: 12px 16px; font-weight: 800;
  cursor: pointer; display: inline-flex; justify-content: center; align-items: center; min-height: 44px;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.secondary { background: #e5eeeb; color: #123531; }
.btn.danger { background: #fce8e6; color: var(--danger); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn[aria-disabled="true"] { opacity: .55; pointer-events: none; }

.flash-stack { margin-bottom: 18px; display: grid; gap: 10px; }
.flash { padding: 12px 14px; border-radius: 8px; background: #edf8f5; color: var(--accent-dark); border: 1px solid #bfe1d9; }
.flash.error { background: #fff1f0; color: var(--danger); border-color: #ffd1cc; }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 18px; margin-bottom: 22px; }
.quota-strip { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 22px; }
.quota-strip article {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 18px; box-shadow: var(--shadow);
}
.quota-strip span { display: block; color: var(--muted); font-weight: 800; font-size: 13px; margin-bottom: 8px; }
.quota-strip strong { color: var(--accent-dark); font-size: 22px; }
.hero-panel, .side-panel, .content-band, .insight-panel, .form-band, .template-form, .feedback-panel, .score-panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow);
}
.hero-panel { display: grid; grid-template-columns: minmax(0, 1fr) 360px; overflow: hidden; min-height: 260px; }
.hero-panel > div { padding: 34px; align-self: center; }
.hero-panel h2 { font-size: 34px; line-height: 1.15; margin: 0 0 14px; max-width: 620px; }
.hero-panel p { color: var(--muted); font-size: 17px; line-height: 1.65; max-width: 560px; }
.hero-panel img { width: 100%; height: 100%; object-fit: cover; }
.side-panel { padding: 26px; display: grid; align-content: center; }
.side-panel strong { font-size: 56px; line-height: 1; }
.side-panel span { color: var(--muted); }

.content-band { padding: 24px; margin-bottom: 22px; }
.section-heading { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 18px; }
.section-heading h2 { margin: 0; font-size: 22px; }
.section-heading span { color: var(--muted); font-size: 14px; }

.template-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.template-card { border: 1px solid var(--line); border-radius: 8px; padding: 20px; display: grid; gap: 16px; background: #fbfcfc; }
.template-card h3, .template-row h3 { margin: 0 0 6px; }
.template-card p { margin: 0; color: var(--muted); }
.template-card ul { margin: 0; padding-left: 18px; color: #3f4c49; line-height: 1.55; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th { text-align: left; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
th, td { padding: 14px 12px; border-bottom: 1px solid var(--line); }
td { color: #263430; }
.empty { text-align: center; color: var(--muted); }
.state { padding: 5px 9px; border-radius: 999px; background: #e8efed; color: #29413c; font-size: 12px; font-weight: 800; }
.state.completed { background: #e0f5eb; color: #11643f; }
.state.running { background: #fff0d9; color: #8a4d06; }

.interview-room { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 18px; }
.interview-stage, .coach-panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow);
}
.interview-stage { padding: 22px; display: grid; gap: 18px; }
.stage-header { display: flex; justify-content: space-between; align-items: center; gap: 18px; }
.stage-header h2 { margin: 0; font-size: 26px; }
.timer { background: var(--surface-2); border-radius: 8px; padding: 11px 14px; font-weight: 900; color: var(--accent-dark); }
.timer.ending { background: #fff0d9; color: #8a4d06; }
.video-frame { position: relative; min-height: 500px; border-radius: 8px; overflow: hidden; background: #102522; }
.video-frame img { width: 100%; height: 100%; min-height: 500px; object-fit: cover; display: block; transition: filter .18s ease, transform .32s ease; transform-origin: 50% 42%; }
.avatar-speaking img { filter: brightness(1.1) saturate(1.06); transform: scale(calc(1.018 + var(--voice-level, .35) * .018)) translateY(calc(var(--voice-level, .35) * -2px)); }
.avatar-listening img { filter: brightness(.96) saturate(.96); }
.avatar-connecting img { filter: brightness(.9) saturate(.9); }
.mouth-pulse {
  position: absolute; left: 50%; top: 57%; width: 72px; height: 24px; transform: translateX(-50%);
  border-radius: 999px; opacity: 0; background: rgba(217, 242, 234, .7); filter: blur(8px);
}
.avatar-speaking .mouth-pulse {
  opacity: calc(.5 + var(--voice-level, .35) * .45); animation: mouthPulse .3s ease-in-out infinite alternate;
}
.voice-bars { position: absolute; right: 18px; bottom: 72px; display: flex; align-items: flex-end; gap: 5px; height: 36px; }
.voice-bars span { width: 5px; height: 10px; border-radius: 99px; background: rgba(217,242,234,.9); opacity: .45; }
.avatar-speaking .voice-bars span { animation: voiceBar .44s ease-in-out infinite alternate; opacity: .95; }
.avatar-speaking .voice-bars span:nth-child(2) { animation-delay: .12s; }
.avatar-speaking .voice-bars span:nth-child(3) { animation-delay: .24s; }
.avatar-speaking .voice-bars span:nth-child(4) { animation-delay: .36s; }
.avatar-idle img { animation: avatarBreath 3.8s ease-in-out infinite; }
.avatar-speaking::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(circle at 50% 55%, rgba(217, 242, 234, .2), transparent 34%);
  opacity: calc(.35 + var(--voice-level, .35) * .45);
}
.voice-state {
  position: absolute; left: 18px; bottom: 18px; background: rgba(16,37,34,.84); color: #fff;
  padding: 10px 13px; border-radius: 8px; font-weight: 800;
}
.control-bar { display: flex; gap: 12px; flex-wrap: wrap; }
.voice-picker { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.voice-card {
  border: 1px solid var(--line); background: #f8fbfa; border-radius: 8px; padding: 12px;
  text-align: left; display: grid; gap: 4px; color: var(--ink); cursor: pointer;
}
.voice-card span { font-weight: 900; }
.voice-card small { color: var(--muted); font-weight: 700; }
.voice-card.selected { border-color: var(--accent); background: #e9f6f3; box-shadow: 0 0 0 3px rgba(15,118,110,.12); }
.coach-panel { padding: 22px; display: grid; gap: 22px; align-content: start; max-height: 720px; overflow: hidden; }
.progress-track { height: 9px; background: #e2ebe8; border-radius: 999px; overflow: hidden; }
.progress-track span { display: block; width: 14%; height: 100%; background: var(--accent); transition: width .25s ease; }
.question-list { padding-left: 20px; margin: 0; line-height: 1.55; color: #34423f; }
.transcript { display: grid; gap: 10px; max-height: 300px; overflow-y: auto; padding-right: 4px; }
.transcript-full { max-height: none; }
.message { padding: 12px 14px; border-radius: 8px; line-height: 1.55; }
.message.ai { background: #eef5f3; color: #183c37; }
.message.student { background: #172f2b; color: #fff; margin-left: 32px; }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat-grid article { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 22px; box-shadow: var(--shadow); }
.stat-grid span { color: var(--muted); font-weight: 700; }
.stat-grid strong { display: block; margin-top: 10px; font-size: 38px; }
.admin-split { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; }
.insight-panel { padding: 24px; }
.insight-panel h2 { margin: 0 0 10px; }
.insight-panel p { color: var(--muted); line-height: 1.6; }
.mini-chart { height: 160px; display: flex; align-items: flex-end; gap: 12px; margin-top: 24px; }
.mini-chart span { flex: 1; background: linear-gradient(180deg, #24a399, #0f766e); border-radius: 8px 8px 0 0; }
.analytics-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.score-bars { display: grid; gap: 14px; }
.score-bars div { display: grid; grid-template-columns: 120px minmax(120px, 1fr) 54px; align-items: center; gap: 14px; color: var(--muted); }
.score-bars b { height: 16px; display: block; border-radius: 5px; background: linear-gradient(90deg, var(--accent), #2f8fca); }
.score-bars em { font-style: normal; color: #33413e; font-weight: 800; }
.rank-list { display: grid; gap: 13px; margin: 0; padding-left: 22px; }
.rank-list li { padding-left: 4px; color: #2f3e3b; }
.rank-list span { display: inline-block; width: calc(100% - 80px); }
.rank-list strong { color: var(--accent-dark); }
.settings-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 18px; }
.settings-form, .settings-summary {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow);
}
.settings-form { padding: 24px; display: grid; gap: 16px; }
.settings-form h2 { margin: 0; }
.settings-form > p { margin: 0 0 4px; line-height: 1.6; }
.settings-summary { padding: 24px; align-self: start; }
.settings-summary dl { display: grid; gap: 16px; margin: 0 0 20px; }
.settings-summary div { display: grid; gap: 5px; border-bottom: 1px solid var(--line); padding-bottom: 13px; }
.settings-summary dt { color: var(--muted); font-size: 13px; font-weight: 800; }
.settings-summary dd { margin: 0; color: var(--ink); font-weight: 800; overflow-wrap: anywhere; }

.form-band { padding: 20px; margin-bottom: 22px; }
.inline-form { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)) auto; gap: 14px; align-items: end; }
.quota-default-form { grid-template-columns: repeat(2, minmax(0, 220px)) auto; }
.quota-mini-form { display: grid; grid-template-columns: 88px 88px auto; gap: 8px; align-items: center; min-width: 280px; }
.quota-mini-form input { padding: 9px 10px; min-height: 38px; }
.quota-mini-form .btn { min-height: 38px; padding: 8px 11px; }
.template-admin { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(360px, .95fr); gap: 18px; }
.ai-template-band { margin-bottom: 22px; }
.template-form { padding: 24px; display: grid; gap: 16px; }
.template-form h2 { margin: 0; }
.template-form p { margin: 0; line-height: 1.6; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.check-row { display: flex; align-items: center; gap: 10px; align-self: end; }
.check-row input { width: auto; }
.template-list { display: grid; gap: 12px; align-content: start; }
.template-row { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 18px; display: flex; justify-content: space-between; gap: 16px; box-shadow: var(--shadow); }

.result-layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 18px; margin-bottom: 22px; }
.score-panel { padding: 28px; display: grid; align-content: center; }
.score-panel strong { font-size: 72px; line-height: 1; color: var(--accent-dark); }
.score-panel span { color: var(--muted); margin-top: 8px; }
.feedback-panel { padding: 28px; }
.feedback-panel h2 { margin: 0 0 18px; }
.feedback-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.feedback-grid article { background: #f7faf9; border: 1px solid var(--line); border-radius: 8px; padding: 16px; }
.feedback-grid p:last-child { line-height: 1.6; color: #34423f; }
.feedback-grid ul { margin: 0; padding-left: 18px; color: #34423f; line-height: 1.6; }
.coaching-layout { display: grid; grid-template-columns: .95fr 1.05fr; gap: 18px; }
.diagnostic-list { display: grid; gap: 12px; }
.diagnostic-row {
  display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 14px;
  border-bottom: 1px solid var(--line); padding-bottom: 12px; align-items: start;
}
.diagnostic-row strong { color: var(--accent-dark); }
.diagnostic-row span { color: #34423f; line-height: 1.55; }
.coaching-card ol { margin: 0; padding-left: 20px; display: grid; gap: 10px; color: #34423f; line-height: 1.58; }

@media (max-width: 1040px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .dashboard-grid, .hero-panel, .interview-room, .admin-split, .template-admin, .result-layout, .analytics-grid, .settings-layout, .coaching-layout, .quota-strip { grid-template-columns: 1fr; }
  .template-grid, .stat-grid, .feedback-grid, .voice-picker { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .inline-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 680px) {
  .main { padding: 20px 16px 34px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .login-page { grid-template-columns: 1fr; }
  .login-visual { min-height: 46vh; padding: 28px; }
  .login-copy h1 { font-size: 38px; }
  .template-grid, .stat-grid, .feedback-grid, .form-grid, .inline-form, .voice-picker { grid-template-columns: 1fr; }
  .hero-panel img { min-height: 260px; }
  .video-frame, .video-frame img { min-height: 360px; }
}

@keyframes avatarBreath {
  from, to { transform: scale(1); }
  50% { transform: scale(1.006); }
}

@keyframes mouthPulse {
  from { transform: translateX(-50%) scaleX(.75); }
  to { transform: translateX(-50%) scaleX(1.25); }
}

@keyframes voiceBar {
  from { height: 9px; }
  to { height: calc(18px + var(--voice-level, .45) * 28px); }
}
