/* 课程颜色 CSS 变量 */
:root {
  --bg-0: #1f2531;
  --bg-1: #263041;
  --bg-2: #2d394a;
  --bg-3: #334155;
  --line-soft: #3a4658;
  --line-strong: #445268;
  --text-1: #edf3fb;
  --text-2: #bcc7d8;
  --text-3: #8e9aae;
  --accent: #63d0c8;
  --accent-2: #80aaff;
  --accent-strong: #1e6e72;
  --accent-surface: #2b4650;
  --today-bg: rgba(95, 212, 203, 0.1);
  --shadow-lg: 0 18px 42px rgba(7, 11, 18, 0.28);

  --c-blue-bg: #273a56; --c-blue-border: #81a8ff;
  --c-green-bg: #263f36; --c-green-border: #86c8aa;
  --c-orange-bg: #4a3a2a; --c-orange-border: #e4b170;
  --c-purple-bg: #3a3456; --c-purple-border: #a792ff;
  --c-pink-bg: #4a3341; --c-pink-border: #df91b1;
  --c-teal-bg: #24464a; --c-teal-border: #63d0c8;
  --c-red-bg: #4a3134; --c-red-border: #ef8d90;
  --c-indigo-bg: #2d3756; --c-indigo-border: #8ea2ff;
}
  * { margin: 0; padding: 0; box-sizing: border-box; }
  body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background:
      radial-gradient(circle at top left, rgba(99,208,200,0.08), transparent 28%),
      radial-gradient(circle at top right, rgba(128,170,255,0.08), transparent 24%),
      linear-gradient(180deg, #1a212c 0%, var(--bg-0) 100%);
    color: var(--text-1);
    min-height: 100vh;
    overflow-x: hidden;
  }
  .container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
  }
  @media (max-width: 768px) { .container { padding: 12px; } }
  @media (max-width: 480px) { .container { padding: 8px; } }

  /* ---- Header ---- */
  .header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 10px;
  }
  .header h1 { font-size: 26px; font-weight: 800; letter-spacing: -0.5px; }
  .header h1 span { background: linear-gradient(135deg, #8cb5ff, #63d0c8); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
  .header-actions { display: flex; gap: 8px; flex-wrap: wrap; }
  .mode-pill {
    display: inline-flex; align-items: center;
    padding: 7px 12px; border-radius: 999px;
    border: 1px solid rgba(99,208,200,0.22);
    background: rgba(28, 49, 56, 0.88);
    color: #d7fbf7; font-size: 12px; font-weight: 800;
    letter-spacing: 0.2px; white-space: nowrap;
    box-shadow: 0 6px 18px rgba(7, 11, 18, 0.16);
  }
  body.is-admin .mode-pill {
    border-color: rgba(128,170,255,0.28);
    background: rgba(38, 51, 74, 0.92);
    color: #dfeaff;
  }
  .header-actions .btn {
    padding: 8px 14px; border-radius: 10px; border: 1px solid var(--line-soft);
    background: rgba(45,57,74,0.92); color: var(--text-2); font-size: 13px; font-weight: 600;
    cursor: pointer; white-space: nowrap; transition: all 0.15s; user-select: none;
    box-shadow: 0 6px 18px rgba(7, 11, 18, 0.16);
  }
  .header-actions .btn:hover { background: var(--bg-3); border-color: var(--accent); color: var(--text-1); transform: translateY(-1px); }
  .header-actions .btn-primary { background: linear-gradient(135deg, #3b5f74, #1e6e72); border-color: #4f8991; color: #f4fffe; }
  .header-actions .btn-primary:hover { background: linear-gradient(135deg, #467287, #278187); }
  .header-actions .btn-admin { background: rgba(37,52,74,0.92); border-color: #6ea8ff; color: #a8ccff; }
  .header-actions .btn-admin:hover { background: #31445d; }
  .header-actions .btn-import { background: rgba(34,72,76,0.92); border-color: #3a8e8b; color: #8ce7de; }
  .header-actions .btn-import:hover { background: #2c555c; }
  .header-actions .btn-sync { background: rgba(42,63,88,0.94); border-color: #6aa7d8; color: #cfe8ff; }
  .header-actions .btn-sync:hover { background: #365271; border-color: #8fd8d2; color: #f3fffe; }
  .header-actions .btn-sync:disabled {
    opacity: 0.6; cursor: not-allowed; transform: none;
    background: rgba(58,70,88,0.84); border-color: var(--line-soft); color: var(--text-3);
  }
  .header-actions .btn-app-download { background: rgba(30,110,114,0.88); border-color: #3a8e8b; color: #a8f4ef; text-decoration: none; }
  .header-actions .btn-app-download:hover { background: #24565a; border-color: #63d0c8; color: #d7fbf7; }
  .sync-status {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 7px 11px; border-radius: 999px;
    border: 1px solid var(--line-soft); background: rgba(45,57,74,0.9);
    color: var(--text-2); font-size: 12px; font-weight: 700;
    box-shadow: 0 6px 18px rgba(7, 11, 18, 0.16);
    white-space: nowrap;
  }
  .sync-status .copy {
    display: inline-flex; flex-direction: column; gap: 1px;
    line-height: 1.15;
  }
  .sync-status .text { color: var(--text-1); }
  .sync-status .meta { color: var(--text-3); font-size: 10px; font-weight: 600; }
  .sync-status .dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: #8e9aae; box-shadow: 0 0 0 4px rgba(142,154,174,0.12);
    transition: all 0.2s;
  }
  .sync-status[data-state="pending"] .dot { background: #80aaff; box-shadow: 0 0 0 4px rgba(128,170,255,0.14); }
  .sync-status[data-state="syncing"] .dot { background: #efc07d; box-shadow: 0 0 0 4px rgba(239,192,125,0.14); }
  .sync-status[data-state="ok"] .dot { background: #63d0c8; box-shadow: 0 0 0 4px rgba(99,208,200,0.14); }
  .sync-status[data-state="error"] .dot { background: #f08a90; box-shadow: 0 0 0 4px rgba(240,138,144,0.14); }
  .admin-only { display: none !important; }
  body.is-admin .admin-only { display: inline-flex !important; }
  body.is-admin .viewer-only { display: none !important; }
  @media (max-width: 768px) {
    .header h1 { font-size: 20px; }
    .header-actions .btn { padding: 6px 10px; font-size: 12px; }
    .sync-status { font-size: 11px; padding: 6px 10px; }
    .mode-pill { font-size: 11px; padding: 6px 10px; }
  }
  @media (max-width: 480px) {
    .header h1 { font-size: 17px; }
    .header-actions .btn { font-size: 11px; padding: 5px 8px; }
    .header-actions { gap: 5px; }
    .sync-status { font-size: 10px; padding: 5px 8px; }
    .mode-pill { font-size: 10px; padding: 5px 8px; }
  }

  /* ===== 课程状态栏 ===== */
  .status-bar {
    display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap;
  }
  .status-card {
    flex: 1; min-width: 160px; background: rgba(45,57,74,0.94);
    border-radius: 14px; padding: 12px 15px; border: 1px solid var(--line-soft);
    display: flex; flex-direction: column; gap: 3px;
    box-shadow: var(--shadow-lg);
  }
  .status-card .label { font-size: 11px; color: var(--text-3); font-weight: 600; display: flex; align-items: center; gap: 5px; }
  .status-card .course-name { font-size: 14px; font-weight: 700; color: var(--text-1); }
  .status-card .countdown { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
  .status-card .countdown.urgent { color: #efc07d; }
  .status-card .countdown.critical { color: #f08a90; }
  .status-card .countdown.steady { color: var(--accent); }
  .status-card .meta { font-size: 11px; color: var(--text-3); }
  .status-card .no-course { font-size: 13px; color: var(--text-3); padding: 6px 0; }
  @media (max-width: 480px) {
    .status-card { min-width: 120px; padding: 8px 10px; }
    .status-card .course-name { font-size: 12px; }
    .status-card .countdown { font-size: 15px; }
    .status-bar { flex-direction: column; gap: 6px; }
  }

  /* ---- Week tabs ---- */
  .week-tabs-wrap {
    display: flex; align-items: stretch; gap: 4px; margin-bottom: 14px;
  }
  .week-nav-btn {
    flex-shrink: 0; width: 32px; background: var(--bg-2); border: 1px solid var(--line-soft);
    color: var(--text-3); border-radius: 10px; cursor: pointer; font-size: 14px;
    transition: all 0.15s; line-height: 1;
  }
  .week-nav-btn:hover { background: var(--bg-3); color: var(--text-1); border-color: var(--accent); }
  .week-tabs {
    flex: 1; display: flex; gap: 4px; overflow-x: auto;
    scroll-behavior: smooth; padding: 2px 0;
    -webkit-overflow-scrolling: touch;
  }
  .week-tabs::-webkit-scrollbar { height: 3px; }
  .week-tabs::-webkit-scrollbar-thumb { background: var(--line-soft); border-radius: 3px; }
  .week-tab {
    flex-shrink: 0; padding: 7px 14px; border-radius: 10px; border: 1px solid var(--line-soft);
    background: rgba(45,57,74,0.92); color: var(--text-3); font-size: 12px; font-weight: 600;
    cursor: pointer; white-space: nowrap; transition: all 0.15s;
    display: flex; flex-direction: column; align-items: center; gap: 1px;
  }
  .week-tab .date-range { font-size: 10px; font-weight: 400; opacity: 0.6; }
  .week-tab:hover { border-color: var(--accent); color: var(--text-1); background: var(--bg-3); }
  .week-tab.active { background: linear-gradient(135deg, #315056, #235f63); border-color: #4fa4a0; color: #f4fffe; }
  .week-tab.current { border-color: var(--accent-2); }
  @media (max-width: 480px) {
    .week-tab { padding: 5px 10px; font-size: 11px; }
    .week-tab .date-range { font-size: 9px; }
  }

  /* ---- Schedule grid ---- */
  .schedule-wrapper {
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 16px;
    border: 1px solid var(--line-soft);
    background: rgba(38,48,65,0.88);
    box-shadow: var(--shadow-lg);
  }
  .schedule {
    display: grid;
    min-width: 820px;
  }
  .day-header {
    background: var(--bg-2); font-weight: 700; font-size: 13px;
    padding: 10px 6px; text-align: center; border-bottom: 2px solid var(--line-strong);
    border-right: 1px solid var(--line-soft); position: sticky; top: 0; z-index: 5;
  }
  .day-header.today { color: #a8f4ef; }
  .time-cell {
    background: var(--bg-2); border-bottom: 1px solid var(--line-soft);
    border-right: 1px solid var(--line-strong); padding: 2px 8px 2px 0;
    display: flex; flex-direction: column; align-items: flex-end; justify-content: center;
  }
  .time-cell .period { font-weight: 600; font-size: 12px; color: var(--text-2); }
  .time-cell .clock { font-size: 9px; color: var(--text-3); }
  .cell {
    border-bottom: 1px solid var(--line-soft); border-left: 1px solid var(--line-soft);
    height: 68px; position: relative; cursor: pointer; overflow: hidden;
    background: rgba(32,38,49,0.72);
  }
  .cell:hover { background: #293545; }
  .cell.today-col { background: var(--today-bg); }

  /* ---- Course cards ---- */
  .course {
    position: absolute; left: 2px; right: 2px; top: 2px;
    bottom: 2px;
    border-radius: 8px; padding: 4px 6px;
    display: flex; flex-direction: column; justify-content: center;
    border: 1px solid transparent; z-index: 10;
    overflow: hidden;
    gap: 2px;
    box-shadow: 0 8px 18px rgba(11, 15, 24, 0.18);
  }
  .course .name {
    font-weight: 700; font-size: 12px; line-height: 1.25;
    word-break: break-word; overflow-wrap: break-word;
    overflow: hidden; text-overflow: ellipsis;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  }
  .course .info { font-size: 9px; opacity: 0.65; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .course .location {
    display: inline-block; background: rgba(255,255,255,0.12);
    border-radius: 3px; padding: 1px 5px; font-size: 10px; font-weight: 700;
    line-height: 1.4; color: #fff; align-self: flex-start;
    white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis;
  }
  .course .remove {
    position: absolute; top: 1px; right: 2px; width: 18px; height: 18px;
    border: none; background: rgba(0,0,0,0.4); color: #fff;
    border-radius: 50%; font-size: 12px; line-height: 18px; text-align: center;
    cursor: pointer; display: none;
  }
  body.is-admin .course .remove { display: block; }
  .course .remove:hover { background: #e06060; }

  .c-blue { background: var(--c-blue-bg); border-color: var(--c-blue-border); }
  .c-green { background: var(--c-green-bg); border-color: var(--c-green-border); }
  .c-orange { background: var(--c-orange-bg); border-color: var(--c-orange-border); }
  .c-purple { background: var(--c-purple-bg); border-color: var(--c-purple-border); }
  .c-pink { background: var(--c-pink-bg); border-color: var(--c-pink-border); }
  .c-teal { background: var(--c-teal-bg); border-color: var(--c-teal-border); }
  .c-red { background: var(--c-red-bg); border-color: var(--c-red-border); }
  .c-indigo { background: var(--c-indigo-bg); border-color: var(--c-indigo-border); }

  /* ---- Empty state ---- */
  .empty-state {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 60px 20px; color: var(--text-3); text-align: center;
  }
  .empty-state .icon { font-size: 48px; margin-bottom: 16px; }
  .empty-state h3 { font-size: 18px; margin-bottom: 8px; color: var(--text-2); }
  .empty-state p { font-size: 14px; max-width: 360px; line-height: 1.6; }
  .empty-state .btn {
    margin-top: 16px; padding: 10px 24px; border-radius: 10px; border: 1px solid var(--line-soft);
    background: var(--bg-2); color: var(--text-2); font-size: 14px; font-weight: 600;
    cursor: pointer;
  }
  .empty-state .btn:hover { background: var(--bg-3); border-color: var(--accent); }

  /* ---- Toast ---- */
  .toast {
    position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%);
    background: linear-gradient(135deg, #2d5960, #1e6e72); color: #f5fffe; padding: 12px 24px;
    border-radius: 12px; font-size: 14px; font-weight: 600;
    box-shadow: 0 12px 32px rgba(10,15,22,0.34);
    opacity: 0; transition: opacity 0.3s; z-index: 999;
    pointer-events: none; white-space: nowrap;
  }
  .toast.show { opacity: 1; }

  /* ---- Modal ---- */
  .modal-overlay {
    position: fixed; inset: 0; background: rgba(8,12,18,0.68);
    backdrop-filter: blur(4px); z-index: 100;
    display: none; align-items: center; justify-content: center;
    padding: 20px;
  }
  .modal-overlay.show { display: flex; }
  .modal {
    background: var(--bg-2); border-radius: 18px; padding: 24px;
    width: 100%; max-width: 400px; border: 1px solid var(--line-strong);
    max-height: 90vh; overflow-y: auto;
    box-shadow: var(--shadow-lg);
  }
  .modal h2 { font-size: 18px; margin-bottom: 16px; }
  .modal label { display: block; font-size: 12px; color: var(--text-3); margin: 10px 0 4px; font-weight: 600; }
  .modal input, .modal select {
    width: 100%; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line-soft);
    background: #222b39; color: var(--text-1); font-size: 14px; outline: none;
  }
  .modal input:focus, .modal select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(99,208,200,0.12); }
  .modal .btn-row { display: flex; gap: 8px; margin-top: 16px; }
  .modal .btn-row button { flex: 1; padding: 10px; border-radius: 8px; border: none; font-size: 14px; font-weight: 600; cursor: pointer; }
  .modal .btn-row .btn-cancel { background: #364255; color: var(--text-2); }
  .modal .btn-row .btn-save { background: linear-gradient(135deg, #315056, #1e6e72); color: #f3fffe; }
  .modal .half-row { display: flex; gap: 8px; }
  .modal .half-row > * { flex: 1; }
  .special-date-editor {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    margin-top: 8px;
  }
  .special-date-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
  }
  .special-date-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 9px 10px;
    border: 1px solid var(--line-soft);
    border-radius: 10px;
    background: rgba(34, 43, 57, 0.78);
  }
  .special-date-item .copy {
    min-width: 0;
    color: var(--text-2);
    font-size: 12px;
    line-height: 1.5;
  }
  .special-date-item .copy strong {
    color: var(--text-1);
    margin-right: 6px;
  }
  .special-date-item button {
    flex: 0 0 auto;
    padding: 5px 9px;
    border: none;
    border-radius: 8px;
    background: rgba(224, 96, 96, 0.22);
    color: #ffc9cc;
    cursor: pointer;
  }

  @media (max-width: 768px) {
    .schedule { min-width: 700px; }
    .cell { height: 62px; }
    .time-cell { padding: 2px 6px 2px 0; }
  }
  @media (max-width: 480px) {
    .schedule { min-width: 640px; }
    .cell { height: 70px; }
    .time-cell .period { font-size: 10px; }
    .time-cell .clock { font-size: 8px; }
    .course { padding: 3px 4px; gap: 1px; }
    .course .name { font-size: 11px; -webkit-line-clamp: 2; }
    .course .location { font-size: 9px; padding: 0 4px; }
    .course .info { font-size: 8px; }
    .day-header { font-size: 11px; padding: 8px 3px; }
    .modal { padding: 16px; }
  }
  @media (max-width: 380px) {
    .schedule { min-width: 580px; }
    .cell { height: 72px; }
  }

  /* ===== 移动端日视图 ===== */
  .daily-view { display: none; }
  @media (max-width: 767px) {
    .daily-view { display: block; }
    .schedule-wrapper { display: none; }
  }
  .dv-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 14px; user-select: none;
  }
  .dv-nav {
    width: 40px; height: 40px; border-radius: 50%;
    border: 1px solid var(--line-soft); background: var(--bg-2);
    color: var(--text-2); font-size: 18px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.15s; -webkit-tap-highlight-color: transparent;
  }
  .dv-nav:active { background: var(--bg-3); border-color: var(--accent); }
  .dv-nav.disabled { opacity: 0.3; pointer-events: none; }
  .dv-day-title {
    font-size: 18px; font-weight: 700; text-align: center;
    display: flex; flex-direction: column; align-items: center; gap: 2px;
  }
  .dv-day-title .dv-date { font-size: 12px; color: var(--text-3); font-weight: 400; }
  .dv-day-title .dv-today-badge {
    font-size: 10px; background: #1e6e72; color: #f3fffe;
    padding: 1px 8px; border-radius: 8px; font-weight: 600;
  }
  .dv-dots {
    display: flex; justify-content: center; gap: 5px; margin-bottom: 12px;
  }
  .dv-dot {
    width: 7px; height: 7px; border-radius: 50%; background: var(--line-soft);
    transition: all 0.2s;
  }
  .dv-dot.active { background: var(--accent); width: 18px; border-radius: 4px; }
  .dv-scroll {
    overflow-y: auto; -webkit-overflow-scrolling: touch;
    padding-bottom: 80px;
  }
  .dv-slot { margin-bottom: 10px; }
  .dv-time-label {
    display: flex; align-items: center; gap: 10px; margin-bottom: 6px;
    font-size: 12px; color: var(--text-3); font-weight: 600;
  }
  .dv-time-label::after {
    content: ''; flex: 1; height: 1px; background: var(--line-soft);
  }
  .dv-card {
    background: rgba(45,57,74,0.96); border-radius: 14px; padding: 12px 14px;
    border: 1px solid var(--line-soft); position: relative; overflow: hidden;
    box-shadow: var(--shadow-lg);
  }
  .dv-card .name {
    font-size: 16px; font-weight: 700; color: var(--text-1);
    margin-bottom: 4px; word-break: break-word;
  }
  .dv-card .meta {
    font-size: 13px; color: var(--text-2);
    display: flex; flex-wrap: wrap; gap: 8px;
  }
  .dv-card .meta .tag {
    display: inline-flex; align-items: center; gap: 3px;
  }
  .dv-card .remove {
    position: absolute; top: 8px; right: 10px; width: 24px; height: 24px;
    border: none; background: rgba(0,0,0,0.3); color: #fff;
    border-radius: 50%; font-size: 14px; cursor: pointer;
    display: none; align-items: center; justify-content: center;
  }
  body.is-admin .dv-card .remove { display: flex; }
  .dv-color-bar {
    position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  }
  .dv-color-bar.c-blue { background: var(--c-blue-border); }
  .dv-color-bar.c-green { background: var(--c-green-border); }
  .dv-color-bar.c-orange { background: var(--c-orange-border); }
  .dv-color-bar.c-purple { background: var(--c-purple-border); }
  .dv-color-bar.c-pink { background: var(--c-pink-border); }
  .dv-color-bar.c-teal { background: var(--c-teal-border); }
  .dv-color-bar.c-red { background: var(--c-red-border); }
  .dv-color-bar.c-indigo { background: var(--c-indigo-border); }

.detail-body p { margin: 8px 0; font-size: 14px; color: var(--text-2); line-height: 1.6; }
.detail-body strong { color: var(--text-3); font-weight: 600; min-width: 50px; display: inline-block; }
.sync-conflict-text { font-size: 14px; color: var(--text-2); line-height: 1.7; margin-bottom: 10px; }
.sync-conflict-meta { font-size: 12px; color: var(--text-3); line-height: 1.7; margin-bottom: 10px; }

.week-count {
  text-align: center; font-size: 13px; color: var(--text-3);
  padding: 8px 0 2px; display: none;
}
body:not(.is-admin) .week-count { display: block; }

/* ===== 教师模式 - 班级标签 ===== */
.class-name-tag {
  display: inline-block;
  background: rgba(128, 170, 255, 0.15);
  border: 1px solid rgba(128, 170, 255, 0.3);
  border-radius: 4px;
  padding: 0 5px;
  font-size: 9px;
  font-weight: 600;
  color: #80aaff;
  line-height: 1.6;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.class-name-tag-inline {
  display: inline-flex;
  align-items: center;
  background: rgba(128, 170, 255, 0.15);
  border: 1px solid rgba(128, 170, 255, 0.3);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 600;
  color: #80aaff;
  white-space: nowrap;
}
body.is-teacher .btn-admin {
  background: rgba(30,110,114,0.88);
  border-color: #3a8e8b;
  color: #a8f4ef;
}
body.is-teacher .btn-admin:hover {
  background: #24565a;
  border-color: #63d0c8;
  color: #d7fbf7;
}
