:root {
  --sidebar-w: 240px;
  --calendar-cell-size: 34px;
  --calendar-gap: 4px;
  --calendar-weekday-width: 2.5rem;
  --header-height: 56px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font: 16px/1.45 system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, "Helvetica Neue", Arial, "Noto Sans";
  overflow-x: hidden;
}

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas: "header header" "sidebar main";
  min-height: 100vh;
}

.header {
  grid-area: header;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 12px 8px;
  border-bottom: 1px solid #e5e7eb;
}

.header__bar {
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
}

.header__title {
  margin: 0;
  text-align: center;
  font-size: 1.25rem;
}

.header-actions-container {
  position: relative;
}

.header-actions__toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: #4b5563;
  border: 1px solid transparent;
  padding: 0.5rem;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.header-actions__toggle:hover,
.header-actions__toggle:focus {
  background: #f3f4f6;
  color: #1f2937;
  outline: none;
}

.dropdown-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 0.5rem;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  min-width: 200px;
  z-index: 50;
  padding: 0.5rem;
  transform-origin: top right;
  animation: dropdown-enter 0.1s ease-out;
}

@keyframes dropdown-enter {
  from {
    opacity: 0;
    transform: scale(0.95);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

.dropdown-menu__content {
  display: flex;
  flex-direction: column;
}

.dropdown-item-form {
  display: contents;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.625rem 0.75rem;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: #374151;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.15s;
}

.dropdown-item:hover,
.dropdown-item:focus {
  background: #f3f4f6;
  color: #111827;
  outline: none;
}

.dropdown-item--danger {
  color: #ef4444;
}

.dropdown-item--danger:hover,
.dropdown-item--danger:focus {
  background: #fef2f2;
  color: #dc2626;
}

.dropdown-item__icon {
  font-size: 1.1em;
  width: 1.5rem;
  text-align: center;
  color: #6b7280;
}

.dropdown-item--danger .dropdown-item__icon {
  color: inherit;
}

.dropdown-divider {
  height: 1px;
  background: #e5e7eb;
  margin: 0.5rem 0;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.sidebar {
  grid-area: sidebar;
  border-right: 1px solid #e5e7eb;
  padding: 8px;
}

.main {
  grid-area: main;
  padding: 12px;
}

.calendar {
  display: inline-flex;
  flex-direction: column;
  gap: 0.5rem;
  overflow-x: auto;
  max-width: 100%;
  padding-bottom: 0.25rem;
}

.calendar-header {
  display: grid;
  grid-template-columns: var(--calendar-weekday-width) 1fr;
  column-gap: var(--calendar-gap);
  font-size: 0.75rem;
  color: #4b5563;
}

.month-spacer {
  width: var(--calendar-weekday-width);
}

.month-labels {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: var(--calendar-cell-size);
  gap: var(--calendar-gap);
  text-align: left;
}

.month-label {
  display: block;
  white-space: nowrap;
}

.calendar-grid {
  display: grid;
  grid-template-columns: var(--calendar-weekday-width) 1fr;
  column-gap: var(--calendar-gap);
}

.weekday-labels {
  display: grid;
  grid-template-rows: repeat(7, var(--calendar-cell-size));
  gap: var(--calendar-gap);
  justify-items: end;
  font-size: 0.75rem;
  color: #6b7280;
  padding-top: 0.1rem;
}

.weekday-label {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  width: 100%;
  height: var(--calendar-cell-size);
}

.week-columns {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: var(--calendar-cell-size);
  gap: var(--calendar-gap);
}

.week-column {
  display: grid;
  grid-template-rows: repeat(7, var(--calendar-cell-size));
  gap: var(--calendar-gap);
}

.calendar .cell {
  width: var(--calendar-cell-size);
  height: var(--calendar-cell-size);
  border: 1px solid #ddd;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  user-select: none;
  cursor: pointer;
  background: #fff;
  color: #333;
}

.calendar .cell.on {
  background: var(--habit-color, #cdeafe);
  color: #1f2937;
  border-color: rgba(0, 0, 0, 0.06);
}

.calendar .cell.off {
  background: #fff;
  color: #333;
}

.calendar .cell.placeholder {
  background: transparent;
  border-color: transparent;
  cursor: default;
  pointer-events: none;
}

.calendar .cell:focus {
  outline: 3px solid #111;
  outline-offset: 2px;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  padding: 8px;
  border-bottom: 1px solid #eee;
  text-align: left;
}

@media (max-width:640px) {
  .table {
    display: block;
  }

  .table thead {
    display: none;
  }

  .table tr {
    display: block;
    padding: 10px;
    border: 1px solid #eee;
    border-radius: 10px;
    margin-bottom: 10px;
  }

  .table td {
    display: flex;
    justify-content: space-between;
    border: 0;
    padding: 6px 0;
  }

  .table td::before {
    content: attr(data-label);
    font-weight: 600;
    margin-right: 12px;
  }

  .header {
    padding: 8px 10px 12px;
    gap: 10px;
  }

  .header__bar {
    grid-template-columns: auto 1fr auto;
    align-items: center;
  }

  .header__title {
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 1.1rem;
  }

  .header-actions__toggle {
    display: inline-flex;
    justify-content: flex-end;
  }

  .header-actions {
    display: none;
  }

  .header-actions.open {
    display: block;
  }

  .action-menu {
    grid-template-columns: 1fr;
  }
}



@media (max-width:960px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-areas: "header" "main";
  }

  .sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    bottom: 0;
    width: var(--sidebar-w);
    background: #fff;
    transform: translateX(-100%);
    transition: transform .2s ease;
    z-index: 20;
    box-shadow: 2px 0 12px rgba(0, 0, 0, .08);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .backdrop {
    position: fixed;
    inset: var(--header-height) 0 0 0;
    background: rgba(0, 0, 0, .3);
    display: none;
    z-index: 10;
  }

  .backdrop.show {
    display: block;
  }
}

/* Additional styling for forms and layout */
form {
  background: #f9f9f9;
  padding: 1rem;
  border-radius: 6px;
  margin-bottom: 1.5rem;
}

form h3 {
  margin-top: 0;
  margin-bottom: 1rem;
  color: #333;
}

input[type="text"],
input[type="password"],
input[type="date"] {
  padding: 0.65rem 0.75rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 1rem;
  min-height: 42px;
  width: 100%;
  box-sizing: border-box;
}

.habit-form {
  display: grid;
  gap: 1rem;
}

.form-field {
  display: grid;
  grid-template-columns: minmax(160px, 200px) 1fr;
  gap: 0.35rem 0.75rem;
  align-items: center;
}

.form-field label {
  font-weight: 600;
  color: #1f2937;
}

.form-helper {
  grid-column: 2;
  color: #4b5563;
  font-size: 0.95rem;
  line-height: 1.4;
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

button {
  background: #007bff;
  color: white;
  border: none;
  padding: 0.65rem 1.1rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
  min-height: 42px;
  min-width: 42px;
}

button:hover {
  background: #0056b3;
}

button:focus {
  outline: 3px solid #111;
  outline-offset: 2px;
}

#menuBtn {
  background: transparent;
  color: #333;
  font-size: 1.2rem;
  padding: 0.5rem;
}

.habit-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  border-top: 6px solid var(--habit-color, #cdeafe);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.04);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.habit-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.habit-card__title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.habit-card h3 {
  margin: 0;
  color: #1f2937;
}

.habit-card__color-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--habit-color, #cdeafe);
  border: 1px solid rgba(15, 23, 42, 0.12);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.6);
}

.habit-card__delete-form {
  margin: 0;
  background: transparent;
  padding: 0;
  border-radius: 0;
}

.habit-card__actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 1rem;
}

