/* app.css — custom styles on top of Pico CSS v2 */

/* --- Pico custom property overrides --- */
/* Slightly denser layout for admin tool with ~5 users */
/* Remove default underline on links — hover shows underline instead */
:root {
  --pico-typography-spacing-vertical: 1.25rem;
  --pico-spacing: 0.75rem;
}

/* Links: no underline by default, underline on hover */
a:not([role=button]) {
  text-decoration: none;
}

a:not([role=button]):hover {
  text-decoration: underline;
}

/* --- Visually hidden (for accessible labels on icon-only or search inputs) --- */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* --- Flash messages --- */
.flash-success {
  border-left: 4px solid #20c997;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  background: #d1e7dd;
  color: #0f5132;
  border-radius: 0.25rem;
}

.flash-error {
  border-left: 4px solid #e14646;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  background: #f8d7da;
  color: #842029;
  border-radius: 0.25rem;
}

/* --- Top nav --- */
.top-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--pico-background-color);
  border-bottom: 1px solid var(--pico-muted-border-color, #e9ecef);
  backdrop-filter: blur(0.5rem);
  -webkit-backdrop-filter: blur(0.5rem);
}

.top-nav > .container {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
  gap: 0.5rem;
}

.top-nav ul {
  margin-bottom: 0;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* --- Table rows with data-href --- */
table tbody tr[data-href] {
  cursor: pointer;
}

table tbody tr[data-href]:hover {
  background: var(--pico-secondary-background, #f8f9fa);
}

table tbody tr[data-href]:hover td {
  background: transparent;
}

/* --- Dialog forms --- */
dialog article {
  max-width: 32rem;
}

/* --- Session selection checkboxes --- */
.session-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0;
}

.session-option input[type="checkbox"] {
  margin-bottom: 0;
}

/* --- Utility classes --- */
.inline-form {
  display: inline;
}

.btn-sm {
  display: inline;
  padding: 0.2rem 0.5rem;
}

.text-danger {
  color: #e14646;
  font-weight: bold;
}

/* --- Dashboard summary cards --- */
.dashboard-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
}

.dashboard-cards article {
  text-align: center;
  display: flex;
  flex-direction: column;
}

.dashboard-cards article header {
  font-size: 2.25rem;
  font-weight: 700;
  line-height: 1.2;
  padding: 1.25rem 1rem 0.5rem;
}

.dashboard-cards article > small {
  display: block;
  padding: 0 1rem 1rem;
  color: var(--pico-muted-color);
  font-size: 0.9rem;
  flex: 1;
}

.dashboard-cards article footer {
  font-size: 0.85rem;
}

.dashboard-cards article footer:empty::before {
  content: "\00a0";
}

/* --- Flex utility --- */
.flex-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* --- Pagination nav --- */
nav[aria-label="Seiten"] {
  display: flex;
  justify-content: space-between;
  margin-top: 1rem;
}

/* --- Status badges --- */
/* Small inline badge with text label + subtle color. Never color alone. */
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 1rem;
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
}

.badge-success {
  background: #d1e7dd;
  color: #0f5132;
}

.badge-warning {
  background: #fff3cd;
  color: #664d03;
}

.badge-danger {
  background: #f8d7da;
  color: #842029;
}

.badge-info {
  background: #cfe2ff;
  color: #084298;
}

.badge-muted {
  background: #e9ecef;
  color: #495057;
}

/* --- Responsive table wrapper --- */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* --- Numeric columns: right-align, tabular figures --- */
td.num,
th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* --- Badge and compact action cells: prevent wrapping --- */
td.badge-cell,
td.action-cell {
  white-space: nowrap;
}

/* --- Destructive button --- */
/* Use alongside .secondary.outline for visually distinct destructive actions. */
.btn-danger {
  border-color: #e14646;
  color: #e14646;
}

.btn-danger:hover {
  background: #e14646;
  color: #fff;
}

.btn-danger:focus-visible {
  outline: 2px solid #e14646;
  outline-offset: 2px;
}

/* --- Detail page key-value pairs --- */
/* Using <dl> for structured key-value display on detail pages */
dl.key-values {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.3rem 1rem;
  margin: 0;
}

dl.key-values dt {
  font-weight: 600;
  color: var(--pico-muted-color, #6c757d);
}

dl.key-values dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: break-word;
}

@media (max-width: 576px) {
  dl.key-values {
    grid-template-columns: 1fr;
    gap: 0.1rem;
  }
  dl.key-values dt {
    margin-top: 0.5rem;
  }
  dl.key-values dt:first-child {
    margin-top: 0;
  }
}

/* --- Login page --- */
.login-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 70vh;
}

.login-wrapper article {
  max-width: 24rem;
  width: 100%;
}

.login-wrapper hgroup {
  text-align: center;
  margin-bottom: 1.5rem;
}

/* --- Empty state --- */
.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--pico-muted-color);
}

.empty-state p {
  margin-bottom: 0;
}

