/* ===== CSS Variables & Reset ===== */
:root {
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-card: rgba(30, 30, 60, 0.7);
  --bg-card-hover: rgba(40, 40, 80, 0.8);
  --bg-glass: rgba(255, 255, 255, 0.05);
  --bg-input: rgba(255, 255, 255, 0.08);
  --text-primary: #e8e8f0;
  --text-secondary: #9898b8;
  --text-muted: #6868a0;
  --accent: #7c4dff;
  --accent-light: #b388ff;
  --accent-glow: rgba(124, 77, 255, 0.3);
  --danger: #ff5252;
  --danger-dark: #c62828;
  --success: #69f0ae;
  --warning: #ffd740;
  --border: rgba(255, 255, 255, 0.08);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 6px;
  --header-height: 56px;
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Hiragino Sans',
    'Hiragino Kaku Gothic ProN', 'Noto Sans JP', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Background gradient mesh */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(ellipse at 20% 20%, rgba(124, 77, 255, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 80%, rgba(0, 150, 255, 0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 50%, rgba(255, 0, 128, 0.04) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* ===== Header ===== */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: calc(var(--header-height) + var(--safe-top));
  padding-top: var(--safe-top);
  display: flex;
  align-items: center;
  padding-left: 16px;
  padding-right: 16px;
  background: rgba(15, 15, 26, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}

.header-back {
  background: none;
  border: none;
  color: var(--accent-light);
  cursor: pointer;
  padding: 8px;
  margin-left: -8px;
  margin-right: 4px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
}

.header-back:active {
  background: var(--bg-glass);
}

.header-title {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-spacer {
  width: 40px;
}

/* ===== Views ===== */
.view {
  display: none;
  padding-top: calc(var(--header-height) + var(--safe-top) + 16px);
  padding-bottom: calc(80px + var(--safe-bottom));
  padding-left: 16px;
  padding-right: 16px;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
  z-index: 1;
  animation: fadeIn 0.3s ease;
}

.view.active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeOut {
  from {
    opacity: 1;
    transform: translateY(0);
  }

  to {
    opacity: 0;
    transform: translateY(-8px);
  }
}

/* ===== Empty State ===== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  text-align: center;
  color: var(--text-secondary);
}

.empty-icon {
  font-size: 4rem;
  margin-bottom: 16px;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-10px);
  }
}

.empty-state p {
  font-size: 1rem;
  margin-bottom: 4px;
}

.empty-sub {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ===== Schedule List ===== */
.schedule-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.schedule-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: all var(--transition);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  position: relative;
  overflow: hidden;
}

.schedule-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: linear-gradient(180deg, var(--accent), var(--accent-light));
  border-radius: 4px 0 0 4px;
}

.schedule-card:active {
  transform: scale(0.98);
  background: var(--bg-card-hover);
}

.schedule-card.past {
  opacity: 0.5;
}

.schedule-card.past::before {
  background: var(--text-muted);
}

.schedule-card-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 6px;
  padding-left: 12px;
}

.schedule-card-datetime {
  font-size: 0.85rem;
  color: var(--text-secondary);
  padding-left: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.schedule-card-notify {
  font-size: 0.75rem;
  color: var(--accent-light);
  padding-left: 12px;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.schedule-card-notify.off {
  color: var(--text-muted);
}

.notify-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 600;
}

.notify-badge.on {
  background: rgba(124, 77, 255, 0.2);
  color: var(--accent-light);
}

.notify-badge.off {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
}

/* ===== FAB ===== */
.fab {
  position: fixed;
  bottom: calc(24px + var(--safe-bottom));
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #536dfe);
  border: none;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px var(--accent-glow), var(--shadow);
  cursor: pointer;
  z-index: 50;
  transition: all var(--transition);
}

.fab:active {
  transform: scale(0.9);
}

@keyframes pulse {

  0%,
  100% {
    box-shadow: 0 4px 20px var(--accent-glow), var(--shadow);
  }

  50% {
    box-shadow: 0 4px 30px rgba(124, 77, 255, 0.5), var(--shadow);
  }
}

.fab:not(:active) {
  animation: pulse 2s ease-in-out infinite;
}

/* ===== Capture View ===== */
.capture-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 70vh;
  gap: 16px;
}

.capture-hero {
  text-align: center;
  margin-bottom: 16px;
}

.capture-icon {
  font-size: 4rem;
  margin-bottom: 12px;
}

.capture-hero h2 {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.capture-hero p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  max-width: 280px;
  line-height: 1.6;
}

.capture-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  max-width: 300px;
  padding: 16px 24px;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  border: none;
  font-family: inherit;
  background: linear-gradient(135deg, var(--accent), #536dfe);
  color: white;
  box-shadow: 0 4px 16px var(--accent-glow);
}

.capture-btn:active {
  transform: scale(0.97);
}

.capture-btn.secondary {
  background: var(--bg-glass);
  border: 1px solid var(--border);
  color: var(--text-primary);
  box-shadow: none;
}

.capture-btn.secondary:active {
  background: var(--bg-input);
}

.capture-btn.tertiary {
  background: transparent;
  color: var(--text-secondary);
  box-shadow: none;
  font-weight: 500;
  font-size: 0.9rem;
}

/* ===== Edit View ===== */
.edit-container {
  max-width: 500px;
  margin: 0 auto;
}

.image-preview-wrapper {
  position: relative;
  margin-bottom: 20px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

.image-preview {
  width: 100%;
  max-height: 200px;
  object-fit: cover;
  display: block;
}

.image-remove {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  border: none;
  color: white;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
}

.image-remove:active {
  background: rgba(255, 0, 0, 0.5);
}

.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
  letter-spacing: 0.03em;
}

.form-input {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 1rem;
  font-family: inherit;
  transition: all var(--transition);
  -webkit-appearance: none;
  appearance: none;
}

.form-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background: rgba(255, 255, 255, 0.1);
}

.form-input::placeholder {
  color: var(--text-muted);
}

.form-textarea {
  resize: vertical;
  min-height: 80px;
  line-height: 1.6;
}

.form-select {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%239898b8' d='M6 8.825L.35 3.175l.7-.7L6 7.425l4.95-4.95.7.7z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
  padding-right: 40px;
}

/* Toggle Switch */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.toggle-switch {
  position: relative;
  width: 52px;
  height: 30px;
  cursor: pointer;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 30px;
  transition: all var(--transition);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 24px;
  height: 24px;
  left: 3px;
  bottom: 2px;
  background: var(--text-secondary);
  border-radius: 50%;
  transition: all var(--transition);
}

.toggle-switch input:checked+.toggle-slider {
  background: var(--accent);
  border-color: var(--accent);
}

.toggle-switch input:checked+.toggle-slider::before {
  transform: translateX(21px);
  background: white;
}

/* Buttons */
.form-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 32px;
  padding-bottom: 24px;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px 24px;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
  border: none;
  font-family: inherit;
  letter-spacing: 0.02em;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #536dfe);
  color: white;
  box-shadow: 0 4px 16px var(--accent-glow);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(255, 82, 82, 0.3);
}