.habit-card__delete-button {
  background: #fff;
  border: 1px solid #fca5a5;
  color: #b91c1c;
  padding: 0.35rem 0.75rem;
  border-radius: 4px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s, border-color 0.2s;
}

.habit-card__delete-button:hover,
.habit-card__delete-button:focus {
  background-color: #fee2e2;
  color: #991b1b;
  border-color: #f87171;
  outline: none;
}

.habit-card__pause-form,
.habit-card__delete-form {
  margin: 0;
  background: transparent;
  padding: 0;
  border-radius: 0;
  width: auto !important;
  display: inline-block;
}

.habit-card__pause-button {
  background: #fff !important;
  border: 1px solid #d1d5db !important;
  color: #4b5563 !important;
  padding: 0.35rem 0.75rem;
  border-radius: 4px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
  min-width: 80px;
}

.habit-card__pause-button:hover,
.habit-card__pause-button:focus {
  background-color: #f3f4f6 !important;
  color: #1f2937 !important;
  border-color: #9ca3af !important;
}

.habit-card__pause-button.paused {
  border-color: #3b82f6 !important;
  color: #2563eb !important;
}

.habit-card__pause-button.paused:hover,
.habit-card__pause-button.paused:focus {
  background-color: #eff6ff !important;
  color: #1d4ed8 !important;
  border-color: #2563eb !important;
}

.habit-card__not-today-form {
  margin: 0;
  background: transparent;
  padding: 0;
  border-radius: 0;
  width: auto !important;
  display: inline-block;
}

.habit-card__not-today-button {
  background: #fff;
  border: 1px solid #fdba74;
  color: #c2410c;
  padding: 0.35rem 0.75rem;
  border-radius: 4px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s, border-color 0.2s;
  min-width: 80px;
}

.habit-card__not-today-button:hover,
.habit-card__not-today-button:focus {
  background-color: #ffedd5;
  color: #9a3412;
  border-color: #fb923c;
  outline: none;
}

