/* Dashboard-spezifische Styles: bildschirmfüllendes 2x2 Kreuz */

/* Basis: Grid soll den kompletten Viewport füllen */
/* #dashboard soll nicht die komplette Seite überlagern sondern
   die volle Fläche des übergeordneten `#content`-Containers einnehmen */
/* Dashboard color palette and layout */
#dashboard {
  /* modern, slightly cool gray background that contrasts with the
     dark widget headers while remaining distinct from the sidebar */
  --dashboard-bg: #f3f4f6; /* leicht grauer Hintergrund für das Dashboard */
  --card-bg: #ffffff; /* widget card surface */
  --card-surface: #ffffff; /* item surface (news/appointments) */
  --muted-text: #556066;
  --text-color: #111827;
  --accent: #0b76ef; /* primary accent */
  --divider: #d6dde4; /* softer divider between widgets */
  --divider-thickness: 6px;

  position: relative;
  width: 100%;
  height: 100%;
  padding: 0;
  margin: 0;
  overflow: hidden; /* verhindert Scrollen innerhalb des Dashboards */
  background: var(--dashboard-bg);
}

/* Grid füllt das Dashboard-Element (welches bereits viewport-gebunden ist) */
#dashboard .dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 0; /* keine Lücken, damit die Linien durchgehend sind */
  width: 100%;
  height: 100%;
}

/* Ensure grid cells (widgets) all stay equal height and inner content doesn't force expansion */
#dashboard .dashboard-grid {
  align-items: stretch;
  grid-auto-rows: 1fr;
}

/* Widgets: vollflächig, ohne abgerundete Ecken oder Schatten, damit die Trennlinien sauber bis zum Rand laufen */
#dashboard .widget {
  background: var(--card-bg, #fff);
  padding: 1rem;
  border-radius: 0;
  box-shadow: none;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  min-height: 0; /* allow grid row to control height */
  min-width: 0; /* prevent long content from forcing widget wider */
  align-self: stretch;
}

#dashboard .widget-title {
  margin: 0 0 0.75rem 0;
  font-size: 1rem;
  color: #fff;
  /* modern dark header */
  background: linear-gradient(180deg, #111827 0%, #1f2937 100%);
  padding: 0 0.75rem;
  border-radius: 8px;
  box-shadow: 0 4px 10px rgba(2, 6, 23, 0.25);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  font-weight: 600;
  line-height: 1;
  box-sizing: border-box;
  height: 48px; /* consistent header height */
  min-height: 48px;
}

/* Ensure the title text stays left-aligned and can ellipsize if very long */
#dashboard .widget-title > span {
  display: inline-block;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

/* make sure buttons inside the title keep their appearance but sit to the right */
#dashboard .widget-title .btn-icon {
  margin-left: 8px;
}

@media (max-width: 800px) {
  #dashboard .widget-title {
    height: 44px;
    min-height: 44px;
    padding: 0 0.6rem;
  }
}

#dashboard .widget-body {
  flex: 1 1 auto;
  color: var(--muted-text, #444);
  font-size: 0.95rem;
  min-height: 0; /* prevents content from forcing parent taller */
  overflow: auto; /* enable internal scrolling when content overflows */
}

/* Kreuz: rechte Linie der linken Spalte und untere Linie der oberen Zeile */
/* Dicke und Farbe anpassbar über CSS-Variable --divider */
:root {
  /* fallback global divider variables; dashboard overrides these above */
  --divider: #2b2b2b;
  --divider-thickness: 6px;
}

/* rechte Grenze für die linke Spalte */
#widget-1,
#widget-3 {
  border-right: var(--divider-thickness) solid var(--divider);
}

/* untere Grenze für die obere Zeile */
#widget-1,
#widget-2 {
  border-bottom: var(--divider-thickness) solid var(--divider);
}

/* Zentrierung und Stil für die eingefügte Dashboard-Überschrift im ersten Widget */
.dashboard-heading {
  margin: 0 0 0.25rem 0;
  font-size: 1.4rem;
}

