* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #ffffff;
  color: #1a1a1a;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.container {
  width: 100%;
  max-width: 420px;
  padding: 48px 24px;
}

h1 {
  font-size: 28px;
  margin: 0 0 24px;
  text-align: center;
}

input,
select {
  width: 100%;
  padding: 14px 16px;
  margin-bottom: 12px;
  border: 1px solid #d9d9d9;
  border-radius: 14px;
  font-size: 16px;
  outline: none;
  background: #ffffff;
  color: #1a1a1a;
  font-family: inherit;
}

input:focus,
select:focus {
  border-color: #2563eb;
}

button {
  width: 100%;
  padding: 14px 16px;
  margin-bottom: 12px;
  border: none;
  border-radius: 14px;
  background: #2563eb;
  color: #ffffff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

button:hover {
  background: #1d4ed8;
}

button.secondary {
  background: #ffffff;
  color: #2563eb;
  border: 1px solid #2563eb;
}

button.secondary:hover {
  background: #eff4ff;
}

button.danger {
  background: #ffffff;
  color: #dc2626;
  border: 1px solid #dc2626;
  padding: 8px 14px;
  width: auto;
  margin: 0;
  font-size: 14px;
}

button.danger:hover {
  background: #fef2f2;
}

.error {
  color: #dc2626;
  font-size: 14px;
  margin: -4px 0 12px;
  min-height: 18px;
}

.card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border: 1px solid #eee;
  border-radius: 16px;
  margin-bottom: 12px;
}

.card-title {
  font-weight: 600;
  font-size: 17px;
}

.card-sub {
  color: #888;
  font-size: 13px;
  margin-top: 4px;
}

.card-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.card-actions button {
  width: auto;
  margin: 0;
}

.card-edit {
  flex-direction: column;
  align-items: stretch;
}

.card-edit input,
.card-edit select {
  margin-bottom: 10px;
}

.card-edit .card-actions {
  margin-top: 2px;
}

.card-edit .card-actions button {
  flex: 1;
}

.type-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.type-btn {
  flex: 1;
  width: auto;
  margin: 0;
  background: #ffffff;
  color: #2563eb;
  border: 1px solid #2563eb;
}

.type-btn:hover {
  background: #eff4ff;
}

.type-btn.active {
  background: #2563eb;
  color: #ffffff;
}

.tag-badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  color: #2563eb;
  background: #eff4ff;
  padding: 3px 10px;
  border-radius: 999px;
  margin-top: 6px;
}

.amount-income {
  color: #16a34a;
}

.amount-expense {
  color: #dc2626;
}

.top-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.top-bar h1 {
  margin: 0;
  text-align: left;
  flex: 1;
}

.menu-btn {
  width: 44px;
  height: 44px;
  padding: 0;
  margin: 0;
  flex-shrink: 0;
  background: #ffffff;
  color: #1a1a1a;
  border: 1px solid #eee;
  border-radius: 14px;
  font-size: 20px;
  line-height: 1;
}

.menu-btn:hover {
  background: #f5f5f5;
}

.menu-panel {
  background: #ffffff;
  border: 1px solid #eee;
  border-radius: 16px;
  padding: 8px;
  margin-bottom: 24px;
}

.menu-panel.hidden {
  display: none;
}

.menu-link {
  display: block;
  padding: 12px 14px;
  border-radius: 12px;
  color: #1a1a1a;
  text-decoration: none;
  font-weight: 600;
}

.menu-link:hover {
  background: #f5f5f5;
}

.menu-link.active {
  color: #2563eb;
  background: #eff4ff;
}

.menu-logout {
  width: 100%;
  margin: 4px 0 0;
}

.summary-grid {
  display: flex;
  gap: 10px;
  margin-bottom: 28px;
}

.summary-card {
  flex: 1;
  border: 1px solid #eee;
  border-radius: 16px;
  padding: 14px 8px;
  text-align: center;
}

.summary-label {
  font-size: 12px;
  color: #888;
  margin-bottom: 6px;
}

.summary-value {
  font-size: 18px;
  font-weight: 700;
}

.section-title {
  font-size: 15px;
  font-weight: 700;
  margin: 0 0 16px;
}

.pie-chart {
  width: 200px;
  height: 200px;
  border-radius: 50%;
  margin: 0 auto 24px;
}

.legend-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid #f2f2f2;
}

.legend-item:last-child {
  border-bottom: none;
}

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

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-name {
  font-weight: 600;
  font-size: 14px;
}

.legend-value {
  color: #888;
  font-size: 13px;
  text-align: right;
}

/* Månadsväljare */
.month-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.month-nav select {
  margin: 0;
}

.month-nav .nav-arrow {
  width: 44px;
  flex-shrink: 0;
  margin: 0;
  padding: 12px 0;
}

