:root {
  --bg: #f4efe7;
  --ink: #2a2319;
  --muted: #716552;
  --paper: #fffef9;
  --line: #d0c2ae;
  --panel-shadow: 0 18px 50px rgba(52, 39, 16, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "IBM Plex Sans", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
}

.page-bg {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(1200px 600px at 90% 10%, rgba(252, 171, 92, 0.35), transparent 60%),
    radial-gradient(1000px 700px at 5% 100%, rgba(179, 207, 255, 0.3), transparent 70%),
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.35) 0 2px, transparent 2px 7px);
  pointer-events: none;
}

.app-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(360px, 520px) minmax(520px, 1fr);
  gap: 18px;
  padding: 20px;
}

.panel {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.82), rgba(255, 254, 248, 0.96));
  border: 1px solid rgba(130, 98, 59, 0.2);
  border-radius: 20px;
  box-shadow: var(--panel-shadow);
  padding: 18px;
  backdrop-filter: blur(2px);
}

.eyebrow {
  margin: 0;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 0.75rem;
  color: #a55a1b;
}

h1 {
  margin: 4px 0;
  font-size: clamp(1.45rem, 2vw, 1.9rem);
  font-family: "Avenir Next Condensed", "DIN Condensed", "Helvetica Neue", sans-serif;
}

.muted {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.92rem;
}

.hidden {
  display: none !important;
}

.event-form label {
  display: block;
  font-size: 0.88rem;
  color: var(--muted);
}

input {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.8);
  padding: 8px 10px;
  margin-top: 5px;
  font: inherit;
  color: var(--ink);
}

input:focus {
  outline: 2px solid rgba(80, 122, 194, 0.35);
  border-color: #7ca2d8;
}

.row-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 8px;
}

.actions {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fffaf0;
  color: #4b3b24;
  padding: 8px 12px;
  font-weight: 600;
  cursor: pointer;
}

.btn:hover {
  filter: brightness(0.97);
}

.btn-primary {
  background: linear-gradient(135deg, #ffba64, #ff8c39);
  border-color: rgba(158, 92, 30, 0.45);
}

.btn-danger {
  background: linear-gradient(135deg, #ffd0cc, #ffb1aa);
  border-color: rgba(166, 63, 45, 0.45);
}

.status {
  min-height: 24px;
  margin: 10px 0 8px;
  font-size: 0.9rem;
  color: #503d2b;
}

.status.ok {
  color: #1e6a30;
}

.status.warn {
  color: #92470f;
}

.status.err {
  color: #a22f2f;
}

.table-wrap {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: auto;
  max-height: 48vh;
  background: rgba(255, 255, 255, 0.7);
}

.event-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

.event-table th,
.event-table td {
  border-bottom: 1px solid rgba(205, 187, 160, 0.65);
  padding: 8px 6px;
  text-align: left;
}

.event-table thead th {
  position: sticky;
  top: 0;
  background: #f5ecdd;
  z-index: 2;
}

.event-table td input {
  margin: 0;
  padding: 5px 7px;
  font-size: 0.82rem;
}

.panel-viz {
  display: grid;
  grid-template-rows: auto auto minmax(280px, 1fr) auto;
  gap: 8px;
}

#sphere-stage {
  width: 100%;
  height: min(64vh, 540px);
  border-radius: 16px;
  border: 1px solid rgba(114, 94, 69, 0.22);
  background:
    radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.7), rgba(244, 235, 219, 0.75) 65%, rgba(216, 201, 178, 0.65)),
    #f8f2e8;
  overflow: hidden;
  position: relative;
}

/* Calendar Strip */
.calendar-strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 2px 2px 4px;
  margin: -6px 0 2px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
  align-items: center;
}

.calendar-item {
  flex: 0 0 auto;
  min-width: 126px;
  text-align: center;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid var(--line);
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
  user-select: none;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.calendar-item:hover {
  transform: translateY(-2px);
  background: #fffbf5;
  border-color: #ba9e74;
  box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.calendar-item.active {
  background: linear-gradient(135deg, #fff0d4, #ffeacc);
  border-color: #e6b062;
  box-shadow: 0 4px 12px rgba(230, 176, 98, 0.3);
  transform: scale(1.05);
}

.calendar-item .month {
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 2px;
  letter-spacing: 0.5px;
}

.calendar-item .date {
  font-size: 1.08rem;
  font-weight: 700;
  color: var(--ink);
  font-family: "IBM Plex Sans", "Noto Sans SC", sans-serif;
  line-height: 1.05;
}

.calendar-actions {
  margin: 0 0 2px;
}

.recent-7d-btn {
  font-size: 0.96rem;
  padding: 10px 18px;
}

.recent-7d-btn.active {
  background: linear-gradient(135deg, #ffc46e, #ff8e3d);
  border-color: rgba(158, 92, 30, 0.5);
}

#sphere-stage canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(160px, 1fr));
  gap: 8px;
}

.stat-card {
  border-radius: 14px;
  border: 1px solid rgba(99, 74, 46, 0.25);
  padding: 10px;
  background: rgba(255, 255, 255, 0.84);
}

.stat-title {
  margin: 0 0 6px;
  font-size: 0.86rem;
  color: #4c3b2a;
}

.chip {
  display: inline-block;
  min-width: 42px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid rgba(79, 64, 43, 0.18);
  font-size: 0.78rem;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .panel-viz {
    grid-template-rows: auto auto minmax(240px, 1fr) auto;
  }

  #sphere-stage {
    height: 420px;
  }
}

/* Overlays */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.4);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  transition: opacity 0.2s;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
  display: none;
}

.login-card {
  background: rgba(255, 255, 255, 0.9);
  padding: 32px;
  border-radius: 20px;
  box-shadow: 0 25px 80px rgba(78, 59, 31, 0.15);
  border: 1px solid white;
  width: 90%;
  max-width: 360px;
}

.history-card {
  width: 90%;
  max-width: 900px; /* Widen for charts */
  height: 85vh;
  display: flex;
  flex-direction: column;
  background: white;
  box-shadow: 0 40px 100px rgba(0,0,0,0.2);
  padding: 24px;
}

.history-layout {
  display: flex;
  gap: 24px;
  flex: 1;
  overflow: hidden;
}

.history-sidebar {
  flex: 0 0 280px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  padding-right: 16px;
  overflow-y: auto;
}

.history-charts {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding-right: 8px;
}

.chart-container {
  background: #fffcf5;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  min-height: 200px;
  position: relative;
}

.history-item {
  padding: 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
  border-bottom: 1px solid rgba(205, 187, 160, 0.4);
}

.history-item:hover {
  background: #fdf6e7;
}

.history-item.active {
  background: #fff0d4;
  border-color: #e6b062;
}

.history-list {
  flex: 1;
  overflow-y: auto;
}

@media (max-width: 800px) {
  .history-layout {
    flex-direction: column;
  }
  .history-sidebar {
    flex: 0 0 200px;
    border-right: none;
    border-bottom: 1px solid var(--line);
    padding-bottom: 16px;
  }
}

.history-item:last-child {
  border-bottom: none;
}

.history-date {
  font-weight: 600;
  color: var(--ink);
  font-size: 0.95rem;
}

.history-summary {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 4px;
}
