:root {
  --bg: #f8f9fa;
  --surface: #ffffff;
  --border: #dadce0;
  --text: #202124;
  --text-muted: #5f6368;
  --primary: #1a73e8;
  --primary-dark: #1765cc;
  --danger: #d93025;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(60, 64, 67, .3), 0 4px 8px 3px rgba(60, 64, 67, .15);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ---------- Header ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-header h1 {
  font-size: 20px;
  font-weight: 600;
  margin: 0;
  margin-right: 8px;
}

.app-header h2 {
  font-size: 18px;
  font-weight: 400;
  margin: 0;
  color: var(--text);
  min-width: 180px;
}

.nav-arrows { display: flex; gap: 2px; }

/* ---------- Buttons ---------- */
.btn {
  font-size: 14px;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  background: none;
  font-family: inherit;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { border-color: var(--border); color: var(--text); background: var(--surface); }
.btn-outline:hover { background: #f1f3f4; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b3261e; }
.btn-icon {
  font-size: 20px;
  line-height: 1;
  padding: 4px 12px;
  border-radius: 50%;
  color: var(--text-muted);
}
.btn-icon:hover { background: #f1f3f4; }

.view-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.toggle-btn {
  border: none;
  background: var(--surface);
  padding: 8px 16px;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
}

.toggle-btn.active { background: #e8f0fe; color: var(--primary); font-weight: 600; }

.settings-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
}

/* ---------- Settings tabs ---------- */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.tab-btn {
  border: none;
  background: none;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  font-family: inherit;
}

.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

.tab-panel label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.tab-panel .checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text);
}

.tab-panel .checkbox input { margin: 0; }

/* ---------- Toolbar (filter + legend) ---------- */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 8px 20px;
}

.person-filter { display: flex; flex-wrap: wrap; gap: 6px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 3px 12px 3px 4px;
  background: var(--surface);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
}

.pill.all { padding: 3px 12px; }
.pill.dotted { padding: 3px 12px 3px 8px; }
.pill:hover { background: #f1f3f4; }
.pill.active { background: #e8f0fe; border-color: var(--primary); color: var(--primary); font-weight: 600; }

/* ---------- Avatars ---------- */
.avatar {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 600;
  flex-shrink: 0;
  line-height: 1;
}

.chip-avatar {
  width: 14px;
  height: 14px;
  font-size: 8px;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .75);
}

/* ---------- Client legend (also a filter) ---------- */
.client-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 13px;
}
.legend-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* ---------- Calendar ---------- */
.calendar { padding: 0 20px 20px; }

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border-left: 1px solid var(--border);
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.cal-dow {
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  padding: 8px 4px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: #f8f9fa;
}

.cal-day {
  min-height: 110px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 4px;
  cursor: pointer;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cal-day:hover { background: #f8fbff; }
.cal-day.other-month { background: #f8f9fa; }
.cal-day.other-month .day-num { color: #bdc1c6; }

.week-view .cal-day { min-height: 420px; }

.day-num {
  font-size: 12px;
  color: var(--text-muted);
  width: 24px;
  height: 24px;
  line-height: 24px;
  text-align: center;
  border-radius: 50%;
  flex-shrink: 0;
}

.cal-day.today .day-num { background: var(--primary); color: #fff; font-weight: 600; }

.task-chip {
  font-size: 12px;
  color: #fff;
  border-radius: 4px;
  padding: 2px 6px;
  cursor: pointer;
  flex-shrink: 0;
  overflow: hidden;
}

.chip-head {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
}

.chip-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.week-view .chip-head { flex-wrap: wrap; }

.week-view .chip-label {
  white-space: normal;
  text-overflow: clip;
  overflow-wrap: break-word;
}

.task-chip:hover { filter: brightness(.92); }

.week-view .task-chip { padding: 6px 8px; }

.task-chip .chip-meta {
  display: block;
  font-size: 11px;
  opacity: .85;
  margin-top: 2px;
}

.more-link { font-size: 11px; color: var(--text-muted); padding-left: 4px; }

/* ---------- Modals ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(32, 33, 36, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 420px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 64px);
  overflow-y: auto;
  padding: 20px 24px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.modal-header h3 { margin: 0; font-size: 18px; font-weight: 600; }

.modal-close {
  border: none;
  background: none;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: 50%;
}
.modal-close:hover { background: #f1f3f4; }

.modal form label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.modal input[type="text"],
.modal input[type="date"],
.modal select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
}

.modal input:focus, .modal select:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
  border-color: var(--primary);
}

.dep-fieldset {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px 12px 12px;
  margin: 0 0 12px;
}

.dep-fieldset legend { font-size: 13px; color: var(--text-muted); padding: 0 4px; }
.optional { font-style: italic; }

.dep-mode { display: flex; gap: 16px; margin-bottom: 8px; }

.radio {
  display: inline-flex !important;
  align-items: center;
  gap: 4px;
  margin: 0 !important;
  font-size: 13px;
}

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

.inline-form { display: flex; gap: 8px; margin-bottom: 4px; }
.inline-form input { flex: 1; margin-top: 0 !important; }

.hint { font-size: 12px; color: var(--text-muted); margin: 4px 0 12px; }

.manage-list { list-style: none; margin: 8px 0 0; padding: 0; }

.manage-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  border-bottom: 1px solid #f1f3f4;
  font-size: 14px;
}

.manage-list .spacer { flex: 1; }

.remove-btn {
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 2px 8px;
  border-radius: 50%;
}
.remove-btn:hover { background: #fce8e6; color: var(--danger); }

/* ---------- Details ---------- */
.details-list { margin: 0; font-size: 14px; }
.details-list dt { color: var(--text-muted); font-size: 12px; margin-top: 10px; }
.details-list dd { margin: 2px 0 0; }

.details-client { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #323232;
  color: #fff;
  padding: 10px 20px;
  border-radius: 4px;
  font-size: 14px;
  box-shadow: var(--shadow);
  z-index: 200;
}

.hidden { display: none !important; }
