:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --panel: #ffffff;
  --panel-soft: #f8fbfd;
  --text: #172033;
  --muted: #667085;
  --line: #d9e2ec;
  --accent: #0f766e;
  --accent-strong: #0b5e59;
  --accent-soft: #e7f4f2;
  --secondary: #3b5bdb;
  --secondary-soft: #e9eeff;
  --month: #3b5bdb;
  --month-line: #bdc8ff;
  --warn: #b42318;
  --warn-soft: #fee4e2;
  --shadow: 0 12px 34px rgba(23, 32, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans TC", "Microsoft JhengHei", Arial, sans-serif;
  line-height: 1.5;
}

a {
  color: var(--accent);
}

button,
input,
select {
  font: inherit;
}

button {
  width: fit-content;
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  padding: 0 16px;
  cursor: pointer;
  font-weight: 700;
}

button:hover {
  background: var(--accent-strong);
}

button.ghost {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

button.danger {
  background: var(--warn-soft);
  color: var(--warn);
}

button.confirm-delete {
  background: var(--warn);
  color: #fff;
}

input,
select {
  min-height: 42px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 8px 10px;
}

label span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 18px;
  padding: 14px clamp(16px, 3vw, 34px);
  border-bottom: 1px solid var(--line);
  background: rgba(244, 247, 251, 0.94);
  backdrop-filter: blur(10px);
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 20px;
  font-weight: 900;
}

.brand-icon {
  display: block;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
}

nav {
  display: flex;
  gap: 8px;
}

.nav-link {
  border-radius: 999px;
  color: var(--muted);
  padding: 8px 12px;
  text-decoration: none;
  font-weight: 700;
}

.nav-link.active,
.nav-link:hover {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.header-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px 12px;
  text-align: right;
}

.header-actions {
  flex-wrap: nowrap;
}

.external-link {
  display: inline-grid;
  width: 26px;
  height: 26px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 6px;
  text-decoration: none;
}

.external-link img {
  display: block;
  width: 22px;
  height: 22px;
}

.view-stats {
  color: var(--secondary);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.version,
.muted {
  color: var(--muted);
  font-size: 14px;
}

.page-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 22px auto 56px;
}

.panel {
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: clamp(16px, 2.5vw, 26px);
}

.hero-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  background: linear-gradient(135deg, #ffffff 0%, #edf7f5 100%);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 14px;
  font-weight: 900;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(30px, 5vw, 46px);
  line-height: 1.12;
}

h2 {
  margin-bottom: 14px;
  font-size: 22px;
}

.section-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
}

.section-title {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  align-items: baseline;
  gap: 12px;
}

.today-date {
  color: var(--accent-strong);
  font-weight: 900;
  white-space: nowrap;
}

.inline-form,
.stock-form {
  display: grid;
  grid-template-columns: minmax(160px, 0.6fr) minmax(220px, 1fr) auto;
  align-items: end;
  gap: 12px;
  margin-bottom: 18px;
}

.stock-form {
  grid-template-columns: 1fr;
  align-items: stretch;
}

.grow {
  min-width: 0;
}

.timeline {
  display: grid;
  gap: 10px;
}

.month-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px 0 2px;
  color: var(--month);
  font-weight: 900;
}

.month-divider::after {
  content: "";
  height: 1px;
  flex: 1;
  background: var(--month-line);
}

.event-row,
.other-row {
  display: grid;
  grid-template-columns: 150px 1fr auto;
  gap: 12px;
  align-items: center;
  border: 1px solid #e5edf5;
  border-radius: 8px;
  padding: 10px;
}

.draggable-row,
.draggable-card {
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease, opacity 0.16s ease;
}

.draggable-row:hover,
.draggable-card:hover {
  border-color: #9fb0ff;
  box-shadow: 0 10px 24px rgba(59, 91, 219, 0.12);
}

.draggable-row.is-dragging,
.draggable-card.is-dragging {
  opacity: 0.45;
  transform: scale(0.99);
}

.icon-button,
.drag-handle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  min-width: 44px;
  height: 44px;
  min-height: 44px;
  border-radius: 8px;
  padding: 0;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 900;
}

.icon-button svg,
.drag-handle svg {
  display: block;
  width: 30px;
  height: 30px;
  fill: currentColor;
}

.icon-button:hover,
.drag-handle:hover {
  background: var(--accent);
  color: #fff;
}

.drag-handle {
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
}

.drag-handle:active {
  cursor: grabbing;
}

.sortable-chosen {
  border-color: var(--secondary);
  box-shadow: 0 16px 34px rgba(59, 91, 219, 0.24);
}

