/* Personal Study Planner v0.10 - styles */

:root {
  --bg: #faf7ef;
  --panel: #ffffff;
  --panel-soft: #fbf8f0;
  --text: #1c1f26;
  --muted: #6b7280;
  --muted-2: #9aa1ad;
  --border: #e8e3d6;
  --border-strong: #d8d1c0;
  --primary: #3b6ff5;
  --primary-dark: #2c59cf;
  --primary-soft: #eaf0ff;
  --danger: #e5484d;
  --danger-soft: #fdeeee;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 12px 32px rgba(24, 30, 48, 0.1);
  --shadow-soft: 0 2px 10px rgba(24, 30, 48, 0.05);
  --header-h: 60px;
  font-size: 15px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

.hidden {
  display: none !important;
}

/* ---------------- Login ---------------- */
.login-view {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 15% 10%, #f2e8d3 0%, transparent 55%),
    radial-gradient(900px 500px at 90% 85%, #f0e5d2 0%, transparent 50%),
    var(--bg);
}

.login-card {
  width: min(380px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 32px 28px 24px;
}

.login-brand {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.login-sub {
  margin: 6px 0 24px;
  color: var(--muted);
  font-size: 13px;
}

.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin: 12px 0 6px;
}

.input,
.select,
.textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  padding: 9px 11px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 111, 245, 0.15);
}

.textarea {
  min-height: 88px;
  resize: vertical;
}

.login-submit {
  width: 100%;
  margin-top: 18px;
  padding: 11px 14px;
  font-size: 15px;
}

.login-error {
  min-height: 20px;
  margin: 12px 0 0;
  color: var(--danger);
  font-size: 13px;
  text-align: center;
}

.login-version {
  margin: 22px 0 0;
  text-align: center;
  color: var(--muted-2);
  font-size: 12px;
}

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 8px 13px;
  background: #fff;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}

.btn:hover {
  background: #f7f2e7;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(59, 111, 245, 0.25);
}

.btn-primary:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
}

.btn-ghost {
  border-color: var(--border-strong);
  background: #fff;
  color: var(--text);
}

.btn-ghost:hover {
  background: #f7f2e7;
}

.btn-danger {
  color: var(--danger);
  border-color: #f3c9ca;
  background: #fff;
}

.btn-danger:hover {
  background: var(--danger-soft);
}

.btn-sm {
  padding: 5px 9px;
  font-size: 13px;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  color: var(--muted);
}

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

