/* assets/css/app.css - Sorten custom styles */

:root {
  --color-bg:           #F3F5FB;
  --color-surface:      #FFFFFF;
  --color-primary:      #7e9ffd;
  --color-primary-hover:#6b8fef;
  --color-primary-dark: #456697;
  --color-accent:       #EEF2FF;
  --color-text:         #1e2a3a;
  --color-muted:        #8a96b0;
  --color-border:       #e2e8f4;
  --color-success:      #34C880;
  --color-warning:      #F5A623;
  --color-danger:       #F05252;
  --radius-sm:          8px;
  --radius-md:          14px;
  --radius-lg:          20px;
  --shadow-sm:          0 2px 8px rgba(126,159,253,0.08);
  --shadow-md:          0 4px 20px rgba(126,159,253,0.14);
  --shadow-lg:          0 8px 32px rgba(126,159,253,0.18);
  --font-sans:          'Inter', system-ui, -apple-system, sans-serif;
  --font-brand:         'Fredoka', 'Arial Rounded MT Bold', sans-serif;
  --transition:         0.18s ease;
}

/* ---- Reset / Base ---- */
*, *::before, *::after { box-sizing: border-box; }

html {
  overflow-x:          hidden;
  overscroll-behavior: none;
  /* Lock to viewport height — prevents WKWebView root scroll which causes bounce */
  height:              100%;
}

body {
  overflow-x:          hidden;
  overscroll-behavior: none;
  /* Must also be fixed height so root scroll container has nothing to scroll */
  height:              100%;
  overflow-y:          hidden;
}