.sortable-ghost {
  opacity: 0.28;
  background: var(--secondary-soft);
}

.sortable-drag {
  cursor: grabbing;
  box-shadow: 0 24px 54px rgba(23, 32, 51, 0.28);
  opacity: 0.96;
}

.sort-highlight {
  animation: sortPulse 1.05s ease-out;
  border-color: #14b8a6 !important;
  box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.18), 0 14px 30px rgba(20, 184, 166, 0.14) !important;
}

@keyframes sortPulse {
  0% {
    background: #ccfbf1;
  }
  100% {
    background: inherit;
  }
}

.mobile-drag-clone {
  position: fixed;
  z-index: 9999;
  pointer-events: none;
  box-shadow: 0 28px 64px rgba(23, 32, 51, 0.32);
  opacity: 0.98;
  transform: rotate(0.5deg);
}

.mobile-drag-source {
  opacity: 0.28;
  outline: 2px dashed var(--secondary);
  outline-offset: -4px;
}

.mobile-sort-active .stock-card,
.mobile-sort-active .other-row {
  transition: transform 0.12s ease, opacity 0.12s ease, box-shadow 0.12s ease;
}

.expand-button {
  background: var(--secondary-soft);
  color: var(--secondary);
}

.expand-button:hover {
  background: var(--secondary);
  color: #fff;
}

.event-row.has-actions {
  grid-template-columns: 150px 1fr auto;
}

.other-row.has-actions {
  grid-template-columns: 1fr;
  align-items: start;
}

.other-row.has-actions .row-actions {
  border-top: 1px solid var(--line);
  justify-content: flex-start;
  margin-top: 2px;
  padding-top: 10px;
  width: 100%;
}

.other-row-main {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: start;
  gap: 12px;
  width: 100%;
}

.other-link-text {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.other-link-text a {
  overflow-wrap: anywhere;
}

.other-tools {
  display: flex;
  justify-content: flex-end;
}

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

.event-date {
  color: var(--accent-strong);
  font-weight: 900;
  white-space: nowrap;
}

.event-row.event-today {
  border-color: #f59e0b;
  background: #fff7ed;
  box-shadow: 0 10px 24px rgba(245, 158, 11, 0.16);
}

.event-row.event-today .event-date {
  color: #b45309;
}

.event-row.event-past {
  background: #f8fafc;
  color: #8a94a6;
}

.event-row.event-past .event-date {
  color: #98a2b3;
}

.event-row.event-upcoming {
  background: #fff;
}

.feature-link {
  display: block;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 18px;
  color: var(--accent-strong);
  text-decoration: none;
  font-size: 22px;
  font-weight: 900;
}

.manage-link {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--secondary-soft);
  color: var(--secondary);
  padding: 10px 14px;
  text-decoration: none;
  font-weight: 900;
}

.back-link {
  color: var(--accent-strong);
  font-weight: 900;
  text-decoration: none;
}

.editor-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
  padding: 8px;
}

.toolbar button,
.toolbar select,
.toolbar input[type="color"] {
  width: auto;
  min-width: 42px;
  min-height: 36px;
  padding: 4px 10px;
}

.toolbar input[type="color"] {
  padding: 3px;
}

.rich-editor {
  min-height: 112px;
  overflow-wrap: anywhere;
  padding: 12px;
  outline: none;
}

.title-editor {
  min-height: 74px;
}

.rich-editor:empty::before {
  content: attr(data-placeholder);
  color: #9aa4ad;
}

.event-text,
.rich-title {
  overflow-wrap: anywhere;
}

.rich-title {
  display: block;
}

.stock-groups {
  display: grid;
  gap: 18px;
  margin-bottom: 22px;
}

.form-section-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 26px 0 16px;
  color: var(--secondary);
  font-size: 14px;
  font-weight: 900;
}

.form-section-divider::before,
.form-section-divider::after {
  content: "";
  height: 1px;
  flex: 1;
  background: var(--month-line);
}

.stock-category-group {
  display: grid;
  gap: 10px;
}

.stock-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.stock-card {
  display: flex;
  min-height: 170px;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
}

.card-topbar {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: start;
  gap: 10px;
  margin-bottom: 10px;
}

.card-tools {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.stock-card h3 {
  margin-bottom: 0;
  padding-top: 3px;
  font-size: 19px;
}

.stock-body {
  flex: 1;
  overflow-wrap: anywhere;
}

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

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 8px;
}

