:root {
  --bg: #ffffff;
  --panel: #ffffff;
  --line: #f0f0ee;
  --line-table: #ebebea;
  --text: #37352f;
  --text-secondary: #6b6b6b;
  --muted: #9b9a97;
  --hover: #f7f7f5;
  --active: #efefed;
  --surface: #f7f6f3;

  --m1: #448361;
  --m1-bg: #e8f5ee;
  --m2: #5b8ac4;
  --m2-bg: #e8f0fb;
  --m3: #c77d48;
  --m3-bg: #fdf0e5;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.05), 0 0 0 1px rgba(0, 0, 0, 0.03);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.08), 0 0 0 1px rgba(0, 0, 0, 0.03);

  --radius-lg: 12px;
  --radius-md: 8px;
  --radius-sm: 6px;

  --transition: 120ms ease;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", "Segoe UI", system-ui, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-variant-numeric: tabular-nums;
}

#app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 40px 24px 60px;
}

/* ─── Icon helper ─── */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.icon-btn:hover {
  background: var(--hover);
  color: var(--text);
}

.icon-btn:active {
  background: var(--active);
}

.icon-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.icon-btn:disabled:hover {
  background: transparent;
  color: var(--text-secondary);
}

.icon-btn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ─── Header ─── */
.header {
  margin-bottom: 24px;
}

.header h1 {
  font-size: 30px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
  color: var(--text);
  margin-bottom: 2px;
}

.header-meta {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
}

/* ─── Toolbar ─── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.toolbar-group {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.week-label {
  display: inline-flex;
  align-items: center;
  gap: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  padding: 0 6px;
  height: 28px;
  user-select: none;
  white-space: nowrap;
}

.toolbar-divider {
  width: 1px;
  height: 20px;
  background: var(--line);
  margin: 0 6px;
}

.toolbar-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 28px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  padding: 0 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
}

.toolbar-btn:hover {
  background: var(--hover);
  color: var(--text);
}

.toolbar-btn:active {
  background: var(--active);
}

.toolbar-btn.active {
  background: var(--surface);
  color: var(--text);
}

.toolbar-btn svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.toolbar-spacer {
  flex: 1;
}

/* ─── Settings Panel ─── */
.settings-panel {
  margin-bottom: 20px;
  padding: 14px 16px;
  background: var(--surface);
  border-radius: var(--radius-md);
  animation: panelIn 150ms ease;
}

