:root {
  --bg: #F6F8FB;
  --card: #FFFFFF;
  --border: #E3E8F0;
  --text: #0F172A;
  --muted: #475569;
  --muted2: #94A3B8;
  --accent: #2563EB;
  --accent-soft: #EEF2FF;
  --success: #10B981;
  --warning: #F59E0B;
  --danger: #EF4444;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  line-height: 1.55;
}

.app { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 240px;
  background: #fff;
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  flex-shrink: 0;
}

.logo { margin: 4px 8px 18px; font-size: 18px; font-weight: 700; }

.sidebar a {
  display: block;
  padding: 10px 12px;
  border-radius: 12px;
  color: var(--muted);
  text-decoration: none;
  margin: 6px;
  transition: all 0.15s;
}

.sidebar a.active,
.sidebar a:hover {
  background: var(--accent-soft);
  color: var(--text);
}

/* Main */
.main { flex: 1; padding: 18px; overflow-y: auto; }

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 14px 16px;
  margin-bottom: 16px;
}

.top-left { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #F1F4F9;
  color: var(--muted);
  font-size: 13px;
}

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

/* Buttons */
button {
  border: 1px solid var(--border);
  background: #fff;
  padding: 10px 14px;
  border-radius: 14px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  transition: all 0.15s;
  font-family: inherit;
}

button:hover { background: #F8FAFC; }

button.primary {
  border-color: transparent;
  background: var(--accent);
  color: white;
}

button.primary:hover { filter: brightness(0.95); }

button.danger {
  border-color: transparent;
  background: var(--danger);
  color: white;
}

button.danger:hover { filter: brightness(0.95); }

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Grid & Cards */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 18px;
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.03);
}

.card h2 {
  margin: 0 0 14px;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card h3 {
  margin: 0 0 10px;
  font-size: 16px;
  color: var(--muted);
}

/* Forms */
.form-row { margin: 16px 0; }

label {
  display: block;
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 8px;
}

input[type="text"],
input[type="email"],
input[type="date"],
input[type="time"],
input[type="number"],
input[type="url"],
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 0;
}

textarea {
  resize: vertical;
  min-height: 80px;
}

textarea::placeholder { color: var(--muted2); }

input[type="range"] {
  width: 100%;
  height: 8px;
  border-radius: 4px;
  background: var(--border);
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
}

.range-display {
  text-align: center;
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
  margin: 8px 0;
}

/* Emoji Selector */
.emoji-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.emoji-row span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: #fff;
  font-size: 20px;
  cursor: pointer;
  transition: all 0.15s;
}

.emoji-row span:hover {
  border-color: var(--accent);
  transform: scale(1.05);
}

.emoji-row span.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* Lists */
.list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}

.list-item:last-child { border-bottom: 0; }

.list-item:hover { background: #F8FAFC; }

.list-item-content {
  flex: 1;
  min-width: 0;
}

.list-item-title {
  font-weight: 600;
  margin-bottom: 4px;
}

.list-item-meta {
  font-size: 13px;
  color: var(--muted);
}

.list-item-icon {
  font-size: 20px;
  flex-shrink: 0;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  background: #F1F4F9;
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 999px;
  flex-shrink: 0;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--muted);
}

.empty-state-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.5;
}

.empty-state h3 {
  margin: 0 0 8px;
  font-size: 18px;
  color: var(--text);
}

.empty-state p {
  margin: 0 0 20px;
  font-size: 14px;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 9999;
}

.modal-content {
  width: min(560px, 100%);
  max-height: 90vh;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 24px;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.2);
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-header h2 {
  margin: 0;
  font-size: 20px;
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  padding: 4px 8px;
  color: var(--muted);
}

.modal-close:hover {
  color: var(--text);
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 24px;
}

/* Timeline */
.timeline {
  list-style: none;
  padding: 0;
  margin: 0;
}