.dashboard-intro {
  margin: 0 0 0.75rem 0;
  color: var(--muted-text, #666);
}

/* Auf kleinen Bildschirmen: Kreuz beibehalten (2x2), aber Dicke ggf. reduzieren */
@media (max-width: 600px) {
  :root {
    --divider-thickness: 4px;

    /* action buttons in appointment items */
    .appt-actions {
      margin-left: 8px;
      display: inline-flex;
      align-items: center;
    }
    .appt-actions .btn-edit,
    .appt-actions .btn-delete {
      border: 1px solid rgba(0, 0, 0, 0.08);
      background: #fff;
      padding: 4px 8px;
      border-radius: 4px;
      font-size: 0.85rem;
      cursor: pointer;
    }
    .appt-actions .btn-edit:hover {
      background: rgba(11, 118, 239, 0.06);
    }
    .appt-actions .btn-delete {
      background: #fff6f6;
      border-color: rgba(255, 0, 0, 0.12);
    }
    .appt-actions .btn-delete:hover {
      background: #ffecec;
    }
  }
}

/* --- Styles für die Terminübersicht (Next Appointments) --- */
#nextAppointments {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#nextAppointmentsLoading {
  color: var(--muted-text, #666);
  font-size: 0.95rem;
}

#nextAppointmentsList {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.appointment-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  background: var(--card-surface, #ffffff);
  border: 1px solid rgba(16, 24, 32, 0.04);
  color: var(--text-color, #111827);
  font-size: 0.95rem;
  min-width: 0; /* allow children to shrink and text-overflow to work */
  overflow: hidden; /* ensure long children don't expand the item */
}

.appointment-item:hover {
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.98),
    rgba(249, 250, 251, 0.98)
  );
  transform: translateY(-1px);
}

.appointment-item::before {
  content: "\25CF"; /* small dot */
  display: inline-block;
  width: 0.9em;
  text-align: center;
  color: var(--accent, #0b76ef);
  font-size: 0.8em;
  margin-right: 0.25rem;
}

/* Modern circular action buttons (used for the + buttons in widgets) */
.btn-icon.modern {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent, #0b76ef);
  color: #fff;
  border: none;
  padding: 0;
  box-shadow: 0 6px 18px rgba(11, 118, 239, 0.12);
  transition: transform 150ms ease, box-shadow 150ms ease, background 150ms ease;
  cursor: pointer;
}
.btn-icon.modern svg {
  display: block;
  width: 18px;
  height: 18px;
}
.btn-icon.modern:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 6px 18px rgba(11, 118, 239, 0.22);
}
.btn-icon.modern:active {
  transform: translateY(0) scale(0.99);
}
.btn-icon.modern:focus {
  outline: 2px solid rgba(11, 118, 239, 0.22);
  outline-offset: 2px;
}

/* variant: subtle (white background, accent icon) - for contrast if needed */
.btn-icon.modern.subtle {
  background: #fff;
  color: var(--accent, #0b76ef);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
}

.appointment-item .appt-date {
  font-weight: 600;
  margin-right: 0.5rem;
  color: var(--muted-text, #444);
}

.appointment-item .appt-title {
  flex: 1 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0; /* ensure ellipsis kicks in instead of growing the container */
  display: block;
  max-width: 100%;
}

/* Ensure widget body doesn't force the grid column wider when children overflow */
#dashboard .widget-body {
  min-width: 0;
}

.empty-state {
  color: var(--muted-text, #666);
  font-style: italic;
}

/* laufender Termin: grüner Rahmen */
.appointment-item.current {
  border: 2px solid #2ecc71;
  box-shadow: 0 2px 6px rgba(46, 204, 113, 0.08);
}

@media (max-width: 800px) {
  .appointment-item {
    font-size: 0.9rem;
    padding: 0.4rem 0.5rem;
  }
}

/* Activity widget styles - added for "Letzte Aktivitäten" */
#widget-2 .widget-body {
  padding: 12px;
}

#recentActivitiesList,
#widget-2 .recent-activities {
  list-style: none;
  margin: 0;
  padding: 0;
  /* Let the widget body handle scrolling to avoid nested scrollbars */
  max-height: none;
  overflow: visible;
}

#recentActivitiesList li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 8px;
  border-radius: 6px;
  margin-bottom: 8px;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.02),
    rgba(0, 0, 0, 0.02)
  );
  border: 1px solid rgba(0, 0, 0, 0.06);
}

