/* ========================================================
   DAILY PLANNER — Design System
   Premium warm-paper aesthetic, tablet-first
   ======================================================== */

/* ---- CSS Custom Properties ---- */
:root {
  /* Backgrounds */
  --bg-primary: #FAF6F0;
  --bg-surface: #FFFFFF;
  --bg-surface-hover: #F5F0E8;
  --bg-header: #1B2A4A;
  --bg-header-light: #243556;

  /* Text */
  --text-primary: #1A1A2E;
  --text-secondary: #6B7280;
  --text-tertiary: #9CA3AF;
  --text-inverse: #F9FAFB;
  --text-header: #E8DCC8;

  /* Accent */
  --accent-gold: #C9A84C;
  --accent-gold-light: rgba(201, 168, 76, 0.12);
  --accent-gold-medium: rgba(201, 168, 76, 0.25);
  --accent-gold-solid: #D4B85C;

  /* Borders */
  --border-grid: #E0D8CC;
  --border-light: #EDE8DF;
  --border-focus: #C9A84C;

  /* Semantic */
  --success: #2D8A4E;
  --success-bg: rgba(45, 138, 78, 0.1);
  --danger: #C0392B;
  --danger-bg: rgba(192, 57, 43, 0.08);
  --info: #2563EB;
  --warning: #D97706;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(27, 42, 74, 0.06);
  --shadow-md: 0 4px 12px rgba(27, 42, 74, 0.08);
  --shadow-lg: 0 8px 24px rgba(27, 42, 74, 0.12);
  --shadow-overlay: 0 -4px 32px rgba(27, 42, 74, 0.18);

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 24px;
  --space-2xl: 32px;

  /* Radii */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  /* Typography */
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-size-xs: 11px;
  --font-size-sm: 13px;
  --font-size-base: 15px;
  --font-size-lg: 17px;
  --font-size-xl: 20px;
  --font-size-2xl: 24px;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --transition-spring: 300ms cubic-bezier(0.34, 1.56, 0.64, 1);

  /* Layout */
  --top-bar-height: 52px;
  --tab-bar-height: 44px;
  --history-banner-height: 32px;
}

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

html {
  font-size: var(--font-size-base);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-family);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  overflow: hidden;
  height: 100dvh;
  width: 100dvw;
  position: fixed;
  top: 0;
  left: 0;
  /* Subtle warm noise texture */
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(201, 168, 76, 0.04) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(201, 168, 76, 0.03) 0%, transparent 50%);
}

/* ---- App Shell ---- */
.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

/* Top Navigation Bar Removed */

.date-nav {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.nav-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  color: var(--text-inverse);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.nav-btn:hover,
.nav-btn:active {
  background: rgba(255, 255, 255, 0.12);
}

.date-display {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-xs) var(--space-md);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-md);
  color: var(--text-inverse);
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition-fast);
  min-width: 170px;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.date-display:hover,
.date-display:active {
  background: rgba(255, 255, 255, 0.15);
}

.date-picker-hidden {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.today-btn {
  padding: var(--space-xs) var(--space-md);
  background: var(--accent-gold);
  color: var(--bg-header);
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-family);
  font-size: var(--font-size-xs);
  font-weight: 700;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: all var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.today-btn:hover {
  background: var(--accent-gold-solid);
  transform: scale(1.02);
}

.today-btn.is-today {
  background: rgba(255, 255, 255, 0.12);
  color: var(--accent-gold);
}

/* Floating Save Indicator */
.floating-save {
  position: fixed;
  bottom: var(--space-xl);
  left: var(--space-xl);
  background: var(--bg-header);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  z-index: 9999;
  color: var(--text-inverse);
}

.save-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  opacity: 0;
  transition: opacity var(--transition-normal);
  font-size: var(--font-size-xs);
  color: rgba(255, 255, 255, 0.7);
}

.save-indicator.visible {
  opacity: 1;
}

.save-indicator.saving .save-text::after {
  content: '...';
}

.save-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
}

.save-indicator.saving .save-dot {
  background: var(--accent-gold);
  animation: pulse-dot 1s ease infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.7); }
}

/* ---- History Banner ---- */
.history-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  height: var(--history-banner-height);
  background: linear-gradient(135deg, #FFF3E0, #FDE8CD);
  color: #8B6914;
  font-size: var(--font-size-xs);
  font-weight: 600;
  letter-spacing: 0.3px;
  flex-shrink: 0;
  border-bottom: 1px solid #E8D5B0;
}

.history-banner.hidden {
  display: none;
}

/* ---- Tab Bar ---- */
.tab-bar {
  display: flex;
  align-items: stretch;
  height: var(--tab-bar-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-grid);
  flex-shrink: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.tab-bar::-webkit-scrollbar {
  display: none;
}

.tab-item {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-width: 0;
  padding: 0 var(--space-md);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-family);
  font-size: var(--font-size-sm);
  font-weight: 600;
  cursor: pointer;
  position: relative;
  transition: color var(--transition-fast);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-tap-highlight-color: transparent;
}

