:root {
  --bg: #f5f5f2;
  --surface: #ffffff;
  --surface-sunken: #efeee9;
  --border: #e2e0d8;
  --text: #1c1b18;
  --text-muted: #6b6a63;
  --accent: #0d6e63;
  --accent-hover: #0a564e;
  --accent-soft: #e3f1ee;
  --amber: #b5680a;
  --amber-soft: #fbedd8;
  --red: #b3261e;
  --red-soft: #f8e2e0;
  --green: #1a7a3c;
  --green-soft: #e2f2e6;
  --violet: #5b4b9e;
  --violet-soft: #ece8f7;
  --gray: #8a887f;
  --gray-soft: #eceae3;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(28, 27, 24, 0.06), 0 1px 12px rgba(28, 27, 24, 0.04);
  --font-display: "Space Grotesk", "Inter", system-ui, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

button, input, select {
  font-family: inherit;
  font-size: 15px;
}

h1, h2, h3 { font-family: var(--font-display); margin: 0; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ---------- Top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 12px;
  padding: 14px 16px 10px;
  max-width: 1180px;
  margin: 0 auto;
}

.brand { display: flex; align-items: center; gap: 10px; }

.brand-mark {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--accent);
  background-image: linear-gradient(155deg, var(--accent) 0%, var(--accent-hover) 100%);
  flex-shrink: 0;
}

.brand-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
  letter-spacing: -0.01em;
}

.acting-as {
  display: flex;
  align-items: center;
  gap: 8px;
}

.acting-as-label {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}

#creatorSelect {
  height: 40px;
  padding: 0 32px 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-sunken);
  color: var(--text);
  font-weight: 500;
  min-width: 160px;
}

.tabnav {
  display: flex;
  gap: 4px;
  padding: 0 16px;
  max-width: 1180px;
  margin: 0 auto;
  overflow-x: auto;
}

.tab {
  appearance: none;
  border: none;
  background: none;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 14px;
  padding: 10px 14px;
  min-height: 44px;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}

.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab:hover { color: var(--text); }

/* ---------- Layout ---------- */

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 16px 64px;
}

.view[hidden] { display: none; }

.board-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  align-items: start;
}

@media (min-width: 640px) {
  .board-grid { grid-template-columns: 1fr 1fr; }
}

@media (min-width: 1100px) {
  .board-grid { grid-template-columns: repeat(4, 1fr); }
}

.approvals-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  align-items: start;
}

@media (min-width: 800px) {
  .approvals-grid { grid-template-columns: 1fr 1fr; }
}

.panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.panel-head h2 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.panel-head-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.count-badge {
  background: var(--surface-sunken);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  min-width: 22px;
  text-align: center;
}

.card-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

/* ---------- Op card ---------- */

.op-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.op-card:hover, .approval-card:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.op-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.op-client {
  font-weight: 600;
  font-size: 14.5px;
  line-height: 1.3;
}

.op-task {
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.3;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 4px;
}
.status-dot.gray { background: var(--gray); }
.status-dot.green { background: var(--green); }
.status-dot.amber { background: var(--amber); }
.status-dot.red { background: var(--red); }
.status-dot.violet { background: var(--violet); }

.op-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 12.5px;
  color: var(--text-muted);
}

.op-meta-item strong { color: var(--text); font-weight: 600; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  width: fit-content;
}
.badge.gray { background: var(--gray-soft); color: #55534b; }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.violet { background: var(--violet-soft); color: var(--violet); }

.op-actions {
  display: flex;
  gap: 8px;
  margin-top: 2px;
  flex-wrap: wrap;
}

/* ---------- Buttons ---------- */

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 13.5px;
  min-height: 40px;
  padding: 0 14px;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { background: var(--gray); cursor: not-allowed; }

.btn-secondary { background: var(--surface-sunken); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--gray-soft); }

.btn-ghost { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-ghost:hover { color: var(--text); background: var(--surface-sunken); }

.btn-danger { background: var(--red-soft); color: var(--red); }
.btn-danger:hover { background: #f3cfcc; }

.btn-sm { min-height: 36px; padding: 0 12px; font-size: 13px; }

/* ---------- Tables ---------- */

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

.log-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  min-width: 560px;
}

.log-table th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  font-weight: 600;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.log-table td {
  padding: 10px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  white-space: nowrap;
}

.log-table tbody tr:last-child td { border-bottom: none; }
.log-table tbody tr:hover { background: var(--surface-sunken); }

/* ---------- Filters ---------- */

.filters-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.filter-select, .date-filter input {
  height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-sunken);
  color: var(--text);
  padding: 0 10px;
}