.btn-danger:active {
  background: rgba(255, 82, 82, 0.1);
}

/* ===== Detail View ===== */
.detail-container {
  max-width: 500px;
  margin: 0 auto;
}

.detail-image-wrapper {
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 20px;
  border: 1px solid var(--border);
}

.detail-image {
  width: 100%;
  max-height: 250px;
  object-fit: cover;
  display: block;
}

.detail-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.detail-title {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 16px;
}

.detail-meta {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.detail-datetime {
  font-size: 0.95rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.detail-datetime::before {
  content: '📅';
}

.detail-notify {
  font-size: 0.85rem;
  color: var(--accent-light);
  display: flex;
  align-items: center;
  gap: 8px;
}

.detail-notify::before {
  content: '🔔';
}

.detail-notify.off {
  color: var(--text-muted);
}

.detail-notify.off::before {
  content: '🔕';
}

.detail-memo {
  font-size: 0.95rem;
  color: var(--text-secondary);
  line-height: 1.7;
  white-space: pre-wrap;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.detail-memo:empty {
  display: none;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: calc(100px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 12px 24px;
  border-radius: 30px;
  font-size: 0.9rem;
  font-weight: 500;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
  z-index: 200;
  opacity: 0;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--bg-glass);
  border-radius: 4px;
}

/* ===== Compact Entry Cards ===== */
.entry-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.entry-card.compact {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  animation: fadeIn 0.25s ease;
}

.entry-row-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.entry-num {
  min-width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 0.7rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.entry-title-input {
  flex: 1;
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color var(--transition);
}

.entry-title-input:focus {
  outline: none;
  border-color: var(--accent);
}

.entry-title-input::placeholder {
  color: var(--text-muted);
}

.entry-rm {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid rgba(255, 82, 82, 0.3);
  background: none;
  color: var(--danger);
  font-size: 0.8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition);
}

.entry-rm:active {
  background: rgba(255, 82, 82, 0.2);
}

.entry-row-bottom {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 30px;
}

.entry-dt-input {
  flex: 1;
  padding: 7px 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text-primary);
  font-size: 0.82rem;
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color var(--transition);
}

.entry-dt-input:focus {
  outline: none;
  border-color: var(--accent);
}

.entry-notify-inline {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.entry-mins-input {
  width: 48px;
  padding: 7px 4px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--accent-light);
  font-size: 0.82rem;
  font-family: inherit;
  text-align: center;
  -webkit-appearance: none;
  -moz-appearance: textfield;
  appearance: none;
  transition: border-color var(--transition);
}

.entry-mins-input:focus {
  outline: none;
  border-color: var(--accent);
}

.entry-mins-input::-webkit-inner-spin-button,
.entry-mins-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.entry-mins-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.btn-add-entry {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-glass);
  border: 2px dashed var(--border);
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  margin-top: 4px;
}

.btn-add-entry:active {
  background: var(--bg-input);
  border-color: var(--accent);
  color: var(--accent-light);
}

/* ===== OCR Overlay ===== */
.ocr-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
}

.ocr-modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 40px;
  text-align: center;
  max-width: 320px;
  width: 90%;
  box-shadow: var(--shadow);
}

.ocr-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 20px;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.ocr-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.ocr-progress {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.ocr-progress-bar {
  width: 100%;
  height: 6px;
  background: var(--bg-input);
  border-radius: 3px;
  overflow: hidden;
}

.ocr-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-light));
  border-radius: 3px;
  transition: width 0.3s ease;
}

/* ===== Section Divider for date ===== */
.date-divider {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 8px 0 4px 4px;
  margin-top: 8px;
}

.date-divider:first-child {
  margin-top: 0;
}