/* --- Action group --- */
.action-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.action-group form {
  margin-bottom: 0;
}

.action-group button {
  margin-bottom: 0;
}

/* --- Form fieldset sections --- */
fieldset.form-section {
  border: var(--pico-border-width) solid var(--pico-muted-border-color);
  border-radius: var(--pico-border-radius);
  padding: var(--pico-spacing);
  padding-top: 0;
  margin-bottom: var(--pico-typography-spacing-vertical);
}

fieldset.form-section legend {
  padding: 0 0.5rem;
  font-weight: 600;
}

/* --- Filter bar (compact inline filters) --- */
.filter-bar {
  margin-bottom: var(--pico-typography-spacing-vertical);
}

.filter-bar .grid {
  margin-bottom: 0;
}

.filter-bar label {
  margin-bottom: 0;
}

.filter-bar select {
  margin-bottom: 0;
}

/* --- Inline-editable table cells --- */
/* Inputs inside table cells are compact and borderless, blending into the row.
   The form's submit button (✓) provides the save action. */
.cell-input,
table .cell-input {
  width: 100%;
  margin-bottom: 0;
  padding: calc(var(--pico-form-element-spacing-vertical) * 0.35) calc(var(--pico-form-element-spacing-horizontal) * 0.5);
  font-size: 0.95rem;
  border: 1px solid transparent;
  border-radius: calc(var(--pico-border-radius) * 0.5);
  background: transparent;
  color: var(--pico-color);
  transition: border-color var(--pico-transition), background var(--pico-transition);
}

table .cell-input:hover {
  border-color: var(--pico-muted-border-color);
}

table .cell-input:focus {
  border-color: var(--pico-primary-border);
  background: var(--pico-form-element-active-background-color);
  box-shadow: none;
}

.cell-num {
  text-align: right;
  max-width: 6rem;
}

/* --- Section rhythm --- */
main > section + section {
  margin-top: calc(var(--pico-typography-spacing-vertical) * 1.5);
}

/* --- Card sections on detail pages --- */
.detail-card {
  margin-bottom: var(--pico-typography-spacing-vertical);
}

.detail-card > h2 {
  margin-bottom: 0.75rem;
}

/* --- Edit accordion list --- */
.edit-accordion {
  margin-top: 1rem;
}

.edit-accordion > details {
  margin-bottom: 0.5rem;
}

.edit-accordion > details > summary {
  font-weight: 600;
}

/* ===== Dark mode overrides ===== */
/* Pico v2 doesn't define named color variables (green-100, red-100, etc.)
   so our badge/flash CSS uses hardcoded hex values that are light-mode only.
   These overrides ensure readable contrast in dark mode via prefers-color-scheme
   and data-theme="dark". */

@media only screen and (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    /* Flash messages */
    .flash-success {
      background: #0f3526;
      color: #9be8c6;
      border-left-color: #20c997;
    }
    .flash-error {
      background: #3d1418;
      color: #f4a8ae;
      border-left-color: #e14646;
    }

    /* Badges */
    .badge-success {
      background: #0f3526;
      color: #9be8c6;
    }
    .badge-warning {
      background: #3d2f00;
      color: #ffdf8a;
    }
    .badge-danger {
      background: #3d1418;
      color: #f4a8ae;
    }
    .badge-info {
      background: #0a2440;
      color: #a3c8ff;
    }
    .badge-muted {
      background: #2a2f38;
      color: #b3b9c5;
    }

    /* Destructive button */
    .btn-danger {
      border-color: #e14646;
      color: #f4a8ae;
    }
    .btn-danger:hover {
      background: #e14646;
      color: #fff;
    }

    /* Table hover */
    table tbody tr[data-href]:hover {
      background: #202632;
    }
    table tbody tr[data-href]:hover td {
      background: transparent;
    }
  }
}

[data-theme="dark"] {
  /* Flash messages */
  .flash-success {
    background: #0f3526;
    color: #9be8c6;
    border-left-color: #20c997;
  }
  .flash-error {
    background: #3d1418;
    color: #f4a8ae;
    border-left-color: #e14646;
  }

  /* Badges */
  .badge-success {
    background: #0f3526;
    color: #9be8c6;
  }
  .badge-warning {
    background: #3d2f00;
    color: #ffdf8a;
  }
  .badge-danger {
    background: #3d1418;
    color: #f4a8ae;
  }
  .badge-info {
    background: #0a2440;
    color: #a3c8ff;
  }
  .badge-muted {
    background: #2a2f38;
    color: #b3b9c5;
  }

  /* Destructive button */
  .btn-danger {
    border-color: #e14646;
    color: #f4a8ae;
  }
  .btn-danger:hover {
    background: #e14646;
    color: #fff;
  }

  /* Table hover */
  table tbody tr[data-href]:hover {
    background: #202632;
  }
  table tbody tr[data-href]:hover td {
    background: transparent;
  }
}