.today-btn {
  margin-bottom: 24px;
}

/* Budgetrader */
.budget-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid #f2f2f2;
}

.budget-row .cat-name {
  flex: 1;
  font-weight: 600;
}

.budget-row input.amount-input {
  width: 120px;
  margin: 0;
  text-align: right;
}

.budget-row .row-actions {
  display: flex;
  gap: 6px;
}

.row-actions button {
  width: auto;
  margin: 0;
  padding: 8px 12px;
  font-size: 13px;
}

/* Filter */
.filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 20px;
}

.filters select {
  margin: 0;
}

/* Budget mot verklighet */
.compare-row {
  padding: 14px 0;
  border-bottom: 1px solid #f2f2f2;
}

.compare-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}

.compare-name {
  font-weight: 600;
  font-size: 15px;
}

.compare-numbers {
  font-size: 13px;
  color: #666;
}

.progress-track {
  height: 10px;
  background: #f0f0f0;
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
}

.status-good { background: #16a34a; }
.status-warn { background: #f59e0b; }
.status-over { background: #dc2626; }

.stat-diff-over { color: #dc2626; font-weight: 600; }
.stat-diff-under { color: #16a34a; font-weight: 600; }

.subheading {
  font-size: 13px;
  color: #888;
  margin: 20px 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Diagram-vyväxlare */
.chart-toggle {
  display: flex;
  gap: 6px;
  margin: 8px 0 16px;
  flex-wrap: wrap;
}

.chart-toggle button {
  flex: 1;
  min-width: 90px;
  margin: 0;
  padding: 10px 6px;
  font-size: 13px;
  background: #ffffff;
  color: #2563eb;
  border: 1px solid #2563eb;
}

.chart-toggle button.active {
  background: #2563eb;
  color: #ffffff;
}

.chart-box {
  position: relative;
  height: 260px;
  margin-bottom: 24px;
}

.hint {
  font-size: 12px;
  color: #999;
  margin: -8px 0 16px;
}

/* Generisk döljning */
.hidden {
  display: none !important;
}

/* Kalender */
.share-btn {
  width: auto;
  margin: 0;
  padding: 10px 14px;
  font-size: 14px;
  flex-shrink: 0;
}

.cal-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.cal-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid #eee;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  transition: opacity 0.15s;
}

.cal-chip.off {
  opacity: 0.4;
}

.cal-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 11px;
  color: #888;
  font-weight: 700;
  margin-bottom: 4px;
}

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

.cal-day {
  min-height: 64px;
  border-radius: 12px;
  border: 1px solid #f2f2f2;
  padding: 4px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  cursor: pointer;
  overflow: hidden;
}

.cal-day:hover {
  background: #f8f9fb;
}

.cal-day.outside {
  opacity: 0.35;
}

.cal-day.today .cal-day-num {
  background: #2563eb;
  color: #fff;
}

.cal-day-num {
  align-self: flex-start;
  font-size: 12px;
  font-weight: 600;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  margin-bottom: 2px;
  flex-shrink: 0;
}

.cal-events {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
}

.cal-event-chip {
  font-size: 10px;
  line-height: 1.4;
  color: #fff;
  padding: 1px 5px;
  border-radius: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

.cal-more {
  font-size: 10px;
  color: #888;
  padding: 0 5px;
}

/* Modaler */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}

.modal-panel {
  background: #fff;
  width: 100%;
  max-width: 420px;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  padding: 20px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  font-size: 17px;
  font-weight: 700;
}

.modal-close {
  width: auto;
  margin: 0;
  padding: 6px 10px;
  background: #fff;
  color: #1a1a1a;
  border: 1px solid #eee;
  font-size: 14px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  margin: -4px 0 12px;
}

.check-row input {
  width: auto;
  margin: 0;
}

.color-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.color-swatch {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
}

.color-swatch.selected {
  border-color: #1a1a1a;
}

.agenda-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid #f2f2f2;
  cursor: pointer;
}

.agenda-item:last-child {
  border-bottom: none;
}

.agenda-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.agenda-title {
  font-weight: 600;
  font-size: 14px;
}

.agenda-sub {
  font-size: 12px;
  color: #888;
}

.share-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid #f2f2f2;
}

.share-row:last-child {
  border-bottom: none;
}

.share-name {
  font-weight: 600;
  font-size: 14px;
}

.share-perm {
  font-size: 12px;
  color: #888;
}

/* ============ Datorvy ============ */

/* Bredare container ju mer skärmyta som finns. Formulärtunga sidor blir
   inte orimligt breda, medan .container-calendar (kalendern) får extra plats. */
@media (min-width: 640px) {
  .container {
    max-width: 640px;
    padding: 56px 40px;
  }
}

@media (min-width: 1000px) {
  .container {
    max-width: 760px;
  }
}

.container-calendar,
.container-wide {
  max-width: 420px;
}

@media (min-width: 800px) {
  .container-calendar,
  .container-wide {
    max-width: 900px;
  }
}

@media (min-width: 1200px) {
  .container-calendar,
  .container-wide {
    max-width: 1100px;
  }
}

/* Hamburgarmenyn blir en horisontell navigeringsrad på större skärmar,
   alltid synlig istället för att döljas bakom en knapp. */
@media (min-width: 800px) {
  .menu-btn {
    display: none;
  }

  .top-bar {
    margin-bottom: 12px;
  }

  .menu-panel,
  .menu-panel.hidden {
    display: flex !important;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    background: none;
    border: none;
    padding: 0;
    margin: 0 0 32px;
  }

  .menu-link {
    padding: 8px 16px;
  }

  .menu-logout {
    width: auto;
    margin: 0 0 0 auto;
    padding: 8px 16px;
  }
}

/* Kalendern får mer luft och riktiga händelserader istället för prickar
   när det finns tillräckligt med skärmbredd. */
@media (min-width: 800px) {
  .cal-day {
    min-height: 110px;
    padding: 6px;
  }

  .cal-day-num {
    width: 24px;
    height: 24px;
    font-size: 13px;
  }

  .cal-event-chip {
    font-size: 12px;
    padding: 2px 6px;
  }

  .cal-more {
    font-size: 11px;
  }

  .modal-overlay {
    align-items: center;
  }

  .modal-panel {
    max-width: 480px;
    border-radius: 20px;
  }
}

/* ============ Mat ============ */

.food-department {
  margin-bottom: 28px;
}

.food-department-header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0;
  margin-bottom: 12px;
  border-bottom: 2px solid #1a1a1a;
}

.food-department-title {
  font-size: 15px;
  font-weight: 700;
  margin: 0;
}

.food-add-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  margin: 0;
  flex-shrink: 0;
  border-radius: 50%;
  background: #2563eb;
  color: #ffffff;
  font-size: 18px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.food-add-btn:hover {
  background: #1d4ed8;
}

.food-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
}

