@import url("https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@400;700&display=swap");

:root {
  --header-h: 50px;
  --plan-h: 50px;
  --sidebar-w: 12rem;
  --count-w: 260px;

  --max-w: 1140px;
  --table-w: 98%;

  --bg-gray: rgb(229, 228, 228);
  --border: 1px solid #403f3f;

  --z-header: 6000;
  --z-sidebar: 5500;
  --z-plan: 5000;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
body {
  font-family: "Noto Sans KR", sans-serif;
}

.container {
  width: 100%;
  max-width: var(--max-w);
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  height: var(--header-h);
  background: var(--bg-gray);
  display: flex;
  align-items: center;
  justify-content: center;

  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: var(--z-header);
}

.aside-main-wrapper {
  display: flex;
  flex-grow: 1;
  align-items: flex-start;
}

/* 왼쪽 메뉴: 헤더 아래에서 고정 */
aside {
  width: var(--sidebar-w);
  background: var(--bg-gray);

  position: fixed;
  top: var(--header-h);
  left: calc(50% - (var(--max-w) / 2));
  height: calc(100vh - var(--header-h));
  overflow: hidden;

  display: flex;
  flex-direction: column;
  align-items: center;

  z-index: var(--z-sidebar);
}

/* 화면이 좁아져 max-w보다 작을 때 왼쪽 정렬 */
@media (max-width: 1140px) {
  aside {
    left: 0;
  }
}

aside nav {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: calc(var(--plan-h) + 10px) 0 20px;
  gap: 6px;
}

aside nav button {
  width: 6rem;
  padding: 0.5rem;
  background: #faf9f9;
  border: var(--border);
  border-radius: 4px;
  font-size: 1rem;
  cursor: pointer;
}
aside nav button:hover {
  background: #d1d1d1;
}
.selected-month-button {
  background: #d1d1d1;
  font-weight: 700;
}

.plan-order {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.plan-order-hint {
  width: 8rem;
  color: #777;
  font-size: 0.68rem;
  line-height: 1.25;
  text-align: center;
  white-space: nowrap;
  word-break: keep-all;
}

.plan-order-row {
  width: 6rem;
  touch-action: none;
  user-select: none;
}

.plan-order-row.is-dragging {
  opacity: 0.35;
}

.plan-order-row.is-drag-over .plan-tab-button {
  background: #e3e3e3;
}

aside nav .plan-tab-button {
  width: 100%;
  touch-action: none;
  cursor: grab;
}

aside nav .plan-tab-button:active {
  cursor: grabbing;
}

.plan-drag-ghost {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 8000;
  pointer-events: none;
  opacity: 0.96;
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.2));
  transform-origin: top left;
}

.plan-drag-ghost .plan-tab-button {
  width: 100%;
  padding: 0.5rem;
  background: #fff;
  border: var(--border);
  border-radius: 4px;
  font-family: "Noto Sans KR", sans-serif;
  font-size: 1rem;
  color: inherit;
  cursor: grabbing;
}

.plan-drag-ghost .plan-tab-button.selected-month-button {
  background: #d1d1d1;
  font-weight: 700;
}

hr {
  width: 7rem;
  border: none;
  border-top: 1px solid #888;
  margin: 6px 0;
}

/* 본문 영역: 사이드바 폭만큼 왼쪽 여백 + 헤더+플랜바만큼 위 여백 */
main {
  flex: 1;
  min-width: 0;

  margin-left: var(--sidebar-w);
  margin-top: var(--header-h);
}

/* Psalm/구약/신약 + 카운터: 헤더 바로 아래에 고정, 테이블 폭 안에서만 */
.plan-header {
  position: static;
  top: auto;
  left: auto;
  transform: none;
  width: var(--table-w);
  max-width: var(--max-w);
  height: var(--plan-h);
  margin: 0 auto;
  background: #fff;
  z-index: var(--z-plan);
  display: flex;
  align-items: center;
}

.plan-header-inner {
  width: 100%;
  position: relative;
  display: block;
  align-items: center;
  height: 100%;
}

.plan-header-spacer {
  display: none;
}

.plan-header-title {
  margin: 0;
  text-align: center;
  font-weight: 700;
  font-size: 1.6rem;
  line-height: var(--plan-h);
  padding-right: var(--count-w);
  transform: none;
}

.count-wrap {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: var(--count-w);
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

.count-box {
  display: inline-flex;
  align-items: center;
  justify-content: center;

  padding: 4px 14px;
  min-width: 48px;
  font-size: 0.9em;
  line-height: 1;

  border: 2px solid #ccc;
  border-radius: 10px;
  cursor: pointer;
}

.count-text {
  font-weight: 800;
}

.count-reset {
  display: inline-flex;
  align-items: center;
  justify-content: center;

  padding: 4px 8px;
  border: var(--border);
  border-radius: 10px;
  background: #faf9f9;

  font-weight: 800;
  font-size: 0.9em;
  line-height: 1;
  cursor: pointer;
}

.count-reset:hover,
.count-box:hover {
  background: #d1d1d1;
}

#schedule-container {
  width: 100%;
  overflow-x: auto;
}