.calendar-container {
  margin: 1rem 0;
}

.sidebar ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sidebar li {
  margin-bottom: 0.5rem;
}

.sidebar a {
  display: block;
  padding: 0.75rem;
  text-decoration: none;
  color: #333;
  border-radius: 4px;
  transition: background-color 0.2s;
}

.sidebar a:hover,
.sidebar a:focus,
.sidebar a.active,
.sidebar a[aria-current="page"] {
  background: #f0f0f0;
}

.error {
  background: #ffebee;
  border: 1px solid #e57373;
  color: #c62828;
  padding: 1rem;
  border-radius: 4px;
  margin-bottom: 1rem;
}

@media (max-width: 640px) {
  :root {
    --calendar-cell-size: 34px;
  }

  .habit-card {
    padding: 1rem;
  }

  .calendar .cell {
    font-size: 0.9rem;
  }

  .calendar-header,
  .weekday-labels {
    font-size: 0.85rem;
  }

  .dropdown-item {
    font-size: 1rem;
    padding: 0.8rem 1rem;
  }

  .header__title {
    font-size: 1.3rem;
  }
}

/* Authentication Pages Styling */
.auth-card {
  max-width: 400px;
  margin: 3rem auto;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 2rem;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.04);
}

.auth-card h2 {
  margin-top: 0;
  margin-bottom: 1.5rem;
  text-align: center;
  color: #1f2937;
  font-size: 1.5rem;
}

.auth-card form {
  background: transparent;
  padding: 0;
  border-radius: 0;
  margin-bottom: 0;
}

@media (max-width: 640px) {
  .habit-form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }

  .form-field {
    grid-template-columns: 1fr;
    gap: 0.25rem;
  }

  .form-helper {
    grid-column: 1;
  }

  .form-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .form-actions button {
    width: 100%;
  }

  input[type="text"],
  input[type="password"],
  input[type="date"],
  button {
    min-height: 46px;
  }

  .calendar {
    display: flex;
    width: 100%;
  }

  .calendar-container {
    width: 100%;
    min-width: 0;
    overflow-x: auto;
  }

  .main {
    padding: 0;
  }

  .main>h2 {
    padding: 0 1rem;
  }

  .habit-card,
  form,
  .table tr {
    border-radius: 0;
    border-left: none;
    border-right: none;
    margin-left: 0;
    margin-right: 0;
    width: 100%;
    max-width: 100vw;
  }


}

/* Notification Page Styling */
.notifications-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 1rem;
}

.notifications-section {
  margin-bottom: 2rem;
}

.notifications-section__title {
  font-size: 1.25rem;
  color: #1f2937;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px solid #e5e7eb;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  gap: 1rem;
}

.section-header__form {
  margin: 0;
  padding: 0;
  background: none;
  min-height: auto;
  width: auto !important;
}

.link-button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.5rem;
  min-height: auto;
  min-width: auto;
}

.link-button--primary {
  color: #3b82f6;
}

.link-button--danger {
  color: #ef4444;
}

.notifications-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.notification-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  transition: transform 0.2s, box-shadow 0.2s;
}

.notification-item:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.notification-item--new {
  border-left: 4px solid #3b82f6;
  /* Blue indicator for new */
}

.notification-item--seen {
  border-left: 4px solid #9ca3af;
  /* Grey indicator for seen */
  background: #f9fafb;
}

.notification-item__message {
  flex: 1;
  font-size: 1rem;
  color: #374151;
  margin-right: 1rem;
  /* Ensure single line with ellipsis if too long, though usually short */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.notification-item__action {
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
}

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s;
  width: 32px;
  height: 32px;
  font-size: 1rem;
  line-height: 1;
}

.btn-icon--grey {
  color: #6b7280;
}

.btn-icon--grey:hover {
  background-color: #f3f4f6;
  color: #374151;
}

.btn-icon--red {
  color: #ef4444;
}

.btn-icon--red:hover {
  background-color: #fef2f2;
  color: #dc2626;
}

.empty-state {
  color: #9ca3af;
  font-style: italic;
  text-align: center;
  padding: 1rem;
  background: #f9fafb;
  border-radius: 6px;
  border: 1px dashed #d1d5db;
}

/* Mobile adjustments */
@media (max-width: 640px) {
  .notifications-container {
    padding: 0.5rem;
  }

  .notification-item {
    padding: 0.75rem;
  }

  .notification-item__message {
    font-size: 0.95rem;
  }

  /* Ensure single line concept holds on mobile */
  .notification-item {
    flex-wrap: nowrap;
  }

  /* Fix for global form width: 100% on mobile overriding the button container */
  form.notification-item__action {
    width: auto;
    margin: 0;
    min-width: 0;
    background: transparent;
    padding: 0;
  }
}