:root {
    --bg: #f4f6fb;
    --card: #ffffff;
    --text: #1f2430;
    --muted: #6b7280;
    --border: #e2e6ee;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --danger: #dc2626;
    --warn: #d97706;
    --ok: #059669;
    --sunday-color: #dc2626;
    --saturday-color: #2563eb;
    --hours-color: #16a34a;
    --regular-color: #4f46e5;
    --overtime-color: #f59e0b;
    --shadow: 0 6px 20px rgba(0,0,0,.06);
}
[data-theme="dark"] {
    --bg: #0f1420;
    --card: #1a2130;
    --text: #e6e9f0;
    --muted: #9aa4b6;
    --border: #2a3346;
    --primary: #6366f1;
    --primary-hover: #818cf8;
    --sunday-color: #f87171;
    --saturday-color: #60a5fa;
    --hours-color: #4ade80;
    --regular-color: #818cf8;
    --overtime-color: #fbbf24;
    --shadow: 0 6px 20px rgba(0,0,0,.4);
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: -apple-system, "Segoe UI", Roboto, "Malgun Gothic", sans-serif;
    background: var(--bg);
    color: var(--text);
    transition: background .25s, color .25s;
}

/* 상단바 */
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 20px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    flex-wrap: wrap;
    gap: 8px;
}
.brand a { font-weight: 700; font-size: 18px; text-decoration: none; color: var(--text); }
.nav { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.nav a { text-decoration: none; color: var(--muted); font-size: 14px; }
.nav a:hover { color: var(--primary); }
.nav .user { font-size: 14px; font-weight: 600; }
.nav .logout { color: var(--danger); }
.theme-toggle {
    border: 1px solid var(--border);
    background: transparent;
    border-radius: 50%;
    width: 36px; height: 36px;
    cursor: pointer; font-size: 16px;
    display: flex; align-items: center; justify-content: center;
}

/* 컨테이너 */
.container { max-width: 720px; margin: 32px auto; padding: 0 16px; }

/* 카드 */
.auth-card, .tts-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 28px;
    box-shadow: var(--shadow);
}
.tts-card.wide, .work-card { max-width: 100%; }
.container:has(.wide), .container:has(.work-card) { max-width: 1300px; }

h1 { margin-top: 0; font-size: 22px; }
h2.sub { font-size: 16px; margin: 0 0 8px; }
.danger-title { color: var(--danger); }
.sep { border: none; border-top: 1px solid var(--border); margin: 24px 0; }

/* 폼 */
label { display: block; font-size: 14px; margin-bottom: 12px; color: var(--muted); }
label.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 14px; }
label.checkbox-row input { width: auto; }
input[type=text], input[type=password], input[type=number], select, textarea {
    width: 100%;
    padding: 10px 12px;
    margin-top: 6px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
}
.field { margin-bottom: 18px; }

