/* =============================================
   TimeScheduler - Complete Styles
   ============================================= */

/* ---- Reset & Base ---- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #f0f2f5;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 40px 20px;
}

.container {
  width: 100%;
  max-width: 1200px;
}

/* ---- Header ---- */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.header h1 {
  font-size: 28px;
  font-weight: 700;
  color: #1a1a2e;
}

.header-actions {
  display: flex;
  gap: 12px;
}

/* ---- Buttons ---- */
.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: #4f46e5;
  color: white;
}

.btn-primary:hover {
  background: #6366f1;
  transform: translateY(-1px);
}

.btn-success {
  background: #059669;
  color: white;
}

.btn-success:hover {
  background: #10b981;
  transform: translateY(-1px);
}

.btn-secondary {
  background: white;
  color: #4f46e5;
  border: 1.5px solid #e0e0e0;
}

.btn-secondary:hover {
  border-color: #4f46e5;
  background: #f8f9ff;
}

.btn-icon-only { display: none; }

/* ---- View Controls (tabs + nav bar) ---- */
.view-controls {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
  background: white;
  border-radius: 12px;
  padding: 10px 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.view-tabs {
  display: flex;
  gap: 4px;
  background: #f0f2f5;
  border-radius: 8px;
  padding: 3px;
}

.view-tab {
  padding: 8px 18px;
  border: none;
  background: transparent;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  color: #64748b;
  cursor: pointer;
  transition: all 0.15s;
}

.view-tab:hover {
  color: #1a1a2e;
}

.view-tab.active {
  background: white;
  color: #4f46e5;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.nav-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.nav-btn {
  width: 32px;
  height: 32px;
  border: 1.5px solid #e0e0e0;
  border-radius: 8px;
  background: white;
  font-size: 18px;
  line-height: 1;
  color: #4a5568;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.nav-btn:hover {
  border-color: #4f46e5;
  color: #4f46e5;
  background: #f8f9ff;
}

.nav-title {
  font-size: 15px;
  font-weight: 600;
  color: #1a1a2e;
  min-width: 160px;
  text-align: center;
  user-select: none;
}

.nav-today {
  padding: 6px 14px;
  font-size: 13px;
}

/* ---- View Container ---- */
#view-container {
  min-height: 400px;
}

/* ---- Table (Week View) ---- */
.table-wrapper {
  background: white;
  border-radius: 16px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
  overflow: hidden;
  overflow-x: auto;
}

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

thead th {
  background: #f8f9ff;
  color: #1a1a2e;
  font-weight: 600;
  font-size: 14px;
  padding: 16px 12px;
  text-align: center;
  border-bottom: 2px solid #e8eaf6;
  position: sticky;
  top: 0;
  z-index: 10;
}

thead th:first-child {
  text-align: center;
  width: 130px;
}

tbody td {
  padding: 0;
  text-align: center;
  border: 1px solid #eef0f5;
  height: 64px;
  vertical-align: middle;
  transition: background 0.15s;
  position: relative;
}

tbody td:first-child {
  background: #fafbff;
  font-size: 13px;
  font-weight: 500;
  color: #4a5568;
  padding: 0 12px;
  white-space: nowrap;
}

tbody tr:hover td:first-child {
  background: #f0f1ff;
}

.cell-content {
  width: 100%;
  height: 100%;
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
}

.cell-content:hover {
  background: #f0f4ff;
}

.cell-content:hover::after {
  content: "✎";
  position: absolute;
  top: 4px;
  right: 8px;
  font-size: 12px;
  color: #93a3b8;
}

.cell-content.has-value {
  background: #eef2ff;
}

/* ---- Name Tag ---- */
.name-tag {
  color: white;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.2s;
}

.name-tag-wrapper {
  position: relative;
  display: inline-flex;
  align-items: center;
}

/* ---- Note Badge & Tooltip ---- */
.note-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #4f46e5;
  border: 2px solid white;
}

.note-tooltip {
  position: fixed;
  background: #1a1a2e;
  color: white;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  width: 340px;
  max-height: 220px;
  overflow-y: auto;
  pointer-events: auto;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.12s, visibility 0.12s;
  z-index: 10000;
  word-break: break-word;
  text-align: left;
}

.note-tooltip.show {
  opacity: 1;
  visibility: visible;
}

.note-tooltip .tip-arrow {
  position: absolute;
  left: 50%;
  margin-left: -6px;
  width: 0;
  height: 0;
  border: 6px solid transparent;
}

.note-tooltip[data-dir="up"] .tip-arrow {
  top: 100%;
  border-top-color: #1a1a2e;
}

.note-tooltip[data-dir="down"] .tip-arrow {
  bottom: 100%;
  border-bottom-color: #1a1a2e;
}