table {
  width: var(--table-w);
  max-width: var(--max-w);
  margin: 0 auto;
  border-collapse: collapse;
  table-layout: auto;
}
table,
th,
td {
  border: 1px solid rgb(169, 168, 168);
}
th,
td {
  height: 2rem;
  padding: 2px;
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
}

.schedule-table {
  margin-bottom: 20vh;
}

#schedule-container .plan-table {
  table-layout: fixed;
}

#schedule-container .plan-table th:nth-child(1),
#schedule-container .plan-table td:nth-child(1),
#schedule-container .plan-table th:nth-child(3),
#schedule-container .plan-table td:nth-child(3) {
  width: 22%;
}

#schedule-container .plan-table th:nth-child(2),
#schedule-container .plan-table td:nth-child(2),
#schedule-container .plan-table th:nth-child(4),
#schedule-container .plan-table td:nth-child(4) {
  width: 28%;
}

.highlight {
  color: red;
  font-weight: 700;
}

.read-yn {
  display: block;
  width: 1.15rem;
  height: 1.15rem;
  margin: 0 auto;
}

.psalm-table tbody tr:nth-child(10n + 6),
.psalm-table tbody tr:nth-child(10n + 7),
.psalm-table tbody tr:nth-child(10n + 8),
.psalm-table tbody tr:nth-child(10n + 9),
.psalm-table tbody tr:nth-child(10n + 10),
.plan-table tbody tr:nth-child(10n + 6),
.plan-table tbody tr:nth-child(10n + 7),
.plan-table tbody tr:nth-child(10n + 8),
.plan-table tbody tr:nth-child(10n + 9),
.plan-table tbody tr:nth-child(10n + 10) {
  background: #f2f2f2;
}

.section-row td {
  background: #e9e9e9;
  font-weight: 700;
  text-align: left;
  padding-left: 10px;
}

footer {
  position: fixed;      /* 항상 화면 하단에 붙게 */
  left: 0;
  right: 0;
  bottom: 0;
  width: 100vw;         /* ✅ 전체 폭 */
  background: #333;
  color: #fff;
  text-align: center;
  padding: 10px;
  z-index: 7000;        /* header/plan보다 낮게 */
}

header, footer {
  left: 0;
  right: 0;
}

.header-inner, .footer-inner {
  max-width: var(--max-w);
  margin: 0 auto;
}

/* 반응형: 사이드바 폭만 조절 */
@media (max-width: 992px) {
  :root {
    --sidebar-w: 10rem;
    --count-w: 188px;
  }

  .plan-order-row {
    width: 6rem;
  }

  .plan-header-inner {
    display: flex;
    align-items: center;
  }

  .plan-header-title {
    flex: 1;
    min-width: 0;
    font-size: 1.45rem;
    line-height: 1.1;
    text-align: left;
    padding-left: 10px;
    padding-right: 8px;
    white-space: nowrap;
    overflow: visible;
    text-overflow: clip;
  }

  .count-wrap {
    position: static;
    transform: none;
    width: auto;
    flex: 0 0 auto;
    gap: 6px;
  }

  .count-reset {
    padding: 4px 6px;
  }
}

/* ✅ 모바일: 제목/카운트 분리 배치 */
@media (max-width: 768px) {
  :root {
    --sidebar-w: 8rem;
    --plan-h: 42px;
  }
  html {
    font-size: 0.85rem;
  }

  .plan-header {
    height: var(--plan-h);
  }

  .plan-order-row {
    width: 6rem;
  }

  .plan-header-inner {
    height: 100%;
    padding: 0;

    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: nowrap;
    gap: 8px;

    position: relative;
  }

  .plan-header-spacer {
    display: none;
  }

  .plan-header-title {
    position: static;
    flex: 1;
    min-width: 0;
    margin: 0;
    text-align: center;
    white-space: nowrap;
    overflow: visible;
    text-overflow: clip;
    line-height: 1.1;
    font-size: 1.3rem;
    padding-left: 0;
    padding-right: 0;
  }

  .count-wrap {
    margin-left: auto;
    width: auto;
    flex: 0 1 auto;
    min-width: 0;

    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    line-height: 1;
  }

  .count-box,
  .count-reset {
    height: 28px;
    padding: 0 10px;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    font-size: 0.9em;
    line-height: 1;
  }

  .count-box {
    border: 2px solid #bfbfbf;
    border-radius: 14px;
  }

  input {
    zoom: 1.1;
  }
}

/* ✅ 더 작은 화면: 컴팩트 조정 */
@media (max-width: 576px) {
  :root {
    --sidebar-w: 7rem;
    --plan-h: 40px;
  }
  html {
    font-size: 0.75rem;
  }

  .plan-header-title {
    font-size: 1.15rem;
  }

  .plan-order-row {
    width: 5.4rem;
  }

  .plan-order-hint {
    width: 5.9rem;
    font-size: 0.6rem;
  }

  .count-wrap {
    gap: 4px;
  }

  .count-box,
  .count-reset {
    height: 26px;
    padding: 0 8px;
    font-size: 0.85em;
  }

  input {
    zoom: 1.05;
  }
}