.category-manager {
  margin-top: 20px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.category-manager h3 {
  margin-bottom: 12px;
  font-size: 18px;
}

.compact-form {
  grid-template-columns: minmax(220px, 1fr) auto auto;
}

.category-list {
  display: grid;
  gap: 8px;
}

.category-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) auto auto auto;
  gap: 10px;
  align-items: center;
  border: 1px solid #e5edf5;
  border-radius: 8px;
  padding: 10px;
}

.other-list {
  display: grid;
  gap: 10px;
}

.other-row {
  grid-template-columns: 1fr;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: rgba(23, 32, 51, 0.46);
  padding: 20px;
  animation: modalFadeIn 0.18s ease-out;
}

.stock-modal {
  width: min(760px, 100%);
  max-height: min(86vh, 820px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(23, 32, 51, 0.28);
  padding: clamp(18px, 3vw, 28px);
  animation: modalZoomIn 0.2s ease-out;
  transform-origin: center;
}

.modal-backdrop.is-closing {
  animation: modalFadeOut 0.18s ease-in forwards;
}

.modal-backdrop.is-closing .stock-modal {
  animation: modalZoomOut 0.18s ease-in forwards;
}

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

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

@keyframes modalZoomIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes modalZoomOut {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateY(8px) scale(0.96);
  }
}

.stock-modal-main {
  display: grid;
  gap: 12px;
}

.stock-modal-category {
  width: fit-content;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 900;
}

.stock-modal h2 {
  margin-bottom: 0;
  font-size: clamp(24px, 4vw, 34px);
}

.stock-modal-body {
  overflow-wrap: anywhere;
  border-top: 1px solid var(--line);
  padding-top: 14px;
  font-size: 18px;
}

.stock-modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
}

.help-backdrop[hidden] {
  display: none;
}

.help-modal {
  width: min(560px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(23, 32, 51, 0.28);
  padding: clamp(18px, 3vw, 28px);
  animation: modalZoomIn 0.2s ease-out;
}

.help-content {
  display: grid;
  gap: 10px;
}

.help-content p {
  margin-bottom: 0;
}

.help-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 20px;
}

.floating-actions {
  position: fixed;
  right: clamp(14px, 3vw, 28px);
  bottom: clamp(14px, 3vw, 28px);
  z-index: 25;
  display: grid;
  gap: 10px;
}

.floating-button {
  width: 48px;
  min-width: 48px;
  height: 48px;
  min-height: 48px;
  border-radius: 999px;
  padding: 0;
  box-shadow: 0 14px 32px rgba(23, 32, 51, 0.18);
  font-size: 22px;
}

.release-notes {
  display: grid;
  gap: 10px;
}

.release-notes h2 {
  margin: 18px 0 4px;
  color: var(--secondary);
  font-size: 20px;
}

.release-notes h2:first-child {
  margin-top: 0;
}

.release-list {
  margin: 0 0 8px;
  padding-left: 22px;
}

.release-list li {
  margin-bottom: 6px;
}

.empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 18px;
  text-align: center;
}

@media (max-width: 900px) {
  .section-grid,
  .stock-grid {
    grid-template-columns: 1fr;
  }

  .inline-form,
  .stock-form,
  .compact-form {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .site-header {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .header-meta {
    justify-content: flex-start;
    text-align: left;
  }

  .view-stats {
    white-space: normal;
  }

  nav {
    overflow-x: auto;
  }

  .hero-panel,
  .section-title {
    align-items: flex-start;
  }

  .section-title {
    grid-template-columns: 1fr;
  }

  .today-date {
    white-space: normal;
  }

  .icon-button,
  .drag-handle {
    width: 48px;
    min-width: 48px;
    height: 48px;
    min-height: 48px;
  }

  .icon-button svg,
  .drag-handle svg {
    width: 32px;
    height: 32px;
  }

  .event-row,
  .other-row,
  .category-row {
    grid-template-columns: 1fr;
  }

  .other-row-main,
  .card-topbar {
    grid-template-columns: 1fr auto;
  }

  .event-row.has-actions {
    grid-template-columns: 1fr;
  }

  .event-row.has-actions .event-date,
  .event-row.has-actions .row-actions {
    width: 100%;
  }

  .event-row.has-actions .row-actions {
    border-top: 1px solid var(--line);
    margin-top: 2px;
    padding-top: 10px;
  }

  .form-actions {
    align-items: center;
  }

  .row-actions,
  .card-actions,
  .stock-modal-actions {
    justify-content: flex-start;
  }

  button,
  .manage-link,
  .feature-link {
    max-width: 100%;
  }
}