body {
  font-family: var(--font-sans);
  background:  var(--color-bg);
  color:       var(--color-text);
  min-height:  100vh;
  margin:      0;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ---- Typography ---- */
h1, h2, h3, h4, h5, h6 { font-weight: 600; line-height: 1.3; }
.text-muted { color: var(--color-muted) !important; }

/* ---- Sidebar ---- */
.sidebar {
  width:       240px;
  min-height:  100vh;
  background:  var(--color-surface);
  border-right: 1px solid var(--color-border);
  position:    fixed;
  top:         0;
  left:        0;
  padding:     24px 0;
  display:     flex;
  flex-direction: column;
  z-index:     100;
  transition:  transform var(--transition);
}

.sidebar-brand {
  padding:     0 24px 24px;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 12px;
  display:     flex;
  align-items: center;
  gap:         12px;
}

.sidebar-brand-text {
  display:     flex;
  flex-direction: column;
}

.sidebar-brand-name {
  font-family: var(--font-brand);
  font-size:   1.35rem;
  font-weight: 600;
  color:       var(--color-primary-dark);
  line-height: 1.1;
}

.sidebar-brand-tag {
  font-size:   0.68rem;
  font-weight: 400;
  color:       var(--color-muted);
  letter-spacing: 0.01em;
  margin-top:  1px;
}

.nav-link-sidebar {
  display:     flex;
  align-items: center;
  gap:         12px;
  padding:     11px 24px;
  color:       var(--color-muted);
  font-size:   0.92rem;
  font-weight: 500;
  text-decoration: none;
  border-radius: 0;
  transition:  background var(--transition), color var(--transition);
  cursor:      pointer;
  border:      none;
  background:  none;
  width:       100%;
  text-align:  left;
}

.nav-link-sidebar:hover,
.nav-link-sidebar.active {
  background: var(--color-accent);
  color:      var(--color-primary);
}

.nav-link-sidebar svg { flex-shrink: 0; }

/* ---- Main Content ---- */
.main-content {
  margin-left:         240px;
  padding:             36px 32px 80px;
  min-height:          100vh;
  /* On mobile this becomes the ONLY scroll container, eliminating WKWebView root bounce */
  overflow-y:          auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* ---- Cards ---- */
.card {
  background:    var(--color-surface);
  border:        1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow:    var(--shadow-sm);
  padding:       16px 20px;
  margin-bottom: 12px;
}

.card-header-custom {
  display:         flex;
  align-items:     center;
  justify-content: space-between;
  margin-bottom:   10px;
}

.card-title {
  font-size:   0.88rem;
  font-weight: 600;
  color:       var(--color-text);
  margin:      0;
}

.card-subtitle {
  font-size: 0.72rem;
  color:     var(--color-muted);
  margin-top: 1px;
}

/* ---- Greeting ---- */
.greeting-title {
  font-size:   1.9rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 4px;
}

.greeting-sub {
  color:     var(--color-muted);
  font-size: 0.95rem;
}

/* ---- Item Rows ---- */
.item-row {
  display:         flex;
  align-items:     center;
  gap:             10px;
  padding:         7px 0;
  border-bottom:   1px solid var(--color-border);
}
.item-row:last-child { border-bottom: none; }

.item-title {
  flex:        1;
  font-size:   0.83rem;
  font-weight: 500;
}

.item-meta {
  font-size: 0.72rem;
  color:     var(--color-muted);
  white-space: nowrap;
}

/* ---- Shopping list ---- */
.shopping-title--done { text-decoration: line-through; opacity: 0.45; }
.shopping-divider {
  font-size: 0.72rem; font-weight: 600; color: var(--color-muted);
  text-transform: uppercase; letter-spacing: 0.05em;
  padding: 8px 0 4px;
}

/* ---- Checkbox (task complete) ---- */
.task-check {
  width:         20px;
  height:        20px;
  border-radius: 50%;
  border:        2px solid var(--color-border);
  cursor:        pointer;
  flex-shrink:   0;
  transition:    border-color var(--transition), background var(--transition);
  display:       flex;
  align-items:   center;
  justify-content: center;
}
.task-check:hover { border-color: var(--color-primary); }
.task-check.done  {
  background:   var(--color-success);
  border-color: var(--color-success);
}
.task-check.done::after {
  content: '';
  width:   6px; height: 6px;
  background: white;
  border-radius: 50%;
}

/* ---- Badges ---- */
.badge-due-soon {
  background: #FFF5E6;
  color:      var(--color-warning);
  font-size:  0.7rem;
  padding:    2px 8px;
  border-radius: 20px;
  font-weight: 600;
}
.badge-overdue {
  background: #FEF0F0;
  color:      var(--color-danger);
  font-size:  0.7rem;
  padding:    2px 8px;
  border-radius: 20px;
  font-weight: 600;
}
.badge-paid {
  background: #EDFAF4;
  color:      var(--color-success);
  font-size:  0.7rem;
  padding:    2px 8px;
  border-radius: 20px;
  font-weight: 600;
}

/* ---- Buttons ---- */
.btn-primary {
  background:    var(--color-primary);
  border:        none;
  border-radius: var(--radius-sm);
  color:         white;
  font-weight:   600;
  font-size:     0.9rem;
  padding:       10px 22px;
  transition:    background var(--transition), transform var(--transition), box-shadow var(--transition);
  cursor:        pointer;
}
.btn-primary:hover {
  background:  var(--color-primary-hover);
  box-shadow:  var(--shadow-md);
  transform:   translateY(-1px);
  color:       white;
}

.btn-ghost {
  background:    transparent;
  border:        1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color:         var(--color-muted);
  font-size:     0.85rem;
  padding:       8px 16px;
  cursor:        pointer;
  transition:    all var(--transition);
}
.btn-ghost:hover {
  border-color: var(--color-primary);
  color:        var(--color-primary);
}

.btn-danger-ghost {
  background:    transparent;
  border:        none;
  color:         var(--color-danger);
  opacity:       0.5;
  cursor:        pointer;
  padding:       4px;
  font-size:     0.8rem;
  transition:    opacity var(--transition);
  line-height:   1;
}
.btn-danger-ghost:hover { opacity: 1; }

/* ---- Floating Add Button ---- */
.fab {
  position:      fixed;
  bottom:        28px;
  right:         28px;
  width:         56px;
  height:        56px;
  background:    var(--color-primary);
  border:        none;
  border-radius: 50%;
  color:         white;
  font-size:     1.6rem;
  line-height:   1;
  cursor:        pointer;
  box-shadow:    var(--shadow-lg);
  display:       flex;
  align-items:   center;
  justify-content: center;
  transition:    background var(--transition), transform var(--transition);
  z-index:       200;
}
.fab:hover {
  background: var(--color-primary-hover);
  transform:  scale(1.08);
}

/* ---- Modals ---- */
.modal-content {
  border-radius: var(--radius-lg);
  border:        none;
  box-shadow:    var(--shadow-lg);
}
.modal-header {
  border-bottom: 1px solid var(--color-border);
  padding:       20px 24px;
}
.modal-body   { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--color-border); }
.modal-title  { font-weight: 600; font-size: 1rem; }

/* ---- Form controls ---- */
.form-control, .form-select {
  border:        1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size:     0.92rem;
  padding:       10px 14px;
  color:         var(--color-text);
  background:    var(--color-surface);
  transition:    border-color var(--transition), box-shadow var(--transition);
}
.form-control:focus, .form-select:focus {
  border-color: var(--color-primary);
  box-shadow:   0 0 0 3px rgba(91,110,245,0.12);
  outline:      none;
}
.form-label {
  font-size:   0.85rem;
  font-weight: 500;
  color:       var(--color-muted);
  margin-bottom: 6px;
}

/* ---- Stat Cards ---- */
.stat-card {
  background:    var(--color-surface);
  border:        1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding:       20px 24px;
  box-shadow:    var(--shadow-sm);
}
.stat-number {
  font-size:   2rem;
  font-weight: 700;
  color:       var(--color-primary);
  line-height: 1;
}
.stat-label {
  font-size: 0.82rem;
  color:     var(--color-muted);
  margin-top: 4px;
}
.stat-inline {
  display:       inline-block;
  font-size:     0.78rem;
  font-weight:   600;
  color:         var(--color-primary);
  background:    var(--color-accent);
  border-radius: 20px;
  padding:       2px 10px;
  margin-left:   8px;
  vertical-align: middle;
}

/* ---- Empty state ---- */
.empty-state {
  text-align:   center;
  padding:      16px 12px;
  color:        var(--color-muted);
  font-size:    0.8rem;
}
.empty-state-icon {
  font-size:    2rem;
  margin-bottom: 8px;
  opacity:      0.4;
}

/* ---- Page views (SPA) ---- */
.view { display: none; }
.view.active { display: block; }

/* ---- Toast ---- */
.toast-container { z-index: 9999; }
.toast {
  border-radius: var(--radius-sm) !important;
  border:        none !important;
  box-shadow:    var(--shadow-md) !important;
  font-size:     0.88rem;
}

/* ---- Auth pages ---- */
.auth-wrapper {
  min-height:      100vh;
  display:         flex;
  align-items:     flex-start;
  justify-content: center;
  background:      var(--color-bg);
  padding-top:     40px;
}
.auth-card {
  background:    var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow:    var(--shadow-lg);
  padding:       40px 36px;
  width:         100%;
  max-width:     420px;
}
.auth-logo {
  display:     flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 4px;
  gap:         4px;
}

.auth-logo-badge {
  width:  160px;
  height: 160px;
  object-fit: contain;
}

.auth-logo-name {
  font-family: var(--font-brand);
  font-size:   1.8rem;
  font-weight: 600;
  color:       var(--color-primary-dark);
  line-height: 1;
}

/* ---- Upgrade banner ---- */
.upgrade-banner {
  display:    none !important;
  background: linear-gradient(135deg, var(--color-primary) 0%, #7C8FF7 100%);
  color:      white;
  border-radius: var(--radius-md);
  padding:    20px 24px;
  align-items: center;
  justify-content: space-between;
  gap:        16px;
  margin-bottom: 20px;
}
.upgrade-banner p { margin: 0; font-size: 0.9rem; opacity: 0.9; }
.upgrade-banner h4 { margin: 0 0 4px; font-size: 1rem; font-weight: 700; }

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .sidebar {
    transform:  translateX(-100%);
    width:      260px;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-brand {
    padding-top: calc(env(safe-area-inset-top, 0px) + 60px);
  }
  .main-content {
    margin-left:  0;
    padding:      calc(env(safe-area-inset-top, 0px) + 56px + 16px) 16px 80px;
    /* Fixed height = full viewport, scroll stays inside this element not the WKWebView root */
    height:       100vh;
    min-height:   unset;
    overflow-y:   auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
  .fab { bottom: 20px; right: 16px; }
  .mobile-top-bar  { display: flex !important; }
  .mobile-menu-btn { display: flex !important; }
  .overlay {
    display:    none;
    position:   fixed;
    inset:      0;
    background: rgba(0,0,0,0.3);
    z-index:    99;
  }
  .overlay.active { display: block; }
}
/* ---- Mobile top bar ---- */
.mobile-top-bar {
  display:          none;
  position:         fixed;
  top:              0;
  left:             0;
  right:            0;
  /* Use padding-top for safe area + fixed height underneath — avoids min-height
     reflow when Bootstrap toggles body overflow during modal open/close */
  padding-top:      env(safe-area-inset-top, 0px);
  height:           calc(env(safe-area-inset-top, 0px) + 52px);
  background:       var(--color-surface);
  border-bottom:    1px solid var(--color-border);
  box-shadow:       0 2px 12px rgba(91,110,245,0.07);
  z-index:          200;
  align-items:      center;
  justify-content:  space-between;
  padding-left:     8px;
  padding-right:    16px;
  /* GPU layer — keeps bar crisp during scroll/pull */
  transform:        translateZ(0);
  -webkit-transform: translateZ(0);
  will-change:      transform;
  /* Prevent any content from ever expanding the bar */
  overflow:         hidden;
}
.mobile-top-bar-logo {
  display:     flex;
  align-items: center;
  gap:         8px;
  font-family: var(--font-brand);
  font-size:   1.1rem;
  font-weight: 700;
  color:       var(--color-text);
}
.mobile-menu-btn {
  display:       none;
  background:    none;
  border:        none;
  padding:       10px 14px;
  cursor:        pointer;
  color:         var(--color-text);
  border-radius: var(--radius-sm);
  -webkit-tap-highlight-color: transparent;
}

/* ---- FAB Speed-dial ---- */
.fab-menu {
  position:       fixed;
  bottom:         calc(72px + 72px);
  right:          16px;
  flex-direction: column-reverse;
  gap:            12px;
  z-index:        199;
  align-items:    flex-end;
}
.fab-menu-item {
  display:        flex;
  align-items:    center;
  gap:            10px;
  background:     none;
  border:         none;
  cursor:         pointer;
  padding:        0;
  -webkit-tap-highlight-color: transparent;
}
.fab-menu-label {
  background:     var(--color-surface);
  color:          var(--color-text);
  font-size:      0.82rem;
  font-weight:    600;
  padding:        5px 12px;
  border-radius:  20px;
  box-shadow:     var(--shadow-md);
  white-space:    nowrap;
}
.fab-menu-icon {
  width:          44px;
  height:         44px;
  border-radius:  50%;
  display:        flex;
  align-items:    center;
  justify-content: center;
  box-shadow:     var(--shadow-md);
  flex-shrink:    0;
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 3px; }

/* ---- Smart AI Input Bar ---- */
.smart-input-bar {
  position:   fixed;
  bottom:     0;
  left:       240px;
  right:      0;
  z-index:    190;
  padding:    10px 20px 12px;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  box-shadow: 0 -2px 16px rgba(126,159,253,0.10);
}

.smart-input-bar form {
  display:     flex;
  align-items: center;
  gap:         8px;
  max-width:   860px;
  margin:      0 auto;
}

.smart-input-field {
  flex:          1;
  border:        1.5px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding:       10px 16px;
  font-size:     0.9rem;
  font-family:   var(--font-sans);
  background:    var(--color-bg);
  color:         var(--color-text);
  outline:       none;
  transition:    border-color var(--transition), box-shadow var(--transition);
}
.smart-input-field:focus {
  border-color: var(--color-primary);
  box-shadow:   0 0 0 3px rgba(126,159,253,0.15);
}
.smart-input-field::placeholder { color: var(--color-muted); font-size: 0.85rem; }

.smart-input-mic,
.smart-input-send {
  width:         38px;
  height:        38px;
  border-radius: 50%;
  border:        none;
  cursor:        pointer;
  display:       flex;
  align-items:   center;
  justify-content: center;
  transition:    background var(--transition), color var(--transition), transform 0.1s;
  flex-shrink:   0;
}
.smart-input-mic {
  background: var(--color-accent);
  color:      var(--color-primary);
}
.smart-input-mic:hover { background: var(--color-primary); color: white; }
.smart-input-mic.listening {
  background: var(--color-danger);
  color:      white;
  animation:  pulse 1s infinite;
}
.smart-input-send {
  background: var(--color-primary-dark);
  color:      white;
}
.smart-input-send:disabled { opacity: 0.4; cursor: default; }
.smart-input-send:not(:disabled):hover { background: #334f7a; }

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.1); }
}

/* Prevent Bootstrap modal scroll-lock from shifting layout on mobile */
body.modal-open {
  padding-right: 0 !important;
  overflow-y:    hidden;
  overflow-x:    hidden;
  /* Do NOT touch width — Bootstrap may try to set it */
}
html.modal-open { padding-right: 0 !important; overflow-x: hidden; }

/* ---- Bottom Nav ---- */
.bottom-nav {
  display:          flex;
  position:         fixed;
  bottom:           0;
  left:             0;
  right:            0;
  background:       var(--color-surface);
  border-top:       1px solid var(--color-border);
  z-index:          200;
  padding:          0 4px;
  padding-bottom:   env(safe-area-inset-bottom, 0px);
  box-shadow:       0 -2px 16px rgba(91,110,245,0.08);
}
.bottom-nav-item {
  flex:             1;
  display:          flex;
  flex-direction:   column;
  align-items:      center;
  justify-content:  center;
  gap:              3px;
  padding:          10px 4px 8px;
  background:       none;
  border:           none;
  color:            var(--color-muted);
  font-size:        0.65rem;
  font-weight:      500;
  cursor:           pointer;
  transition:       color var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.bottom-nav-item.active,
.bottom-nav-item:active {
  color: var(--color-primary);
}
.bottom-nav-item svg { transition: stroke var(--transition); }
.bottom-nav-item.active svg { stroke: var(--color-primary); }

/* ---- Calendar ---- */
.cal-grid {
  display:               grid;
  grid-template-columns: repeat(7, 1fr);
  gap:                   2px;
}
.cal-dow {
  text-align:  center;
  font-size:   0.7rem;
  font-weight: 600;
  color:       var(--color-muted);
  padding:     4px 0 8px;
}
.cal-cell {
  min-height:    52px;
  border-radius: var(--radius-sm);
  padding:       5px 4px 4px;
  cursor:        pointer;
  transition:    background var(--transition);
  display:       flex;
  flex-direction: column;
  align-items:   center;
  gap:           3px;
}
.cal-cell:hover          { background: var(--color-accent); }
.cal-cell--empty         { cursor: default; }
.cal-cell--today .cal-day-num {
  background:    var(--color-primary);
  color:         white;
  border-radius: 50%;
  width:         24px;
  height:        24px;
  display:       flex;
  align-items:   center;
  justify-content: center;
}
.cal-cell--selected      { background: var(--color-accent); outline: 2px solid var(--color-primary); }
.cal-day-num {
  font-size:   0.78rem;
  font-weight: 500;
  line-height: 24px;
  width:       24px;
  text-align:  center;
}
.cal-day--weekend        { color: var(--color-muted); }
.cal-dots {
  display:  flex;
  gap:      3px;
  flex-wrap: wrap;
  justify-content: center;
}
.cal-dot {
  width:         7px;
  height:        7px;
  border-radius: 50%;
  display:       inline-block;
  flex-shrink:   0;
}
.cal-legend-item {
  display:     flex;
  align-items: center;
  gap:         5px;
}

@media (min-width: 769px) {
  .bottom-nav { display: none; }
}

@media (max-width: 768px) {
  .smart-input-bar {
    left:    0;
    bottom:  calc(56px + env(safe-area-inset-bottom, 0px));
    padding: 8px 12px;
  }
  .main-content { padding-bottom: calc(120px + env(safe-area-inset-bottom, 0px)); }
  .bottom-nav { display: flex; }
  .fab { bottom: calc(56px + 68px + env(safe-area-inset-bottom, 0px)); right: 16px; }
  .fab-menu { bottom: calc(72px + 72px + 50px + env(safe-area-inset-bottom, 0px)); }
  /* Prevent iOS WebKit zoom on input focus (font-size < 16px triggers zoom) */
  input, textarea, select { font-size: 16px !important; }
}

/* ---- Household Load Balancer ---- */
.load-row {
  display:     flex;
  align-items: center;
  gap:         10px;
  padding:     8px 0;
  border-bottom: 1px solid var(--color-border);
}
.load-row:last-child { border-bottom: none; }

.load-name {
  width:       88px;
  flex-shrink: 0;
  font-size:   0.82rem;
  font-weight: 500;
  overflow:    hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.load-bar-track {
  flex:         1;
  height:       10px;
  background:   var(--color-border);
  border-radius: 6px;
  position:     relative;
  overflow:     visible;
}

.load-bar-fill {
  height:        100%;
  border-radius: 6px;
  transition:    width 0.6s ease;
  min-width:     2px;
}

/* Vertical dashed line showing the "fair share" mark */
.load-fair-line {
  position:   absolute;
  top:        -4px;
  bottom:     -4px;
  width:      2px;
  background: var(--color-muted);
  opacity:    0.35;
  transform:  translateX(-50%);
  border-radius: 1px;
}

.load-count {
  width:       56px;
  flex-shrink: 0;
  font-size:   0.78rem;
  color:       var(--color-muted);
  text-align:  right;
  white-space: nowrap;
}
