/* ===== Reset & Variables ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-primary: #6C5CE7;
  --color-primary-light: #a29bfe;
  --color-success: #00B894;
  --color-warning: #FDCB6E;
  --color-danger: #E17055;
  --color-info: #74b9ff;
  --color-bg: #F0F2F5;
  --color-card: #FFFFFF;
  --color-text: #2d3436;
  --color-text-secondary: #636e72;
  --color-border: #dfe6e9;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  --shadow-sm: 0 1px 4px rgba(0, 0, 0, 0.06);
  --transition: 0.2s ease;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
    'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ===== App Shell ===== */
.app {
  max-width: 500px;
  margin: 0 auto;
  padding: 0 16px 32px;
}

/* ===== Header ===== */
.header {
  position: sticky;
  top: 0;
  background: var(--color-bg);
  padding: 16px 0 0;
  z-index: 100;
}

.header-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 22px;
  font-weight: 700;
  color: var(--color-primary);
  margin-bottom: 12px;
}

.header-icon {
  flex-shrink: 0;
}

/* ===== Navigation ===== */
.nav {
  display: flex;
  background: var(--color-card);
  border-radius: var(--radius);
  padding: 4px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
}

.nav-btn {
  flex: 1;
  padding: 10px 0;
  border: none;
  background: transparent;
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-secondary);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.nav-btn:hover {
  color: var(--color-primary);
}

.nav-btn.active {
  background: var(--color-primary);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

/* ===== Views ===== */
.view {
  display: none;
}

.view.active {
  display: block;
  animation: fadeIn 0.25s ease;
}

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

/* ===== Card ===== */
.card {
  background: var(--color-card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

/* ===== Punch Mode ===== */
.punch-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 16px;
}

.punch-status-card {
  text-align: center;
  padding: 32px 20px;
}

.punch-icon-wrap {
  margin-bottom: 16px;
  color: var(--color-primary-light);
}

.punch-icon.pulse {
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.6; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.08); }
}

.punch-hint {
  font-size: 15px;
  color: var(--color-text-secondary);
}

.sleeping-card {
  background: linear-gradient(135deg, #2d1b69, #4a2d8a);
  color: #fff;
}

.sleeping-icon {
  color: #f1c40f;
}

.punch-sleeping-label {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 8px;
  letter-spacing: 2px;
}

.punch-sleeping-time {
  font-size: 14px;
  opacity: 0.85;
  margin-bottom: 4px;
}

.punch-elapsed {
  font-size: 14px;
  opacity: 0.85;
}

.punch-elapsed strong {
  font-size: 28px;
  display: block;
  margin-top: 8px;
}

.punch-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 18px;
  font-size: 18px;
  font-weight: 700;
  border-radius: var(--radius);
  letter-spacing: 1px;
}

.punch-btn-sleep {
  background: linear-gradient(135deg, #6C5CE7, #a29bfe);
  color: #fff;
  box-shadow: 0 4px 20px rgba(108, 92, 231, 0.35);
}

.punch-btn-sleep:hover {
  background: linear-gradient(135deg, #5b4bd5, #8e82f5);
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(108, 92, 231, 0.45);
}

.punch-btn-wake {
  background: linear-gradient(135deg, #f39c12, #f1c40f);
  color: #2d3436;
  box-shadow: 0 4px 20px rgba(243, 156, 18, 0.35);
}

.punch-btn-wake:hover {
  background: linear-gradient(135deg, #e67e22, #f39c12);
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(243, 156, 18, 0.45);
}

.punch-btn-cancel {
  display: block;
  width: 100%;
  padding: 12px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}

.punch-btn-cancel:hover {
  border-color: var(--color-danger);
  color: var(--color-danger);
}

/* ===== Button ===== */
.btn {
  display: block;
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
}

.btn-primary:hover {
  background: #5b4bd5;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(108, 92, 231, 0.4);
}

.btn-primary:active {
  transform: translateY(0);
}

/* ===== Today Summary ===== */
.today-summary {
  text-align: center;
}

.summary-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.summary-content {
  font-size: 15px;
  color: var(--color-text);
}

/* ===== History List ===== */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  background: var(--color-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.history-item:hover {
  box-shadow: var(--shadow);
}

.history-duration-badge {
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  line-height: 1.1;
  color: #fff;
}

.history-duration-badge .badge-unit {
  font-size: 10px;
  font-weight: 500;
  opacity: 0.85;
}

.badge-danger { background: var(--color-danger); }
.badge-warning { background: var(--color-warning); color: #2d3436; }
.badge-success { background: var(--color-success); }
.badge-info { background: var(--color-info); }

.history-info {
  flex: 1;
  min-width: 0;
}

.history-date {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 2px;
}

.history-times {
  font-size: 13px;
  color: var(--color-text-secondary);
}

.history-delete {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.history-delete:hover {
  background: rgba(225, 112, 85, 0.1);
  color: var(--color-danger);
}

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--color-text-secondary);
}

.empty-state svg {
  margin-bottom: 16px;
  opacity: 0.3;
}

.empty-state p {
  font-size: 16px;
  font-weight: 600;
}

.empty-sub {
  font-size: 13px !important;
  font-weight: 400 !important;
  margin-top: 4px;
  opacity: 0.7;
}

/* ===== Stats Cards ===== */
.stats-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.stat-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 12px;
  text-align: center;
}

.stat-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--color-primary);
}

/* ===== Chart Card ===== */
.chart-card {
  margin-bottom: 16px;
}

.chart-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: 12px;
}

.chart-container {
  position: relative;
  height: 250px;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--color-text);
  color: #fff;
  padding: 12px 24px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
  transition: transform 0.3s ease, opacity 0.3s ease;
  opacity: 0;
  z-index: 1000;
  white-space: nowrap;
}

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

/* ===== Responsive ===== */
@media (max-width: 640px) {
  .app {
    padding: 0 12px 24px;
  }

  .header-title {
    font-size: 20px;
  }

  .duration-value {
    font-size: 20px;
  }

  .stat-value {
    font-size: 18px;
  }

  .chart-container {
    height: 200px;
  }
}