.note-tooltip::-webkit-scrollbar { width: 4px; }
.note-tooltip::-webkit-scrollbar-track { background: transparent; }
.note-tooltip::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.3); border-radius: 2px; }

/* ---- Edit Mode ---- */
.edit-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 6px;
}

.edit-name-input {
  width: 100%;
  border: 2px solid #4f46e5;
  border-radius: 6px;
  outline: none;
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  background: #f8f9ff;
  padding: 8px 10px;
  font-family: inherit;
}

.edit-name-input:focus {
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.color-picker {
  display: flex;
  gap: 8px;
  align-items: center;
}

.color-picker-label {
  font-size: 11px;
  color: #94a3b8;
  font-weight: 500;
}

.color-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.15s;
}

.color-dot:hover {
  transform: scale(1.2);
}

.color-dot.active {
  border-color: #1a1a2e;
  box-shadow: 0 0 0 2px white, 0 0 0 4px #1a1a2e;
}

.edit-note-input {
  width: 100%;
  border: 1.5px solid #dde0e8;
  border-radius: 6px;
  outline: none;
  font-size: 12px;
  background: #fafbff;
  padding: 6px 8px;
  font-family: inherit;
  resize: vertical;
  min-height: 36px;
  max-height: 60px;
  line-height: 1.4;
  transition: border-color 0.15s;
}

.edit-note-input:focus {
  border-color: #4f46e5;
}

/* ---- Context Menu ---- */
.context-menu {
  position: fixed;
  background: white;
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  border: 1px solid #eef0f5;
  padding: 6px;
  z-index: 1000;
  min-width: 140px;
  display: none;
}

.context-menu button {
  display: block;
  width: 100%;
  padding: 10px 16px;
  border: none;
  background: none;
  text-align: left;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.1s;
}

.context-menu button:hover {
  background: #f0f4ff;
  color: #4f46e5;
}

.context-menu button.danger:hover {
  background: #fef2f2;
  color: #ef4444;
}

.context-menu .color-submenu {
  display: flex;
  gap: 6px;
  padding: 6px 16px 10px;
}

/* ---- Note Modal ---- */
.note-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.25);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}

.note-modal-overlay.show {
  display: flex;
}

.note-modal {
  background: white;
  border-radius: 16px;
  padding: 24px;
  width: 360px;
  max-width: 90vw;
  box-shadow: 0 12px 48px rgba(0,0,0,0.15);
}

.note-modal h3 {
  font-size: 16px;
  font-weight: 600;
  color: #1a1a2e;
  margin-bottom: 12px;
}

.note-modal .cell-info {
  font-size: 12px;
  color: #94a3b8;
  margin-bottom: 12px;
}

.note-modal textarea {
  width: 100%;
  min-height: 80px;
  max-height: 200px;
  border: 1.5px solid #dde0e8;
  border-radius: 8px;
  outline: none;
  font-size: 13px;
  font-family: inherit;
  padding: 10px 12px;
  resize: vertical;
  line-height: 1.5;
  transition: border-color 0.15s;
}

.note-modal textarea:focus {
  border-color: #4f46e5;
}

.note-modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 12px;
}

.note-modal-actions .btn {
  padding: 8px 20px;
  font-size: 13px;
}

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #1a1a2e;
  color: white;
  padding: 12px 24px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  transition: all 0.3s;
  pointer-events: none;
  z-index: 999;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---- Loading Overlay (export) ---- */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.loading-overlay.show {
  display: flex;
}

