:root {
  --ink: #17212b;
  --muted: #66717d;
  --line: #d8dee5;
  --soft: #f4f6f8;
  --paper: #ffffff;
  --primary: #176b87;
  --primary-dark: #105268;
  --accent: #d97820;
  --danger: #b42318;
  --success: #16794b;
  --shadow: 0 12px 32px rgba(23, 33, 43, .12);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { font-family: "Malgun Gothic", "맑은 고딕", Arial, sans-serif; color: var(--ink); background: #edf1f4; letter-spacing: 0; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { min-height: 34px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); padding: 6px 11px; cursor: pointer; border-radius: 4px; }
button:hover { border-color: #9aa7b3; background: #f9fafb; }
button:disabled { opacity: .45; cursor: default; }
button.primary { color: white; background: var(--primary); border-color: var(--primary); }
button.primary:hover { background: var(--primary-dark); }
button.strong { color: white; background: var(--accent); border-color: var(--accent); }
button.ghost { border-color: transparent; background: transparent; }
.button-link { display: inline-flex; min-height: 34px; align-items: center; border: 1px solid var(--line); border-radius: 4px; padding: 6px 11px; color: var(--ink); background: var(--paper); text-decoration: none; font-size: 13px; }
.button-link:hover { border-color: #9aa7b3; background: #f9fafb; }
button.wide { width: 100%; min-height: 42px; }
.danger-text { color: var(--danger); }

.app-header { height: 64px; background: #182630; color: white; display: flex; align-items: center; justify-content: space-between; padding: 0 22px; border-bottom: 3px solid var(--accent); }
.brand, .account { display: flex; align-items: center; gap: 12px; }
.brand > div { display: flex; flex-direction: column; gap: 2px; }
.brand strong { font-size: 16px; }
.brand span { font-size: 11px; color: #b9c5cc; }
.brand-mark { width: 52px; height: 52px; display: grid; place-items: center; background: var(--accent); color: white; font-weight: 800; font-size: 19px; border-radius: 6px; }
.brand-mark.small { width: 34px; height: 34px; font-size: 13px; }
.account { font-size: 13px; }
.account .ghost { color: #dce4e8; }

.app-main { padding: 14px 18px 30px; max-width: 1800px; margin: 0 auto; }
.band { background: var(--paper); border: 1px solid var(--line); }
.toolbar { min-height: 58px; padding: 10px; display: flex; align-items: end; gap: 8px; flex-wrap: wrap; }
.import-status { flex: 1 0 100%; color: var(--muted); font-size: 12px; padding: 4px 2px 0; line-height: 1.5; }
label { display: flex; flex-direction: column; gap: 5px; color: #46515c; font-size: 12px; font-weight: 600; }
label.compact { min-width: 150px; }
input, select, textarea { min-height: 34px; border: 1px solid #bfc9d2; border-radius: 4px; background: white; padding: 6px 9px; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(23,107,135,.2); border-color: var(--primary); }
.file-button { display: inline-flex; flex-direction: row; align-items: center; min-height: 34px; border: 1px solid var(--line); background: white; color: var(--ink); padding: 6px 11px; border-radius: 4px; cursor: pointer; font-weight: 400; }
.file-button.secondary { background: #eef5f7; border-color: #a8c7d1; }
.file-button input { display: none; }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(130px, 1fr)); margin: 12px 0; border: 1px solid var(--line); background: var(--paper); }
.metrics > button { min-height: 76px; padding: 13px 16px; border: 0; border-right: 1px solid var(--line); border-radius: 0; display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 5px; }
.metrics > button:hover { background: #f3f8fa; }
.metrics > button:last-child { border-right: 0; }
.metrics span { font-size: 12px; color: var(--muted); }
.metrics strong { font-size: 24px; line-height: 1; }

.active-work { display: grid; grid-template-columns: 120px 1fr; align-items: start; gap: 14px; margin: -1px 0 12px; padding: 12px 16px; border: 1px solid #d7a05f; background: #fff8ee; }
.active-work[hidden] { display: none; }
.active-work > strong { color: #8b4513; font-size: 13px; }
.active-work > div { display: grid; gap: 7px; }
.active-work span { display: grid; grid-template-columns: minmax(260px, 1fr) minmax(180px, .8fr); gap: 14px; font-size: 12px; }
.active-work em { color: #6b4b2f; font-style: normal; }

.tabs { display: flex; border-bottom: 1px solid #9fadb8; margin-top: 8px; }
.tab { border: 0; background: transparent; min-height: 43px; padding: 8px 18px; color: var(--muted); border-bottom: 3px solid transparent; border-radius: 0; }
.tab.active { color: var(--ink); border-bottom-color: var(--primary); font-weight: 700; }
.panel { display: none; }
.panel.active { display: block; }
.actionbar { min-height: 51px; background: var(--paper); border: 1px solid var(--line); border-top: 0; padding: 8px; display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.actionbar .separator { width: 1px; height: 27px; background: var(--line); margin: 0 4px; }
.actionbar select { min-width: 170px; }

.table-wrap { background: var(--paper); border: 1px solid var(--line); border-top: 0; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 1280px; font-size: 13px; }
th { position: sticky; top: 0; z-index: 1; background: #e9eef2; color: #36434e; text-align: left; padding: 10px 9px; border-bottom: 1px solid #aeb9c2; white-space: nowrap; }
th.sortable { cursor: pointer; padding-right: 22px; }
th.sortable::after { content: "↕"; position: absolute; right: 7px; color: #8b96a0; font-weight: 400; }
th.sortable[data-sort-direction="asc"]::after { content: "↑"; color: var(--primary); font-weight: 800; }
th.sortable[data-sort-direction="desc"]::after { content: "↓"; color: var(--primary); font-weight: 800; }
.filter-row th { top: 38px; padding: 5px; background: #f6f8fa; }
.filter-row input, .filter-row select { width: 100%; min-width: 82px; min-height: 29px; padding: 4px 6px; font-size: 11px; font-weight: 400; }
.filter-row input::placeholder { color: #89939d; }
td { padding: 9px; border-bottom: 1px solid #e1e6ea; vertical-align: middle; }
tbody tr:hover { background: #f3f8fa; }
tbody tr.selected { background: #e5f1f5; }
tbody tr.schedule-start { background: #eef8f1; }
tbody tr.schedule-start:hover { background: #e2f3e8; }
tbody tr.schedule-end { background: #fff7eb; }
tbody tr.schedule-end:hover { background: #ffefd7; }
tbody tr.schedule-start.selected, tbody tr.schedule-end.selected { background: #dcecf3; }
.schedule-kind { font-weight: 700; white-space: nowrap; }
.schedule-start .schedule-kind { color: #16794b; }
.schedule-end .schedule-kind { color: #a45112; }
.progress-cell { min-width: 190px; }
.progress-label { display: flex; justify-content: space-between; gap: 8px; font-size: 11px; color: #46515c; margin-bottom: 4px; }
.progress-track { height: 5px; background: #dfe6eb; overflow: hidden; }
.progress-track > span { display: block; height: 100%; background: var(--primary); }
th.check, td.check { width: 42px; text-align: center; }
td.course { min-width: 240px; }
.reminder-copy { min-width: 92px; min-height: 30px; padding: 4px 8px; color: var(--primary-dark); border-color: #9fc2ce; background: #f1f8fa; white-space: nowrap; }
.reminder-progress { display: grid; grid-template-columns: minmax(240px, 1fr) minmax(180px, 35%); align-items: center; gap: 16px; padding: 11px 14px; margin-top: 8px; border: 1px solid #99bcc8; border-left: 4px solid var(--primary); background: #f1f8fa; }
.reminder-progress[hidden] { display: none; }
.reminder-progress > div:first-child { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.reminder-progress strong { white-space: nowrap; }
.reminder-progress span { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reminder-progress-track { height: 7px; background: #d8e5e9; overflow: hidden; }
.reminder-progress-track > span { display: block; width: 8%; height: 100%; background: var(--primary); transition: width .25s ease; }
.reminder-progress.error { border-color: #e6aaa5; border-left-color: var(--danger); background: #fff1f0; }
td.multiline { white-space: pre-line; min-width: 100px; }
.status { font-weight: 700; }
.status.complete { color: var(--success); }
.status.partial, .status.error { color: var(--danger); }
.status.running { color: var(--accent); }
.empty { display: none; color: var(--muted); text-align: center; padding: 45px 20px; }
.empty.show { display: block; }
.result-links { display: flex; gap: 4px; }
.result-links a { color: var(--primary); text-decoration: none; font-weight: 700; }

.kakao-settings { display: grid; grid-template-columns: minmax(130px, auto) minmax(180px, .8fr) minmax(160px, auto) minmax(190px, .7fr) minmax(320px, 1.5fr) auto; align-items: end; gap: 10px; padding: 12px; margin-top: 10px; }
.kakao-settings .toggle-label { min-height: 34px; flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 9px; border: 1px solid var(--line); background: #f7f9fa; }
.kakao-settings .toggle-label input { width: 18px; min-height: 18px; margin: 0; }
.kakao-table { min-width: 1200px; }
.kakao-table td:last-child { max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

dialog { width: min(650px, calc(100vw - 28px)); border: 0; padding: 0; border-radius: 6px; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(12, 23, 31, .56); }
dialog form { padding: 18px; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.dialog-head h2 { margin: 0; font-size: 18px; }
.icon-close { width: 34px; height: 34px; padding: 0; font-size: 23px; line-height: 1; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.form-grid .span-2 { grid-column: span 2; }
.ampm-time { display: grid; grid-template-columns: 76px minmax(54px, 1fr) auto minmax(54px, 1fr); align-items: center; gap: 6px; }
.ampm-time input { min-width: 0; text-align: center; }
.ampm-time > span { color: var(--muted); font-weight: 700; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 7px; margin-top: 20px; }
.attendance-dialog { width: min(1100px, calc(100vw - 28px)); }
.attendance-view { padding: 18px; }
.attendance-view .dialog-head p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.attendance-summary { display: grid; grid-template-columns: repeat(5, 1fr); border: 1px solid var(--line); margin-bottom: 12px; }
.attendance-summary span { padding: 10px; border-right: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.attendance-summary span:last-child { border-right: 0; }
.attendance-summary strong { display: block; margin-top: 4px; color: var(--ink); font-size: 20px; }

#toast { position: fixed; right: 20px; bottom: 20px; max-width: min(440px, calc(100vw - 40px)); background: #182630; color: white; padding: 12px 15px; box-shadow: var(--shadow); border-left: 4px solid var(--primary); border-radius: 4px; opacity: 0; transform: translateY(12px); pointer-events: none; transition: .18s ease; white-space: pre-line; font-size: 13px; }
#toast.show { opacity: 1; transform: translateY(0); }
#toast.error { border-left-color: var(--danger); }

.login-page { background: #e9eef1; }
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-panel { width: min(410px, 100%); background: white; border: 1px solid var(--line); border-top: 4px solid var(--accent); padding: 34px; box-shadow: var(--shadow); }
.login-panel .brand-mark { margin-bottom: 24px; }
.login-panel h1 { margin: 0 0 7px; font-size: 25px; }
.login-panel > p { margin: 0 0 25px; color: var(--muted); }
.login-form { display: grid; gap: 16px; }
.alert { padding: 10px 12px; margin-bottom: 16px; font-size: 13px; border: 1px solid; }
.alert.error { color: #8e1b13; background: #fff1f0; border-color: #e6aaa5; }
.warning-dialog { width: min(560px, calc(100vw - 28px)); }
.warning-view { padding: 20px; border-top: 5px solid var(--danger); }
.warning-content { display: grid; gap: 10px; }
.warning-item { padding: 12px; border: 1px solid #e6aaa5; background: #fff1f0; color: #7b1b14; line-height: 1.6; }
.warning-item strong { display: block; color: #55120d; }
.reminder-dialog { width: min(720px, calc(100vw - 28px)); }
.reminder-view { padding: 20px; }
.reminder-view .dialog-head p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
#reminder-text { width: 100%; min-height: 390px; resize: vertical; padding: 14px; line-height: 1.65; font-family: inherit; font-size: 14px; }
#post-survey-reminder { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--line); }
#post-survey-reminder h3 { margin: 0 0 5px; }
#post-survey-reminder .subtle { margin: 0 0 10px; color: var(--muted); font-size: 12px; }
#post-survey-text { width: 100%; min-height: 260px; resize: vertical; padding: 14px; line-height: 1.65; font-family: inherit; font-size: 14px; }
.copy-status { min-height: 20px; margin: 8px 0 0; color: var(--muted); font-size: 12px; }
.copy-status.success { color: var(--success); font-weight: 700; }
.copy-status.error { color: var(--danger); font-weight: 700; }

@media (max-width: 900px) {
  .app-main { padding: 10px 10px 24px; }
  .app-header { padding: 0 12px; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .metrics > button:nth-child(2) { border-right: 0; }
  .metrics > button:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .actionbar { align-items: stretch; }
  .actionbar button, .actionbar .file-button { flex: 1 0 auto; justify-content: center; }
  .kakao-settings { grid-template-columns: 1fr 1fr; }
  .kakao-settings .kakao-url { grid-column: span 2; }
}

@media (max-width: 560px) {
  .account > span { display: none; }
  .toolbar > * { flex: 1 0 45%; }
  .toolbar > .import-status { flex-basis: 100%; }
  .toolbar .compact { min-width: 0 !important; }
  .metrics strong { font-size: 20px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: span 1; }
  .login-panel { padding: 26px 22px; }
  .attendance-summary { grid-template-columns: 1fr 1fr; }
  .attendance-summary span { border-bottom: 1px solid var(--line); }
  .active-work { grid-template-columns: 1fr; gap: 7px; }
  .active-work span { grid-template-columns: 1fr; gap: 3px; }
  .kakao-settings { grid-template-columns: 1fr; }
  .kakao-settings .kakao-url { grid-column: span 1; }
  .reminder-progress { grid-template-columns: 1fr; gap: 8px; }
}