@keyframes panelIn {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.settings-grid {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.week-box {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.week-input {
  width: 56px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.week-input:focus {
  border-color: #2383e2;
  box-shadow: 0 0 0 3px rgba(35, 131, 226, 0.12);
}

.apply-btn {
  height: 28px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--text);
  color: #fff;
  padding: 0 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity var(--transition);
}

.apply-btn:hover {
  opacity: 0.85;
}

/* ─── Filters ─── */
.filters {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 6px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--panel);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: background var(--transition);
  user-select: none;
  box-shadow: var(--shadow-sm);
}

.chip:hover {
  background: var(--hover);
}

.chip input {
  margin: 0;
  accent-color: var(--text);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.dot.m1 { background: var(--m1); }
.dot.m2 { background: var(--m2); }
.dot.m3 { background: var(--m3); }
.dot.weekend { background: #9065b0; }

/* ─── Table (desktop) ─── */
.table-wrap {
  border: 1px solid var(--line-table);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
}

th, td {
  border: 1px solid var(--line-table);
  vertical-align: top;
  overflow-wrap: break-word;
  word-break: normal;
}

th {
  background: var(--surface);
  padding: 10px 10px;
  font-weight: 600;
  text-align: left;
  font-size: 12px;
  line-height: 1.4;
  color: var(--text-secondary);
  text-transform: none;
  letter-spacing: 0;
}

th:first-child,
td:first-child {
  border-left: none;
}

th:last-child,
td:last-child {
  border-right: none;
}

thead th:first-child {
  border-top: none;
}

thead th {
  border-top: none;
}

tbody tr:last-child td {
  border-bottom: none;
}

th.period,
td.period {
  width: 72px;
  min-width: 72px;
  text-align: center;
}

th.period {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

td.period {
  padding: 10px 6px;
  font-weight: 600;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text-secondary);
  background: var(--surface);
  position: sticky;
  left: 0;
  z-index: 1;
}

.day-name {
  display: block;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text);
}

.day-date {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  line-height: 1.3;
  color: var(--muted);
  font-weight: 400;
}

td.cell {
  padding: 6px 8px;
  background: var(--panel);
  transition: background var(--transition);
}

td.cell:hover {
  background: #fafaf9;
}

.member {
  display: block;
  padding: 4px 0;
}

.member + .member {
  border-top: 1px solid var(--line);
}

.lead {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  margin-right: 4px;
  vertical-align: middle;
  letter-spacing: 0;
  line-height: 1;
  flex-shrink: 0;
}

.lead.m1 { background: var(--m1-bg); color: var(--m1); }
.lead.m2 { background: var(--m2-bg); color: var(--m2); }
.lead.m3 { background: var(--m3-bg); color: var(--m3); }

.course-list {
  display: grid;
  gap: 3px;
}

.course {
  padding: 2px 0;
  border: 0;
  background: transparent;
  font-size: 12px;
  line-height: 1.5;
  white-space: normal;
  color: var(--text);
  display: flex;
  align-items: flex-start;
  gap: 0;
}

.course-detail {
  font-size: 11px;
  color: var(--muted);
  margin-left: 22px;
  line-height: 1.4;
}

.free {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  display: inline-flex;
  align-items: center;
  gap: 0;
}

/* ─── Status ─── */
.status-bar {
  font-size: 12px;
  line-height: 1.4;
  color: var(--muted);
}

/* ─── Mobile view (hidden on desktop) ─── */
.mobile-view {
  display: none;
}

/* ─── Responsive: Tablet ─── */
@media (max-width: 768px) {
  #app {
    padding: 20px 12px 32px;
  }

  .header h1 {
    font-size: 24px;
  }

  .toolbar {
    gap: 6px;
    margin-bottom: 14px;
    padding-bottom: 12px;
  }

  .table-wrap {
    border-radius: var(--radius-sm);
  }

  th {
    padding: 8px 6px;
  }

  td.cell {
    padding: 5px 5px;
  }

  .member {
    padding: 3px 0;
  }

  .course {
    font-size: 12px;
  }
}

/* ─── Responsive: Mobile ─── */
@media (max-width: 640px) {
  #app {
    padding: 16px 14px 32px;
  }

  .header {
    margin-bottom: 12px;
  }

  .header h1 {
    font-size: 22px;
  }

  .header-meta {
    font-size: 11px;
  }

  .toolbar {
    gap: 4px;
    margin-bottom: 0;
    padding-bottom: 10px;
    border-bottom: none;
  }

  .toolbar-btn {
    height: 26px;
    font-size: 12px;
    padding: 0 6px;
  }

  .icon-btn {
    width: 26px;
    height: 26px;
  }

  .week-label {
    font-size: 13px;
    height: 26px;
    padding: 0 4px;
  }

  .settings-panel {
    padding: 10px 12px;
    margin-bottom: 10px;
  }

  .settings-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .settings-grid .week-box {
    width: 100%;
    justify-content: center;
  }

  .table-wrap {
    display: none;
  }

  .mobile-view {
    display: block;
  }

  /* ─── Day tabs ─── */
  .day-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--line);
  }

  .day-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    padding: 8px 0 10px;
    border: none;
    background: transparent;
    cursor: pointer;
    position: relative;
    transition: color var(--transition);
    -webkit-tap-highlight-color: transparent;
  }

  .day-tab::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 20%;
    right: 20%;
    height: 2px;
    background: transparent;
    border-radius: 1px;
    transition: background var(--transition);
  }

  .day-tab-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    transition: color var(--transition);
  }

  .day-tab-date {
    font-size: 10px;
    color: var(--muted);
    font-weight: 400;
    transition: color var(--transition);
  }

  .day-tab.is-active .day-tab-name {
    color: var(--text);
  }

  .day-tab.is-active .day-tab-date {
    color: var(--text-secondary);
  }

  .day-tab.is-active::after {
    background: var(--text);
  }

  /* ─── Day content ─── */
  .day-content {
    animation: fadeIn 120ms ease;
  }

  @keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
  }

  .period-block {
    padding: 0 0 12px;
  }

  .period-block + .period-block {
    border-top: 1px solid var(--line);
    padding-top: 12px;
  }

  .period-block-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--muted);
    letter-spacing: 0.03em;
    margin-bottom: 8px;
  }

  .period-block-empty {
    font-size: 13px;
    color: var(--muted);
    padding: 2px 0;
  }

  /* ─── Member row ─── */
  .m-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 6px 0;
  }

  .m-row + .m-row {
    border-top: 1px solid var(--line);
  }

  .m-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
    flex-shrink: 0;
    margin-top: 1px;
  }

  .m-avatar.m1 { background: var(--m1-bg); color: var(--m1); }
  .m-avatar.m2 { background: var(--m2-bg); color: var(--m2); }
  .m-avatar.m3 { background: var(--m3-bg); color: var(--m3); }

  .m-info {
    flex: 1;
    min-width: 0;
  }

  .m-course-item {
    padding: 1px 0;
  }

  .m-course-item + .m-course-item {
    margin-top: 4px;
  }

  .m-course-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    line-height: 1.35;
  }

  .m-course-meta {
    font-size: 12px;
    color: var(--muted);
    line-height: 1.35;
    margin-top: 1px;
  }

  .m-free {
    font-size: 13px;
    color: var(--muted);
    line-height: 1.35;
  }
}