.loading-box {
  background: white;
  padding: 24px 40px;
  border-radius: 16px;
  font-size: 16px;
  font-weight: 600;
  color: #1a1a2e;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}

/* ---- Sync Indicator ---- */
.sync-indicator {
  font-size: 12px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 20px;
  background: #f0f2f5;
  color: #94a3b8;
  white-space: nowrap;
  transition: all 0.3s;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* ---- Weekday Header in Table ---- */
.weekday-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.weekday-header .weekday-label {
  font-size: 14px;
}

.weekday-header .weekday-sub {
  font-size: 11px;
  color: #94a3b8;
  font-weight: 400;
}

/* =============================================
   Month View
   ============================================= */
.month-view {
  background: white;
  border-radius: 16px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
  overflow: hidden;
}

.month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: #eef0f5;
}

.month-header {
  background: #f8f9ff;
  padding: 12px 8px;
  text-align: center;
  font-weight: 600;
  font-size: 13px;
  color: #1a1a2e;
  border-bottom: 2px solid #e8eaf6;
}

.month-cell {
  min-height: 100px;
  padding: 6px 8px;
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid #eef0f5;
  border-right: 1px solid #eef0f5;
}

.month-cell:nth-child(7n) {
  border-right: none;
}

.month-cell:hover {
  background: #f0f4ff;
}

.month-cell.today {
  background: #eef2ff;
}

.month-cell.other-month {
  background: #fafafa;
}

.month-cell.other-month .month-day-number {
  color: #cbd5e1;
}

.month-day-number {
  font-size: 14px;
  font-weight: 600;
  color: #1a1a2e;
  margin-bottom: 6px;
}

.month-name-tag {
  display: inline-block;
  color: white;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  margin: 2px 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: default;
}

.month-more {
  font-size: 11px;
  color: #94a3b8;
  font-weight: 500;
  margin-top: 2px;
}

/* =============================================
   Year View
   ============================================= */
.year-view {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.mini-month {
  background: white;
  border-radius: 12px;
  padding: 14px 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.mini-month-title {
  text-align: center;
  font-weight: 600;
  font-size: 14px;
  color: #4f46e5;
  margin-bottom: 10px;
  cursor: pointer;
  transition: color 0.15s;
}

.mini-month-title:hover {
  color: #6366f1;
}

.mini-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
}

.mini-header {
  text-align: center;
  font-size: 10px;
  color: #94a3b8;
  padding: 3px 0;
  font-weight: 500;
}

.mini-cell {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: #4a5568;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.1s;
  position: relative;
}

.mini-cell:hover {
  background: #f0f4ff;
}

.mini-cell.today {
  background: #eef2ff;
  font-weight: 600;
  color: #4f46e5;
}

.mini-cell.other-month {
  color: #d1d5db;
}

.mini-dot-container {
  display: flex;
  gap: 2px;
  margin-top: 1px;
  justify-content: center;
}

.mini-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
}

/* =============================================
   Responsive
   ============================================= */
@media (max-width: 768px) {
  body { padding: 16px 8px; }

  .header { flex-direction: column; align-items: flex-start; gap: 12px; }
  .header-actions { flex-wrap: wrap; }

  .view-controls { flex-wrap: wrap; gap: 10px; }
  .nav-bar { margin-left: 0; width: 100%; justify-content: center; }

  thead th { font-size: 12px; padding: 12px 6px; }
  thead th:first-child { width: 80px; font-size: 11px; }
  tbody td:first-child { font-size: 11px; padding: 0 6px; }

  .month-cell { min-height: 70px; padding: 4px 6px; }
  .month-name-tag { font-size: 10px; padding: 1px 5px; }
  .month-day-number { font-size: 12px; }

  .year-view { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .mini-month { padding: 10px 6px; }
  .mini-cell { font-size: 10px; }
}

@media (max-width: 480px) {
  .year-view { grid-template-columns: repeat(1, 1fr); }

  /* ---- Icon-only buttons ---- */
  .btn-icon .btn-label { display: none; }
  .btn-icon .btn-icon-only { display: inline; }
  .btn-icon { padding: 8px; min-width: 36px; display: inline-flex; align-items: center; justify-content: center; }

  /* ---- Compact header ---- */
  .header h1 { font-size: 20px; }

  /* ---- Compact nav bar ---- */
  .view-controls { padding: 8px 10px; gap: 6px; }
  .view-tab { padding: 6px 10px; font-size: 12px; }
  .nav-title { font-size: 13px; min-width: 110px; }
  .nav-btn { width: 28px; height: 28px; font-size: 15px; }
  .nav-today { padding: 4px 10px; font-size: 12px; }

  /* ---- Compact week table ---- */
  table { min-width: 480px; }
  thead th { font-size: 11px; padding: 8px 4px; }
  thead th:first-child { width: 55px; font-size: 10px; }
  tbody td { height: 44px; }
  tbody td:first-child { font-size: 10px; padding: 0 3px; }
  .cell-content { min-height: 44px; padding: 2px; }
  .cell-content:hover::after { display: none; }
  .name-tag { padding: 3px 8px; font-size: 11px; }

  /* ---- Touch-friendly edit inputs ---- */
  .edit-name-input { padding: 10px 12px; font-size: 16px; }
  .edit-note-input { padding: 10px; font-size: 14px; }
  .color-dot { width: 26px; height: 26px; }

  /* ---- Compact month view ---- */
  .month-cell { min-height: 44px; padding: 2px 4px; }
  .month-day-number { font-size: 11px; margin-bottom: 2px; }
  .month-name-tag {
    width: 8px; height: 8px; padding: 0;
    font-size: 0; border-radius: 50%;
    display: inline-block; vertical-align: top;
    margin: 1px 0; overflow: hidden;
    text-indent: -9999px;
  }
  .month-more { font-size: 10px; }

  /* ---- Compact note modal ---- */
  .note-modal { padding: 16px; }
  .note-modal textarea { font-size: 16px; }
}