/* ---------------- App shell ---------------- */
.app-view {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.app-header {
  height: var(--header-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 20px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
  z-index: 20;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.brand-title {
  font-size: 17px;
  font-weight: 700;
}

.version-badge {
  font-size: 11px;
  color: var(--muted);
  background: #efe9dc;
  border-radius: 999px;
  padding: 2px 7px;
}

.tabs {
  display: flex;
  gap: 4px;
  background: #efe9dc;
  border-radius: 10px;
  padding: 4px;
}

.tab-btn {
  border: none;
  background: transparent;
  padding: 7px 18px;
  border-radius: 7px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
}

.tab-btn.is-active {
  background: #fff;
  color: var(--text);
  box-shadow: var(--shadow-soft);
}

.header-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.app-main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.toolbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 20px 12px;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.toolbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.nav-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.period-label {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.segmented {
  display: flex;
  background: #eee9dd;
  border-radius: 9px;
  padding: 3px;
}

.segmented button {
  border: none;
  background: transparent;
  padding: 6px 14px;
  border-radius: 7px;
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.segmented button.is-active {
  background: #fff;
  color: var(--text);
  box-shadow: var(--shadow-soft);
}

.select {
  width: auto;
  min-width: 96px;
  padding: 7px 30px 7px 10px;
  font-size: 13px;
  background: #fff;
  color: var(--text);
}

.view-root {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0 20px 20px;
}

/* ---------------- Month view ---------------- */
.month-view {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-soft);
}

.weekday-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border-bottom: 1px solid var(--border);
  background: var(--panel-soft);
}

.weekday-row div {
  padding: 9px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-align: left;
}

.weekday-row div.is-weekend {
  color: #a8835b;
}

.month-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-auto-rows: minmax(96px, 1fr);
}

.month-cell {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 6px 6px 4px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
  min-width: 0;
  transition: background 0.12s;
}

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

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

.month-cell.is-outside {
  background: #fcfbf6;
}

.month-cell.is-outside .cell-date {
  color: var(--muted-2);
}

/* 周末：非常淡的一层米色底，和普通工作日区分开 */
.month-cell.is-weekend {
  background: #faf4e4;
}

.month-cell.is-weekend.is-outside {
  background: #fcf8ee;
}

.month-cell.is-today {
  background: #fbeccd;
}

.month-cell.is-today.is-weekend {
  background: #fae9c9;
}

.cell-head {
  display: flex;
  align-items: center;
  gap: 6px;
}

.cell-date {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.month-cell.is-today .cell-date {
  background: var(--primary);
  color: #fff;
}

.cell-events {
  display: flex;
  flex-direction: column;
  gap: 3px;
  overflow: hidden;
}

.event-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  border: none;
  border-left: 3px solid var(--chip-color, #c7c7cc);
  background: var(--chip-bg, rgba(199, 199, 204, 0.18));
  border-radius: 5px;
  padding: 2px 6px;
  font-size: 12px;
  line-height: 18px;
  text-align: left;
  cursor: pointer;
  color: var(--text);
  overflow: hidden;
}

.event-chip:hover {
  filter: brightness(0.97);
  box-shadow: inset 0 0 0 1px rgba(24, 30, 48, 0.08);
}

.event-chip .chip-time {
  color: var(--muted);
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
}

.event-chip .chip-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.event-chip.is-completed .chip-title {
  text-decoration: line-through;
  color: var(--muted);
}

.chip-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.more-link {
  border: none;
  background: transparent;
  color: var(--muted);
  text-align: left;
  font-size: 11px;
  padding: 1px 2px;
  cursor: pointer;
}

.more-link:hover {
  color: var(--primary);
}

/* ---------------- Week / day time view ---------------- */
.time-view {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-soft);
}

.time-header,
.allday-row {
  display: flex;
  background: var(--panel);
  position: sticky;
  z-index: 6;
}

.time-header {
  top: 0;
  border-bottom: 1px solid var(--border);
}

.time-header .time-gutter {
  width: 58px;
  flex: 0 0 58px;
}

.day-head {
  flex: 1;
  min-width: 0;
  padding: 7px 4px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  border-left: 1px solid var(--border);
}

.day-head .day-head-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 26px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin-top: 2px;
}

.day-head.is-today .day-head-num {
  background: var(--primary);
  color: #fff;
}

.day-head.is-weekend {
  background: #faf4e4;
}

.allday-row {
  top: 37px;
  border-bottom: 1px solid var(--border);
  min-height: 30px;
}

.allday-row .time-gutter {
  width: 58px;
  flex: 0 0 58px;
  font-size: 11px;
  color: var(--muted-2);
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 5px 8px 0 0;
}

.allday-cell {
  flex: 1;
  min-width: 0;
  border-left: 1px solid var(--border);
  padding: 3px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-height: 30px;
}

.allday-cell .event-chip {
  font-size: 11px;
}

.allday-cell.is-weekend {
  background: #faf4e4;
}

.time-scroll {
  height: clamp(320px, calc(100vh - 260px), 760px);
  min-height: 320px;
  overflow-y: auto;
  overflow-x: hidden;
}

.time-grid {
  display: flex;
  min-width: 100%;
}

.time-axis {
  width: 58px;
  flex: 0 0 58px;
  position: relative;
  height: var(--grid-height, 1152px);
}

.time-axis-label {
  position: absolute;
  right: 8px;
  transform: translateY(-50%);
  font-size: 11px;
  color: var(--muted-2);
  font-variant-numeric: tabular-nums;
}

.day-columns {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(var(--days, 7), minmax(0, 1fr));
}

.day-col {
  position: relative;
  height: var(--grid-height, 1152px);
  border-left: 1px solid var(--border);
  background-image: repeating-linear-gradient(
    to bottom,
    var(--border) 0,
    var(--border) 1px,
    transparent 1px,
    transparent 48px
  );
}

.day-col.is-weekend {
  background-color: #fbf6e9;
}

.day-col.is-today {
  background-color: #fcefd8;
}

.day-col.is-today.is-weekend {
  background-color: #fbeacb;
}

.hour-slot {
  position: absolute;
  left: 0;
  right: 0;
  height: 48px;
  cursor: pointer;
}

.hour-slot:hover {
  background: rgba(59, 111, 245, 0.045);
}

.timed-event {
  position: absolute;
  border: none;
  border-left: 4px solid var(--chip-color, #c7c7cc);
  background: var(--chip-bg, rgba(199, 199, 204, 0.2));
  border-radius: 6px;
  padding: 3px 6px;
  font-size: 11px;
  line-height: 1.35;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  z-index: 2;
  color: var(--text);
  box-shadow: 0 1px 2px rgba(24, 30, 48, 0.06);
}

.timed-event:hover {
  filter: brightness(0.97);
  box-shadow: 0 2px 8px rgba(24, 30, 48, 0.14);
  z-index: 3;
}

.timed-event .timed-time {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.timed-event .timed-title {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
}

.timed-event.is-completed .timed-title {
  text-decoration: line-through;
  color: var(--muted);
}

.timed-event .timed-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  font-size: 10px;
}

/* ---------------- Empty states ---------------- */
.empty-state {
  padding: 46px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.empty-state .empty-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

/* ---------------- Modal ---------------- */
.modal-overlay,
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 24, 38, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
  animation: fade-in 0.12s ease-out;
}

.confirm-overlay {
  z-index: 200;
  background: rgba(20, 24, 38, 0.5);
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.modal {
  width: min(560px, 100%);
  max-height: min(88vh, 900px);
  background: var(--panel);
  border-radius: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  animation: pop-in 0.14s ease-out;
}

.modal-wide {
  width: min(760px, 100%);
}

@keyframes pop-in {
  from {
    transform: translateY(8px) scale(0.99);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  margin: 0;
  font-size: 17px;
}

.modal-close {
  border: none;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
}

.modal-close:hover {
  background: #f1ece0;
  color: var(--text);
}

.modal-body {
  padding: 16px 20px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px 16px;
  border-top: 1px solid var(--border);
}

.modal-footer .footer-left {
  margin-right: auto;
}

/* ---------------- Forms ---------------- */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 14px;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-row.is-full {
  grid-column: 1 / -1;
}

.form-row > label,
.form-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.form-hint {
  font-size: 12px;
  color: var(--muted-2);
  line-height: 1.5;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
  user-select: none;
}

.checkbox-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}

.priority-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.priority-option {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
  background: #fff;
}

.priority-option input {
  display: none;
}

.priority-option .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.priority-option.is-selected {
  border-color: var(--primary);
  background: var(--primary-soft);
  font-weight: 600;
}

.reminder-box {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  background: var(--panel-soft);
}

.reminder-days {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin-top: 10px;
}

.reminder-days label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
}

.reminder-days input {
  accent-color: var(--primary);
}

.form-error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 10px;
  min-height: 18px;
}

/* ---------------- Settings ---------------- */
.settings-section {
  margin-bottom: 26px;
}

.settings-section:last-child {
  margin-bottom: 0;
}

.settings-section h4 {
  margin: 0 0 4px;
  font-size: 15px;
}

.settings-desc {
  margin: 0 0 12px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
}

.setting-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.setting-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
}