.timeline-item {
  display: flex;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.timeline-item:last-child { border-bottom: 0; }

.timeline-marker {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  margin-top: 6px;
  flex-shrink: 0;
}

.timeline-content {
  flex: 1;
}

.timeline-date {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 4px;
}

.timeline-title {
  font-weight: 600;
  margin-bottom: 4px;
}

.timeline-text {
  font-size: 14px;
  color: var(--muted);
}

/* Calendar */
.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
}

.calendar-day-header {
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  padding: 8px 4px;
}

.calendar-day {
  aspect-ratio: 1;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px;
  font-size: 14px;
  position: relative;
  background: #fff;
  cursor: pointer;
  transition: all 0.15s;
}

.calendar-day:hover {
  border-color: var(--accent);
}

.calendar-day.today {
  border-color: var(--accent);
  background: var(--accent-soft);
  font-weight: 700;
}

.calendar-day.other-month {
  opacity: 0.3;
}

.calendar-day-dots {
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 2px;
}

.calendar-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
}

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin: 16px 0;
}

.stat-card {
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  text-align: center;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 4px;
}

.stat-label {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

/* Utilities */
.hidden { display: none !important; }

.text-muted { color: var(--muted); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-danger { color: var(--danger); }

.mb-0 { margin-bottom: 0; }
.mt-16 { margin-top: 16px; }

/* Responsive */
@media (max-width: 980px) {
  .sidebar { display: none; }
  .grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
  .main { padding: 12px; }
  .topbar { flex-direction: column; align-items: stretch; }
  .top-actions { justify-content: stretch; }
  .modal-content { padding: 20px; }
}

/* ========== MOBILE IMPROVEMENTS ========== */

/* Mobile menu toggle */
.mobile-menu-toggle {
  display: none;
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 56px;
  height: 56px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 50%;
  font-size: 24px;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
  cursor: pointer;
  z-index: 999;
}

.mobile-menu-toggle:active {
  transform: scale(0.95);
}

/* Mobile sidebar overlay */
@media (max-width: 980px) {
  .sidebar {
    display: block;
    position: fixed;
    left: -260px;
    top: 0;
    bottom: 0;
    width: 260px;
    z-index: 1000;
    transition: left 0.3s ease;
    box-shadow: 2px 0 10px rgba(0,0,0,0.1);
  }
  
  .sidebar.open {
    left: 0;
  }
  
  .mobile-menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 999;
  }
  
  .sidebar-overlay.show {
    display: block;
  }
}

/* Touch-friendly improvements */
@media (max-width: 980px) {
  button {
    min-height: 44px;
    padding: 12px 16px;
  }
  
  .sidebar a {
    padding: 14px 16px;
    font-size: 16px;
  }
  
  .list-item {
    padding: 16px 0;
  }
  
  .card {
    padding: 20px;
  }
  
  input, select, textarea {
    font-size: 16px; /* Prevents zoom on iOS */
    min-height: 44px;
  }
  
  .emoji-row span {
    width: 48px;
    height: 48px;
    font-size: 22px;
  }
}

/* iPad mini specific (768px) */
@media (min-width: 768px) and (max-width: 980px) {
  .grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  
  .sidebar {
    width: 240px;
    left: -250px;
  }
}

/* Better calendar on mobile */
@media (max-width: 640px) {
  .calendar-day {
    padding: 4px;
    font-size: 12px;
  }
  
  .calendar-grid {
    gap: 4px;
  }
  
  .calendar-day-header {
    font-size: 11px;
    padding: 6px 2px;
  }
}

/* Modal improvements for mobile */
@media (max-width: 640px) {
  .modal {
    padding: 12px;
    align-items: flex-start;
    padding-top: 40px;
  }
  
  .modal-content {
    max-height: 85vh;
    padding: 20px;
  }
  
  .modal-actions {
    flex-direction: column;
  }
  
  .modal-actions button {
    width: 100%;
  }
}
