:root {
  --bg: #f4f5f1;
  --surface: #ffffff;
  --surface-muted: #f7f8f5;
  --ink: #1c211e;
  --ink-muted: #5b625c;
  --accent: #b4732e;
  --line: #dcded7;
  --danger: #a1453d;
  --success: #4c7a52;
}

* {
  box-sizing: border-box;
}

/* The browser's own [hidden] { display: none } rule lives in the
   lowest-priority (user-agent) origin, so any author rule setting
   display on the same element — .btn's display: inline-flex, say —
   silently wins and leaves a "hidden" element visible. This reasserts
   it at author-with-!important, the only thing that reliably beats an
   arbitrary future .whatever { display: ... } rule too. */
[hidden] {
  display: none !important;
}

.impersonation-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 8px 16px;
  background: var(--accent);
  color: #fff;
  font-size: 0.85rem;
  text-align: center;
}

.impersonation-banner .btn {
  background: transparent;
  border-color: #fff;
  color: #fff;
}

.impersonation-banner .btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
}

header.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

header.topbar .brand {
  font-weight: 700;
  color: var(--ink);
  text-decoration: none;
}

header.topbar .brand:hover {
  color: var(--accent);
}

footer.site-footer {
  max-width: 960px;
  margin: 0 auto;
  padding: 8px 24px 32px;
  color: var(--ink-muted);
  font-size: 0.85rem;
}

footer.site-footer a {
  color: var(--ink-muted);
}

footer.site-footer a:hover {
  color: var(--accent);
}

nav.main-nav {
  display: flex;
  align-items: center;
  gap: 18px;
}

nav.main-nav a {
  color: var(--ink-muted);
  text-decoration: none;
  font-size: 0.92rem;
}

nav.main-nav a:hover,
nav.main-nav a.active {
  color: var(--accent);
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 24px;
}

h1 {
  font-size: 1.6rem;
  margin-bottom: 4px;
}

h2 {
  font-size: 1.15rem;
  margin-top: 32px;
}

p.subtitle {
  color: var(--ink-muted);
  margin-top: 0;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 32px;
}

.section-header h1,
.section-header h2 {
  margin-top: 0;
}

.table-wrap {
  overflow-x: auto;
}

#item-search-field {
  max-width: 22rem;
  margin-bottom: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 20px;
}

th,
td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 0.92rem;
}

th {
  color: var(--ink-muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
}

th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

th.sortable:hover {
  color: var(--accent);
}

.clickable-rows tr {
  cursor: pointer;
}

.clickable-rows tr:hover {
  background: var(--surface-muted);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-top: 20px;
}

.card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px 18px;
  color: inherit;
  text-decoration: none;
}

.card h3 {
  margin: 0 0 6px;
  font-size: 1rem;
}

.card p {
  margin: 0;
  color: var(--ink-muted);
  font-size: 0.88rem;
}

.card .card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.card select.status-select {
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 0.8rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--ink);
}

.edit-fields:not([hidden]) {
  margin-top: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.edit-fields label {
  font-size: 0.8rem;
  color: var(--ink-muted);
}

.detail-list {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 0.85rem;
}

.detail-list .detail-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 0;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  background: #eee;
}

.badge-removable {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 4px 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  background: #f1e6da;
  color: var(--ink);
  margin: 2px 4px 2px 0;
}

.badge-removable button {
  background: none;
  border: none;
  color: var(--ink-muted);
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
  padding: 0 2px;
}

.badge-removable button:hover {
  color: var(--danger);
}

.role-checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  padding: 8px 0;
}

.role-checkbox-group label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.88rem;
  font-weight: normal;
}

.filter-groups {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 4px 0 10px;
}

.filter-group {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 10px;
}

.filter-group-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-muted);
  min-width: 100px;
}

.role-add-row {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  align-items: center;
}

.role-add-row select {
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 0.8rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--ink);
}

.badge.status-planned {
  background: #e6eef5;
  color: #3e6e8e;
}

.badge.status-completed {
  background: #e8f0e9;
  color: #4c7a52;
}

.badge.status-cancelled {
  background: #f6e9e8;
  color: var(--danger);
}

form.form-panel {
  max-width: 360px;
  margin: 60px auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 28px;
}