.setting-row input[type="color"] {
  width: 34px;
  height: 34px;
  padding: 2px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: #fff;
  cursor: pointer;
  flex: 0 0 auto;
}

.setting-row input[type="text"] {
  flex: 1;
  min-width: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 7px 9px;
  background: #f8f4ea;
}

.setting-row input[type="text"]:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(59, 111, 245, 0.12);
}

.setting-add {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.setting-empty {
  color: var(--muted-2);
  font-size: 13px;
  padding: 8px 2px;
}

.settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.backup-note {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.7;
  background: var(--panel-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-top: 10px;
}

/* ---------------- Confirm ---------------- */
.confirm-box {
  width: min(400px, 100%);
  background: #fff;
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 22px;
  animation: pop-in 0.14s ease-out;
}

.confirm-box h3 {
  margin: 0 0 8px;
  font-size: 17px;
}

.confirm-box p {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-line;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ---------------- Toast ---------------- */
.toast-root {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 300;
  pointer-events: none;
}

.toast {
  min-width: 180px;
  max-width: 360px;
  background: #242a38;
  color: #fff;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.5;
  box-shadow: 0 10px 26px rgba(20, 24, 38, 0.28);
  animation: toast-in 0.18s ease-out;
}

.toast.is-error {
  background: #b3262b;
}

.toast.is-success {
  background: #1e7a4c;
}

@keyframes toast-in {
  from {
    transform: translateY(6px);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

/* ---------------- Scrollbars ---------------- */
.view-root::-webkit-scrollbar,
.time-scroll::-webkit-scrollbar,
.modal-body::-webkit-scrollbar {
  width: 10px;
}

.view-root::-webkit-scrollbar-thumb,
.time-scroll::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb {
  background: #cfd4df;
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: content-box;
}

/* ---------------- Responsive ---------------- */
@media (max-width: 1100px) {
  .toolbar-right .select {
    display: none;
  }
}

@media (max-width: 820px) {
  :root {
    --header-h: auto;
  }

  .app-header {
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px 14px;
  }

  .tabs {
    order: 3;
    width: 100%;
    justify-content: center;
  }

  .header-actions {
    margin-left: auto;
  }

  .toolbar {
    padding: 10px 14px;
    gap: 10px;
  }

  .toolbar-right {
    width: 100%;
    margin-left: 0;
  }

  .view-root {
    padding: 0 10px 14px;
  }

  .period-label {
    font-size: 17px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .day-head .day-head-sub {
    display: none;
  }

  .month-grid {
    grid-auto-rows: minmax(74px, 1fr);
  }
}
