/* Calendar and contacts (M4). Reuses the app tokens: no new palette, only
   layout and the calendar grid. Light and dark follow prefers-color-scheme. */

/* ------------------------------------------------------------- Topbar bell */

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  min-width: 0;
}

.bell-button {
  position: relative;
}

.bell-badge {
  position: absolute;
  top: 0.15rem;
  right: 0.1rem;
  min-width: 1.1rem;
  padding: 0 0.25rem;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--accent-ink);
  font-family: var(--font-mono);
  font-size: 0.625rem;
  line-height: 1.1rem;
  text-align: center;
}

.notifications-panel {
  width: min(22rem, calc(100vw - 2rem));
  max-height: min(28rem, calc(100dvh - 5rem));
  overflow: auto;
}

.notifications-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.notifications-list {
  display: grid;
  gap: 2px;
  margin: 0;
  padding: var(--space-1);
  list-style: none;
}

.notification-item {
  display: flex;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: inherit;
  text-align: start;
  cursor: pointer;
}

.notification-item:hover,
.notification-item:focus-visible {
  background: var(--surface-2);
}

.notification-dot {
  flex: none;
  width: 0.45rem;
  height: 0.45rem;
  margin-top: 0.42rem;
  border-radius: 50%;
  background: transparent;
}

.notification-item.is-unread .notification-dot {
  background: var(--accent);
}

.notification-text {
  display: grid;
  gap: 0.1rem;
  min-width: 0;
}

.notification-title {
  font-size: var(--text-sm);
  font-weight: 600;
  overflow-wrap: anywhere;
}

.notification-body,
.notification-time {
  color: var(--muted);
  font-size: var(--text-xs);
}

.notifications-empty {
  margin: 0;
  padding: var(--space-4);
  color: var(--muted);
  font-size: var(--text-sm);
  text-align: center;
}

.notifications-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-top: 1px solid var(--line);
}

.notifications-push-note {
  margin: 0;
  padding: 0 var(--space-3) var(--space-3);
}

.btn-link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: var(--text-sm);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ---------------------------------------------------------------- Page head */