/* left-side icon for activity items */
.activity-icon {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.activity-icon svg {
  width: 18px;
  height: 18px;
  display: block;
}

#recentActivitiesList li .activity-content {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0; /* allow children to shrink */
  width: 100%;
}

/* left column: stacked title + appointment date */
#recentActivitiesList li .activity-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  flex: 1 1 auto;
}

#recentActivitiesList li .activity-title {
  font-size: 13px;
  color: #212121;
  margin: 0;
  line-height: 1.2;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#recentActivitiesList li .activity-date {
  font-size: 12px;
  color: #6b6b6b;
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* right column: actor + change timestamp (keeps fixed width) */
#recentActivitiesList li .activity-meta {
  font-size: 11px;
  color: #6b6b6b;
  flex: 0 0 auto;
  white-space: nowrap;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

/* ensure list respects widget width */
#recentActivitiesList {
  box-sizing: border-box;
  width: 100%;
}
#widget-2 .widget-body {
  box-sizing: border-box;
}

#recentActivitiesList li .activity-actor {
  font-style: normal;
  color: #6b6b6b;
}

#recentActivitiesList li.activity-new {
  border-left: 4px solid #2e7d32; /* green */
}

#recentActivitiesList li.activity-updated {
  border-left: 4px solid #1565c0; /* blue */
}

#recentActivitiesList li.activity-deleted {
  border-left: 4px solid #c62828; /* red */
  opacity: 0.95;
}

/* subtle hover */
#recentActivitiesList li:hover {
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

/* small timestamp style */
.activity-time {
  font-size: 11px;
  color: #9a9a9a;
}

/* --- Schwarzes Brett / News styles --- */
/* news list: similar visual language to activities but optimized for title + remarks + actions */
#widget-4 .widget-body {
  padding: 12px;
  box-sizing: border-box;
}

.news-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  /* allow the widget body to scroll, but give the list a sensible max-height */
  width: 100%;
}

.news-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px;
  border-radius: 8px;
  background: var(--card-surface, #ffffff);
  border: 1px solid rgba(16, 24, 32, 0.04);
  box-shadow: 0 1px 3px rgba(16, 24, 32, 0.04);
  cursor: pointer;
}

.news-item .activity-icon {
  flex: 0 0 22px;
  width: 22px;
  height: 22px;
}

.news-item .activity-content {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  flex: 1 1 auto;
}

.news-item .activity-title {
  font-size: 13px;
  font-weight: 700;
  color: #212121;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.news-item .activity-title a {
  color: inherit;
  text-decoration: none;
}
.news-item .activity-title a:hover {
  text-decoration: underline;
}

.news-item .activity-date {
  font-size: 12px;
  color: #6b6b6b;
  white-space: nowrap;
}

.news-item .activity-text .activity-date {
  /* use as remarks line in news: clamp to 3 lines with ellipsis */
  font-size: 13px;
  color: #4b4b4b;
  white-space: normal;
  line-height: 1.2em;
  max-height: calc(1.2em * 3);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  text-overflow: ellipsis;
}

.news-item .activity-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  flex: 0 0 auto;
  white-space: nowrap;
  font-size: 12px;
  color: #6b6b6b;
}

.news-item .activity-actor {
  font-weight: 600;
  color: #333;
}

.news-item .activity-time {
  font-size: 11px;
  color: #9a9a9a;
}

.news-item .btn-edit,
.news-item .btn-delete {
  border: 1px solid rgba(0, 0, 0, 0.06);
  background: #fff;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
}
.news-item .btn-edit:hover {
  background: rgba(11, 118, 239, 0.06);
}
.news-item .btn-delete {
  background: #fff6f6;
  border-color: rgba(255, 0, 0, 0.08);
}
.news-item .btn-delete:hover {
  background: #ffecec;
}

/* Apply the same edit/delete button style to appointment widget buttons
   so Terminübersicht buttons and Schwarzes Brett buttons look identical */
.btn-edit,
.btn-delete {
  border: 1px solid rgba(0, 0, 0, 0.06);
  background: #fff;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
}
.btn-edit:hover {
  background: rgba(11, 118, 239, 0.06);
}
.btn-delete {
  background: #fff6f6;
  border-color: rgba(255, 0, 0, 0.08);
}
.btn-delete:hover {
  background: #ffecec;
}