@media (min-width: 800px) {
  .food-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 16px;
  }
}

.food-search-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}

.food-search-row #searchInput {
  flex: 1;
  margin-bottom: 0;
}

.food-fav-filter {
  width: auto;
  margin: 0;
  padding: 0 16px;
  height: 48px;
  flex-shrink: 0;
  font-size: 14px;
  background: #fff;
  color: #1a1a1a;
  border: 1px solid #d9d9d9;
}

.food-fav-filter.active {
  background: #fffbeb;
  color: #b45309;
  border-color: #f59e0b;
}

.food-card {
  position: relative;
  border: 1px solid #eee;
  border-radius: 16px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  transition: opacity 0.15s;
}

.food-star-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  padding: 0;
  margin: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid #eee;
  font-size: 15px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #b0b0b0;
  z-index: 1;
}

.food-star-btn.active {
  color: #f59e0b;
  border-color: #f59e0b;
}

.food-card.deleted {
  opacity: 0.5;
}

.food-card-image {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 12px;
  background: #f5f5f5;
  object-fit: contain;
  margin-bottom: 8px;
}

.food-card-placeholder {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 12px;
  background: #f5f5f5;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  margin-bottom: 8px;
}

.food-card-name {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
  line-height: 1.3;
  cursor: text;
  border-radius: 6px;
  padding: 2px 4px;
}

.food-card-name:hover {
  background: #f5f5f5;
}

.food-card-name-input {
  width: 100%;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  text-align: center;
  padding: 2px 4px;
  margin: 0 0 8px;
  border: 1px solid #2563eb;
  border-radius: 6px;
}

.food-card-btn {
  width: 100%;
  margin: 0;
  padding: 8px 6px;
  font-size: 12px;
  background: #fff;
  color: #dc2626;
  border: 1px solid #dc2626;
}

.food-card-btn:hover {
  background: #fef2f2;
}

.food-card-btn.is-deleted {
  color: #2563eb;
  border-color: #2563eb;
}

.food-card-btn.is-deleted:hover {
  background: #eff4ff;
}

.food-card-btn + .food-card-btn {
  margin-top: 6px;
}

.food-hide-btn {
  color: #6b7280;
  border: 1px solid #6b7280;
}

.food-hide-btn:hover {
  background: #f3f4f6;
}

.food-hide-btn.is-hidden {
  color: #2563eb;
  border-color: #2563eb;
}

.food-hide-btn.is-hidden:hover {
  background: #eff4ff;
}

.food-card.food-hidden {
  opacity: 0.5;
}

.food-empty {
  color: #888;
  text-align: center;
  padding: 40px 0;
}