form.form-panel label {
  display: block;
  font-size: 0.85rem;
  margin: 14px 0 4px;
}

form.form-panel input {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 0.95rem;
}

form.form-panel button {
  margin-top: 20px;
  width: 100%;
  padding: 10px;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-size: 0.95rem;
  cursor: pointer;
}

.error-message {
  background: #f6e9e8;
  color: var(--danger);
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 0.88rem;
  margin-top: 14px;
}

.success-message {
  background: #e8f0e9;
  color: var(--success);
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 0.88rem;
  margin-top: 14px;
}

button.link-button {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 0.88rem;
  padding: 4px 8px;
}

/* Generic panel: bordered box used for creation forms and grouped actions. */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 20px 22px;
  margin-top: 16px;
}

.panel h3 {
  margin: 0 0 4px;
  font-size: 1rem;
}

.panel p.hint {
  margin: 0 0 16px;
  color: var(--ink-muted);
  font-size: 0.85rem;
}

/* Field grid: label-above-input pairs, wrapping into columns on wide screens. */
.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field.span-2 {
  grid-column: span 2;
}

.field label {
  font-size: 0.85rem;
}

.field .optional {
  color: var(--ink-muted);
  font-weight: 400;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--ink);
}

.field textarea {
  resize: vertical;
  min-height: 64px;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
}

/* Buttons: one shared base, three intents, one size variant. */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid transparent;
  font-size: 0.88rem;
  font-family: inherit;
  cursor: pointer;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
}

.btn-danger {
  background: var(--surface);
  border-color: var(--line);
  color: var(--danger);
}

.btn-small {
  padding: 5px 10px;
  font-size: 0.8rem;
}

.btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.table-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.breadcrumbs {
  margin: 16px 0;
  color: var(--ink-muted);
  font-size: 0.9rem;
}

.breadcrumbs a {
  color: inherit;
}

.document-text {
  white-space: pre-wrap;
  font-family: inherit;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 16px;
  margin-top: 16px;
}

.document-embed {
  width: 100%;
  height: 80vh;
  border: 1px solid var(--line);
  border-radius: 6px;
  margin-top: 16px;
}

.document-frame {
  width: 100%;
  height: 80vh;
  border: 1px solid var(--line);
  border-radius: 6px;
  margin-top: 16px;
  background: #fff;
}

.document-image {
  max-width: 100%;
  margin-top: 16px;
  border-radius: 6px;
}

/* Activities calendar view */

.calendar-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin: 10px 0 4px;
  font-size: 0.8rem;
  color: var(--ink-muted);
}

.calendar-legend-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  margin-right: 5px;
  vertical-align: -1px;
}

.calendar-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 0 4px;
}

.calendar-year-label {
  font-weight: 600;
  min-width: 3.5em;
  text-align: center;
}

.calendar-legend-non-working {
  background: #f3dcda;
  border: 1px solid var(--danger);
}

.calendar-legend-activity {
  background: var(--accent);
}

.calendar-legend-today {
  background: var(--surface);
  border: 2px solid var(--accent);
}

.calendar-view {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 18px;
  margin-top: 12px;
}

.calendar-month {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: var(--surface);
}

.calendar-month h3 {
  margin: 0 0 8px;
  font-size: 0.9rem;
  text-transform: capitalize;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.calendar-weekday {
  font-size: 0.68rem;
  color: var(--ink-muted);
  text-align: center;
  padding-bottom: 3px;
}

.calendar-day {
  min-height: 40px;
  border-radius: 4px;
  padding: 2px 2px;
  background: var(--surface-muted);
  overflow: hidden;
}

.calendar-day.calendar-day-empty {
  background: transparent;
}

.calendar-day-number {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--ink);
}

.calendar-day.calendar-day-non-working {
  background: #f3dcda;
}

.calendar-day.calendar-day-today {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.calendar-day-activity {
  display: block;
  background: var(--accent);
  color: #fff;
  border-radius: 3px;
  padding: 0 3px;
  margin-top: 1px;
  font-size: 0.6rem;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-decoration: none;
}

.calendar-day-activity:hover {
  filter: brightness(1.1);
}

.calendar-day-more {
  display: block;
  font-size: 0.6rem;
  color: var(--ink-muted);
  padding: 0 3px;
}