.date-filter {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-muted);
}

.empty-note {
  color: var(--text-muted);
  font-size: 13.5px;
  padding: 10px 2px;
  grid-column: 1 / -1;
}

/* ---------- Approval card ---------- */

.approval-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  cursor: pointer;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.approval-note {
  background: var(--surface-sunken);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translate(-50%, 12px);
  background: var(--text);
  color: #fff;
  font-size: 13.5px;
  font-weight: 500;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  z-index: 50;
  max-width: 90vw;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.error { background: var(--red); }

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(28, 27, 24, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 60;
  padding: 16px;
}

@media (min-width: 560px) {
  .modal-overlay { align-items: center; }
}

.modal-overlay[hidden] { display: none; }

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal h3 { font-size: 16px; }

.modal-desc { font-size: 13.5px; color: var(--text-muted); margin: 0; }

.modal textarea {
  font-family: inherit;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  resize: vertical;
  background: var(--surface-sunken);
  color: var(--text);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

/* ---------- Job detail / create job modal ---------- */

.modal-lg {
  max-width: 540px;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--surface-sunken);
  color: var(--text-muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.modal-close:hover { background: var(--gray-soft); color: var(--text); }

.detail-header { padding-right: 32px; margin-bottom: 4px; }

.detail-client { font-size: 18px; font-weight: 600; font-family: var(--font-display); }
.detail-task { color: var(--text-muted); font-size: 14px; margin-top: 2px; }

.detail-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px 0 4px;
}

.detail-section { margin-top: 18px; }

.detail-section-label {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 6px;
}

.detail-text { font-size: 14px; line-height: 1.5; }
.detail-text.muted { color: var(--text-muted); font-style: italic; }

.steps-list {
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  line-height: 1.4;
}

.step-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.step-row input[type="text"] {
  flex: 1;
  height: 38px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-sunken);
  color: var(--text);
  padding: 0 10px;
  font-size: 14px;
}

.step-remove {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}
.step-remove:hover { background: var(--red-soft); color: var(--red); border-color: var(--red-soft); }

.detail-form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 14px;
}

.detail-form-field label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
}

.detail-form-field input[type="text"],
.detail-form-field select,
.detail-form-field textarea {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  color: var(--text);
  padding: 9px 10px;
  font-size: 14px;
  font-family: inherit;
}

.detail-form-field textarea { resize: vertical; }

.weekday-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.weekday-toggle {
  border: 1px solid var(--border);
  background: var(--surface-sunken);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  min-width: 44px;
  min-height: 40px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.weekday-toggle.selected {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

.detail-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.detail-note {
  background: var(--surface-sunken);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 10px;
}

/* ---------- Weekly schedule timeline ---------- */

.week-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.week-column {
  width: 100%;
  border: 2px solid var(--gray);
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.week-column.is-today {
  background: var(--accent-soft);
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.week-column.is-overdue {
  background: var(--red-soft);
  border-color: var(--red);
  box-shadow: 0 0 0 1px var(--red);
}

.week-col-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
}

.week-col-day {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.01em;
}

.week-column.is-overdue .week-col-day { color: var(--red); }

.week-col-date {
  font-size: 11.5px;
  color: var(--text-muted);
}

.week-col-count {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface);
  border-radius: 999px;
  padding: 1px 7px;
  flex-shrink: 0;
}

.week-today-pill {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
}

.week-items {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 8px;
}

.week-empty {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
  padding: 4px 0;
}

.week-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 9px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 5px;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.week-item.is-rejected {
  background: var(--red-soft);
  border: 2px solid var(--red);
}

.week-item:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.week-item-top {
  display: flex;
  align-items: flex-start;
  gap: 6px;
}

.week-item-client {
  font-weight: 600;
  font-size: 12.5px;
  line-height: 1.25;
}

.week-item-task {
  color: var(--text-muted);
  font-size: 11.5px;
  line-height: 1.25;
}

.week-item .btn {
  min-height: 44px;
  font-size: 12.5px;
  padding: 0 10px;
  width: 100%;
}