.pim-head {
  align-items: flex-end;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.pim-actions {
  flex-wrap: wrap;
  gap: var(--space-2);
}

.segmented {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.segmented-btn {
  min-height: var(--control-h-sm);
  padding: 0 var(--space-3);
  border: 0;
  border-radius: calc(var(--radius) - 2px);
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: var(--text-sm);
  cursor: pointer;
}

.segmented-btn:hover {
  color: var(--ink);
}

.segmented-btn[aria-pressed="true"] {
  background: var(--surface-raised);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.pim-nav {
  display: inline-flex;
  gap: var(--space-1);
}

.pim-flip {
  transform: scaleX(-1);
}

/* --------------------------------------------------------------- Two panes */

.pim-layout {
  display: grid;
  grid-template-columns: 16rem minmax(0, 1fr);
  gap: var(--space-4);
  align-items: start;
  margin-top: var(--space-4);
}

.pim-side {
  display: grid;
  gap: var(--space-2);
  padding: var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.pim-side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.pim-side-title {
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
}

.pim-list {
  display: grid;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.pim-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 2.25rem;
  padding: 0 var(--space-2);
  border-radius: var(--radius-sm);
}

.pim-row:hover {
  background: var(--surface-2);
}

.pim-row.is-active {
  background: var(--accent-soft);
}

.pim-check {
  flex: none;
  width: 1rem;
  height: 1rem;
  accent-color: var(--accent);
}

.pim-dot {
  flex: none;
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
  background: var(--cal-color, var(--accent));
}

.pim-row-label {
  display: flex;
  flex: 1;
  min-width: 0;
}

.pim-row-name {
  max-width: 100%;
  padding: 0.2rem 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: start;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.pim-row-name[aria-current="true"] {
  font-weight: 600;
  color: var(--accent);
}

.pim-row-actions {
  display: flex;
  flex: none;
  align-items: center;
  gap: 2px;
}

.pim-count {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

.badge-soft {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.625rem;
}

.pim-side-hint,
.pim-side-foot {
  margin: 0;
  color: var(--muted);
  font-size: var(--text-xs);
}

.pim-side-foot {
  padding-top: var(--space-2);
  border-block-start: 1px solid var(--line);
}

.pim-main {
  min-width: 0;
}

.pim-state {
  margin: 0;
  padding: var(--space-5);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.pim-board {
  min-width: 0;
}

/* ------------------------------------------------------------- Month grid */

.month-grid {
  min-width: 40rem;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.month-grid-row {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.pim-board {
  overflow-x: auto;
}

.pim-scroll-hint {
  display: none;
  margin: var(--space-2) 0 0;
  color: var(--muted);
  font-size: var(--text-xs);
}

.month-weekday {
  padding: var(--space-2);
  border-block-end: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 600;
  text-align: center;
  text-transform: uppercase;
}

.month-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 6.5rem;
  padding: var(--space-1);
  border-inline-end: 1px solid var(--line);
}

.month-grid-row + .month-grid-row .month-cell {
  border-block-start: 1px solid var(--line);
}

.month-cell:nth-child(7n) {
  border-inline-end: 0;
}

.month-cell.is-outside {
  background: var(--surface-2);
}

.month-cell.is-outside .month-day {
  color: var(--muted);
}

.month-cell.is-today {
  background: var(--accent-soft);
}

.month-day {
  align-self: flex-start;
  min-width: 1.75rem;
  min-height: 1.75rem;
  padding: 0 0.35rem;
  border: 0;
  border-radius: var(--radius-pill);
  background: none;
  color: inherit;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  cursor: pointer;
}

.month-cell.is-today .month-day {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.month-day:hover {
  background: var(--surface-raised);
}

.month-cell.is-today .month-day:hover {
  background: var(--accent-hover);
}

.event-chip {
  display: flex;
  align-items: baseline;
  gap: var(--space-1);
  width: 100%;
  padding: 0.1rem 0.3rem;
  border: 0;
  border-inline-start: 3px solid var(--cal-color, var(--accent));
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--cal-color, var(--accent)) 14%, var(--surface));
  color: var(--ink);
  font: inherit;
  font-size: var(--text-xs);
  text-align: start;
  cursor: pointer;
  overflow: hidden;
  white-space: nowrap;
}

.event-chip:hover,
.event-chip:focus-visible {
  background: color-mix(in srgb, var(--cal-color, var(--accent)) 26%, var(--surface));
}

.event-chip-time {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.625rem;
}

.event-chip-title {
  overflow: hidden;
  text-overflow: ellipsis;
}

.event-chip-repeat {
  flex: none;
  margin-inline-start: auto;
  opacity: 0.65;
}

.month-more {
  align-self: flex-start;
  padding: 0 0.3rem;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: var(--text-xs);
  cursor: pointer;
}

/* -------------------------------------------------------------- Week/day */

.week-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(9rem, 1fr));
  min-width: 52rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.week-col {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-height: 24rem;
  padding: var(--space-2);
  border-inline-end: 1px solid var(--line);
}

.week-col:last-child {
  border-inline-end: 0;
}

.week-col.is-today {
  background: var(--accent-soft);
}

.week-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-1);
  padding: var(--space-1);
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.week-head:hover {
  background: var(--surface-2);
}

.week-head-name {
  color: var(--muted);
  font-size: var(--text-xs);
  text-transform: uppercase;
}

.week-head-date {
  font-family: var(--font-mono);
  font-size: var(--text-md);
  font-weight: 600;
}

.week-col.is-today .week-head-date {
  color: var(--accent);
}

.week-empty {
  margin: 0;
  color: var(--muted);
  font-size: var(--text-xs);
  text-align: center;
}

.week-col .event-chip {
  white-space: normal;
}

.day-view {
  display: grid;
  gap: var(--space-3);
}

.day-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.day-title {
  font-size: var(--text-lg);
}

.day-list {
  display: grid;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

.day-item {
  display: grid;
  grid-template-columns: 9rem minmax(0, 1fr);
  gap: var(--space-3);
  align-items: start;
  padding: var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.day-item-time {
  padding-top: 0.15rem;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

.day-item-body {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: var(--space-2);
  align-items: center;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: start;
  cursor: pointer;
}

.day-item-title {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.day-item-meta {
  grid-column: 2;
  color: var(--muted);
  font-size: var(--text-xs);
}

.list-view {
  display: grid;
  gap: var(--space-4);
}

.list-day-title {
  margin: 0 0 var(--space-2);
  font-size: var(--text-md);
}

.list-events {
  display: grid;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  list-style: none;
}

.list-event + .list-event {
  border-block-start: 1px solid var(--line);
}

.list-event-body {
  display: grid;
  grid-template-columns: auto 7rem minmax(0, 1fr) auto;
  gap: var(--space-2);
  align-items: center;
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: start;
  cursor: pointer;
}

.list-event-body:hover {
  background: var(--surface-2);
}

.list-event-time {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

.list-event-title {
  font-weight: 500;
  overflow-wrap: anywhere;
}

.list-event-cal {
  color: var(--muted);
  font-size: var(--text-xs);
}

.pim-empty {
  display: grid;
  gap: var(--space-2);
  justify-items: center;
  padding: var(--space-6);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.pim-empty p {
  margin: 0;
}

.pim-empty-inline {
  margin: 0;
  color: var(--muted);
  font-size: var(--text-sm);
}

/* ----------------------------------------------------------------- Forms */

.pim-form-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
}

.input-color {
  min-height: var(--control-h);
  padding: 0.2rem;
}

.checkline {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
}

.dialog-foot-group {
  display: flex;
  gap: var(--space-2);
  margin-inline-start: auto;
}

.input-sm {
  min-height: 2rem;
  padding: 0 var(--space-2);
  font-size: var(--text-sm);
}

/* --------------------------------------------------------------- Sharing */

.share-list {
  display: grid;
  gap: var(--space-1);
  margin: 0;
  padding: 0;
  list-style: none;
}

.share-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.share-who {
  display: grid;
  gap: 0.1rem;
  min-width: 0;
}

.share-name {
  font-size: var(--text-sm);
  font-weight: 500;
  overflow-wrap: anywhere;
}

.share-kind {
  color: var(--muted);
  font-size: var(--text-xs);
}

.share-actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.share-form {
  display: grid;
  gap: var(--space-3);
  padding-top: var(--space-3);
  border-block-start: 1px solid var(--line);
}

.share-form > .dialog-error {
  margin: 0;
}

.share-form > .dialog-foot {
  padding: var(--space-3) 0 0;
  border: 0;
}

.share-loading {
  padding: var(--space-3);
  color: var(--muted);
  font-size: var(--text-sm);
  text-align: center;
}

/* --------------------------------------------------------------- Contacts */

.pim-layout-contacts {
  grid-template-columns: 15rem minmax(0, 1fr);
}

.contacts-main {
  display: grid;
  gap: var(--space-3);
  align-content: start;
}

.pim-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.pim-search {
  flex: 1;
  max-width: 28rem;
}

.contacts-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-3);
  align-items: start;
}

.contacts-split:has(.contact-card:not([hidden])) {
  grid-template-columns: minmax(0, 1fr) 21rem;
}

.contacts-table-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.contacts-table {
  table-layout: fixed;
  width: 100%;
}

.contacts-col {
  color: var(--muted);
  font-size: var(--text-xs);
}

.contacts-table th:nth-child(1) { width: 27%; }
.contacts-table th:nth-child(2) { width: 21%; }
.contacts-table th:nth-child(3) { width: 30%; }
.contacts-table th:nth-child(4) { width: 22%; }

.contacts-table td {
  overflow-wrap: anywhere;
}

/* The card repeats organisation and phones; hiding those columns keeps the
   remaining name/email readable at 1366-1440 px, where the split is narrow. */
.contacts-split:has(.contact-card:not([hidden])) .contacts-table th:nth-child(2),
.contacts-split:has(.contact-card:not([hidden])) .contacts-table td:nth-child(2),
.contacts-split:has(.contact-card:not([hidden])) .contacts-table th:nth-child(4),
.contacts-split:has(.contact-card:not([hidden])) .contacts-table td:nth-child(4) {
  display: none;
}

.contacts-split:has(.contact-card:not([hidden])) .contacts-table th:nth-child(1) {
  width: 38%;
}

.contacts-split:has(.contact-card:not([hidden])) .contacts-table th:nth-child(3) {
  width: 62%;
}

.contacts-table tr {
  cursor: pointer;
}

.contacts-table tr:hover {
  background: var(--surface-2);
}

.contacts-table tr.is-selected {
  background: var(--accent-soft);
}

.contact-open {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-weight: 500;
  text-align: start;
  cursor: pointer;
}

.contact-open:hover {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.contact-card {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.contact-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-2);
}

.contact-name {
  font-size: var(--text-lg);
  overflow-wrap: anywhere;
}

.contact-sub {
  margin-top: var(--space-1);
  color: var(--muted);
  font-size: var(--text-sm);
}

.contact-fields {
  display: grid;
  grid-template-columns: 7rem minmax(0, 1fr);
  gap: var(--space-2);
  margin: 0;
  font-size: var(--text-sm);
}

.contact-fields dt {
  color: var(--muted);
}

.contact-fields dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.contact-fields a {
  color: var(--accent);
}

.contact-actions {
  display: flex;
  gap: var(--space-2);
  padding-top: var(--space-2);
  border-block-start: 1px solid var(--line);
}

/* ------------------------------------------------------------- Responsive */

@media (max-width: 960px) {
  .pim-layout,
  .pim-layout-contacts {
    grid-template-columns: 1fr;
  }

  .pim-side {
    padding: var(--space-2);
  }

  .pim-list {
    grid-auto-flow: column;
    grid-auto-columns: minmax(17rem, max-content);
    overflow-x: auto;
    padding-block-end: var(--space-1);
  }

  .pim-side-hint {
    display: none;
  }

  .contacts-split:has(.contact-card:not([hidden])) {
    grid-template-columns: 1fr;
  }

  .contact-card {
    order: -1;
  }
}

@media (max-width: 640px) {
  .pim-head {
    align-items: flex-start;
  }

  .pim-actions {
    width: 100%;
  }

  .pim-actions .segmented {
    flex: 1;
    justify-content: space-between;
  }

  .segmented-btn {
    flex: 1;
    padding-inline: var(--space-1);
  }

  .pim-nav {
    order: 3;
    margin-inline-start: auto;
  }

  .pim-form-row {
    grid-template-columns: 1fr;
  }

  .pim-list {
    grid-auto-flow: row;
    grid-auto-columns: auto;
    grid-template-columns: minmax(0, 1fr);
    overflow: visible;
  }

  .pim-scroll-hint {
    display: block;
  }

  .month-grid {
    min-width: 34rem;
  }

  .month-cell {
    min-height: 5rem;
  }

  .event-chip-time {
    display: none;
  }

  .day-item {
    grid-template-columns: 1fr;
    gap: var(--space-1);
  }

  .day-item-body {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .day-item-meta {
    grid-column: 2;
  }

  .list-event-body {
    grid-template-columns: auto 5rem minmax(0, 1fr);
  }

  .list-event-cal {
    display: none;
  }

  .contacts-table th:nth-child(2),
  .contacts-table td:nth-child(2),
  .contacts-table th:nth-child(4),
  .contacts-table td:nth-child(4) {
    display: none;
  }

  .contacts-table th:nth-child(1) { width: 38%; }
  .contacts-table th:nth-child(3) { width: 62%; }

  .contact-fields {
    grid-template-columns: 1fr;
    gap: var(--space-1);
  }

  .contact-fields dt {
    margin-top: var(--space-1);
    font-size: var(--text-xs);
    text-transform: uppercase;
  }

  .share-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .share-actions {
    width: 100%;
  }

  .share-actions .input-sm {
    flex: 1;
  }

  .notifications-panel {
    width: calc(100vw - 1.5rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  .event-chip,
  .month-day,
  .week-head {
    transition: none;
  }
}