.tab-item::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%) scaleX(0);
  width: 60%;
  height: 3px;
  background: var(--accent-gold);
  border-radius: 3px 3px 0 0;
  transition: transform var(--transition-normal);
}

.tab-item.active {
  color: var(--accent-gold);
}

.tab-item.active::after {
  transform: translateX(-50%) scaleX(1);
}

.tab-item:hover:not(.active) {
  color: var(--text-primary);
}

/* ---- Main Content (Sheet Container) ---- */
.sheet-container {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

/* ---- Loading State ---- */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: var(--space-lg);
  color: var(--text-secondary);
}

.loading-state.hidden {
  display: none;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border-grid);
  border-top-color: var(--accent-gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---- Update Toast ---- */
.update-toast {
  position: fixed;
  bottom: var(--space-lg);
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-header);
  color: var(--text-inverse);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 9999;
  transition: transform var(--transition-spring);
  font-size: var(--font-size-sm);
}

.update-toast.visible {
  transform: translateX(-50%) translateY(0);
}

.update-toast.hidden {
  transform: translateX(-50%) translateY(100px);
}

.toast-content {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.toast-btn {
  padding: 6px 14px;
  background: var(--accent-gold);
  color: var(--bg-header);
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-family);
  font-size: var(--font-size-xs);
  font-weight: 700;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.toast-btn:hover {
  background: var(--accent-gold-solid);
}

.toast-dismiss {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-inverse);
  border-radius: 50%;
  cursor: pointer;
}

/* ---- Utility Classes ---- */
.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* ---- Scrollbar Styling (Desktop) ---- */
@media (pointer: fine) {
  .sheet-container::-webkit-scrollbar {
    width: 6px;
    height: 6px;
  }
  .sheet-container::-webkit-scrollbar-track {
    background: transparent;
  }
  .sheet-container::-webkit-scrollbar-thumb {
    background: var(--border-grid);
    border-radius: 3px;
  }
  .sheet-container::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
  }
}

/* ---- Responsive: Landscape ---- */
@media (orientation: landscape) {
  :root {
    --font-size-base: 14px;
  }
}

/* ---- Responsive: Desktop ---- */
@media (min-width: 1024px) {
  :root {
    --font-size-base: 15px;
    --top-bar-height: 56px;
  }

  .date-display {
    min-width: 200px;
  }
}

/* ===================== PASSWORD LOCK SCREEN ===================== */
.lock-overlay {
  position: fixed;
  inset: 0;
  background: transparent;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.lock-overlay.hidden {
  display: none;
}

.lock-circle-transition {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0px;
  height: 0px;
  border-radius: 50%;
  box-shadow: 0 0 0 4000px #1B2A4A;
  transform: translate(-50%, -50%);
  z-index: 1;
  pointer-events: none;
}

.lock-card {
  background: var(--bg-surface);
  padding: var(--space-2xl);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(255, 255, 255, 0.05);
  text-align: center;
  max-width: 400px;
  width: 90%;
  position: relative;
  z-index: 2;
  animation: lockFadeIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

.lock-icon {
  width: 64px;
  height: 64px;
  background: var(--accent-gold-light);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto var(--space-md);
}

.lock-title {
  font-size: var(--font-size-2xl);
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 var(--space-xs);
}

.lock-subtitle {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  margin: 0 0 var(--space-xl);
  line-height: 1.5;
}

.lock-input-group {
  display: flex;
  align-items: center;
  background: var(--bg-primary);
  border: 1px solid var(--border-grid);
  border-radius: var(--radius-md);
  padding: 4px;
  transition: border-color var(--transition-fast);
}

.lock-input-group:focus-within {
  border-color: var(--accent-gold-solid);
}

.lock-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: var(--font-size-md);
  padding: var(--space-sm) var(--space-md);
  outline: none;
}

.lock-input::placeholder {
  color: var(--text-tertiary);
}

.lock-btn {
  background: var(--accent-gold-solid);
  color: #fff;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--transition-fast), transform var(--transition-fast);
}

.lock-btn:hover {
  background: var(--accent-gold);
}

.lock-btn:active {
  transform: scale(0.95);
}

.lock-error {
  color: #E74C3C;
  font-size: var(--font-size-xs);
  margin-top: var(--space-sm);
  animation: shake 0.4s ease-in-out;
}

.lock-error.hidden {
  display: none;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.lock-overlay.animating .lock-circle-transition {
  animation: holeExpand 0.8s cubic-bezier(0.65, 0, 0.35, 1) forwards;
}

.lock-overlay.animating .lock-card {
  opacity: 0;
  transition: opacity 0.3s ease;
}

@keyframes holeExpand {
  0% { width: 0px; height: 0px; box-shadow: 0 0 0 4000px #1B2A4A; }
  100% { width: 300vmax; height: 300vmax; box-shadow: 0 0 0 0px #1B2A4A; }
}