/* Responsive: compact action column on narrow screens */
@media (max-width: 700px) {
  .news-item {
    padding: 8px;
    gap: 8px;
  }
  .news-item .activity-meta {
    align-items: flex-start;
    white-space: normal;
  }
  .news-item .activity-title {
    font-size: 14px;
  }
}

/* responsive tweak */
@media (max-width: 700px) {
  #recentActivitiesList li .activity-title {
    font-size: 12px;
  }
  #recentActivitiesList {
    max-height: 240px;
  }
}

/* --- Aufgaben-Widget (widget-3) Styles --- */
#widget-3 .widget-body {
  padding: 12px;
  box-sizing: border-box;
}
.tasks-overview {
  /* legacy: not used with table layout, kept for backwards compatibility */
  display: block;
}

/* Table layout for tasks */
.tasks-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}
.tasks-table thead th {
  text-align: left;
  font-size: 0.98rem;
  padding: 8px 10px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  background: rgba(0, 0, 0, 0.02);
}
.tasks-table thead th {
  font-weight: 700;
  color: #1f2937; /* slightly stronger text color */
  letter-spacing: 0.2px;
  text-transform: none;
}
.tasks-table thead th:first-child {
  background: rgba(255, 235, 238, 0.95); /* match left column pale red */
  border-top-left-radius: 6px;
}
.tasks-table thead th:last-child {
  background: rgba(237, 247, 237, 0.98); /* match right column pale green */
  border-top-right-radius: 6px;
}
.tasks-table thead th + th {
  border-left: 1px solid rgba(0, 0, 0, 0.03);
}
.tasks-table thead th .header-count {
  display: inline-block;
  margin-left: 8px;
  font-weight: 600;
  color: #4b5563;
  font-size: 0.9rem;
}
.tasks-table td {
  vertical-align: top;
  padding: 12px 10px;
}
.tasks-table .open-cell {
  background: rgba(255, 235, 238, 0.8); /* blass rot */
  border-right: 1px solid rgba(0, 0, 0, 0.03);
}
.tasks-table .done-cell {
  background: rgba(237, 247, 237, 0.9); /* blass grün */
}
.tasks-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.task-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.04);
  font-size: 0.95rem;
}
.task-item.task-open {
  border-left: 4px solid #f39c12; /* orange for open */
}
.task-item.task-done {
  border-left: 4px solid #2ecc71; /* green for done */
  opacity: 0.95;
}
.task-date {
  color: var(--muted-text, #666);
  font-size: 0.85rem;
  margin-left: 8px;
}

@media (max-width: 800px) {
  .tasks-overview {
    flex-direction: column;
  }
}

/* --- Modal / News editor classes (moved from inline JS styles) --- */
.news-modal-overlay {
  position: fixed;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}
.news-modal-box {
  width: 520px;
  max-width: 92%;
  background: #fff;
  border-radius: 8px;
  padding: 16px;
  height: 80vh;
  max-height: 80vh;
  overflow: auto;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.2);
}
.news-modal-title {
  margin: 0 0 8px 0;
}
.news-modal-content {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1 1 auto;
  overflow: auto;
}
.news-modal-field {
  width: 100%;
  padding: 8px;
  box-sizing: border-box;
}
.news-modal-field-title {
  margin: 8px 0;
  min-height: 3.2em;
  resize: vertical;
}
.news-modal-field-remarks {
  min-height: 220px;
  resize: vertical;
}
.news-modal-field-link {
  margin-top: 8px;
}
.news-modal-btnrow {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}
.news-modal-btn {
  border: none;
  padding: 8px 12px;
  border-radius: 4px;
  cursor: pointer;
}
.news-modal-btn-cancel {
  background: #e0e0e0;
}
.news-modal-btn-save {
  background: var(--accent, #0b76ef);
  color: #fff;
}

/* actions / controls classes previously set inline */
.news-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.news-controls {
  margin-top: 8px;
  display: flex;
  justify-content: center;
}
.news-controls .btn-loadmore {
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid rgba(0, 0, 0, 0.06);
  background: #fff;
  cursor: pointer;
}

/* appointment actions general class */
.appt-actions {
  display: flex;
  gap: 6px;
}

/* utility hidden class used by scripts to toggle visibility */
.hidden {
  display: none !important;
}
