:root {
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: #e0e7ff;
  --accent: #10b981;
  --accent-warn: #f59e0b;
  --accent-danger: #ef4444;
  --bg-main: #0f172a;
  --bg-card: #1e293b;
  --bg-card-alt: #334155;
  --bg-input: #0f172a;
  --border-color: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
  --safe-bottom: env(safe-area-inset-bottom, 16px);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg-main: #f1f5f9;
    --bg-card: #ffffff;
    --bg-card-alt: #f8fafc;
    --bg-input: #f8fafc;
    --border-color: #e2e8f0;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --text-dim: #94a3b8;
  }
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  padding-bottom: calc(75px + var(--safe-bottom));
  overflow-x: hidden;
}

/* Header & Status Bar */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background-color: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(8px);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-logo {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
}

.header-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header-subtitle {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.header-status-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: 9999px;
  background: var(--bg-card-alt);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  transition: all 0.2s ease;
}

.badge-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--text-dim);
}

.badge.online .badge-dot {
  background-color: var(--accent);
  box-shadow: 0 0 6px var(--accent);
}

.badge.offline .badge-dot {
  background-color: var(--accent-warn);
}

.badge.lan-connected .badge-dot {
  background-color: var(--accent);
  box-shadow: 0 0 6px var(--accent);
}

.badge.lan-pending .badge-dot {
  background-color: var(--accent-warn);
}

.badge.lan-error .badge-dot {
  background-color: var(--accent-danger);
}

/* Main Container */
.container {
  max-width: 680px;
  margin: 0 auto;
  padding: 16px;
}

/* Tabs View Control */
.view-section {
  display: none;
  animation: fadeIn 0.25s ease-in-out;
}

.view-section.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Card & Sections */
.card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-main);
}

.card-title-icon {
  font-size: 1.15rem;
}

/* Form Controls */
.form-group {
  margin-bottom: 16px;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.label-value {
  color: var(--primary);
  font-weight: 700;
  font-size: 0.9rem;
}

.form-input, .form-textarea, .form-select {
  width: 100%;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input:focus, .form-textarea:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.form-textarea {
  min-height: 80px;
  resize: vertical;
}

/* Dual Column Layout */
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 480px) {
  .form-row.mobile-col {
    grid-template-columns: 1fr;
  }
}

/* Slider Controls */
.range-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.range-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 8px;
  border-radius: 4px;
  background: var(--bg-card-alt);
  outline: none;
  margin: 10px 0;
}

.range-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  border: 2px solid #ffffff;
  transition: transform 0.1s ease;
}

.range-slider::-webkit-slider-thumb:active {
  transform: scale(1.15);
}

.slider-scale {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-dim);
}

.mood-display {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card-alt);
  padding: 8px 12px;
  border-radius: var(--radius-md);
  margin-bottom: 8px;
}

.mood-emoji {
  font-size: 1.6rem;
}

.mood-label {
  font-weight: 600;
  font-size: 0.9rem;
}

/* Stepper / Quick Buttons */
.stepper-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stepper-btn {
  background: var(--bg-card-alt);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  font-size: 1.2rem;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.stepper-btn:active {
  background: var(--primary-hover);
  color: white;
}

/* Chip / Pill Selector */
.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.chip {
  background: var(--bg-card-alt);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  padding: 6px 12px;
  border-radius: 9999px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

.chip:hover {
  border-color: var(--primary);
  color: var(--text-main);
}

.chip.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.chip.active-tag {
  background: rgba(99, 102, 241, 0.2);
  color: var(--primary-light);
  border-color: var(--primary);
}

/* Quick List Item Adder (Highlights, Energy Drainers, Learnings) */
.dynamic-list-container {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.list-item-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card-alt);
  padding: 8px 12px;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  border-left: 3px solid var(--primary);
}

.list-item-pill.drainer {
  border-left-color: var(--accent-warn);
}

.list-item-pill.learning {
  border-left-color: var(--accent);
}

.list-item-remove {
  color: var(--text-dim);
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0 4px;
}

.list-item-remove:hover {
  color: var(--accent-danger);
}

.quick-add-row {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

/* Action Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
  width: 100%;
}

.btn-primary {
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: white;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.4);
}

.btn-primary:active {
  transform: translateY(1px);
  box-shadow: 0 2px 6px rgba(99, 102, 241, 0.4);
}

.btn-secondary {
  background: var(--bg-card-alt);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

.btn-secondary:active {
  background: var(--border-color);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.82rem;
  width: auto;
}

.btn-danger {
  background: var(--accent-danger);
  color: white;
}

.btn-success {
  background: var(--accent);
  color: white;
}

/* Bottom Navigation Bar */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(60px + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background-color: var(--bg-card);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 100;
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(10px);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.72rem;
  font-weight: 600;
  gap: 4px;
  cursor: pointer;
  flex: 1;
  height: 100%;
  transition: color 0.15s ease;
}

.nav-icon {
  font-size: 1.25rem;
}

.nav-item.active {
  color: var(--primary);
}

/* Journal History Cards */
.history-item {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.history-date {
  font-size: 1rem;
  font-weight: 700;
}

.history-badges {
  display: flex;
  gap: 6px;
  align-items: center;
}

.history-metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  background: var(--bg-card-alt);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  text-align: center;
}

.metric-box-val {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--primary-light);
}

.metric-box-lbl {
  font-size: 0.68rem;
  color: var(--text-dim);
}

.history-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
}

.history-tag {
  font-size: 0.72rem;
  background: rgba(99, 102, 241, 0.15);
  color: var(--primary-light);
  padding: 2px 8px;
  border-radius: 9999px;
}

.history-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  border-top: 1px solid var(--border-color);
  padding-top: 10px;
}

/* Modal / Drawer */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: var(--bg-card);
  border-top: 1px solid var(--border-color);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 680px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  padding: 20px;
  box-shadow: var(--shadow-lg);
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-overlay.active .modal-content {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
}

.yaml-code-view {
  background: var(--bg-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.82rem;
  color: #38bdf8;
  overflow-y: auto;
  white-space: pre-wrap;
  flex: 1;
  max-height: 50vh;
  user-select: text;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 90%;
  max-width: 400px;
  pointer-events: none;
}

.toast {
  background: var(--bg-card-alt);
  color: var(--text-main);
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-color);
  animation: slideDown 0.2s ease;
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.toast.success {
  border-left: 4px solid var(--accent);
}

.toast.warn {
  border-left: 4px solid var(--accent-warn);
}

.toast.error {
  border-left: 4px solid var(--accent-danger);
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 3rem;
  margin-bottom: 12px;
  opacity: 0.6;
}

/* PWA Install Banner & Notice Box */
.notice-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--shadow-sm);
}

.notice-box.install-banner {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.15), rgba(79, 70, 229, 0.25));
  border-color: var(--primary);
}

.notice-box.warning-banner {
  background: rgba(245, 158, 11, 0.1);
  border-color: var(--accent-warn);
}

.notice-box-content {
  flex: 1;
}

.notice-box-title {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.notice-box-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.status-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.status-card {
  background: var(--bg-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.status-card-lbl {
  font-size: 0.72rem;
  color: var(--text-dim);
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.05em;
}

.status-card-val {
  font-size: 0.9rem;
  font-weight: 600;
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-grid .status-card:nth-child(3) {
  grid-column: 1 / -1;
  word-break: break-all;
}