/* 버튼 */
.btn {
    border: none; border-radius: 8px; cursor: pointer;
    padding: 9px 16px; font-size: 14px; font-weight: 600;
    background: var(--border); color: var(--text);
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.full { width: 100%; margin-top: 8px; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.ok { background: var(--ok); color: #fff; }
.btn.warn { background: var(--warn); color: #fff; }
.btn.danger { background: var(--danger); color: #fff; }

/* 메시지 */
.msg { font-size: 14px; }
.msg.small { font-size: 13px; min-height: 18px; }
.msg.error { color: var(--danger); }
.msg.success { color: var(--ok); }
.msg.denied {
    color: var(--warn);
    background: rgba(217,119,6,.10);
    border: 1px solid rgba(217,119,6,.35);
    padding: 12px 14px;
    border-radius: 8px;
}
.hint { color: var(--muted); font-size: 13px; }
.auth-foot { margin-top: 16px; font-size: 14px; color: var(--muted); }
.auth-foot a { color: var(--primary); }

/* 테이블(관리자) */
.tbl { width: 100%; border-collapse: collapse; margin-top: 12px; }
.tbl th, .tbl td { padding: 10px; text-align: left; border-bottom: 1px solid var(--border); font-size: 14px; }
.tbl th { color: var(--muted); font-weight: 600; }
.nowrap { white-space: nowrap; }
.inline { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.actions { white-space: nowrap; }

/* ---------------- 근무입력 화면 ---------------- */
.ym-row { margin-bottom: 16px; }
.ym-select { display: flex; gap: 10px; }
.ym-select select { width: auto; margin-top: 0; }

.summary-bar {
    display: flex; flex-wrap: wrap; gap: 14px;
    margin-bottom: 18px;
    padding: 14px 16px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
}
.summary-row { display: flex; gap: 14px; flex: 1 1 auto; }
.summary-item { font-size: 14px; color: var(--text); display: flex; flex-direction: column; gap: 2px; }
.summary-label { font-size: 12px; color: var(--muted); }
.summary-value { font-size: 18px; font-weight: 700; color: var(--primary); }
.summary-value-row { font-size: 18px; font-weight: 700; color: var(--primary); }
.summary-item.highlight { flex: 1 1 260px; }
.summary-item.highlight .summary-value { color: var(--danger); font-size: 20px; }

.view-toggle { display: flex; gap: 20px; margin-bottom: 16px; }
.view-toggle label { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--text); margin-bottom: 0; }
.view-toggle input { width: auto; }

/* 달력 */
.calendar-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.calendar-table th {
    padding: 8px 4px; font-size: 13px; font-weight: 600; text-align: center;
    color: var(--muted); border-bottom: 1px solid var(--border);
}
.calendar-table th.sunday { color: var(--sunday-color); }
.calendar-table th.saturday { color: var(--saturday-color); }

.cal-cell {
    height: 74px; vertical-align: top; text-align: center;
    border: 1px solid var(--border); cursor: pointer;
    transition: background .15s;
}
.cal-cell:hover { background: rgba(79,70,229,.06); }
.cal-cell.empty { cursor: default; background: transparent; border-color: transparent; }
.cal-cell.today { outline: 2px solid var(--primary); outline-offset: -2px; }
.cal-day { font-size: 13px; font-weight: 600; margin-top: 6px; }
.cal-holiday { font-size: 10px; color: var(--sunday-color); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 2px; }
.cal-hours { font-size: 13px; font-weight: 700; color: var(--hours-color); margin-top: 4px; }

.cal-cell.weekday .cal-day { color: var(--text); }
.cal-cell.saturday .cal-day { color: var(--saturday-color); }
.cal-cell.sunday .cal-day { color: var(--sunday-color); }

/* 그래프 */
.graph-legend { display: flex; gap: 16px; margin-bottom: 10px; font-size: 13px; color: var(--muted); }
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.legend-swatch.regular { background: var(--regular-color); }
.legend-swatch.over { background: var(--overtime-color); }
.graph-wrap { overflow-x: auto; padding-bottom: 8px; }
.graph-bars {
    display: flex; align-items: flex-end; gap: 4px;
    min-height: 240px;
}
.bar-item {
    flex: 1 1 0; min-width: 0;
    display: flex; flex-direction: column; align-items: center;
    cursor: pointer; padding: 4px 2px; border-radius: 6px;
}
.bar-item:hover { background: rgba(79,70,229,.06); }
.bar-item.today { outline: 2px solid var(--primary); outline-offset: -2px; }
.bar-value { font-size: 11px; font-weight: 700; color: var(--hours-color); margin-bottom: 4px; }
.bar-track {
    position: relative;
    width: 100%; max-width: 48px; height: 170px;
    background: var(--border); border-radius: 4px 4px 0 0;
    overflow: hidden;
}
.bar-fill-regular {
    position: absolute; left: 0; right: 0; bottom: 0;
    background: var(--regular-color); border-radius: 4px 4px 0 0;
    transition: height .2s;
}
.bar-fill-over {
    position: absolute; left: 0; right: 0;
    background: var(--overtime-color);
    transition: height .2s, bottom .2s;
}
.bar-day { font-size: 12px; font-weight: 600; margin-top: 6px; }
.bar-weekday { font-size: 10px; color: var(--muted); }
.bar-item.saturday .bar-day, .bar-item.saturday .bar-weekday { color: var(--saturday-color); }
.bar-item.sunday .bar-day, .bar-item.sunday .bar-weekday { color: var(--sunday-color); }

/* 모바일: 그래프는 한 화면에 1주일만 표시하고 좌우 스크롤 */
@media (max-width: 768px) {
    .graph-bars { min-width: max-content; }
    .bar-item { flex: 0 0 auto; width: calc((100vw - 64px) / 7); }
    .cal-cell { height: 62px; }
    .cal-holiday { display: none; }
    /* 세로 화면: 월간 필요/입력된 근무시간은 한 줄에, 하루 평균 안내는 그 아래 별도 줄에 표시 */
    .summary-bar { flex-direction: column; }
    .summary-row .summary-item { flex: 1 1 0; min-width: 0; }
    .summary-item.highlight { flex: 0 1 auto; width: 100%; }
}

/* 모달 */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,.45);
    display: flex; align-items: center; justify-content: center;
    z-index: 100; padding: 16px;
}
.modal-box {
    background: var(--card); border-radius: 12px; padding: 24px;
    width: 100%; max-width: 320px; box-shadow: var(--shadow);
}
.modal-box h3 { margin-top: 0; font-size: 16px; }
.hm-row { display: flex; gap: 10px; }
.hm-field { flex: 1; }
.modal-actions { display: flex; gap: 8px; margin-top: 12px; }
.modal-actions .btn { flex: 1; }
